Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,11 @@
{
"key": "document-studio",
"name": "Document studio",
"version": "0.1.0",
"version": "0.2.0",
"subpath": "document-studio",
"manifest": "document-studio/module.yaml",
"manifest_sha256": "89c05d34793969a8fccb1b767f9b6aa87bda29d6fb9edaf4f80e1f827e2a0299",
"tree_sha256": "5cc05c17fa5dea65b2b71bd76521530f4aa046fcb50a915c6b3aff3eb4bcb268",
"manifest_sha256": "2e09f02654084161cdea77ebbdeb479e7da92034c5939b63cfb73402747cdecb",
"tree_sha256": "b1d2ddedab8e740cf8313da9a5fa6094b7b8da875035a5c9e98626c8454091d2",
"description": {
"en": "Document studio: draft business documents from a brief, render them to PDF from templates and the company profile, review, approve and issue them with a number, and keep every revision in Storage.",
"fr": "Studio de documents : rédiger des documents professionnels depuis un brief, les rendre en PDF avec des gabarits et la fiche entreprise, les relire, les approuver et les émettre avec un numéro, en gardant chaque révision dans Storage."
Expand Down Expand Up @@ -692,6 +692,14 @@
{
"key": "document-studio-profile-save",
"name": "Save the company profile"
},
{
"key": "document-studio-new-version",
"name": "Add a DOCX version"
},
{
"key": "document-studio-mark-authoritative",
"name": "Mark a version authoritative"
}
],
"queries": [
Expand All @@ -712,7 +720,7 @@
"model": "free"
},
"maturity": "preview",
"workflows": 11,
"workflows": 13,
"miniapps": 1
},
{
Expand Down
22 changes: 21 additions & 1 deletion document-studio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ messages) is French; `fr` is the only locale in V0.
| `document-studio-publish` | requires `approved` and `confirmation_manuelle`. Reserves the next number, renders in `final` mode, stores the issued PDF, moves to `issued` |
| `document-studio-cancel` | moves to `cancelled` with a reason. An issued number is never reused |
| `document-studio-export` | refuses a cancelled document (`document_cancelled`); otherwise copies the issued PDF (or the latest render, flagged as a draft) to a Storage path outside `/document-studio/`, with its SHA-256. Mail and SFTP are out of V0 |
| `document-studio-new-version` | adds a DOCX version of an existing document from a Storage file (`source_path`, `author`): fingerprints it, compares it with the previous version through the MCP tool `office_compare_v1`, stores the redline (tracked changes) and appends the version to the versions manifest. Refuses a stale `base_version` or `base_manifest_sha256` (`base_version_conflict`) and a cancelled document. Same request again: nothing is written (`replayed`) |
| `document-studio-mark-authoritative` | makes one version the authoritative one (`confirmation_manuelle` required, refused before any read otherwise); the previously authoritative version becomes `superseded`. No version file is modified |
| `document-studio-profile-save` | validates and stores the company profile and brand (`/document-studio/profile.json`), with manual confirmation |
| `document-studio-list` | lists the documents (identifier, title, status, number, revision, latest hash) |
| `document-studio-review-read` | full record of a document and previews of its latest render, for the MiniApp |
Expand Down Expand Up @@ -51,6 +53,8 @@ The Module never approves on a person's behalf.
- `/document-studio/docs/<doc_id>/r<revision>-<sha12>/`: PDF and previews of one render attempt (12 first characters of the PDF SHA-256, so a losing attempt never overwrites another attempt's file).
- `/document-studio/docs/<doc_id>/issued/<number>-<sha12>.pdf`: the issued PDF.
- `/document-studio/numbers/<template>/<year>/<4-digit seq>.json`: number token.
- `/document-studio/docs/<doc_id>/versions/manifest.json`: the versions manifest (`document-studio.versions/v1`): `versions` is the list of `{version, sha256, bytes, storage_ref, redline_ref, redline_sha256, changes: {insertions, deletions, changed_paragraphs}, author, created_at, status: draft|authoritative|superseded, supersedes, base_version, request_sha256}` (plus `superseded_by`, `authoritative_at`, `approved_by` when set), and `history` is its journal. At most one version is authoritative.
- `/document-studio/docs/<doc_id>/versions/v<N>-<sha12>.docx` and `v<N>-redline-<sha12>.docx`: one immutable file per version and its redline against version N-1 (the first version has none). The file name carries the content, so a retry rewrites the same bytes.

`doc_id`: `^[a-z0-9][a-z0-9-]{0,47}$`, chosen by the caller or derived from the
title with a short suffix. Number: `<PREFIX>-<year>-<seq>` (`DEV` for the
Expand All @@ -59,6 +63,18 @@ quote, `CR` for the minutes).
Without a company profile, `render` and `publish` fail with `profile_missing`:
store the brand with `document-studio-profile-save`.

## DOCX versions

Versions live in Storage, next to the record, which they never write: an issued or signed document keeps its record and
its PDF, and a new version is only added. `new-version` accepts a DOCX (ZIP package, 20 MiB at most) and numbers it N+1. A DOCX is checked twice before anything is written: a fast structural filter (readable ZIP holding `[Content_Types].xml` and `word/document.xml`), then the document engine. The first version goes through `office_inspect_v1` (it has nothing to compare with), the next ones through `office_compare_v1`; `mark-authoritative` inspects the version again before it makes it authoritative. An engine error or an unreadable document is `docx_invalid`.
`mark-authoritative` is the only action that changes a status, with the manual confirmation, and never on a person's behalf
(`approved_by` is recorded as stated, not attested). A superseded version is never restored: add a new version instead, and an
older draft cannot take over from a newer authoritative one.

The request fingerprint of `new-version` is the canonical hash of `{action, doc_id, sha256 of the file, author}`, stored in the
manifest entry (`request_sha256`). The same request as any entry of the manifest is a replay: it returns that entry and writes nothing, even after later versions were added. To bring old content back, send it under another author.
The same bytes under another author are refused (`version_unchanged`).

## Templates

`examples/templates/quote` and `examples/templates/meeting-minutes` are copies
Expand Down Expand Up @@ -111,10 +127,14 @@ renderer, on synthetic data. They do not prove the behavior on a One.

## Known limits (V0)

- Concurrent `mark-authoritative`: two calls on the same document at the same time are not safe. Both may pass the second read and the later write wins, which can leave the wrong version authoritative or bring a superseded one back while both calls report success. Serialise them (one writer per document). Moving the manifest to `application_data_v1`, which has compare-and-swap, lifts this limit (lot 4).
- Versions: Storage has no compare-and-swap. A manifest is read, the version file and redline are written, then the manifest is read again and written only if its text is unchanged (`concurrent_update` otherwise; a first manifest is written without overwrite). The window between the second read and the write is small, not null: allow one writer at a time per document. Files written before an abandoned manifest write stay orphaned in `versions/`. Pass `base_version` and `base_manifest_sha256` (returned as `manifest_sha256`) to make a stale caller fail.
- Versions are DOCX only (XLSX and PDF are out of this lot), the comparison and its 20 MiB input limit are those of `office_compare_v1`, and there is no review MiniApp for versions yet.

- The brand is read from Storage only. The `profile` Module keeps the profile in an application record whose broker is not wired in the One yet: calling the `cib-profile-read` Workflow would make every render fail until then.
- The logo is a reference (`storage://…`); this Module does not resolve it to a file before rendering.
- Number reservation is not atomic: it lists, writes without overwrite, reads back and checks the owner, at most 5 attempts (`number_conflict`). A number reserved then lost (failed render) stays reserved: it is taken again on the next attempt, never reused by another document. Atomic sequences are a platform follow-up.
- No sending (mail, SFTP), no DOCX, one locale (`fr`).
- No sending (mail, SFTP), no DOCX rendering (DOCX files are only versioned), one locale (`fr`).
- `document-studio-export` reads the PDF in base64 through `read_file`; if the runtime does not allow it, the export fails on the hash (`export_integrity_failed`).
- No Viewer `document` card for a preview in the chat yet.
- Concurrent updates: Storage has no conditional write. Before each record write, `render`, `finalize`, `publish` and `cancel` read the record again and abandon with `concurrent_update` if its revision or status changed (for example a cancel during a render). Files already rendered stay orphaned in `r<revision>-<sha12>/`. The window is small but not null until Storage offers conditional writes.
Expand Down

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions document-studio/agents/main/workflows/document-studio-new-version.json

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion document-studio/module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"schema_version": 2,
"key": "document-studio",
"name": "Document studio",
"version": "0.1.0",
"version": "0.2.0",
"provides": {
"actions": [
{
Expand Down Expand Up @@ -53,6 +53,18 @@
"name": "Save the company profile",
"workflow_id": "document-studio-profile-save",
"workflow_version": "1"
},
{
"key": "document-studio-new-version",
"name": "Add a DOCX version",
"workflow_id": "document-studio-new-version",
"workflow_version": "1"
},
{
"key": "document-studio-mark-authoritative",
"name": "Mark a version authoritative",
"workflow_id": "document-studio-mark-authoritative",
"workflow_version": "1"
}
],
"queries": [
Expand Down
48 changes: 45 additions & 3 deletions inventory/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,9 @@
},
{
"key": "document-studio",
"version": "0.1.0",
"version": "0.2.0",
"manifest": "document-studio/module.yaml",
"workflows": 11,
"workflows": 13,
"miniapps": 1,
"source": {
"repository": "github.com/agentmaurice/modules",
Expand All @@ -1223,6 +1223,8 @@
"document-studio/agents/main/workflows/document-studio-export.json",
"document-studio/agents/main/workflows/document-studio-finalize.json",
"document-studio/agents/main/workflows/document-studio-list.json",
"document-studio/agents/main/workflows/document-studio-mark-authoritative.json",
"document-studio/agents/main/workflows/document-studio-new-version.json",
"document-studio/agents/main/workflows/document-studio-plan.json",
"document-studio/agents/main/workflows/document-studio-profile-save.json",
"document-studio/agents/main/workflows/document-studio-publish.json",
Expand All @@ -1234,12 +1236,14 @@
"document-studio/agents/main/miniapps/document-studio-review.json"
],
"sha256": {
"document-studio/module.yaml": "89c05d34793969a8fccb1b767f9b6aa87bda29d6fb9edaf4f80e1f827e2a0299",
"document-studio/module.yaml": "2e09f02654084161cdea77ebbdeb479e7da92034c5939b63cfb73402747cdecb",
"document-studio/agents/main/workflows/document-studio-cancel.json": "899e24cb5688d92497891ea09a3181f64093df9d2802d818da78f1298f807965",
"document-studio/agents/main/workflows/document-studio-draft.json": "72be0b86b67c6fc4392bff1795c38c59763334582fedf1ccdd95b296e9492b4e",
"document-studio/agents/main/workflows/document-studio-export.json": "52aa5bcc2ee64715be59fab234804fcebd3cc1cfec4e32dd5f9ea5d69c9371db",
"document-studio/agents/main/workflows/document-studio-finalize.json": "07f6f1bce4cb549c1973b06b3523abefc77c253967711415d51bd499360ed020",
"document-studio/agents/main/workflows/document-studio-list.json": "38daf2284f500b2e71d0bbd73dbfbd8d3c3ca1259f600384a6ce95c565ba5a33",
"document-studio/agents/main/workflows/document-studio-mark-authoritative.json": "4077fc003cd00ddee422e776e315515b2deaa1b271846f73bc26b3568beee472",
"document-studio/agents/main/workflows/document-studio-new-version.json": "eff7d8a8f52e1bea1a4282397310b093714e3e6c8f6455ce62c73411cc52fcc5",
"document-studio/agents/main/workflows/document-studio-plan.json": "47a1a75463b75cdfc287a56f80a23f3faef513ae46b6b980a0851579089eb99b",
"document-studio/agents/main/workflows/document-studio-profile-save.json": "686d4ccf1265c6b3990a0fdec57b7ddc3e3252bcc66025f25d640f12c7f9454e",
"document-studio/agents/main/workflows/document-studio-publish.json": "350a0c4318d39c76b907891181c8abb66c6d21ce372f03548c013e7e3653a8b1",
Expand Down Expand Up @@ -1328,6 +1332,32 @@
}
]
},
"document-studio/agents/main/workflows/document-studio-mark-authoritative.json": {
"workflow_id": "document-studio-mark-authoritative",
"actions": [
{
"path": "/actions/0",
"id": "mark",
"type": "code_execution",
"runtime": "deno",
"runtime_source": "contract default",
"code_sha256": "20b53ce431029441722b8867fb76889fd3512c5c6f64919e6cfa9ef147ee4f1f"
}
]
},
"document-studio/agents/main/workflows/document-studio-new-version.json": {
"workflow_id": "document-studio-new-version",
"actions": [
{
"path": "/actions/0",
"id": "new-version",
"type": "code_execution",
"runtime": "deno",
"runtime_source": "contract default",
"code_sha256": "d5f16778a62ce2a1e47972ea74efdb7e171469b25425714d7d5336dc801eafa5"
}
]
},
"document-studio/agents/main/workflows/document-studio-plan.json": {
"workflow_id": "document-studio-plan",
"actions": [
Expand Down Expand Up @@ -1469,6 +1499,18 @@
"name": "Save the company profile",
"workflow_id": "document-studio-profile-save",
"workflow_version": "1"
},
{
"key": "document-studio-new-version",
"name": "Add a DOCX version",
"workflow_id": "document-studio-new-version",
"workflow_version": "1"
},
{
"key": "document-studio-mark-authoritative",
"name": "Mark a version authoritative",
"workflow_id": "document-studio-mark-authoritative",
"workflow_version": "1"
}
],
"queries": [
Expand Down
4 changes: 2 additions & 2 deletions modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
},
{
"key": "document-studio",
"version": "0.1.0",
"version": "0.2.0",
"manifest": "document-studio/module.yaml",
"workflows": 11,
"workflows": 13,
"miniapps": 1
},
{
Expand Down
Loading
Loading