@sentropic/track 0.98.11-rc.7 → 0.98.11-rc.9
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/README.md +22 -0
- package/dist/adopt/apply.d.ts +29 -0
- package/dist/adopt/apply.d.ts.map +1 -0
- package/dist/adopt/apply.js +569 -0
- package/dist/adopt/apply.js.map +1 -0
- package/dist/adopt/plan.d.ts +63 -0
- package/dist/adopt/plan.d.ts.map +1 -0
- package/dist/adopt/plan.js +320 -0
- package/dist/adopt/plan.js.map +1 -0
- package/dist/cli/adopt.d.ts +10 -0
- package/dist/cli/adopt.d.ts.map +1 -0
- package/dist/cli/adopt.js +150 -0
- package/dist/cli/adopt.js.map +1 -0
- package/dist/cli/desync.d.ts +24 -4
- package/dist/cli/desync.d.ts.map +1 -1
- package/dist/cli/desync.js +86 -22
- package/dist/cli/desync.js.map +1 -1
- package/dist/cli/events-contains.d.ts +2 -0
- package/dist/cli/events-contains.d.ts.map +1 -1
- package/dist/cli/events-contains.js +1 -1
- package/dist/cli/events-contains.js.map +1 -1
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +223 -26
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/install-skills.d.ts +2 -0
- package/dist/cli/install-skills.d.ts.map +1 -1
- package/dist/cli/install-skills.js +74 -12
- package/dist/cli/install-skills.js.map +1 -1
- package/dist/cli/journal-reference.d.ts +44 -0
- package/dist/cli/journal-reference.d.ts.map +1 -0
- package/dist/cli/journal-reference.js +422 -0
- package/dist/cli/journal-reference.js.map +1 -0
- package/dist/cli/journal.d.ts +12 -0
- package/dist/cli/journal.d.ts.map +1 -0
- package/dist/cli/journal.js +178 -0
- package/dist/cli/journal.js.map +1 -0
- package/dist/events/types.d.ts +1 -1
- package/dist/events/types.d.ts.map +1 -1
- package/dist/events/types.js +3 -0
- package/dist/events/types.js.map +1 -1
- package/dist/focus-vendor/artifact/check.d.ts +73 -0
- package/dist/focus-vendor/artifact/check.d.ts.map +1 -0
- package/dist/focus-vendor/artifact/check.js +148 -0
- package/dist/focus-vendor/artifact/check.js.map +1 -0
- package/dist/focus-vendor/artifact/index.d.ts +3 -0
- package/dist/focus-vendor/artifact/index.d.ts.map +1 -0
- package/dist/focus-vendor/artifact/index.js +3 -0
- package/dist/focus-vendor/artifact/index.js.map +1 -0
- package/dist/focus-vendor/artifact/manifest.d.ts +74 -0
- package/dist/focus-vendor/artifact/manifest.d.ts.map +1 -0
- package/dist/focus-vendor/artifact/manifest.js +485 -0
- package/dist/focus-vendor/artifact/manifest.js.map +1 -0
- package/dist/focus-vendor/index.d.ts +1 -0
- package/dist/focus-vendor/index.js +1 -0
- package/dist/focus-vendor/index.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/journal/identity.d.ts +37 -0
- package/dist/journal/identity.d.ts.map +1 -0
- package/dist/journal/identity.js +134 -0
- package/dist/journal/identity.js.map +1 -0
- package/dist/journal/index-store.d.ts +56 -0
- package/dist/journal/index-store.d.ts.map +1 -0
- package/dist/journal/index-store.js +182 -0
- package/dist/journal/index-store.js.map +1 -0
- package/dist/journal/index.d.ts +4 -0
- package/dist/journal/index.d.ts.map +1 -0
- package/dist/journal/index.js +4 -0
- package/dist/journal/index.js.map +1 -0
- package/dist/journal/inscription.d.ts +28 -0
- package/dist/journal/inscription.d.ts.map +1 -0
- package/dist/journal/inscription.js +93 -0
- package/dist/journal/inscription.js.map +1 -0
- package/dist/model/decision.d.ts +4 -0
- package/dist/model/decision.d.ts.map +1 -1
- package/dist/model/decision.js +4 -0
- package/dist/model/decision.js.map +1 -1
- package/dist/read/commands.d.ts +11 -4
- package/dist/read/commands.d.ts.map +1 -1
- package/dist/read/commands.js +18 -13
- package/dist/read/commands.js.map +1 -1
- package/dist/read/contract.d.ts +16 -0
- package/dist/read/contract.d.ts.map +1 -1
- package/dist/read/contract.js +58 -12
- package/dist/read/contract.js.map +1 -1
- package/dist/report/owner-table-qualified.d.ts +125 -0
- package/dist/report/owner-table-qualified.d.ts.map +1 -0
- package/dist/report/owner-table-qualified.js +620 -0
- package/dist/report/owner-table-qualified.js.map +1 -0
- package/dist/report/owner-table-scope.d.ts +29 -0
- package/dist/report/owner-table-scope.d.ts.map +1 -0
- package/dist/report/owner-table-scope.js +63 -0
- package/dist/report/owner-table-scope.js.map +1 -0
- package/dist/report/owner-table-strings.d.ts +102 -0
- package/dist/report/owner-table-strings.d.ts.map +1 -0
- package/dist/report/owner-table-strings.js +253 -0
- package/dist/report/owner-table-strings.js.map +1 -0
- package/dist/report/owner-table.d.ts +31 -2
- package/dist/report/owner-table.d.ts.map +1 -1
- package/dist/report/owner-table.js +562 -118
- package/dist/report/owner-table.js.map +1 -1
- package/dist/state/fold.js +8 -0
- package/dist/state/fold.js.map +1 -1
- package/dist/state-home.d.ts +28 -0
- package/dist/state-home.d.ts.map +1 -0
- package/dist/state-home.js +63 -0
- package/dist/state-home.js.map +1 -0
- package/dist/track.d.ts +54 -6
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +398 -24
- package/dist/track.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,3 +112,25 @@ is unchanged for CLI callers. Stage/status labels follow `--lang <bcp47>` (exact
|
|
|
112
112
|
expectations in an additive event. It replaces all prior report metadata; `{}` clears only metadata.
|
|
113
113
|
See [the report skill](../h2a/skills/harness/track-report/SKILL.md) for the normalized vocabulary,
|
|
114
114
|
evidence rules, mandatory red proposals and blue decision dossiers. Legacy missing information is flagged.
|
|
115
|
+
|
|
116
|
+
## Adopting an existing journal (`track adopt`)
|
|
117
|
+
|
|
118
|
+
Bring a legacy journal to the point where `track report --owner-table --strict` exits 0 in three steps:
|
|
119
|
+
|
|
120
|
+
1. **Dry run first (read-only)**:
|
|
121
|
+
```bash
|
|
122
|
+
track adopt plan --out adoption-plan.json
|
|
123
|
+
```
|
|
124
|
+
Inspects the journal through the qualified reader and prints a JSON plan listing every gap as either `mechanical` (derivable from the journal alone) or `to-decide` (carries a human question and `resolution: null`). Writes nothing to the journal folder or state home; `--out` must point outside the journal folder.
|
|
125
|
+
2. **Resolve**: edit `adoption-plan.json` to supply a `resolution` value for every `to-decide` entry (row attachment, options and recommendation for an optionless decision, dossier link, blocked cause, or clean rewrite of a masked text).
|
|
126
|
+
3. **Apply (idempotent)**:
|
|
127
|
+
```bash
|
|
128
|
+
track adopt apply adoption-plan.json [--writer-token-file <path>]
|
|
129
|
+
```
|
|
130
|
+
Re-derives the plan to ensure the journal has not drifted, stamps every write with an entry-derived idempotency key (re-running writes nothing and reports `already applied`), and prints one line per entry (`applied`, `already applied`, or `refused: <reason>`), exiting 1 if any entry is refused. On an exclusive journal, application is refused unless the holder presents its writer token.
|
|
131
|
+
|
|
132
|
+
**What `track adopt` never does:**
|
|
133
|
+
|
|
134
|
+
- Never settles, withdraws, or archives a decision (the plan format has no such action; use `track decision select` once the owner answers).
|
|
135
|
+
- Never invents owner text, causes, options, recommendations, or dossier links (unresolved `to-decide` entries are refused by name).
|
|
136
|
+
- Never inscribes a reconstructed demand with `capture` provenance — reconstructed demands use the ordinary `cli` transport and are rendered `(non capté)`, never quoted.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ActorId } from '../events/types.js';
|
|
2
|
+
import { type BuildAdoptionPlanOptions } from './plan.js';
|
|
3
|
+
export interface AdoptionEntryResult {
|
|
4
|
+
id: string;
|
|
5
|
+
status: 'applied' | 'already applied' | 'refused';
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ApplyAdoptionResult {
|
|
9
|
+
planHash: string;
|
|
10
|
+
results: AdoptionEntryResult[];
|
|
11
|
+
applied: number;
|
|
12
|
+
alreadyApplied: number;
|
|
13
|
+
refused: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ApplyAdoptionOptions extends BuildAdoptionPlanOptions {
|
|
16
|
+
by?: ActorId;
|
|
17
|
+
writerToken?: string;
|
|
18
|
+
writerTokenFile?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Apply an adoption plan to the journal at `eventsPath`.
|
|
22
|
+
* - Enforces exclusive write policy if present.
|
|
23
|
+
* - Re-derives the plan from the journal and refuses a stale/mismatched plan.
|
|
24
|
+
* - Idempotent: entries whose idempotency key is already in the journal are skipped as `already applied`.
|
|
25
|
+
* - Refuses every unresolved `to-decide` entry by name and every unsupported/settling action.
|
|
26
|
+
*/
|
|
27
|
+
export declare function applyAdoptionPlan(eventsPath: string, rawPlan: unknown, options?: ApplyAdoptionOptions): ApplyAdoptionResult;
|
|
28
|
+
export declare function formatApplyResultLines(result: ApplyAdoptionResult): string;
|
|
29
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/adopt/apply.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAA0B,MAAM,oBAAoB,CAAA;AAQzE,OAAO,EAOL,KAAK,wBAAwB,EAC9B,MAAM,WAAW,CAAA;AAIlB,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,SAAS,GAAG,iBAAiB,GAAG,SAAS,CAAA;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,mBAAmB,EAAE,CAAA;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACpE,EAAE,CAAC,EAAE,OAAO,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAgjBD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAuGrB;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAK1E"}
|
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import { createHash, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { EventStore } from '../events/store.js';
|
|
5
|
+
import { DomainError } from '../model/item.js';
|
|
6
|
+
import { hasTextGateViolation, projectOwnerTable } from '../report/owner-table.js';
|
|
7
|
+
import { resolveOwnerTablePolicyFile } from '../state-home.js';
|
|
8
|
+
import { fold } from '../state/fold.js';
|
|
9
|
+
import { Track } from '../track.js';
|
|
10
|
+
import { adoptionEntryClientToken, ALLOWED_ADOPTION_ACTIONS, buildAdoptionPlan, computeAdoptionPlanHash, } from './plan.js';
|
|
11
|
+
const CLI_PROV = { transport: 'cli', proposed: false, auth: 'local-user' };
|
|
12
|
+
function sha256Hex(input) {
|
|
13
|
+
return createHash('sha256').update(input, 'utf8').digest('hex');
|
|
14
|
+
}
|
|
15
|
+
function constantTimeHexEqual(a, b) {
|
|
16
|
+
const normA = a.replace(/^sha256:/iu, '').trim().toLowerCase();
|
|
17
|
+
const normB = b.replace(/^sha256:/iu, '').trim().toLowerCase();
|
|
18
|
+
if (normA.length === 0 || normA.length !== normB.length)
|
|
19
|
+
return false;
|
|
20
|
+
return timingSafeEqual(Buffer.from(normA, 'utf8'), Buffer.from(normB, 'utf8'));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Enforce exclusive write policy when `write-policy.json` beside `events.jsonl` declares
|
|
24
|
+
* `mode: "exclusive"`. Refuses unless the holder presents the matching writer token.
|
|
25
|
+
*/
|
|
26
|
+
function assertWritePolicyAllows(eventsPath, options) {
|
|
27
|
+
const policyPath = join(dirname(eventsPath), 'write-policy.json');
|
|
28
|
+
if (!existsSync(policyPath))
|
|
29
|
+
return;
|
|
30
|
+
let parsed;
|
|
31
|
+
try {
|
|
32
|
+
parsed = JSON.parse(readFileSync(policyPath, 'utf8'));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throw new DomainError(`adopt apply: malformed write-policy.json at ${policyPath}`);
|
|
36
|
+
}
|
|
37
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
|
|
38
|
+
return;
|
|
39
|
+
const policy = parsed;
|
|
40
|
+
if (policy['mode'] !== 'exclusive')
|
|
41
|
+
return;
|
|
42
|
+
const holder = typeof policy['holder'] === 'string' && policy['holder'].trim() !== '' ? policy['holder'] : 'unknown';
|
|
43
|
+
const epoch = typeof policy['epoch'] === 'number' ? policy['epoch'] : 0;
|
|
44
|
+
const expectedDigest = typeof policy['tokenHash'] === 'string'
|
|
45
|
+
? policy['tokenHash']
|
|
46
|
+
: typeof policy['tokenDigest'] === 'string'
|
|
47
|
+
? policy['tokenDigest']
|
|
48
|
+
: undefined;
|
|
49
|
+
let presented = options.writerToken;
|
|
50
|
+
if (presented === undefined && options.writerTokenFile !== undefined) {
|
|
51
|
+
if (!existsSync(options.writerTokenFile)) {
|
|
52
|
+
throw new DomainError(`adopt apply: refused — exclusive journal (holder: ${holder}, epoch: ${epoch}); token file not found`);
|
|
53
|
+
}
|
|
54
|
+
presented = readFileSync(options.writerTokenFile, 'utf8').trim();
|
|
55
|
+
}
|
|
56
|
+
if (presented === undefined) {
|
|
57
|
+
presented = process.env['TRACK_WRITER_TOKEN'];
|
|
58
|
+
}
|
|
59
|
+
if (expectedDigest === undefined ||
|
|
60
|
+
presented === undefined ||
|
|
61
|
+
presented.trim() === '' ||
|
|
62
|
+
!constantTimeHexEqual(sha256Hex(presented.trim()), expectedDigest)) {
|
|
63
|
+
throw new DomainError(`adopt apply: refused — journal is in exclusive write mode (holder: ${holder}, epoch: ${epoch}); only the holder may apply adoption plans`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function tokenDedupe(key) {
|
|
67
|
+
return (_inputs, existing) => {
|
|
68
|
+
const matched = existing.filter((e) => e.clientToken === key);
|
|
69
|
+
return matched.length > 0 ? matched : null;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function assertPlanObject(raw) {
|
|
73
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
74
|
+
throw new DomainError('adopt apply: plan file must be a JSON object');
|
|
75
|
+
}
|
|
76
|
+
const obj = raw;
|
|
77
|
+
if (obj['version'] !== 1) {
|
|
78
|
+
throw new DomainError(`adopt apply: unsupported plan version "${String(obj['version'])}"`);
|
|
79
|
+
}
|
|
80
|
+
if (typeof obj['planHash'] !== 'string' || obj['planHash'].trim() === '') {
|
|
81
|
+
throw new DomainError('adopt apply: plan must carry a non-empty planHash');
|
|
82
|
+
}
|
|
83
|
+
if (!Array.isArray(obj['entries'])) {
|
|
84
|
+
throw new DomainError('adopt apply: plan must carry an entries array');
|
|
85
|
+
}
|
|
86
|
+
for (const e of obj['entries']) {
|
|
87
|
+
if (typeof e !== 'object' || e === null || Array.isArray(e)) {
|
|
88
|
+
throw new DomainError('adopt apply: each plan entry must be an object');
|
|
89
|
+
}
|
|
90
|
+
const rec = e;
|
|
91
|
+
if (typeof rec['id'] !== 'string' || rec['id'].trim() === '') {
|
|
92
|
+
throw new DomainError('adopt apply: each plan entry must carry a non-empty id');
|
|
93
|
+
}
|
|
94
|
+
if (typeof rec['action'] !== 'string' || rec['action'].trim() === '') {
|
|
95
|
+
throw new DomainError(`adopt apply: entry "${rec['id']}" must carry an action`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return raw;
|
|
99
|
+
}
|
|
100
|
+
function entryStructuralKey(entry) {
|
|
101
|
+
return JSON.stringify({
|
|
102
|
+
id: entry.id,
|
|
103
|
+
class: entry.class,
|
|
104
|
+
kind: entry.kind,
|
|
105
|
+
action: entry.action,
|
|
106
|
+
element: entry.element,
|
|
107
|
+
proposedWrite: entry.proposedWrite,
|
|
108
|
+
...(entry.pendingOn !== undefined ? { pendingOn: entry.pendingOn } : {}),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function phaseOf(entry) {
|
|
112
|
+
if (entry.action === 'number-demand' || entry.action === 'reconstruct-demand' || entry.action === 'raise-initial-demand') {
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
115
|
+
if (entry.action === 'instruct-decision')
|
|
116
|
+
return 2;
|
|
117
|
+
if (entry.action === 'number-decision')
|
|
118
|
+
return 3;
|
|
119
|
+
return 4;
|
|
120
|
+
}
|
|
121
|
+
function findItemBackingRow(state, rowNumber, rowId) {
|
|
122
|
+
if (rowId !== undefined) {
|
|
123
|
+
const directItem = state.items.get(rowId);
|
|
124
|
+
if (directItem !== undefined)
|
|
125
|
+
return directItem;
|
|
126
|
+
const demand = state.demands.get(rowId);
|
|
127
|
+
if (demand !== undefined && (demand.itemIds?.length ?? 0) === 1) {
|
|
128
|
+
return state.items.get(demand.itemIds[0]);
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
if (rowNumber !== undefined) {
|
|
133
|
+
for (const demand of state.demands.values()) {
|
|
134
|
+
if (demand.ownerNumber === rowNumber) {
|
|
135
|
+
if ((demand.itemIds?.length ?? 0) === 1) {
|
|
136
|
+
return state.items.get(demand.itemIds[0]);
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const item of state.items.values()) {
|
|
142
|
+
if (item.report?.ownerNumber === rowNumber)
|
|
143
|
+
return item;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
function optionLetterToIndex(letter) {
|
|
149
|
+
let idx = 0;
|
|
150
|
+
for (const ch of letter.toUpperCase()) {
|
|
151
|
+
const code = ch.charCodeAt(0);
|
|
152
|
+
if (code < 65 || code > 90)
|
|
153
|
+
return -1;
|
|
154
|
+
idx = idx * 26 + (code - 64);
|
|
155
|
+
}
|
|
156
|
+
return idx - 1;
|
|
157
|
+
}
|
|
158
|
+
function applySingleEntry(entry, key, track, store, eventsPath, options) {
|
|
159
|
+
if (!ALLOWED_ADOPTION_ACTIONS.has(entry.action)) {
|
|
160
|
+
return {
|
|
161
|
+
id: entry.id,
|
|
162
|
+
status: 'refused',
|
|
163
|
+
reason: `unsupported action "${String(entry.action)}" (this tool never settles, withdraws or archives decisions)`,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (entry.pendingOn === 'lot-2') {
|
|
167
|
+
return {
|
|
168
|
+
id: entry.id,
|
|
169
|
+
status: 'refused',
|
|
170
|
+
reason: 'pending on lot 2 (re-run `track adopt plan` now that lot 2 is available)',
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const res = entry.resolution;
|
|
174
|
+
if (entry.kind === 'to-decide' && (res === undefined || res === null || typeof res !== 'object' || Array.isArray(res))) {
|
|
175
|
+
return {
|
|
176
|
+
id: entry.id,
|
|
177
|
+
status: 'refused',
|
|
178
|
+
reason: `unresolved to-decide entry "${entry.id}"`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const dedupe = tokenDedupe(key);
|
|
182
|
+
try {
|
|
183
|
+
switch (entry.action) {
|
|
184
|
+
case 'number-demand': {
|
|
185
|
+
const demandId = String(entry.proposedWrite['demandId'] ?? entry.element.id ?? '');
|
|
186
|
+
const num = Number(entry.proposedWrite['number']);
|
|
187
|
+
track.withClientToken(key, () => track.numberDemand(demandId, num), { dedupe });
|
|
188
|
+
return { id: entry.id, status: 'applied' };
|
|
189
|
+
}
|
|
190
|
+
case 'reconstruct-demand': {
|
|
191
|
+
const itemId = String(entry.proposedWrite['itemId'] ?? entry.element.id ?? '');
|
|
192
|
+
const num = Number(entry.proposedWrite['number']);
|
|
193
|
+
const text = String(entry.proposedWrite['text'] ?? '');
|
|
194
|
+
const rawType = entry.proposedWrite['type'];
|
|
195
|
+
const type = rawType === 'feature' || rawType === 'defect' || rawType === 'chore' ? rawType : undefined;
|
|
196
|
+
track.withClientToken(key, () => track.adoptItemAsDemand(itemId, { number: num, text, ...(type !== undefined ? { type } : {}) }), { dedupe });
|
|
197
|
+
return { id: entry.id, status: 'applied' };
|
|
198
|
+
}
|
|
199
|
+
case 'raise-initial-demand': {
|
|
200
|
+
const text = typeof res['text'] === 'string' ? res['text'].trim() : '';
|
|
201
|
+
const workspace = typeof res['workspace'] === 'string' ? res['workspace'].trim() : '';
|
|
202
|
+
if (text === '' || workspace === '') {
|
|
203
|
+
return { id: entry.id, status: 'refused', reason: 'resolution requires non-empty "text" and "workspace"' };
|
|
204
|
+
}
|
|
205
|
+
const rawType = res['type'];
|
|
206
|
+
const type = rawType === 'defect' || rawType === 'chore' || rawType === 'feature' ? rawType : 'feature';
|
|
207
|
+
const events = store.readAll();
|
|
208
|
+
const view = projectOwnerTable(fold(events), events);
|
|
209
|
+
const nums = [...view.registeredNumbers, ...view.archivedNumbers];
|
|
210
|
+
const nextNum = (nums.length > 0 ? Math.max(...nums) : 0) + 1;
|
|
211
|
+
const demandId = track.withClientToken(key, () => track.raiseDemand({
|
|
212
|
+
type,
|
|
213
|
+
workspace,
|
|
214
|
+
raw: { text },
|
|
215
|
+
source: { kind: 'human' },
|
|
216
|
+
}), { dedupe });
|
|
217
|
+
track.withClientToken(`${key}:number`, () => track.numberDemand(demandId, nextNum), {
|
|
218
|
+
dedupe: tokenDedupe(`${key}:number`),
|
|
219
|
+
});
|
|
220
|
+
return { id: entry.id, status: 'applied' };
|
|
221
|
+
}
|
|
222
|
+
case 'number-decision': {
|
|
223
|
+
const decisionId = String(entry.proposedWrite['decisionId'] ?? entry.element.id ?? '');
|
|
224
|
+
track.withClientToken(key, () => track.numberDecision(decisionId), { dedupe });
|
|
225
|
+
return { id: entry.id, status: 'applied' };
|
|
226
|
+
}
|
|
227
|
+
case 'instruct-decision': {
|
|
228
|
+
const decisionId = String(entry.proposedWrite['decisionId'] ?? entry.element.id ?? '');
|
|
229
|
+
const current = track.state().decisions.get(decisionId)?.dossier;
|
|
230
|
+
if (current === undefined) {
|
|
231
|
+
return { id: entry.id, status: 'refused', reason: `unknown decision ${decisionId}` };
|
|
232
|
+
}
|
|
233
|
+
const rawOptions = res['options'];
|
|
234
|
+
const rawRec = res['recommendation'];
|
|
235
|
+
if (!Array.isArray(rawOptions) || rawOptions.length < 2) {
|
|
236
|
+
return { id: entry.id, status: 'refused', reason: 'resolution requires at least 2 options' };
|
|
237
|
+
}
|
|
238
|
+
if (typeof rawRec !== 'object' ||
|
|
239
|
+
rawRec === null ||
|
|
240
|
+
typeof rawRec['optionId'] !== 'string' ||
|
|
241
|
+
typeof rawRec['rationale'] !== 'string') {
|
|
242
|
+
return {
|
|
243
|
+
id: entry.id,
|
|
244
|
+
status: 'refused',
|
|
245
|
+
reason: 'resolution requires recommendation { optionId, rationale }',
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const context = typeof res['context'] === 'string' ? res['context'] : current.context;
|
|
249
|
+
track.withClientToken(key, () => track.reviseDossier(decisionId, {
|
|
250
|
+
...current,
|
|
251
|
+
context,
|
|
252
|
+
options: rawOptions,
|
|
253
|
+
recommendation: {
|
|
254
|
+
optionId: rawRec['optionId'],
|
|
255
|
+
rationale: rawRec['rationale'],
|
|
256
|
+
},
|
|
257
|
+
}), { dedupe });
|
|
258
|
+
const instructed = track.state().decisions.get(decisionId);
|
|
259
|
+
if (instructed !== undefined && instructed.ownerNumber === undefined && !/^\s*OWNER\s+GATE\b/iu.test(instructed.title)) {
|
|
260
|
+
track.withClientToken(`${key}:number`, () => track.numberDecision(decisionId), {
|
|
261
|
+
dedupe: tokenDedupe(`${key}:number`),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return { id: entry.id, status: 'applied' };
|
|
265
|
+
}
|
|
266
|
+
case 'attach-dossier': {
|
|
267
|
+
const decisionId = String(entry.proposedWrite['decisionId'] ?? entry.element.id ?? '');
|
|
268
|
+
const dossierLink = typeof res['dossierLink'] === 'string' ? res['dossierLink'].trim() : '';
|
|
269
|
+
if (dossierLink === '') {
|
|
270
|
+
return { id: entry.id, status: 'refused', reason: 'resolution requires a non-empty "dossierLink"' };
|
|
271
|
+
}
|
|
272
|
+
const label = typeof res['label'] === 'string' && res['label'].trim() !== '' ? res['label'].trim() : undefined;
|
|
273
|
+
track.addDecisionArtifact(decisionId, {
|
|
274
|
+
kind: 'rendered-view',
|
|
275
|
+
viewRef: dossierLink,
|
|
276
|
+
...(label !== undefined ? { label } : {}),
|
|
277
|
+
}, key);
|
|
278
|
+
return { id: entry.id, status: 'applied' };
|
|
279
|
+
}
|
|
280
|
+
case 'attach-decision': {
|
|
281
|
+
const decisionId = String(entry.proposedWrite['decisionId'] ?? entry.element.id ?? '');
|
|
282
|
+
const rowNumber = typeof res['rowNumber'] === 'number' && Number.isInteger(res['rowNumber']) && res['rowNumber'] >= 1
|
|
283
|
+
? res['rowNumber']
|
|
284
|
+
: undefined;
|
|
285
|
+
const rowId = typeof res['rowId'] === 'string' && res['rowId'].trim() !== '' ? res['rowId'].trim() : undefined;
|
|
286
|
+
if (rowNumber === undefined && rowId === undefined) {
|
|
287
|
+
return {
|
|
288
|
+
id: entry.id,
|
|
289
|
+
status: 'refused',
|
|
290
|
+
reason: 'resolution requires positive integer "rowNumber" or non-empty "rowId"',
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
const currentEvents = store.readAll();
|
|
294
|
+
const currentState = fold(currentEvents);
|
|
295
|
+
const targetItem = findItemBackingRow(currentState, rowNumber, rowId);
|
|
296
|
+
if (targetItem === undefined) {
|
|
297
|
+
return {
|
|
298
|
+
id: entry.id,
|
|
299
|
+
status: 'refused',
|
|
300
|
+
reason: `target row ${rowNumber !== undefined ? `#${rowNumber}` : rowId} has no backing item to carry decisionRefs; choose an item-backed row`,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const view = projectOwnerTable(currentState, currentEvents, options);
|
|
304
|
+
const decView = view.decisions.find((d) => d.id === decisionId);
|
|
305
|
+
if (decView === undefined || decView.ref.trim() === '') {
|
|
306
|
+
return {
|
|
307
|
+
id: entry.id,
|
|
308
|
+
status: 'refused',
|
|
309
|
+
reason: `decision ${decisionId} has no display reference to attach`,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
const prevReport = targetItem.report ?? {};
|
|
313
|
+
const prevRefs = prevReport.decisionRefs ?? [];
|
|
314
|
+
const nextRefs = prevRefs.includes(decView.ref) ? prevRefs : [...prevRefs, decView.ref];
|
|
315
|
+
track.withClientToken(key, () => track.setReportStatus(targetItem.id, { ...prevReport, decisionRefs: nextRefs }), { dedupe });
|
|
316
|
+
return { id: entry.id, status: 'applied' };
|
|
317
|
+
}
|
|
318
|
+
case 'set-blocked-cause': {
|
|
319
|
+
const cause = typeof res['cause'] === 'string' ? res['cause'].trim() : '';
|
|
320
|
+
if (cause === '') {
|
|
321
|
+
return { id: entry.id, status: 'refused', reason: 'resolution requires a non-empty "cause"' };
|
|
322
|
+
}
|
|
323
|
+
const rowId = String(entry.proposedWrite['rowId'] ?? entry.element.id ?? '');
|
|
324
|
+
const currentState = track.state();
|
|
325
|
+
const targetItem = findItemBackingRow(currentState, undefined, rowId);
|
|
326
|
+
if (targetItem === undefined) {
|
|
327
|
+
return { id: entry.id, status: 'refused', reason: `row ${rowId} has no backing item to record cause` };
|
|
328
|
+
}
|
|
329
|
+
const prevReport = targetItem.report ?? {};
|
|
330
|
+
track.withClientToken(key, () => track.setReportStatus(targetItem.id, { ...prevReport, nextAction: cause }), { dedupe });
|
|
331
|
+
return { id: entry.id, status: 'applied' };
|
|
332
|
+
}
|
|
333
|
+
case 'rewrite-masked-text': {
|
|
334
|
+
const text = typeof res['text'] === 'string' ? res['text'].trim() : '';
|
|
335
|
+
if (text === '') {
|
|
336
|
+
return { id: entry.id, status: 'refused', reason: 'resolution requires a non-empty "text"' };
|
|
337
|
+
}
|
|
338
|
+
const resolvedPolicy = resolveOwnerTablePolicyFile({
|
|
339
|
+
flagPolicyPath: options.policyPath,
|
|
340
|
+
trackDir: dirname(eventsPath),
|
|
341
|
+
});
|
|
342
|
+
if (hasTextGateViolation(text, {
|
|
343
|
+
...(options.policy !== undefined ? { policy: options.policy } : {}),
|
|
344
|
+
...(resolvedPolicy.defaultPolicyPath !== undefined
|
|
345
|
+
? { defaultPolicyPath: resolvedPolicy.defaultPolicyPath }
|
|
346
|
+
: {}),
|
|
347
|
+
statePolicyPath: resolvedPolicy.statePolicyPath,
|
|
348
|
+
...(resolvedPolicy.policyPath !== undefined ? { policyPath: resolvedPolicy.policyPath } : {}),
|
|
349
|
+
})) {
|
|
350
|
+
return { id: entry.id, status: 'refused', reason: 'rewritten text still fails a text gate' };
|
|
351
|
+
}
|
|
352
|
+
const targetKind = String(entry.proposedWrite['targetKind'] ?? entry.element.kind);
|
|
353
|
+
const targetId = String(entry.proposedWrite['id'] ?? entry.element.id ?? '');
|
|
354
|
+
const currentState = track.state();
|
|
355
|
+
if (targetKind === 'row') {
|
|
356
|
+
const cell = String(entry.proposedWrite['cell'] ?? entry.element.cell ?? 'request');
|
|
357
|
+
const demand = currentState.demands.get(targetId);
|
|
358
|
+
if (cell === 'request' && demand !== undefined) {
|
|
359
|
+
track.withClientToken(key, () => track.updateDemandOwnerSummary(demand.id, { summary: text }), { dedupe });
|
|
360
|
+
return { id: entry.id, status: 'applied' };
|
|
361
|
+
}
|
|
362
|
+
const item = findItemBackingRow(currentState, undefined, targetId);
|
|
363
|
+
if (item === undefined) {
|
|
364
|
+
return { id: entry.id, status: 'refused', reason: `unknown row item ${targetId}` };
|
|
365
|
+
}
|
|
366
|
+
const prevReport = item.report ?? {};
|
|
367
|
+
if (cell === 'request') {
|
|
368
|
+
track.withClientToken(key, () => track.setReportStatus(item.id, { ...prevReport, ownerSummary: text }), { dedupe });
|
|
369
|
+
return { id: entry.id, status: 'applied' };
|
|
370
|
+
}
|
|
371
|
+
if (cell === 'done') {
|
|
372
|
+
track.withClientToken(key, () => track.setReportStatus(item.id, { ...prevReport, facts: text }), { dedupe });
|
|
373
|
+
return { id: entry.id, status: 'applied' };
|
|
374
|
+
}
|
|
375
|
+
if (cell === 'todo') {
|
|
376
|
+
track.withClientToken(key, () => track.setReportStatus(item.id, { ...prevReport, nextAction: text }), { dedupe });
|
|
377
|
+
return { id: entry.id, status: 'applied' };
|
|
378
|
+
}
|
|
379
|
+
return { id: entry.id, status: 'refused', reason: `cannot rewrite masked cell "${cell}" automatically` };
|
|
380
|
+
}
|
|
381
|
+
if (targetKind === 'decision') {
|
|
382
|
+
const field = String(entry.proposedWrite['field'] ?? entry.element.field ?? '');
|
|
383
|
+
const dec = currentState.decisions.get(targetId);
|
|
384
|
+
if (dec === undefined) {
|
|
385
|
+
return { id: entry.id, status: 'refused', reason: `unknown decision ${targetId}` };
|
|
386
|
+
}
|
|
387
|
+
if (field === 'recommendation' && dec.dossier.recommendation !== undefined) {
|
|
388
|
+
track.withClientToken(key, () => track.reviseDossier(dec.id, {
|
|
389
|
+
...dec.dossier,
|
|
390
|
+
recommendation: { ...dec.dossier.recommendation, rationale: text },
|
|
391
|
+
}), { dedupe });
|
|
392
|
+
return { id: entry.id, status: 'applied' };
|
|
393
|
+
}
|
|
394
|
+
if (field === 'dossierLink') {
|
|
395
|
+
const artifacts = (dec.dossier.artifacts ?? []).map((a) => a.kind === 'rendered-view' ? { ...a, viewRef: text } : a);
|
|
396
|
+
track.withClientToken(key, () => track.reviseDossier(dec.id, { ...dec.dossier, artifacts }), { dedupe });
|
|
397
|
+
return { id: entry.id, status: 'applied' };
|
|
398
|
+
}
|
|
399
|
+
if (field.startsWith('option:')) {
|
|
400
|
+
const idx = optionLetterToIndex(field.slice('option:'.length));
|
|
401
|
+
const targetOpt = idx >= 0 ? dec.dossier.options[idx] : undefined;
|
|
402
|
+
if (targetOpt === undefined) {
|
|
403
|
+
return { id: entry.id, status: 'refused', reason: `unknown option ${field} on decision ${targetId}` };
|
|
404
|
+
}
|
|
405
|
+
const nextLabel = typeof res['title'] === 'string' && res['title'].trim() !== '' ? res['title'].trim() : targetOpt.title;
|
|
406
|
+
const nextSummary = typeof res['summary'] === 'string' && res['summary'].trim() !== '' ? res['summary'].trim() : text;
|
|
407
|
+
const nextOptions = dec.dossier.options.map((o, i) => i === idx ? { ...o, title: nextLabel, summary: nextSummary } : o);
|
|
408
|
+
track.withClientToken(key, () => track.reviseDossier(dec.id, { ...dec.dossier, options: nextOptions }), { dedupe });
|
|
409
|
+
return { id: entry.id, status: 'applied' };
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
id: entry.id,
|
|
413
|
+
status: 'refused',
|
|
414
|
+
reason: `decision field "${field}" is immutable and cannot be rewritten by adopt`,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
return { id: entry.id, status: 'refused', reason: `unsupported rewrite target kind "${targetKind}"` };
|
|
418
|
+
}
|
|
419
|
+
case 'resolve-row-gap': {
|
|
420
|
+
const check = String(entry.proposedWrite['check'] ?? '');
|
|
421
|
+
const rowId = String(entry.proposedWrite['rowId'] ?? entry.element.id ?? '');
|
|
422
|
+
const currentState = track.state();
|
|
423
|
+
if (check === 'row.withdrawn-no-reason') {
|
|
424
|
+
const reason = typeof res['reason'] === 'string' ? res['reason'].trim() : '';
|
|
425
|
+
if (reason === '') {
|
|
426
|
+
return { id: entry.id, status: 'refused', reason: 'resolution requires a non-empty "reason"' };
|
|
427
|
+
}
|
|
428
|
+
const item = findItemBackingRow(currentState, undefined, rowId);
|
|
429
|
+
if (item === undefined) {
|
|
430
|
+
return { id: entry.id, status: 'refused', reason: `row ${rowId} has no backing item` };
|
|
431
|
+
}
|
|
432
|
+
track.withClientToken(key, () => track.setReportStatus(item.id, { ...(item.report ?? {}), facts: reason }), { dedupe });
|
|
433
|
+
return { id: entry.id, status: 'applied' };
|
|
434
|
+
}
|
|
435
|
+
if (check === 'row.request-missing') {
|
|
436
|
+
const text = typeof res['text'] === 'string' ? res['text'].trim() : '';
|
|
437
|
+
if (text === '') {
|
|
438
|
+
return { id: entry.id, status: 'refused', reason: 'resolution requires a non-empty "text"' };
|
|
439
|
+
}
|
|
440
|
+
const demand = currentState.demands.get(rowId);
|
|
441
|
+
if (demand !== undefined) {
|
|
442
|
+
track.withClientToken(key, () => track.updateDemandOwnerSummary(demand.id, { summary: text }), { dedupe });
|
|
443
|
+
return { id: entry.id, status: 'applied' };
|
|
444
|
+
}
|
|
445
|
+
const item = findItemBackingRow(currentState, undefined, rowId);
|
|
446
|
+
if (item === undefined) {
|
|
447
|
+
return { id: entry.id, status: 'refused', reason: `row ${rowId} has no backing item` };
|
|
448
|
+
}
|
|
449
|
+
track.withClientToken(key, () => track.setReportStatus(item.id, { ...(item.report ?? {}), ownerSummary: text }), { dedupe });
|
|
450
|
+
return { id: entry.id, status: 'applied' };
|
|
451
|
+
}
|
|
452
|
+
return { id: entry.id, status: 'refused', reason: `row gap "${check}" requires manual remediation` };
|
|
453
|
+
}
|
|
454
|
+
case 'resolve-desync':
|
|
455
|
+
return {
|
|
456
|
+
id: entry.id,
|
|
457
|
+
status: 'refused',
|
|
458
|
+
reason: 'document desynchronisation must be resolved on disk outside Track',
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
catch (error) {
|
|
463
|
+
return {
|
|
464
|
+
id: entry.id,
|
|
465
|
+
status: 'refused',
|
|
466
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Apply an adoption plan to the journal at `eventsPath`.
|
|
472
|
+
* - Enforces exclusive write policy if present.
|
|
473
|
+
* - Re-derives the plan from the journal and refuses a stale/mismatched plan.
|
|
474
|
+
* - Idempotent: entries whose idempotency key is already in the journal are skipped as `already applied`.
|
|
475
|
+
* - Refuses every unresolved `to-decide` entry by name and every unsupported/settling action.
|
|
476
|
+
*/
|
|
477
|
+
export function applyAdoptionPlan(eventsPath, rawPlan, options = {}) {
|
|
478
|
+
const plan = assertPlanObject(rawPlan);
|
|
479
|
+
assertWritePolicyAllows(eventsPath, options);
|
|
480
|
+
const expectedHash = computeAdoptionPlanHash(plan.entries);
|
|
481
|
+
if (plan.planHash !== expectedHash) {
|
|
482
|
+
throw new DomainError(`adopt apply: planHash mismatch — declared "${plan.planHash}" != computed "${expectedHash}"`);
|
|
483
|
+
}
|
|
484
|
+
const store = new EventStore(eventsPath);
|
|
485
|
+
const existingEvents = store.readAll();
|
|
486
|
+
const existingTokens = new Set(existingEvents.map((e) => e.clientToken).filter((t) => typeof t === 'string'));
|
|
487
|
+
const alreadyAppliedIds = new Set();
|
|
488
|
+
const remainingEntries = [];
|
|
489
|
+
for (const entry of plan.entries) {
|
|
490
|
+
const key = adoptionEntryClientToken(plan.planHash, entry.id);
|
|
491
|
+
if (existingTokens.has(key)) {
|
|
492
|
+
alreadyAppliedIds.add(entry.id);
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
remainingEntries.push(entry);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// Full idempotent replay: every entry was already applied — write nothing.
|
|
499
|
+
if (remainingEntries.length === 0) {
|
|
500
|
+
const results = plan.entries.map((e) => ({
|
|
501
|
+
id: e.id,
|
|
502
|
+
status: 'already applied',
|
|
503
|
+
}));
|
|
504
|
+
return {
|
|
505
|
+
planHash: plan.planHash,
|
|
506
|
+
results,
|
|
507
|
+
applied: 0,
|
|
508
|
+
alreadyApplied: results.length,
|
|
509
|
+
refused: 0,
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
// Re-derive the plan from the current journal and ensure the plan still matches it.
|
|
513
|
+
const freshPlan = buildAdoptionPlan(eventsPath, options);
|
|
514
|
+
const hasUnsupportedAction = plan.entries.some((e) => !ALLOWED_ADOPTION_ACTIONS.has(e.action));
|
|
515
|
+
if (!hasUnsupportedAction) {
|
|
516
|
+
if (alreadyAppliedIds.size === 0) {
|
|
517
|
+
if (freshPlan.planHash !== plan.planHash ||
|
|
518
|
+
(plan.baseline !== undefined &&
|
|
519
|
+
(plan.baseline.streamLength !== freshPlan.baseline.streamLength ||
|
|
520
|
+
plan.baseline.lastContentHash !== freshPlan.baseline.lastContentHash))) {
|
|
521
|
+
throw new DomainError('adopt apply: plan no longer matches the journal (re-run `track adopt plan`)');
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
const freshById = new Map(freshPlan.entries.map((e) => [e.id, e]));
|
|
526
|
+
for (const rem of remainingEntries) {
|
|
527
|
+
const fresh = freshById.get(rem.id);
|
|
528
|
+
if (fresh === undefined || entryStructuralKey(fresh) !== entryStructuralKey(rem)) {
|
|
529
|
+
throw new DomainError(`adopt apply: entry "${rem.id}" no longer matches the journal (re-run \`track adopt plan\`)`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
const track = new Track(store, {
|
|
535
|
+
by: options.by ?? 'human:adopt',
|
|
536
|
+
prov: CLI_PROV,
|
|
537
|
+
...(options.now !== undefined ? { now: () => options.now } : {}),
|
|
538
|
+
});
|
|
539
|
+
const resultById = new Map();
|
|
540
|
+
for (const id of alreadyAppliedIds) {
|
|
541
|
+
resultById.set(id, { id, status: 'already applied' });
|
|
542
|
+
}
|
|
543
|
+
// Execute in safe dependency order (E1/E2 -> E5 -> E6/E4/E3/E7/E8/E9) while preserving plan order in output.
|
|
544
|
+
const orderedRemaining = [...remainingEntries].sort((a, b) => phaseOf(a) - phaseOf(b));
|
|
545
|
+
for (const entry of orderedRemaining) {
|
|
546
|
+
const key = adoptionEntryClientToken(plan.planHash, entry.id);
|
|
547
|
+
const entryResult = applySingleEntry(entry, key, track, store, eventsPath, options);
|
|
548
|
+
resultById.set(entry.id, entryResult);
|
|
549
|
+
}
|
|
550
|
+
const results = plan.entries.map((e) => resultById.get(e.id));
|
|
551
|
+
const applied = results.filter((r) => r.status === 'applied').length;
|
|
552
|
+
const alreadyApplied = results.filter((r) => r.status === 'already applied').length;
|
|
553
|
+
const refused = results.filter((r) => r.status === 'refused').length;
|
|
554
|
+
return {
|
|
555
|
+
planHash: plan.planHash,
|
|
556
|
+
results,
|
|
557
|
+
applied,
|
|
558
|
+
alreadyApplied,
|
|
559
|
+
refused,
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
export function formatApplyResultLines(result) {
|
|
563
|
+
if (result.results.length === 0)
|
|
564
|
+
return '';
|
|
565
|
+
return `${result.results
|
|
566
|
+
.map((r) => (r.status === 'refused' ? `${r.id}: refused: ${r.reason ?? 'unknown reason'}` : `${r.id}: ${r.status}`))
|
|
567
|
+
.join('\n')}\n`;
|
|
568
|
+
}
|
|
569
|
+
//# sourceMappingURL=apply.js.map
|