@gitroll/tacitt-cli 0.1.0 → 0.3.0
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/dist/{agent-setup-B85GaVIz.mjs → agent-setup-CLXdKr2I.mjs} +2 -2
- package/dist/agent-setup-worker.mjs +5 -5
- package/dist/cli.mjs +165 -9
- package/dist/codex-title-worker.mjs +1 -1
- package/dist/configured-preview-worker.mjs +5 -5
- package/dist/configured-session-worker.mjs +25 -4
- package/dist/{frame-D1j9R8xX.mjs → frame-waS5FnN5.mjs} +1 -1
- package/dist/{heap-tfU61Ehy.mjs → heap-eO_uWpD1.mjs} +63 -9
- package/dist/inspection-worker.mjs +57 -0
- package/dist/job-rK-Ho9OD.mjs +613 -0
- package/dist/{locate-Bn32k2se.mjs → locate-U3-nkird.mjs} +29 -6
- package/dist/messages-D3m3bhva.mjs +40 -0
- package/dist/{model-7Nu7szNP.mjs → model-BBAnsFAx.mjs} +1 -1
- package/dist/operation-executor.mjs +3 -3
- package/dist/preview-worker.mjs +1 -1
- package/dist/privacy-validator.mjs +1 -1
- package/dist/{query-Da-KDbSV.mjs → query-DN99jiRc.mjs} +710 -630
- package/dist/{run-CCATsHS2.mjs → run-4G_CvdDj.mjs} +4 -4
- package/dist/session-process.mjs +6 -1
- package/dist/{src-CPPjOyHZ.mjs → src-B4R5XMEP.mjs} +621 -224
- package/dist/{src-BngGpFKd.mjs → src-CPbdnGrk.mjs} +130 -53
- package/dist/{src-DynBRDBc.mjs → src-qoLRvX-A.mjs} +34 -11
- package/dist/store-database-worker.mjs +1 -1
- package/dist/web/assets/index-BkuUI3Eu.js +67 -0
- package/dist/web/assets/index-Clg6Pfv_.css +1 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/skills/tacitt/SKILL.md +15 -11
- package/skills/tacitt/references/b-method.md +1 -1
- package/skills/tacitt/references/classification.md +3 -3
- package/skills/tacitt/references/commands.md +19 -14
- package/skills/tacitt/references/journey.md +17 -11
- package/skills/tacitt/references/parallel-review.md +3 -3
- package/skills/tacitt/references/send.md +5 -5
- package/skills/tacitt/scripts/INDEX.md +6 -2
- package/skills/tacitt/scripts/answer.mjs +29 -8
- package/skills/tacitt/scripts/journey-card-consolidation.d.mts +13 -4
- package/skills/tacitt/scripts/journey-card-consolidation.mjs +170 -21
- package/skills/tacitt/scripts/journey-card-values.d.mts +17 -0
- package/skills/tacitt/scripts/journey-card-values.mjs +116 -0
- package/skills/tacitt/scripts/journey-classification-progress.mjs +2 -1
- package/skills/tacitt/scripts/journey-classification-validation.mjs +49 -28
- package/skills/tacitt/scripts/journey-classification.mjs +6 -2
- package/skills/tacitt/scripts/journey-consolidation-submit.mjs +42 -5
- package/skills/tacitt/scripts/journey-consolidation.d.mts +5 -0
- package/skills/tacitt/scripts/journey-consolidation.mjs +4 -1
- package/skills/tacitt/scripts/journey-panel-host.d.mts +9 -0
- package/skills/tacitt/scripts/journey-panel-host.mjs +56 -0
- package/skills/tacitt/scripts/journey-state.d.mts +1 -0
- package/skills/tacitt/scripts/journey-state.mjs +38 -6
- package/skills/tacitt/scripts/journey-tasks.mjs +5 -3
- package/skills/tacitt/scripts/journey.d.mts +4 -0
- package/skills/tacitt/scripts/journey.mjs +249 -41
- package/skills/tacitt/scripts/privacy-validator.mjs +25 -6
- package/skills/tacitt/scripts/review-stream-client.mjs +1 -1
- package/skills/tacitt/scripts/review.mjs +24 -3
- package/dist/job--TceKk0l.mjs +0 -194
- package/dist/web/assets/index-CWQ05PFl.js +0 -67
- package/dist/web/assets/index-J-AWt_cW.css +0 -1
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
import { B as writeLogicalJourneyOutput, C as readConfiguredSearchFields, E as prepareCollectionProduction, R as gitSeedsProvider, U as readConfiguredOutputInfo, d as verifyOutputShard, f as writeOutputShard, k as renderJobDigest, y as writeLogicalJourneyBase } from "./src-CPbdnGrk.mjs";
|
|
2
|
+
import { Ht as ApplicationError, Jt as reviewFamilies, zt as filterInventoryByPeriod } from "./locate-U3-nkird.mjs";
|
|
3
|
+
import { Fn as packHideIndex, Ir as staticSessionResourceSchema, Mn as addHideIndexTokens, Nn as hideKeyId, ci as selectFrozenConfiguration, kn as renderedHideValue, oi as defaultScopedSettings, si as freezeConfiguration } from "./src-B4R5XMEP.mjs";
|
|
4
|
+
import { constants } from "node:fs";
|
|
5
|
+
import { link, lstat, open, unlink } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
8
|
+
//#region apps/cli/src/journey/plan.ts
|
|
9
|
+
async function prepareSourcePlan(storage, harnesses, journeyId, sensitiveTerms, signal, period = {}) {
|
|
10
|
+
const saved = (await storage.resources({
|
|
11
|
+
journeyId,
|
|
12
|
+
kind: "plan"
|
|
13
|
+
}))[0];
|
|
14
|
+
if (saved?.kind === "plan") return saved;
|
|
15
|
+
const discovered = await harnesses.discover(signal);
|
|
16
|
+
if (!discovered.complete) throw new ApplicationError("SCOPE_NOT_READY");
|
|
17
|
+
const inventory = filterInventoryByPeriod(discovered, period);
|
|
18
|
+
if (inventory.sessions.length === 0) throw new ApplicationError("INVALID_SELECTION");
|
|
19
|
+
const families = reviewFamilies(inventory);
|
|
20
|
+
const defaults = defaultScopedSettings();
|
|
21
|
+
const settings = {
|
|
22
|
+
...defaults,
|
|
23
|
+
overall: {
|
|
24
|
+
...defaults.overall,
|
|
25
|
+
cleanup: {
|
|
26
|
+
ref: {
|
|
27
|
+
id: "native-evidence",
|
|
28
|
+
version: "2"
|
|
29
|
+
},
|
|
30
|
+
options: { assessedSessionsOnly: true }
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
workspaces: Object.fromEntries(inventory.workspaces.map((work) => [work.id, {
|
|
34
|
+
parameters: {
|
|
35
|
+
"screened-identifiers": { enabled: false },
|
|
36
|
+
"ip-addresses": { enabled: false },
|
|
37
|
+
hostnames: { enabled: false },
|
|
38
|
+
"cloud-resources": { enabled: false },
|
|
39
|
+
"mac-addresses": { enabled: false },
|
|
40
|
+
"public-key-containers": { enabled: false },
|
|
41
|
+
"geographic-coordinates": { enabled: false },
|
|
42
|
+
urls: { enabled: false },
|
|
43
|
+
"filesystem-paths": { mode: "identity-roots" }
|
|
44
|
+
},
|
|
45
|
+
optionalSteps: { "phone-numbers": true }
|
|
46
|
+
}]))
|
|
47
|
+
};
|
|
48
|
+
const configuration = freezeConfiguration(settings, inventory.sessions.flatMap((session) => {
|
|
49
|
+
const owner = families.owners.get(session.id);
|
|
50
|
+
return owner ? [{
|
|
51
|
+
sessionId: session.id,
|
|
52
|
+
workspaceId: session.workspaceId,
|
|
53
|
+
settingsOwner: {
|
|
54
|
+
sessionId: owner.id,
|
|
55
|
+
workspaceId: owner.workspaceId
|
|
56
|
+
}
|
|
57
|
+
}] : [];
|
|
58
|
+
}));
|
|
59
|
+
const resource = {
|
|
60
|
+
kind: "plan",
|
|
61
|
+
journeyId,
|
|
62
|
+
approval: {
|
|
63
|
+
runId: journeyId,
|
|
64
|
+
revision: 0,
|
|
65
|
+
approvedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
66
|
+
inventory,
|
|
67
|
+
sourceChangePolicy: "fail",
|
|
68
|
+
treatment: {
|
|
69
|
+
kind: "configured",
|
|
70
|
+
configuration,
|
|
71
|
+
dictionaryRevision: sensitiveTerms.revision
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
replacementKey: randomBytes(32).toString("hex"),
|
|
75
|
+
sensitiveTerms: {
|
|
76
|
+
revision: sensitiveTerms.revision,
|
|
77
|
+
terms: [...sensitiveTerms.terms]
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
await storage.saveResource(resource);
|
|
81
|
+
return resource;
|
|
82
|
+
}
|
|
83
|
+
function workApproval(approval, rootIds) {
|
|
84
|
+
if (approval.treatment?.kind !== "configured") throw new ApplicationError("PROCESSING_PLAN_UNAVAILABLE");
|
|
85
|
+
const families = reviewFamilies(approval.inventory);
|
|
86
|
+
const ids = new Set(rootIds.flatMap((id) => {
|
|
87
|
+
const members = families.members.get(id);
|
|
88
|
+
if (!members) throw new ApplicationError("UNKNOWN_ITEM");
|
|
89
|
+
return members.map((session) => session.id);
|
|
90
|
+
}));
|
|
91
|
+
const sessions = approval.inventory.sessions.filter((session) => ids.has(session.id));
|
|
92
|
+
const workspaces = new Set(sessions.map((session) => session.workspaceId));
|
|
93
|
+
return {
|
|
94
|
+
...approval,
|
|
95
|
+
inventory: {
|
|
96
|
+
...approval.inventory,
|
|
97
|
+
sessions,
|
|
98
|
+
workspaces: approval.inventory.workspaces.filter((workspace) => workspaces.has(workspace.id))
|
|
99
|
+
},
|
|
100
|
+
treatment: {
|
|
101
|
+
...approval.treatment,
|
|
102
|
+
configuration: selectFrozenConfiguration(approval.treatment.configuration, ids)
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region apps/cli/src/journey/static/production.ts
|
|
108
|
+
/** Store reads of `staticBaseProduction`; undefined when no reviewed root remains. */
|
|
109
|
+
async function staticBaseInputs(storage, state, work) {
|
|
110
|
+
const excluded = work.excludedReview?.snapshotId === state.snapshotId && work.excludedReview.inputRevision === work.inputRevision ? new Set(work.excludedReview.rootSessionIds) : /* @__PURE__ */ new Set();
|
|
111
|
+
const roots = work.rootSessionIds.filter((id) => !excluded.has(id));
|
|
112
|
+
if (!roots.length) return void 0;
|
|
113
|
+
const plan = (await storage.resources({
|
|
114
|
+
journeyId: state.journeyId,
|
|
115
|
+
kind: "plan"
|
|
116
|
+
}))[0];
|
|
117
|
+
if (plan?.kind !== "plan") throw new ApplicationError("CORRUPTED_STATE");
|
|
118
|
+
const approval = workApproval(plan.approval, roots);
|
|
119
|
+
if (approval.treatment?.kind !== "configured") throw new ApplicationError("CORRUPTED_STATE");
|
|
120
|
+
const parts = new Set(approval.inventory.sessions.flatMap((session) => session.parts.map((part) => part.id)));
|
|
121
|
+
const captures = (await storage.resources({
|
|
122
|
+
journeyId: state.journeyId,
|
|
123
|
+
kind: "capture"
|
|
124
|
+
})).flatMap((item) => item.kind === "capture" && parts.has(item.capture.partId) ? [item.capture] : []);
|
|
125
|
+
if (captures.length !== parts.size) throw new ApplicationError("SCOPE_NOT_READY");
|
|
126
|
+
return {
|
|
127
|
+
journeyId: state.journeyId,
|
|
128
|
+
work,
|
|
129
|
+
roots,
|
|
130
|
+
approval,
|
|
131
|
+
captures,
|
|
132
|
+
replacementKey: createHash("sha256").update(JSON.stringify([
|
|
133
|
+
"static-base-v1",
|
|
134
|
+
plan.replacementKey,
|
|
135
|
+
work.id,
|
|
136
|
+
work.inputRevision
|
|
137
|
+
])).digest("hex"),
|
|
138
|
+
staticExceptions: {
|
|
139
|
+
workId: work.id,
|
|
140
|
+
values: state.exceptions.filter((item) => item.workId === work.id).map(({ kind, value }) => ({
|
|
141
|
+
kind,
|
|
142
|
+
value
|
|
143
|
+
}))
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** The production of `staticBaseProduction` from its stored inputs; no store access. */
|
|
148
|
+
async function staticBaseFromInputs(inputs, processing, hooks) {
|
|
149
|
+
const { work, roots, approval } = inputs;
|
|
150
|
+
const { sensitiveTerms: _live, customTerms: _terms, staticExceptions: _unscoped, ...local } = processing;
|
|
151
|
+
const production = await prepareCollectionProduction(approval, inputs.journeyId, {
|
|
152
|
+
configured: {
|
|
153
|
+
...local,
|
|
154
|
+
gitNames: async () => ({
|
|
155
|
+
names: [],
|
|
156
|
+
snapshots: []
|
|
157
|
+
}),
|
|
158
|
+
replacementKey: inputs.replacementKey,
|
|
159
|
+
staticExceptions: inputs.staticExceptions
|
|
160
|
+
},
|
|
161
|
+
captures: inputs.captures,
|
|
162
|
+
everyAdmissionRefusal: true
|
|
163
|
+
}, hooks);
|
|
164
|
+
if (production.kind !== "configured" || production.workspaceFailures.length) throw new ApplicationError("SCOPE_NOT_READY");
|
|
165
|
+
const families = reviewFamilies(approval.inventory);
|
|
166
|
+
const admitted = new Set(production.selection.sessions.map((item) => item.session.id));
|
|
167
|
+
return {
|
|
168
|
+
production,
|
|
169
|
+
families,
|
|
170
|
+
work: {
|
|
171
|
+
...work,
|
|
172
|
+
rootSessionIds: roots.filter((id) => families.members.get(id)?.some((member) => admitted.has(member.id))),
|
|
173
|
+
access: work.access === "private" ? "private" : "public"
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The single production both Track B and packaging use for one Work generation (ADR 0172):
|
|
179
|
+
* frozen captures, built-in static detection only (no custom terms, no Git seeds), the Work's
|
|
180
|
+
* exceptions and a replacement key bound to this generation. Identical inputs give identical
|
|
181
|
+
* session render jobs, so packaging can require the stored Track B result by job digest.
|
|
182
|
+
*/
|
|
183
|
+
async function staticBaseProduction(storage, state, work, processing, hooks) {
|
|
184
|
+
const inputs = await staticBaseInputs(storage, state, work);
|
|
185
|
+
return inputs && staticBaseFromInputs(inputs, processing, hooks);
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region apps/cli/src/journey/static/store.ts
|
|
189
|
+
/** Identity, length and complete digest of one owner-only file; a symlink is never followed. */
|
|
190
|
+
async function describe(path, signal) {
|
|
191
|
+
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
192
|
+
try {
|
|
193
|
+
const before = await handle.stat({ bigint: true });
|
|
194
|
+
if (!before.isFile()) throw new ApplicationError("CORRUPTED_STATE");
|
|
195
|
+
const digest = createHash("sha256");
|
|
196
|
+
let byteLength = 0;
|
|
197
|
+
const buffer = Buffer.allocUnsafe(1048576);
|
|
198
|
+
for (;;) {
|
|
199
|
+
signal.throwIfAborted();
|
|
200
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, byteLength);
|
|
201
|
+
if (!bytesRead) break;
|
|
202
|
+
digest.update(buffer.subarray(0, bytesRead));
|
|
203
|
+
byteLength += bytesRead;
|
|
204
|
+
}
|
|
205
|
+
const after = await handle.stat({ bigint: true });
|
|
206
|
+
if (after.dev !== before.dev || after.ino !== before.ino || after.size !== before.size || after.mtimeNs !== before.mtimeNs || BigInt(byteLength) !== after.size) throw new ApplicationError("CORRUPTED_STATE");
|
|
207
|
+
return {
|
|
208
|
+
path,
|
|
209
|
+
identity: {
|
|
210
|
+
dev: String(after.dev),
|
|
211
|
+
ino: String(after.ino)
|
|
212
|
+
},
|
|
213
|
+
sha256: digest.digest("hex"),
|
|
214
|
+
byteLength
|
|
215
|
+
};
|
|
216
|
+
} finally {
|
|
217
|
+
await handle.close();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/** A stored file must still be the exact recorded file and bytes. */
|
|
221
|
+
async function authenticate(file, signal) {
|
|
222
|
+
const actual = await describe(file.path, signal);
|
|
223
|
+
if (JSON.stringify(actual) !== JSON.stringify(file)) throw new ApplicationError("CORRUPTED_STATE");
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Persist one Track B session as owner-only private state beside the journey's other scan
|
|
227
|
+
* files: its three spools and a digest-bound result description. Nothing here is uploaded.
|
|
228
|
+
*/
|
|
229
|
+
async function saveStaticSession(storage, binding, item, result, signal) {
|
|
230
|
+
const owned = [
|
|
231
|
+
result.spoolPath,
|
|
232
|
+
result.companionSpoolPath,
|
|
233
|
+
result.maskSpoolPath
|
|
234
|
+
];
|
|
235
|
+
const resultPath = join(binding.directory, `${randomUUID()}.static.json`);
|
|
236
|
+
let saved = false;
|
|
237
|
+
try {
|
|
238
|
+
if (result.kind !== "render" || result.maskSpoolPath === void 0 || result.maskEntries === void 0 || result.metadataMasks === void 0 || result.reviewSpoolPath !== void 0) throw new ApplicationError("CORRUPTED_STATE");
|
|
239
|
+
const stored = {
|
|
240
|
+
kind: "render",
|
|
241
|
+
processingMs: result.processingMs,
|
|
242
|
+
maskEntries: result.maskEntries,
|
|
243
|
+
metadataMasks: result.metadataMasks,
|
|
244
|
+
metadata: result.metadata,
|
|
245
|
+
parts: result.parts,
|
|
246
|
+
entries: result.entries,
|
|
247
|
+
agentSetup: result.agentSetup
|
|
248
|
+
};
|
|
249
|
+
const file = await open(resultPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 384);
|
|
250
|
+
owned.push(resultPath);
|
|
251
|
+
try {
|
|
252
|
+
await file.writeFile(JSON.stringify(stored));
|
|
253
|
+
await file.sync();
|
|
254
|
+
} finally {
|
|
255
|
+
await file.close();
|
|
256
|
+
}
|
|
257
|
+
const resource = staticSessionResourceSchema.parse({
|
|
258
|
+
kind: "static-session",
|
|
259
|
+
journeyId: binding.journeyId,
|
|
260
|
+
workId: binding.work.id,
|
|
261
|
+
inputRevision: binding.work.inputRevision,
|
|
262
|
+
snapshotId: binding.snapshotId,
|
|
263
|
+
sessionId: item.sessionId,
|
|
264
|
+
jobDigest: item.digest,
|
|
265
|
+
result: await describe(resultPath, signal),
|
|
266
|
+
primary: await describe(result.spoolPath, signal),
|
|
267
|
+
companion: await describe(result.companionSpoolPath, signal),
|
|
268
|
+
masks: await describe(result.maskSpoolPath, signal),
|
|
269
|
+
...result.images === void 0 ? {} : { imagesOmitted: result.images }
|
|
270
|
+
});
|
|
271
|
+
await storage.saveResource(resource);
|
|
272
|
+
saved = true;
|
|
273
|
+
return resource;
|
|
274
|
+
} finally {
|
|
275
|
+
if (!saved) {
|
|
276
|
+
for (const path of owned) if (path !== void 0) await unlink(path).catch(() => {});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/** Current-generation Track B receipts of one Work, keyed by application session ID. */
|
|
281
|
+
async function staticSessions(storage, journeyId, work) {
|
|
282
|
+
const resources = (await storage.resources({
|
|
283
|
+
journeyId,
|
|
284
|
+
kind: "static-session",
|
|
285
|
+
idPrefix: `${work.id}:${work.inputRevision}:`
|
|
286
|
+
})).filter((item) => item.kind === "static-session" && item.workId === work.id && item.inputRevision === work.inputRevision);
|
|
287
|
+
return new Map(resources.map((item) => [item.sessionId, item]));
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Shape guard like the worker transport's: the bytes are bound by the recorded digest, and the
|
|
291
|
+
* archive writer checks parts, entries and masks again when it consumes them.
|
|
292
|
+
*/
|
|
293
|
+
function isStoredResult(value) {
|
|
294
|
+
return typeof value === "object" && value !== null && Reflect.get(value, "kind") === "render" && Array.isArray(Reflect.get(value, "maskEntries")) && Array.isArray(Reflect.get(value, "metadataMasks")) && Array.isArray(Reflect.get(value, "parts")) && Array.isArray(Reflect.get(value, "entries")) && Array.isArray(Reflect.get(value, "agentSetup")) && typeof Reflect.get(value, "metadata") === "string" && Number.isSafeInteger(Reflect.get(value, "processingMs"));
|
|
295
|
+
}
|
|
296
|
+
/** Authenticated result description of one stored Track B session. */
|
|
297
|
+
async function readStaticResult(resource, signal) {
|
|
298
|
+
await authenticate(resource.result, signal);
|
|
299
|
+
const handle = await open(resource.result.path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
300
|
+
try {
|
|
301
|
+
const text = await handle.readFile("utf8");
|
|
302
|
+
if (createHash("sha256").update(text).digest("hex") !== resource.result.sha256) throw new ApplicationError("CORRUPTED_STATE");
|
|
303
|
+
const value = JSON.parse(text);
|
|
304
|
+
if (!isStoredResult(value)) throw new ApplicationError("CORRUPTED_STATE");
|
|
305
|
+
return value;
|
|
306
|
+
} finally {
|
|
307
|
+
await handle.close();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Packaging from the Track B base: the stored result of exactly this job, with fresh hard links
|
|
312
|
+
* to its authenticated spools that the archive writer may consume. Static detection never runs.
|
|
313
|
+
*/
|
|
314
|
+
async function linkedStaticResult(resource, job, signal) {
|
|
315
|
+
if (!resource || resource.jobDigest !== job.digest) throw new ApplicationError("SCOPE_NOT_READY");
|
|
316
|
+
const result = await readStaticResult(resource, signal);
|
|
317
|
+
const links = [];
|
|
318
|
+
try {
|
|
319
|
+
const linked = async (file) => {
|
|
320
|
+
const path = join(job.spoolDirectory, `${randomUUID()}.session`);
|
|
321
|
+
await link(file.path, path);
|
|
322
|
+
links.push(path);
|
|
323
|
+
const stat = await lstat(path, { bigint: true });
|
|
324
|
+
if (String(stat.dev) !== file.identity.dev || String(stat.ino) !== file.identity.ino) throw new ApplicationError("CORRUPTED_STATE");
|
|
325
|
+
await authenticate({
|
|
326
|
+
...file,
|
|
327
|
+
path
|
|
328
|
+
}, signal);
|
|
329
|
+
return path;
|
|
330
|
+
};
|
|
331
|
+
return {
|
|
332
|
+
...result,
|
|
333
|
+
spoolPath: await linked(resource.primary),
|
|
334
|
+
companionSpoolPath: await linked(resource.companion),
|
|
335
|
+
maskSpoolPath: await linked(resource.masks)
|
|
336
|
+
};
|
|
337
|
+
} catch (error) {
|
|
338
|
+
for (const path of links) await unlink(path).catch(() => {});
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
//#endregion
|
|
343
|
+
//#region apps/cli/src/journey/render/base.ts
|
|
344
|
+
/**
|
|
345
|
+
* The CPU-bound part of base packaging (ADR 0172): the static production from frozen captures,
|
|
346
|
+
* the base pair written from the stored Track B results and its full readback. The owning
|
|
347
|
+
* thread keeps every store read and write; this runs there or in a packaging worker.
|
|
348
|
+
*/
|
|
349
|
+
async function writeJourneyBase(work, signal, onPath) {
|
|
350
|
+
const { inputs } = work;
|
|
351
|
+
const hooks = {
|
|
352
|
+
signal,
|
|
353
|
+
onTemporary: async () => {},
|
|
354
|
+
onPhase: async () => {}
|
|
355
|
+
};
|
|
356
|
+
const prepared = await staticBaseFromInputs(inputs, work.processing, hooks);
|
|
357
|
+
const stored = new Map(work.stored.map((item) => [item.sessionId, item]));
|
|
358
|
+
const written = await writeLogicalJourneyBase({
|
|
359
|
+
production: prepared.production,
|
|
360
|
+
directory: work.directory,
|
|
361
|
+
captureReview: false,
|
|
362
|
+
work: prepared.work,
|
|
363
|
+
prerendered: async (job) => {
|
|
364
|
+
if (job.spoolDirectory === void 0) throw new ApplicationError("CORRUPTED_STATE");
|
|
365
|
+
return linkedStaticResult(stored.get(job.session.id), {
|
|
366
|
+
digest: renderJobDigest(job),
|
|
367
|
+
spoolDirectory: job.spoolDirectory
|
|
368
|
+
}, signal);
|
|
369
|
+
}
|
|
370
|
+
}, hooks, onPath);
|
|
371
|
+
return {
|
|
372
|
+
kind: "base",
|
|
373
|
+
journeyId: inputs.journeyId,
|
|
374
|
+
workId: inputs.work.id,
|
|
375
|
+
inputRevision: inputs.work.inputRevision,
|
|
376
|
+
bundleId: written.bundleId,
|
|
377
|
+
primary: written.primary,
|
|
378
|
+
companion: written.companion,
|
|
379
|
+
maskLedger: written.maskLedger,
|
|
380
|
+
sourceBindings: [...written.sourceBindings],
|
|
381
|
+
sessions: written.sessionBindings.map((binding) => {
|
|
382
|
+
const root = prepared.families.owners.get(binding.applicationSessionId);
|
|
383
|
+
if (!root) throw new ApplicationError("CORRUPTED_STATE");
|
|
384
|
+
return {
|
|
385
|
+
applicationSessionId: binding.applicationSessionId,
|
|
386
|
+
archiveSessionId: binding.sessionId,
|
|
387
|
+
rootSessionId: root.id,
|
|
388
|
+
role: root.id === binding.applicationSessionId ? "main" : "worker"
|
|
389
|
+
};
|
|
390
|
+
})
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function journeyBaseJob(work) {
|
|
394
|
+
const { processing, ...rest } = work;
|
|
395
|
+
return {
|
|
396
|
+
...rest,
|
|
397
|
+
processing: {
|
|
398
|
+
environment: processing.environment,
|
|
399
|
+
...processing.limits === void 0 ? {} : { limits: processing.limits }
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Worker side: `live` holds the worker's own adapters and static processor. The base runs no
|
|
405
|
+
* static detection and reads no Git names (ADR 0172); a Git-name read fails closed.
|
|
406
|
+
*/
|
|
407
|
+
async function runJourneyBaseJob(job, live, signal, onPath) {
|
|
408
|
+
const processing = {
|
|
409
|
+
...live,
|
|
410
|
+
...job.processing,
|
|
411
|
+
gitNames: gitSeedsProvider([])
|
|
412
|
+
};
|
|
413
|
+
return {
|
|
414
|
+
kind: "journey-base",
|
|
415
|
+
base: await writeJourneyBase({
|
|
416
|
+
...job,
|
|
417
|
+
processing
|
|
418
|
+
}, signal, onPath)
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region apps/cli/src/journey/hide-index.ts
|
|
423
|
+
/**
|
|
424
|
+
* Word pieces of render input, gathered as it is read so its texts are not held to the end.
|
|
425
|
+
* `from` continues a collection begun in another thread (ADR 0181).
|
|
426
|
+
*/
|
|
427
|
+
function createHideIndexTokens(from) {
|
|
428
|
+
const tokens = new Set(from?.tokens);
|
|
429
|
+
let complete = from?.complete ?? true;
|
|
430
|
+
return {
|
|
431
|
+
tokens,
|
|
432
|
+
add: (text) => {
|
|
433
|
+
if (complete) complete = addHideIndexTokens(text, (token) => tokens.add(token));
|
|
434
|
+
if (tokens.size > 2e6) complete = false;
|
|
435
|
+
},
|
|
436
|
+
complete: () => complete
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* The pieces of a Work collected in shards (ADR 0199): the same set and completeness as one
|
|
441
|
+
* collection, since pieces only accumulate and the bound applies to their union.
|
|
442
|
+
*/
|
|
443
|
+
function mergeHideIndexTokens(parts) {
|
|
444
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
445
|
+
let complete = true;
|
|
446
|
+
for (const part of parts) {
|
|
447
|
+
complete &&= part.complete;
|
|
448
|
+
for (const token of part.tokens) {
|
|
449
|
+
if (!complete) break;
|
|
450
|
+
tokens.add(token);
|
|
451
|
+
if (tokens.size > 2e6) complete = false;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return createHideIndexTokens({
|
|
455
|
+
tokens: complete ? tokens : [],
|
|
456
|
+
complete
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/** The Work's own texts a render can mask, read before its base archive. */
|
|
460
|
+
function hideIndexTexts(work) {
|
|
461
|
+
const suggestion = work.suggestion;
|
|
462
|
+
return [
|
|
463
|
+
work.title,
|
|
464
|
+
work.description,
|
|
465
|
+
work.reason,
|
|
466
|
+
...suggestion ? [
|
|
467
|
+
suggestion.title,
|
|
468
|
+
suggestion.description,
|
|
469
|
+
suggestion.reason
|
|
470
|
+
] : []
|
|
471
|
+
];
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* The CPU-bound part of a hide index: word pieces of the texts and every base field, or of one
|
|
475
|
+
* shard's base fields (ADR 0199).
|
|
476
|
+
*/
|
|
477
|
+
async function collectHideIndexTokens(texts, primary, processing, { add, complete }, signal, shard) {
|
|
478
|
+
for (const text of texts) add(text);
|
|
479
|
+
for await (const field of readConfiguredSearchFields(primary, processing, signal, true, void 0, shard)) {
|
|
480
|
+
if (!complete()) break;
|
|
481
|
+
add(field.text);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/** Keyed digests of collected word pieces and of the confirmed Hide values. */
|
|
485
|
+
async function packRenderHideIndex(input) {
|
|
486
|
+
const { work } = input;
|
|
487
|
+
const { tokens, complete } = input.tokens;
|
|
488
|
+
const key = await input.storage.hideIndexKey(input.journeyId);
|
|
489
|
+
return {
|
|
490
|
+
kind: "hide-index",
|
|
491
|
+
journeyId: input.journeyId,
|
|
492
|
+
workId: work.id,
|
|
493
|
+
revision: work.revision,
|
|
494
|
+
confirmedHideRevision: input.confirmedHideRevision,
|
|
495
|
+
keyId: hideKeyId(key),
|
|
496
|
+
digests: complete() ? packHideIndex(key, tokens) : null,
|
|
497
|
+
values: packHideIndex(key, [...input.confirmed].map(([term, { kind }]) => renderedHideValue(kind, term)))
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
//#endregion
|
|
501
|
+
//#region apps/cli/src/journey/render/job.ts
|
|
502
|
+
/**
|
|
503
|
+
* The same steps on the owning thread; also the fallback when workers cannot run. The written
|
|
504
|
+
* primary is read back as the publisher reads an existing output.
|
|
505
|
+
*/
|
|
506
|
+
async function writeJourneyOutput(work, signal, onPath) {
|
|
507
|
+
const output = await writeLogicalJourneyOutput(work.request, signal, onPath);
|
|
508
|
+
await readConfiguredOutputInfo(output.primary, signal);
|
|
509
|
+
await collectHideIndexTokens(work.texts, work.request.primary, work.request.processing, work.tokens, signal);
|
|
510
|
+
return {
|
|
511
|
+
output,
|
|
512
|
+
tokens: work.tokens
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function journeyOutputJob(work) {
|
|
516
|
+
const { processing, ...request } = work.request;
|
|
517
|
+
return {
|
|
518
|
+
request,
|
|
519
|
+
processing: {
|
|
520
|
+
environment: processing.environment,
|
|
521
|
+
...processing.limits === void 0 ? {} : { limits: processing.limits },
|
|
522
|
+
...processing.replacementKey === void 0 ? {} : { replacementKey: processing.replacementKey },
|
|
523
|
+
...processing.staticExceptions === void 0 ? {} : { staticExceptions: processing.staticExceptions }
|
|
524
|
+
},
|
|
525
|
+
texts: work.texts,
|
|
526
|
+
tokens: [...work.tokens.tokens],
|
|
527
|
+
tokensComplete: work.tokens.complete()
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
function workerProcessing(job, live) {
|
|
531
|
+
return {
|
|
532
|
+
...live,
|
|
533
|
+
...job.processing,
|
|
534
|
+
gitNames: gitSeedsProvider([])
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Worker side of one shard: its entries rewritten into private archives and the hide-index word
|
|
539
|
+
* pieces of its base entries. The first shard also takes the Work's texts, title pieces and the
|
|
540
|
+
* base manifest's fields, so the shards' pieces together are those of one job.
|
|
541
|
+
*/
|
|
542
|
+
async function runJourneyOutputShardJob(job, live, signal, onPath) {
|
|
543
|
+
const processing = workerProcessing(job, live);
|
|
544
|
+
const { maskEvidence, ...request } = job.request;
|
|
545
|
+
if (!maskEvidence) throw new Error("ARTIFACT_INVALID_APPROVAL");
|
|
546
|
+
const pieces = await writeOutputShard({
|
|
547
|
+
...request,
|
|
548
|
+
processing,
|
|
549
|
+
maskEvidence,
|
|
550
|
+
shard: job.shard
|
|
551
|
+
}, signal, onPath);
|
|
552
|
+
const first = job.shard.index === 0;
|
|
553
|
+
const tokens = createHideIndexTokens(first ? {
|
|
554
|
+
tokens: job.tokens,
|
|
555
|
+
complete: job.tokensComplete
|
|
556
|
+
} : void 0);
|
|
557
|
+
await collectHideIndexTokens(first ? job.texts : [], job.request.primary, processing, tokens, signal, job.shard);
|
|
558
|
+
return {
|
|
559
|
+
kind: "journey-output-shard",
|
|
560
|
+
pieces,
|
|
561
|
+
tokens: [...tokens.tokens],
|
|
562
|
+
tokensComplete: tokens.complete()
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
/** Worker side of one shard of a merged output's readback. */
|
|
566
|
+
async function runJourneyOutputVerifyJob(job, signal) {
|
|
567
|
+
const ledger = job.output.finalMaskLedger;
|
|
568
|
+
if (!ledger) throw new Error("ARTIFACT_INVALID_APPROVAL");
|
|
569
|
+
await verifyOutputShard({
|
|
570
|
+
...job.output,
|
|
571
|
+
finalMaskLedger: ledger
|
|
572
|
+
}, job.shard, signal);
|
|
573
|
+
return { kind: "journey-output-verify" };
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* Worker side: `live` holds the worker's own adapters and static processor. A job with
|
|
577
|
+
* `request.shards` merges them; its caller then reads the output back in shards (ADR 0199).
|
|
578
|
+
*/
|
|
579
|
+
async function runJourneyOutputJob(job, live, signal, onPath) {
|
|
580
|
+
const processing = workerProcessing(job, live);
|
|
581
|
+
if (job.request.shards) {
|
|
582
|
+
const output = await writeLogicalJourneyOutput({
|
|
583
|
+
...job.request,
|
|
584
|
+
processing
|
|
585
|
+
}, signal, onPath);
|
|
586
|
+
await readConfiguredOutputInfo(output.primary, signal);
|
|
587
|
+
return {
|
|
588
|
+
kind: "journey-output",
|
|
589
|
+
output,
|
|
590
|
+
tokens: [],
|
|
591
|
+
tokensComplete: true
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
const written = await writeJourneyOutput({
|
|
595
|
+
request: {
|
|
596
|
+
...job.request,
|
|
597
|
+
processing
|
|
598
|
+
},
|
|
599
|
+
texts: job.texts,
|
|
600
|
+
tokens: createHideIndexTokens({
|
|
601
|
+
tokens: job.tokens,
|
|
602
|
+
complete: job.tokensComplete
|
|
603
|
+
})
|
|
604
|
+
}, signal, onPath);
|
|
605
|
+
return {
|
|
606
|
+
kind: "journey-output",
|
|
607
|
+
output: written.output,
|
|
608
|
+
tokens: [...written.tokens.tokens],
|
|
609
|
+
tokensComplete: written.tokens.complete()
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
//#endregion
|
|
613
|
+
export { staticBaseProduction as _, writeJourneyOutput as a, mergeHideIndexTokens as c, runJourneyBaseJob as d, writeJourneyBase as f, staticBaseInputs as g, staticSessions as h, runJourneyOutputVerifyJob as i, packRenderHideIndex as l, saveStaticSession as m, runJourneyOutputJob as n, createHideIndexTokens as o, readStaticResult as p, runJourneyOutputShardJob as r, hideIndexTexts as s, journeyOutputJob as t, journeyBaseJob as u, prepareSourcePlan as v, workApproval as y };
|
|
@@ -8953,13 +8953,18 @@ const decisionCardInputSchema = z.object({
|
|
|
8953
8953
|
id: z.enum(["hide", "keep"]),
|
|
8954
8954
|
label: z.string().trim().min(1).max(240),
|
|
8955
8955
|
rule: z.string().trim().min(1).max(2e3)
|
|
8956
|
-
}).strict()).length(2).refine((options) => new Set(options.map((option) => option.id)).size === 2, { message: "Decision cards require one hide option and one keep option." })
|
|
8956
|
+
}).strict()).length(2).refine((options) => new Set(options.map((option) => option.id)).size === 2, { message: "Decision cards require one hide option and one keep option." }),
|
|
8957
|
+
suggestion: z.object({
|
|
8958
|
+
optionId: z.enum(["hide", "keep"]),
|
|
8959
|
+
source: z.string().trim().min(1).max(300)
|
|
8960
|
+
}).strict().optional()
|
|
8957
8961
|
}).strict();
|
|
8958
8962
|
const decisionCardSchema = decisionCardInputSchema.extend({ answer: z.object({
|
|
8959
8963
|
optionId: z.string(),
|
|
8960
8964
|
rule: z.string().max(4001),
|
|
8961
8965
|
additionalRule: z.string().max(2e3),
|
|
8962
|
-
remember: z.boolean()
|
|
8966
|
+
remember: z.boolean(),
|
|
8967
|
+
excludedTermKeys: z.array(z.string().min(1)).max(2e4).optional()
|
|
8963
8968
|
}).strict().nullable() }).strict();
|
|
8964
8969
|
const journeyPrivacySchema = z.object({
|
|
8965
8970
|
terms: z.array(privacyTermSchema),
|
|
@@ -8983,7 +8988,18 @@ const write = z.object({
|
|
|
8983
8988
|
expectedRevision: count$2,
|
|
8984
8989
|
idempotencyKey: z.uuid()
|
|
8985
8990
|
});
|
|
8986
|
-
|
|
8991
|
+
/**
|
|
8992
|
+
* `append` (D3) adds a batch while scanning continues: new cards plus values added to existing
|
|
8993
|
+
* cards, covering only Pending values no card covers yet. `replace` republishes the whole deck.
|
|
8994
|
+
*/
|
|
8995
|
+
const cardsSubmitSchema = write.extend({
|
|
8996
|
+
cards: z.array(decisionCardInputSchema).max(20),
|
|
8997
|
+
mode: z.enum(["replace", "append"]).optional(),
|
|
8998
|
+
extend: z.array(z.object({
|
|
8999
|
+
cardId: z.uuid(),
|
|
9000
|
+
termKeys: z.array(z.string().min(1)).min(1).max(2e4)
|
|
9001
|
+
}).strict()).max(20).optional()
|
|
9002
|
+
}).strict();
|
|
8987
9003
|
const privacyResolveSchema = write.extend({
|
|
8988
9004
|
answersRevision: count$2,
|
|
8989
9005
|
resolutions: z.array(privacyTermSchema.omit({ sources: true }).extend({ disposition: z.enum(["hidden", "keep"]) }).strict()).min(1).max(2e4)
|
|
@@ -8993,7 +9009,8 @@ const cardAnswerActionSchema = z.object({
|
|
|
8993
9009
|
cardId: z.uuid(),
|
|
8994
9010
|
optionId: z.string().min(1),
|
|
8995
9011
|
rule: z.string().max(2e3).optional(),
|
|
8996
|
-
remember: z.boolean()
|
|
9012
|
+
remember: z.boolean(),
|
|
9013
|
+
excludedTermKeys: z.array(z.string().min(1)).max(2e4).optional()
|
|
8997
9014
|
}).strict();
|
|
8998
9015
|
const cardsConfirmActionSchema = z.object({
|
|
8999
9016
|
kind: z.literal("cards-confirm"),
|
|
@@ -9310,7 +9327,11 @@ const journeyWorkSchema = z.object({
|
|
|
9310
9327
|
"explicit",
|
|
9311
9328
|
"delegate"
|
|
9312
9329
|
]),
|
|
9313
|
-
placement: z.enum([
|
|
9330
|
+
placement: z.enum([
|
|
9331
|
+
"placed",
|
|
9332
|
+
"unsorted",
|
|
9333
|
+
"classifying"
|
|
9334
|
+
]),
|
|
9314
9335
|
suggestion: journeyWorkSuggestionSchema.nullable(),
|
|
9315
9336
|
classificationRecommendation: z.object({
|
|
9316
9337
|
access: journeyAccessSchema,
|
|
@@ -9357,7 +9378,9 @@ const journeyWorkSchema = z.object({
|
|
|
9357
9378
|
staticReview: z.object({
|
|
9358
9379
|
snapshotId: journeyDigestSchema,
|
|
9359
9380
|
inputRevision: count$1.min(1),
|
|
9360
|
-
digest: journeyDigestSchema
|
|
9381
|
+
digest: journeyDigestSchema,
|
|
9382
|
+
/** Images the Work's sessions leave out (D7); absent when a session receipt predates it. */
|
|
9383
|
+
imagesOmitted: count$1.optional()
|
|
9361
9384
|
}).strict().optional(),
|
|
9362
9385
|
totalBatches: count$1,
|
|
9363
9386
|
completedBatches: count$1,
|