wrxn-reversa 1.12.1 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/agents/reversa/references/coordination.md +61 -7
- package/agents/reversa/references/modo-de-execucao.md +15 -3
- package/agents/reversa/references/state-schema.md +1 -0
- package/agents/reversa/scripts/lib/delegation.mjs +17 -14
- package/agents/reversa/scripts/lib/messages.mjs +22 -13
- package/agents/reversa/scripts/lib/repositories.mjs +2 -1
- package/agents/reversa/scripts/lib/safe-fs.mjs +2 -2
- package/agents/reversa/scripts/session-state.mjs +72 -33
- package/agents/reversa-architect/SKILL.md +1 -1
- package/agents/reversa-debugger-graph/SKILL.md +6 -4
- package/agents/reversa-forward-autonomous/SKILL.md +3 -3
- package/agents/reversa-ideator/SKILL.md +4 -2
- package/agents/reversa-migrate/SKILL.md +12 -4
- package/agents/reversa-new/SKILL.md +10 -3
- package/agents/reversa-worker/SKILL.md +18 -6
- package/bin/reversa.js +3 -1
- package/lib/commands/add-engine.js +7 -1
- package/lib/commands/install.js +8 -10
- package/lib/commands/update.js +162 -63
- package/lib/installer/bundled.js +21 -0
- package/lib/installer/checkout-guard.js +1 -0
- package/lib/installer/installation-records.js +57 -0
- package/lib/installer/skill-layout.js +3 -1
- package/lib/installer/writer.js +97 -41
- package/locales/en/agents/reversa/references/state-schema.md +1 -0
- package/locales/en/agents/reversa-architect/SKILL.md +1 -1
- package/locales/en/agents/reversa-debugger-graph/SKILL.md +6 -4
- package/locales/en/agents/reversa-forward-autonomous/SKILL.md +3 -3
- package/locales/en/agents/reversa-ideator/SKILL.md +4 -2
- package/locales/en/agents/reversa-migrate/SKILL.md +11 -3
- package/locales/en/agents/reversa-new/SKILL.md +10 -3
- package/locales/en/agents/reversa-worker/SKILL.md +18 -6
- package/package.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.13.1
|
|
4
|
+
|
|
5
|
+
### Packaging
|
|
6
|
+
|
|
7
|
+
- Repackaged the release from the exact Git commit.
|
|
8
|
+
- npm version `1.13.0` was published from the working tree.
|
|
9
|
+
Its only file difference from the verified source was CRLF line endings in `agents/impeccable/scripts/impeccable.cmd`; this package uses Git's LF bytes.
|
|
10
|
+
|
|
11
|
+
## 1.13.0
|
|
12
|
+
|
|
13
|
+
### Changes
|
|
14
|
+
|
|
15
|
+
- Update now reports each routing card and reconciles installation records.
|
|
16
|
+
A refused or no-write update gives a reason and exits nonzero.
|
|
17
|
+
- An update leaves an import-only `CLAUDE.md` intact and preserves user text around managed blocks.
|
|
18
|
+
- Use `--impeccable=skip` to keep the installed Impeccable or `--impeccable=<version>` to retain an exact installed version.
|
|
19
|
+
- Save the next flow position when releasing for an update, and reclaim it under a new generation after the update.
|
|
20
|
+
- Control-file writes reject empty replacements unless explicitly allowed, and invalid requests name the bad field.
|
|
21
|
+
- Scoped worker returns preserve questions and gaps, and the coordination instructions cover external code-only workers and bounded review.
|
|
22
|
+
- Greenfield Express reuses the completed Brainstorm brief, headless Migration records a skipped screen phase, and Debugger Graph regenerates only its own views as documented.
|
|
23
|
+
|
|
24
|
+
### Known issues
|
|
25
|
+
|
|
26
|
+
All of these issues predate 1.13.0.
|
|
27
|
+
See the [dry-run backlog](https://github.com/gcunharodrigues/wrxn-reversa/blob/4e094aff39eebf4fb3322a0f0e1afd87d016d3c1/evolucao/multi-repo-delegation/PLAN-coordinated-delegation.md#reversa-1130-dry-run-backlog) for baseline source locations and severity.
|
|
28
|
+
|
|
29
|
+
| ID | Known issue and effect |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `DR-01` | Screen Translator can block required headless skip records or request approval for a skipped mode. |
|
|
32
|
+
| `DR-02` | Headless screen detection runs late; resuming a skipped mode can ask for approval. |
|
|
33
|
+
| `DR-03` | Designer names Inspector next, which can skip Screen Translator and its required records. |
|
|
34
|
+
| `DR-04` | Reconstruction's read limits can omit parity criteria from module tasks. |
|
|
35
|
+
| `DR-05` | A blank Debugger Fix verdict can be mistaken for approval to change the effective spec; answer explicitly. |
|
|
36
|
+
| `DR-06` | First-use Debugger context creation can skip initialization of the registry README and taxonomy. |
|
|
37
|
+
| `DR-07` | Debugger Fix can block required reproduction records before the plan. |
|
|
38
|
+
| `DR-08` | Graph timestamps can change on regeneration even when no bug changed. |
|
|
39
|
+
| `DR-09` | Conflicting Graph rules may expose restricted bug metadata in generated views; check before sharing views. |
|
|
40
|
+
| `DR-10` | Express's artifact limit can omit progress, impact, and regression records. |
|
|
41
|
+
| `DR-11` | Requirements can pause an unattended queue to replace an already completed feature. |
|
|
42
|
+
| `DR-12` | Brainstorm can pass only the decision and omit Pre-Spec scope, exclusions, and open questions. |
|
|
43
|
+
| `DR-13` | Headless Migration refers to an unnamed interaction contract. |
|
|
44
|
+
| `DR-14` | A skipped screen decision template can imply a human decision. |
|
|
45
|
+
| `DR-15` | Inspector calls itself fifth but runs sixth. |
|
|
46
|
+
| `DR-16` | The installed Migration artifact list names a repository-only path; use the local copy. |
|
|
47
|
+
| `DR-17` | Planning can label an owner-approved test runner `detected` instead of `approved`. |
|
|
48
|
+
| `DR-18` | Following the general New brief section out of order can repeat the Express brief question. |
|
|
49
|
+
| `DR-19` | PRD coverage can ask again about exclusions already in Pre-Spec. |
|
|
50
|
+
| `DR-20` | The helper contract does not specify the `generation` type; pass the returned string unchanged. |
|
|
51
|
+
| `DR-21` | Debugger runner approval can be in owner decisions while the stack row remains `unknown`. |
|
|
52
|
+
| `DR-22` | The specification scorer can recommend external failure cases for a component with no external dependencies. |
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
This reference applies when the project has `.reversa/repositories.json`, or when the owner asks for parallel workers.
|
|
4
4
|
Without either, ignore it: the flow runs inline in one repository, as always.
|
|
5
5
|
It extends the execution contract in [`modo-de-execucao.md`](modo-de-execucao.md), which still applies in full.
|
|
6
|
-
A worker follows the `reversa-worker` skill
|
|
6
|
+
A worker follows the `reversa-worker` skill, not this file.
|
|
7
|
+
The helper's scoped dispatch requires a registered, same-version satellite install for a code repository, or a parallel checkout of the hub.
|
|
8
|
+
Do not install a satellite in a code-only repository unless the owner explicitly approves adding its files.
|
|
9
|
+
For code-only repositories, use "External workers without an install" below.
|
|
7
10
|
|
|
8
11
|
## Terms
|
|
9
12
|
|
|
@@ -108,6 +111,8 @@ A deletion of a pre-existing file needs its own explicit yes, and only then goes
|
|
|
108
111
|
|
|
109
112
|
- `inputs` are hub files, with paths relative to the hub root.
|
|
110
113
|
- `deletions` lists tracked files inside the scope that the owner approved for deletion.
|
|
114
|
+
- The helper does not require an input to be tracked in Git.
|
|
115
|
+
Declare each permitted file from a gitignored reference folder separately; do not pass a directory.
|
|
111
116
|
|
|
112
117
|
3. Read the result: `delegation.id`, `delegation.base` (the base commit), `delegation.inputs` (absolute paths and hashes), and `delegation.wholeRepository`.
|
|
113
118
|
When `wholeRepository` is true, tell the owner that the scope covers the whole repository before you dispatch.
|
|
@@ -131,9 +136,9 @@ A deletion of a pre-existing file needs its own explicit yes, and only then goes
|
|
|
131
136
|
|
|
132
137
|
```json
|
|
133
138
|
{ "id": "<delegation.id>", "flow": "forward", "agent": "reversa-coding", "repository": "web", "checkout": "/abs/checkout",
|
|
134
|
-
"scope": ["src/cart/**", "test/cart/**"],
|
|
139
|
+
"branch": "feature/cart", "dispatchBase": "<delegation.base>", "scope": ["src/cart/**", "test/cart/**"],
|
|
135
140
|
"actions": [ { "id": "T004", "description": "...", "file": "src/cart/total.js", "acceptance": "..." } ],
|
|
136
|
-
"inputs": [ { "path": "/abs/hub/_reversa_forward/004-cart/roadmap.md", "sha256": "<hash>", "content": null } ],
|
|
141
|
+
"inputs": [ { "path": "/abs/hub/_reversa_forward/004-cart/roadmap.md", "required": true, "sha256": "<hash>", "content": null } ],
|
|
137
142
|
"decisions": [ "OD-1: test first", "D-03: ..." ],
|
|
138
143
|
"baseline": { "commit": "<commit>", "created": [] },
|
|
139
144
|
"deletions": [] }
|
|
@@ -147,6 +152,7 @@ A deletion of a pre-existing file needs its own explicit yes, and only then goes
|
|
|
147
152
|
- `baseline.commit` is the base commit of the first delegation of this feature into that repository.
|
|
148
153
|
Take it from the first line of this feature's `progress.jsonl` that has that `repository`; for the first delegation, use `delegation.base`.
|
|
149
154
|
`baseline.created` may stay empty: the worker checks the commit.
|
|
155
|
+
- `dispatchBase` is `delegation.base`; review and fix rounds start at a new dispatch base.
|
|
150
156
|
- When the worker cannot read the hub's files, embed each input under 20,000 bytes in `content`, with its hash.
|
|
151
157
|
A larger input that the worker cannot read blocks the delegation: execute inline.
|
|
152
158
|
|
|
@@ -162,6 +168,12 @@ Never send the generation to a worker.
|
|
|
162
168
|
7. While delegations are in flight, keep working on your own actions.
|
|
163
169
|
`checkpoint` and `write` stay available while the phase agent is the same; a checkpoint that changes the agent, and `release`, are refused until every delegation is finished or cancelled.
|
|
164
170
|
The position header gains ` · delegations <n> → <repository IDs>` (` · delegações <n> → <IDs>` in a Portuguese installation).
|
|
171
|
+
8. When a worker needs a decision, receive its numbered question block without marking the delegation finished.
|
|
172
|
+
Resolve or escalate the questions, then reply to that worker once before it continues.
|
|
173
|
+
9. When a worker commits a contract that another worker needs, verify its path and hash at the named commit before relaying it.
|
|
174
|
+
Record the commit and hash in the hub.
|
|
175
|
+
For a new helper-tracked consumer delegation, snapshot a copy of the contract in the hub as a declared input.
|
|
176
|
+
A running delegation's input snapshot is immutable; relay the verified contract as an explicit additional instruction and record the handoff separately.
|
|
165
177
|
|
|
166
178
|
## Finish one delegation
|
|
167
179
|
|
|
@@ -176,12 +188,12 @@ Delegations finish in any order.
|
|
|
176
188
|
|
|
177
189
|
2. The helper compares the checkout with the base commit through Git.
|
|
178
190
|
Trust its lists, not the worker's.
|
|
179
|
-
Read `delegation.status`, `head`, `changed`, `deleted`, `violations`, `accepted`, `installer`, `warnings`, `actions`, and `
|
|
191
|
+
Read `delegation.status`, `head`, `changed`, `deleted`, `violations`, `accepted`, `installer`, `warnings`, `actions`, `questions`, `gaps`, and `workerWarnings`.
|
|
180
192
|
|
|
181
193
|
| Status | What to do |
|
|
182
194
|
|---|---|
|
|
183
|
-
| `completed` |
|
|
184
|
-
| `partial` |
|
|
195
|
+
| `completed` | Record the verified results; wait for independent review and integration before marking actions done |
|
|
196
|
+
| `partial` | Record verified results and gaps; reopen unfinished actions and apply the same review and integration gate to finished actions |
|
|
185
197
|
| `blocked` | Dispatch again or execute inline, after the questions are answered |
|
|
186
198
|
| `violation` | Nothing is accepted yet: show the list and the menu below |
|
|
187
199
|
| `cancelled` | Reopen its actions |
|
|
@@ -261,7 +273,8 @@ When you execute an action whose repository is a satellite yourself:
|
|
|
261
273
|
- Use a new branch for a worktree, named after the feature and the action IDs of the group, and tell the owner its name.
|
|
262
274
|
Commits made in the main checkout after the parallel checkout was created are not in it.
|
|
263
275
|
A parallel checkout serves the delegations of one group until integration.
|
|
264
|
-
|
|
276
|
+
If the target head is an ancestor of the independently approved head and no discarded violation is in that history, request approval to fast-forward.
|
|
277
|
+
Otherwise, after a verified finish and authorization, apply the approved commits in order.
|
|
265
278
|
When an apply conflicts, stop and report the conflicting paths; never resolve a conflict alone.
|
|
266
279
|
When the delegation had a discarded violation, do not apply its commits as they are: apply the net change of its scope paths as one commit, and say so.
|
|
267
280
|
Mark an action of a parallel checkout done only after its commits apply to the main checkout, and add `integrated` (the head of the main checkout after the last applied commit) to its `progress.jsonl` line.
|
|
@@ -270,6 +283,47 @@ When you execute an action whose repository is a satellite yourself:
|
|
|
270
283
|
- Remove a parallel checkout that you created, after its delegation is accepted or discarded, and after you show the owner what will be removed.
|
|
271
284
|
Keep its branch until the owner confirms that it can go.
|
|
272
285
|
|
|
286
|
+
After a round settles, use the same clean checkout and branch for a new scoped fix delegation if needed.
|
|
287
|
+
Never mark an action done before independent review clears the delivery and integration succeeds.
|
|
288
|
+
|
|
289
|
+
## Bounded independent review
|
|
290
|
+
|
|
291
|
+
Give a read-only reviewer subagent the exact delivered commit and a brief for one initial review.
|
|
292
|
+
For manual delegation, let the owner relay the same exact-commit brief to a separate read-only reviewer session and relay its findings back.
|
|
293
|
+
Use that route for targeted rechecks as well.
|
|
294
|
+
If no independent reviewer is available, leave the delivery awaiting review.
|
|
295
|
+
Do not substitute the author's review or mark the actions done.
|
|
296
|
+
Do not open a second write delegation on its checkout.
|
|
297
|
+
The reviewer returns findings with a severity (`high`, `medium`, or `low`) and `file:line`.
|
|
298
|
+
The author fixes every reported high and medium finding within the authorized scope.
|
|
299
|
+
Low cosmetic findings may pass; record them in the delivery return.
|
|
300
|
+
On re-review, give the reviewer the new head and only the findings it reported; do not ask it to search for new problems.
|
|
301
|
+
A finding stays open if the fix is missing, incomplete, or breaks the same behavior.
|
|
302
|
+
The reviewer returns only the findings still open.
|
|
303
|
+
Repeat the fix and targeted recheck until all reported high and medium findings are closed.
|
|
304
|
+
When they are closed, the review passes; follow the applicable integration gate.
|
|
305
|
+
|
|
306
|
+
## External workers without an install
|
|
307
|
+
|
|
308
|
+
The coordinator keeps the hub flow inline and manages such workers outside `delegate-start`.
|
|
309
|
+
Ask for approval of the exact repository, checkout, branch, base commit, actions, path globs, inputs, and review gate.
|
|
310
|
+
Send the worker the repository's instructions and the absolute path of the hub's installed `reversa-worker/SKILL.md`.
|
|
311
|
+
Set the brief's `workerInstall` to `hub` and `skillRoot` to the absolute path of the hub's installed skills directory.
|
|
312
|
+
Use the repository's own written edit policy; never infer authority to edit a pre-existing file from a scope.
|
|
313
|
+
Provide the same scoped v2 brief and require its v2 return by message or in the hub, not in the code branch.
|
|
314
|
+
For each return, confirm checkout, branch, base ancestry, head, clean worktree, and the paths in every commit since the dispatch base before trusting any summary.
|
|
315
|
+
Compare the returned paths and hashes to Git and apply [bounded independent review](#bounded-independent-review) to the integration candidate.
|
|
316
|
+
Treat the external worker IDs and verification records as hub artifacts, not as helper delegation state.
|
|
317
|
+
|
|
318
|
+
## Migrate during coding
|
|
319
|
+
|
|
320
|
+
Do not convert a live v1 brief or redispatch an open worker.
|
|
321
|
+
Record each attempt, its checkout, branch, base, authorizations, and return or cancellation in the hub.
|
|
322
|
+
Finish and reconcile helper-tracked attempts before release.
|
|
323
|
+
While external workers keep working in separate checkouts, pause all hub writes and continue to use their original return format.
|
|
324
|
+
Follow the update and resume procedure in [`modo-de-execucao.md`](modo-de-execucao.md).
|
|
325
|
+
Use v2 for new work only, with helper tracking for eligible checkouts and the external procedure for code-only repositories.
|
|
326
|
+
|
|
273
327
|
## Recovery
|
|
274
328
|
|
|
275
329
|
| Situation | What to do |
|
|
@@ -44,17 +44,22 @@ Send one JSON request on standard input to `node "<installed-reversa>/scripts/se
|
|
|
44
44
|
|
|
45
45
|
| Operation | Additional fields |
|
|
46
46
|
|---|---|
|
|
47
|
-
| `inspect` | Optional `identity`, `paths`; returns current `active` and the SHA-256 of each
|
|
47
|
+
| `inspect` | Optional `identity`, `paths`; returns current `active`, any `resumePosition`, and the SHA-256 of each managed path's exact bytes (`null` if absent) |
|
|
48
48
|
| `claim` | `identity`, `position`; returns `generation` for this owner and `stateHash`, or refuses a foreign owner or different flow |
|
|
49
49
|
| `checkpoint` | `identity`, `generation`, `position`; update the step and refresh the heartbeat; returns `stateHash` |
|
|
50
|
-
| `write` | `identity`, `generation`, `path`, `expectedHash`, `content
|
|
51
|
-
| `release` | `identity`, `generation`; clears `active`
|
|
50
|
+
| `write` | `identity`, `generation`, `path`, `expectedHash`, `content`, and optional `allowEmpty`; returns the new `sha256` of the path and `stateHash` |
|
|
51
|
+
| `release` | `identity`, `generation`, and optional `preservePosition`; clears `active` and returns `stateHash` |
|
|
52
52
|
| `transfer` | `identity`, `expectedOwnerRevision`, `confirmed:true`, `priorSessionQuiescent:true`; see transfer rules below; returns `stateHash` |
|
|
53
53
|
|
|
54
54
|
`position` is `{flow,orchestrator,agent,skill_path,step,step_index,step_total,status}`. The IDs are literal skill directory names. The path is the real installed absolute path of the phase `SKILL.md`. Use `null` for both counts if there is no fixed count. Use `ready`, `working`, or `waiting_user`; only the helper sets `waiting_delegate`. Take `generation` from a successful claim/transfer, or from an inspect that matches the separately authenticated session identity. Do not share the generation with delegates.
|
|
55
55
|
|
|
56
56
|
For managed JSON paths, pass an object as `content`. For `state.json`, send the changed top-level keys only (do not include `active`); preserve other subfields when updating a nested object. The helper merges `checkpoints` key by key, so send only the changed checkpoint key. Other JSON control files take a complete object. Managed Markdown and TOML take a literal string. Use the inspected hash as `expectedHash`, or `null` when creating. Every mutating call (`claim`, `transfer`, `checkpoint`, `write`, `release`, `delegate-start`, `delegate-finish`) returns `stateHash`: a state write uses the `stateHash` of the previous call as its `expectedHash` and needs no `inspect`. The owner session may flip a checkbox or a status value in `actions.md`, `plan.md`, `bug.md`, and `reconstruction-plan.md` with a direct edit, after it rereads the file. Use `write` to create each of these managed paths and for every other change to it: The `sha256` that `write` returns for a path is the next `expectedHash` for that same path.
|
|
57
57
|
|
|
58
|
+
Empty or whitespace-only text and empty JSON objects do not replace existing control files unless you send `allowEmpty:true`.
|
|
59
|
+
An `invalid_request` response identifies the invalid or missing request field in `field`.
|
|
60
|
+
After each successful helper write, commit the shared control file explicitly if the commit tool tracks edits by writer.
|
|
61
|
+
Commit `.reversa/state.json` only after release, so a live generation does not enter Git history.
|
|
62
|
+
|
|
58
63
|
- `.reversa/state.json`, `plan.md`, `config.toml`, `active-requirements.json`, `forward-autonomous.json`, and `active-ideation.json`.
|
|
59
64
|
- `_reversa_docs/.state.json` and `_reversa_docs/.config.json`.
|
|
60
65
|
- `<output_folder>/migration/.state.json` and `<output_folder>/reconstruction-plan.md`.
|
|
@@ -69,6 +74,13 @@ If the helper returns `busy`, stop mutation; it will not steal the lock. If it r
|
|
|
69
74
|
|
|
70
75
|
An ordinary pause at `CONTINUAR` retains ownership. On normal completion or an explicit pause-and-release, save progress and use `release`. Before you suggest a new session or a context reset (for example `/clear`), save progress and use `release`; claim again if the user continues in this session. For a handoff to a different flow, verify the old checkpoint and delegate status, release it, then claim the authorized destination. Stop if another session claims between those operations. A route preview never transfers ownership.
|
|
71
76
|
|
|
77
|
+
For an installer update, commit the flow artifacts, checkpoint the exact next step, and release with `preservePosition:true`.
|
|
78
|
+
Run the installer again after release returns `active:null`.
|
|
79
|
+
After the update, read the installed phase skill, this contract, and the authoritative plan, actions, progress, and decision records for the saved step.
|
|
80
|
+
Use `inspect` to recover `resumePosition`, resolve the phase skill's current real path, and `claim` the same position.
|
|
81
|
+
Use the new generation; never reuse the released one.
|
|
82
|
+
If an older helper released without `resumePosition`, recover the step from the committed progress and the owner session's handoff before claiming.
|
|
83
|
+
|
|
72
84
|
For a foreign owner, display its identity, current step, and last heartbeat. Treat activity within 30 minutes as recent. If the heartbeat is older than 30 minutes or missing, or the user has already said that the earlier session is closed, transfer and tell the user in one line; do not ask again. Only when the heartbeat is recent and the user has not said so, ask the user to confirm the transfer and that the prior writer is stopped or at a safe boundary. Send `transfer` with the `ownerRevision` from inspect as `expectedOwnerRevision`; a new revision requires a new decision. Never interpret `CONTINUAR` as transfer approval.
|
|
73
85
|
|
|
74
86
|
An in-flight delegate blocks release and transfer. If dispatch ended without a valid return, verify cancellation or termination. The current owner can use `delegate-finish` with `stopped:true,result:null`. For an authorized transfer after confirmed termination, include `stoppedDelegationId` for the exact in-flight attempt. Do not retry an uncertain dispatch before reconciling it.
|
|
@@ -65,6 +65,7 @@ Este arquivo persiste o estado completo da análise entre sessões. O Reversa l
|
|
|
65
65
|
| `output_folder` | string | Pasta de saída das specs (padrão: `_reversa_sdd`) |
|
|
66
66
|
| `doc_level_confirmed` | booleano | `false` na instalação nova. Marque `true` só após a resposta ao menu. Estados antigos com nível válido sem este campo preservam o nível. |
|
|
67
67
|
| `active` | objeto \| null | Posição e posse da sessão. Ausente em instalações antigas. Veja o contrato em `modo-de-execucao.md`. |
|
|
68
|
+
| `resume_position` | objeto opcional | Posição salva por `release` com `preservePosition: true`, sem dados de posse ou delegações. `inspect` retorna `resumePosition`; um novo `claim` remove o campo. |
|
|
68
69
|
| `redator_progress` | objeto opcional | Plano de arquivos e último progresso verificado do Writer, mantidos pelo orquestrador. |
|
|
69
70
|
| `phase` | string \| null | Fase atual. `null` = não iniciado |
|
|
70
71
|
| `completed` | string[] | Fases concluídas |
|
|
@@ -67,12 +67,14 @@ function hashWithin(dir, paths) {
|
|
|
67
67
|
const hashAll = (dir, paths) => hashWithin(dir, paths) ?? refuse('scope_too_large', { files: paths.length });
|
|
68
68
|
|
|
69
69
|
function hubInputs(root, entries) {
|
|
70
|
-
if (!Array.isArray(entries) || entries.length > 200) refuse('invalid_request');
|
|
70
|
+
if (!Array.isArray(entries) || entries.length > 200) refuse('invalid_request', { field: 'inputs' });
|
|
71
71
|
const seen = new Set();
|
|
72
|
-
return entries.map(entry => {
|
|
73
|
-
if (!object(entry)
|
|
72
|
+
return entries.map((entry, i) => {
|
|
73
|
+
if (!object(entry)) refuse('invalid_request', { field: `inputs[${i}]` });
|
|
74
|
+
if (!parts(entry.path)) refuse('invalid_request', { field: `inputs[${i}].path` });
|
|
75
|
+
if (typeof entry.required !== 'boolean') refuse('invalid_request', { field: `inputs[${i}].required` });
|
|
74
76
|
const key = entry.path.toLowerCase();
|
|
75
|
-
if (seen.has(key)) refuse('invalid_request');
|
|
77
|
+
if (seen.has(key)) refuse('invalid_request', { field: `inputs[${i}].path` });
|
|
76
78
|
if (key === '.git' || key.startsWith('.git/') || key === LOCK || key.startsWith(`${LOCK}/`)) refuse('unsafe_path', { path: entry.path });
|
|
77
79
|
seen.add(key);
|
|
78
80
|
const sha256 = hash(bytes(safePath(root, entry.path)));
|
|
@@ -98,9 +100,8 @@ export function prepareStart(root, state, req) {
|
|
|
98
100
|
const active = state.active;
|
|
99
101
|
if (!validScope(req.scope)) refuse('invalid_scope');
|
|
100
102
|
const deletions = req.deletions ?? [];
|
|
101
|
-
if (!actionList(req.actions)
|
|
102
|
-
|
|
103
|
-
}
|
|
103
|
+
if (!actionList(req.actions)) refuse('invalid_request', { field: 'actions' });
|
|
104
|
+
if (!pathList(deletions)) refuse('invalid_request', { field: 'deletions' });
|
|
104
105
|
admit(active, req, null);
|
|
105
106
|
const target = resolveCheckout(root, state, req.repository, req.checkout);
|
|
106
107
|
admit(active, req, target);
|
|
@@ -110,7 +111,7 @@ export function prepareStart(root, state, req) {
|
|
|
110
111
|
const dirty = changes.filter(c => inScope(req.scope, c.path, target.outputs)).map(c => c.path);
|
|
111
112
|
if (dirty.length) refuse('dirty_scope', { paths: dirty.slice(0, 20) });
|
|
112
113
|
const files = hashAll(target.checkout, trackedFiles(target.checkout).filter(p => inScope(req.scope, p, target.outputs)));
|
|
113
|
-
if (deletions.some(p => !files.some(f => f.path === p))) refuse('invalid_request', { deletions });
|
|
114
|
+
if (deletions.some(p => !files.some(f => f.path === p))) refuse('invalid_request', { field: 'deletions', deletions });
|
|
114
115
|
// Changes outside the scope that exist before dispatch belong to the coordinator; finish ignores them while they stay the same.
|
|
115
116
|
const preexisting = hashAll(target.checkout, changes.map(c => c.path)).map(({ path, sha256 }) => ({ path, sha256 }));
|
|
116
117
|
const inputs = hubInputs(root, req.inputs);
|
|
@@ -138,7 +139,7 @@ export function commitStart(root, state, plan) {
|
|
|
138
139
|
function findOpen(active, id) {
|
|
139
140
|
const attempt = active?.delegations.find(d => isScoped(d) && d.id === id);
|
|
140
141
|
if (!attempt || !(attempt.status === 'violation' || (attempt.status === 'dispatched' && attempt.generation === active.owner.generation))) {
|
|
141
|
-
refuse('invalid_request');
|
|
142
|
+
refuse('invalid_request', { field: 'id' });
|
|
142
143
|
}
|
|
143
144
|
return attempt;
|
|
144
145
|
}
|
|
@@ -217,7 +218,7 @@ export function prepareFinish(root, state, req) {
|
|
|
217
218
|
const attempt = findOpen(state.active, req.id);
|
|
218
219
|
if (req.stopped !== true) refuse('pending_delegation', { id: attempt.id });
|
|
219
220
|
const reopened = attempt.status === 'violation';
|
|
220
|
-
if (req.accepted !== undefined && (!reopened || !pathList(req.accepted))) refuse('invalid_request');
|
|
221
|
+
if (req.accepted !== undefined && (!reopened || !pathList(req.accepted))) refuse('invalid_request', { field: 'accepted' });
|
|
221
222
|
const common = { id: attempt.id, repository: attempt.repository, checkout: attempt.checkout, base: attempt.base };
|
|
222
223
|
const plan = { id: attempt.id, from: attempt.status };
|
|
223
224
|
if (req.result === null) {
|
|
@@ -226,19 +227,21 @@ export function prepareFinish(root, state, req) {
|
|
|
226
227
|
const record = readRecord(root, attempt);
|
|
227
228
|
if (!record) refuse('missing_record', { id: attempt.id });
|
|
228
229
|
const answer = parseReturn(req.result);
|
|
229
|
-
if (answer.id !== attempt.id
|
|
230
|
+
if (answer.id !== attempt.id) refuse('invalid_request', { field: 'result.id' });
|
|
231
|
+
if (answer.actions.some(a => !attempt.actions.includes(a.id))
|
|
230
232
|
|| (answer.version === 2 && answer.status === 'concluido' && attempt.actions.some(id => !answer.actions.some(a => a.id === id)))) {
|
|
231
|
-
refuse('invalid_request');
|
|
233
|
+
refuse('invalid_request', { field: 'result.acoes' });
|
|
232
234
|
}
|
|
233
235
|
const checked = verify(root, attempt, record, answer, reopened, new Set(req.accepted ?? []));
|
|
234
236
|
const status = checked.violations.length ? 'violation' : FINAL[answer.status];
|
|
235
|
-
return { ...plan, result: { ...common, status, ...checked, actions: answer.actions, questions: answer.questions
|
|
237
|
+
return { ...plan, result: { ...common, status, ...checked, actions: answer.actions, questions: answer.questions,
|
|
238
|
+
gaps: answer.gaps, workerWarnings: answer.workerWarnings } };
|
|
236
239
|
}
|
|
237
240
|
|
|
238
241
|
export function commitFinish(root, state, plan) {
|
|
239
242
|
const attempt = findOpen(state.active, plan.id);
|
|
240
243
|
// A finish that ran meanwhile changed the status; this plan verified the older one.
|
|
241
|
-
if (attempt.status !== plan.from) refuse('invalid_request');
|
|
244
|
+
if (attempt.status !== plan.from) refuse('invalid_request', { field: 'id' });
|
|
242
245
|
let record = null;
|
|
243
246
|
try { record = readRecord(root, attempt); }
|
|
244
247
|
catch (err) { if (!plan.cancel) throw err; }
|
|
@@ -10,39 +10,48 @@ const COMMIT = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/;
|
|
|
10
10
|
function decode(input) {
|
|
11
11
|
if (typeof input !== 'string') return { data: input, version: object(input) && ('commit' in input || 'acoes' in input) ? 2 : 1 };
|
|
12
12
|
const header = HEADER.exec(input);
|
|
13
|
-
if (!header) refuse('invalid_request');
|
|
13
|
+
if (!header) refuse('invalid_request', { field: 'result' });
|
|
14
14
|
try { return { data: JSON.parse(input.slice(header[0].length)), version: Number(header[1]) }; }
|
|
15
|
-
catch { return refuse('invalid_request'); }
|
|
15
|
+
catch { return refuse('invalid_request', { field: 'result' }); }
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const text = (x, limit) => typeof x === 'string' && x.length <= limit;
|
|
19
|
+
const notes = x => Array.isArray(x) && x.length <= 100 && x.every(note => text(note, 2000) && note.trim());
|
|
19
20
|
const question = (q, version) => object(q) && text(q.pergunta, 2000) && q.pergunta.trim() && Array.isArray(q.opcoes)
|
|
20
21
|
&& q.opcoes.length <= 20 && q.opcoes.every(o => text(o, 500)) && text(q.onde_parou, 2000) && (version === 1 || q.recomendada === undefined
|
|
21
22
|
|| (Number.isSafeInteger(q.recomendada) && q.recomendada >= 0 && q.recomendada < q.opcoes.length));
|
|
22
23
|
|
|
23
24
|
export function parseReturn(input) {
|
|
24
25
|
const { data, version } = decode(input);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const require = (valid, field) => { if (!valid) refuse('invalid_request', { field: `result.${field}` }); };
|
|
27
|
+
if (!object(data)) refuse('invalid_request', { field: 'result' });
|
|
28
|
+
require(singleLine(data.id, 80), 'id');
|
|
29
|
+
require(['concluido', 'parcial', 'bloqueado'].includes(data.status), 'status');
|
|
30
|
+
require(Array.isArray(data.arquivos_escritos), 'arquivos_escritos');
|
|
31
|
+
require(object(data.checkpoint_proposto), 'checkpoint_proposto');
|
|
32
|
+
require(version === 2 ? notes(data.lacunas) : Array.isArray(data.lacunas), 'lacunas');
|
|
33
|
+
require(version === 2 ? notes(data.avisos) : Array.isArray(data.avisos), 'avisos');
|
|
34
|
+
require(Array.isArray(data.perguntas_pendentes) && data.perguntas_pendentes.length <= 50
|
|
35
|
+
&& data.perguntas_pendentes.every(q => question(q, version))
|
|
36
|
+
&& (data.status !== 'concluido' || !data.perguntas_pendentes.length), 'perguntas_pendentes');
|
|
30
37
|
const files = new Map();
|
|
31
38
|
for (const entry of data.arquivos_escritos) {
|
|
32
|
-
|
|
39
|
+
require(object(entry) && parts(entry.path) && hex(entry.sha256) && !files.has(entry.path), 'arquivos_escritos');
|
|
33
40
|
files.set(entry.path, entry.sha256);
|
|
34
41
|
}
|
|
35
42
|
let commit = null;
|
|
36
43
|
let actions = [];
|
|
37
44
|
if (version === 2) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
require(typeof data.commit === 'string' && COMMIT.test(data.commit), 'commit');
|
|
46
|
+
require(Array.isArray(data.acoes) && data.acoes.length <= 500
|
|
47
|
+
&& data.acoes.every(a => object(a) && singleLine(a.id, 80) && ACTION_STATUS.has(a.status))
|
|
48
|
+
&& new Set(data.acoes.map(a => a.id)).size === data.acoes.length
|
|
49
|
+
&& (data.status !== 'concluido' || data.acoes.every(a => FINISHED.has(a.status))), 'acoes');
|
|
42
50
|
commit = data.commit;
|
|
43
51
|
actions = data.acoes.map(({ id, status }) => ({ id, status }));
|
|
44
52
|
}
|
|
45
53
|
const questions = data.perguntas_pendentes.map(({ pergunta, opcoes, onde_parou, recomendada }) =>
|
|
46
54
|
({ pergunta, opcoes, onde_parou, ...(recomendada === undefined ? {} : { recomendada }) }));
|
|
47
|
-
return { version, id: data.id, status: data.status, commit, actions, files, questions
|
|
55
|
+
return { version, id: data.id, status: data.status, commit, actions, files, questions,
|
|
56
|
+
gaps: version === 2 ? data.lacunas : [], workerWarnings: version === 2 ? data.avisos : [] };
|
|
48
57
|
}
|
|
@@ -51,7 +51,8 @@ const folders = record => ['output_folder', 'forward_folder'].map(key => record?
|
|
|
51
51
|
.map(value => value.replace(/\\/g, '/').replace(/^\.\/|\/+$/g, ''));
|
|
52
52
|
|
|
53
53
|
export function resolveCheckout(root, hubState, repository, requested) {
|
|
54
|
-
if (!validRepositoryId(repository)
|
|
54
|
+
if (!validRepositoryId(repository)) refuse('invalid_request', { field: 'repository' });
|
|
55
|
+
if (typeof requested !== 'string' || !isAbsolute(requested)) refuse('invalid_request', { field: 'checkout' });
|
|
55
56
|
const registered = registeredPath(root, repository);
|
|
56
57
|
// Only a satellite installation takes delegations; any other registered checkout is unavailable.
|
|
57
58
|
if (repository !== 'hub' && installation(registered)?.role !== 'satellite') refuse('repository_unavailable', { repository });
|
|
@@ -30,7 +30,7 @@ export function stat(path) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function checkout(root) {
|
|
33
|
-
if (typeof root !== 'string' || !isAbsolute(root)) refuse('invalid_request');
|
|
33
|
+
if (typeof root !== 'string' || !isAbsolute(root)) refuse('invalid_request', { field: 'checkout' });
|
|
34
34
|
const physical = realpathSync(root);
|
|
35
35
|
if (!lstatSync(physical).isDirectory()) refuse('unsafe_path');
|
|
36
36
|
return physical;
|
|
@@ -96,7 +96,7 @@ export function parseObject(data, code, path) {
|
|
|
96
96
|
const text = data.toString('utf8');
|
|
97
97
|
try { value = JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text); }
|
|
98
98
|
catch (err) { if (!(err instanceof SyntaxError)) throw err; }
|
|
99
|
-
if (!object(value)) refuse(code, { path });
|
|
99
|
+
if (!object(value)) refuse(code, code === 'invalid_request' ? { field: 'request' } : { path });
|
|
100
100
|
return value;
|
|
101
101
|
}
|
|
102
102
|
|