> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ancha.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These docs describe the Ancha CLI, npm package @ancha-labs/cli version 0.1.4, and the hosted workspace at app.ancha.io. Coding agents should start at https://docs.ancha.io/coding-agents. Run the CLI as `ancha` after `npm install -g @ancha-labs/cli`, or as `npx -y @ancha-labs/cli@0.1.4` without installing. Pass --json for machine-readable output, or set ANCHA_JSON=1. Every command ends with a `next:` line naming the next command. Exit codes: 0 pass, 1 a check failed or a comparison regressed, 2 usage, config or authentication error, 3 infrastructure error, 4 unimplemented endpoint with --strict.

# Microsoft Word

> A stateful replica of Microsoft Graph drive items for Word documents in one OneDrive: folders, .docx files built from paragraphs, versions, sharing links and invitations.

The Microsoft Word replica implements 21 endpoints of Microsoft Graph v1.0 for one OneDrive. Word files are real `.docx` packages built from paragraphs, with PDF conversion on download. Its key is `microsoft-word`. It was tested with `@microsoft/microsoft-graph-client`.

## Connect

| Variable | Value |
| - | - |
| `MICROSOFT_GRAPH_API_URL` | Base URL, standing in for `https://graph.microsoft.com`. Paths start with `/v1.0/`. |
| `MICROSOFT_GRAPH_ACCESS_TOKEN` | Fake access token for the signed-in user. Send `Authorization: Bearer <token>`. |

```js Node theme={null}
import { Client } from '@microsoft/microsoft-graph-client';
const token = process.env.MICROSOFT_GRAPH_ACCESS_TOKEN!;
const graph = Client.init({ baseUrl: process.env.MICROSOFT_GRAPH_API_URL + '/', defaultVersion: 'v1.0', authProvider: (done) => done(null, token), fetchOptions: { headers: { authorization: 'Bearer ' + token } } });
const files = await graph.api('/me/drive/root/children').get();
// Next page: graph.api(files['@odata.nextLink'].slice(files['@odata.nextLink'].indexOf('/v1.0') + 5)).get()
```

This is what `ancha connect microsoft-word --lang ts` prints. The Graph client signs only Microsoft's HTTPS hosts and drops a capitalized `Authorization` header elsewhere, so the token also goes in `fetchOptions` as a lower-case header. Its `api()` takes paths, so follow an `@odata.nextLink` with the part after `/v1.0`.

## Endpoints

All 21 endpoints are partial. Anything else returns HTTP 501 with Graph's error shape and `x-ancha-gap: 1`.

| Method | Path | Notes |
| - | - | - |
| `GET` | `/v1.0/me` | The signed-in user. |
| `GET` | `/v1.0/me/drive` | Quota and owner. |
| `GET` | `/v1.0/me/drive/recent` | |
| `GET` | `/v1.0/me/drive/items/{item-id}` | Also by path, `/me/drive/root:/{path}:`, and under `/drives/{drive-id}/`. `$select` and `$expand=children`. |
| `GET` | `/v1.0/me/drive/items/{item-id}/children` | `$top`, `$skiptoken` and `$orderby` (`name`, `lastModifiedDateTime`, `size`). |
| `POST` | `/v1.0/me/drive/items/{item-id}/children` | Folders, with `@microsoft.graph.conflictBehavior`. |
| `PATCH` | `/v1.0/me/drive/items/{item-id}` | Rename, move (`parentReference`) and description. `If-Match`. |
| `DELETE` | `/v1.0/me/drive/items/{item-id}` | `If-Match`. No recycle bin. |
| `GET` | `/v1.0/me/drive/items/{item-id}/content` | 302 to a pre-authenticated URL. `format=pdf` converts Word documents. |
| `PUT` | `/v1.0/me/drive/items/{parent-id}:/{filename}:/content` | Simple upload up to 250 MB, also by path (folders are created). A new version on replace. Upload sessions are a gap. |
| `POST` | `/v1.0/me/drive/items/{item-id}/copy` | 202 with a monitor URL that reports completion at once. |
| `GET` | `/v1.0/me/drive/root/search(q='{text}')` | Names and the text of Word and text files. |
| `POST` | `/v1.0/me/drive/items/{item-id}/createLink` | View and edit links, anonymous or organization scope. An existing matching link is returned. |
| `POST` | `/v1.0/me/drive/items/{item-id}/invite` | Recorded, never emailed. |
| `GET` | `/v1.0/me/drive/items/{item-id}/permissions` | Owner, own and inherited permissions. |
| `DELETE` | `/v1.0/me/drive/items/{item-id}/permissions/{perm-id}` | |
| `GET` | `/v1.0/me/drive/items/{item-id}/versions` | |
| `GET` | `/v1.0/me/drive/items/{item-id}/versions/{version-id}/content` | 302 to a pre-authenticated URL. |
| `POST` | `/v1.0/me/drive/items/{item-id}/versions/{version-id}/restoreVersion` | |
| `GET` | `/download/{token}`, `/monitor/{token}` | The pre-authenticated download URL and the copy monitor URL. |

## Starter data

The `microsoft-word-starter` dataset is the OneDrive of `ancha@acme.example` in the tenant **Acme**. The users are the automation account, Anna Fischer, Tom Hughes, Mike Turner and the external "Pinecrest Health Legal".

| Folder | Documents |
| - | - |
| `/Contracts` | "Bluefield Logistics - Mutual NDA" (a draft that has not been sent for signature), "Pinecrest Health - MSA (signed)", "Pinecrest Health - Order form - 20 additional seats" (out for review, shared with Pinecrest Health Legal, with an earlier version), "Kestrel Credit Union - Renewal order form 2027" (awaiting countersignature) and "Ridgeway Robotics - Pilot agreement" (signed). |
| `/Policies` | "Information security policy" (with an organization-wide view link) and "Data processing addendum v2". |
| `/Templates` | "Mutual NDA template" and "Order form template". |

Every document is a `.docx` whose paragraphs `ancha sandbox configuration --tools microsoft-word --json` prints.

## Checks

Microsoft Word has no state checks. Use trace checks, for example `{ called: "POST /v1.0/me/drive/items/*/invite" }` or `{ not_called: "DELETE /v1.0/me/drive/items/*" }`.

## Limits

* One OneDrive. Word files are real `.docx` packages built from paragraphs, with PDF conversion. No Word document object model, comments or co-authoring.
* The Graph client signs only HTTPS Graph hosts: set `baseUrl` to `MICROSOFT_GRAPH_API_URL` plus `/` and pass the token as a lower-case `authorization` header in `fetchOptions.headers`. Follow `@odata.nextLink` with the part after `/v1.0`.
* Invitations and sharing are recorded, never emailed; no upload sessions, delta queries or shared-with-me.


## Related topics

- [Tools](https://docs.ancha.io/tools/overview.md)
- [Test file (scene.yaml)](https://docs.ancha.io/reference/test-file.md)
- [Introduction](https://docs.ancha.io/index.md)
- [ancha connect](https://docs.ancha.io/cli/connect.md)
- [Environment variables](https://docs.ancha.io/reference/environment-variables.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.