@kenkyou/supekku 0.1.0-alpha.8 → 0.1.0-alpha.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.
Files changed (32) hide show
  1. package/dist/{archive-fnLRBLHD.mjs → archive-BDQ_oB6g.mjs} +6 -6
  2. package/dist/{archive-YanRypPH.mjs → archive-BEqNOztX.mjs} +98 -3
  3. package/dist/archive-F8QO5Uzt.mjs +1 -0
  4. package/dist/{challenge-brief--2-bDO8A.mjs → challenge-brief-D6e2atsF.mjs} +7 -6
  5. package/dist/{change-DNLxzdWK.mjs → change-B3CIaYav.mjs} +2 -2
  6. package/dist/change-Ueo8V0d5.mjs +1 -0
  7. package/dist/change-archive.md +2 -2
  8. package/dist/{doctor-CK0Ny6ct.mjs → doctor-CKgYDYGQ.mjs} +1 -1
  9. package/dist/doctor-DxcQvrCD.mjs +1 -0
  10. package/dist/index.mjs +12 -12
  11. package/dist/{init-BJ9BXQf-.mjs → init-DL-jiGgQ.mjs} +2 -2
  12. package/dist/{journal-Da95Qqey.mjs → journal-7SNjewV7.mjs} +1 -1
  13. package/dist/{local-PdPue5jY.mjs → local-Dz8Zbwnw.mjs} +1 -1
  14. package/dist/{local-DyZAVffW.mjs → local-odic_qV5.mjs} +1 -1
  15. package/dist/{maintenance-BHKtYJIT.mjs → maintenance-wIhESufF.mjs} +2 -2
  16. package/dist/{project-CWpJQSO5.mjs → project-3tknDiOf.mjs} +1 -1
  17. package/dist/{project-CTKghH7_.mjs → project-CMFCxtKO.mjs} +1 -1
  18. package/dist/{records-DzVfCcPk.mjs → records-DZFyxxNq.mjs} +16 -2
  19. package/dist/skills/supekku-development/references/change-archive.md +2 -2
  20. package/dist/skills/supekku-development/references/task-execution.md +8 -6
  21. package/dist/skills/supekku-development/references/workflow-records.md +1 -1
  22. package/dist/{status-DSbw584b.mjs → status-DKLbxPPK.mjs} +4 -4
  23. package/dist/task-JlFSBhEW.mjs +1 -0
  24. package/dist/{task-C7oNTNC3.mjs → task-dw_E1Rl2.mjs} +98 -16
  25. package/dist/task-execution.md +8 -6
  26. package/dist/workflow-records.md +1 -1
  27. package/package.json +16 -16
  28. package/dist/archive-CpcY2BcO.mjs +0 -1
  29. package/dist/change-Crv0O1j3.mjs +0 -1
  30. package/dist/doctor-CdPqyaCC.mjs +0 -1
  31. package/dist/task-DfJ5t8aZ.mjs +0 -1
  32. package/dist/task-snapshot-CNi4Yswc.mjs +0 -68
@@ -3,16 +3,15 @@ import { t as hash } from "./src-DeDtBfdV.mjs";
3
3
  import { i as syncDocument, t as atomicReplace } from "./files-DphxaLNK.mjs";
4
4
  import { n as workflowId } from "./change-DgUPVNsm.mjs";
5
5
  import { n as inspectWorkflow } from "./verification-B4QMPPeA.mjs";
6
- import { n as checkedArchivePlan, r as mergeFormal, t as archiveReceipt } from "./archive-YanRypPH.mjs";
6
+ import { n as checkedArchivePlan, r as mergeFormal, t as archiveReceipt } from "./archive-BEqNOztX.mjs";
7
7
  import { t as readBounded } from "./files-Ca24RKdp.mjs";
8
8
  import { n as withLocks } from "./locks-C4XYFwbg.mjs";
9
9
  import { t as findProject } from "./project-directory-w_ITkI7O.mjs";
10
- import { n as openJournal, t as listArchiveOperations } from "./journal-Da95Qqey.mjs";
11
- import { t as context } from "./local-DyZAVffW.mjs";
10
+ import { n as openJournal, t as listArchiveOperations } from "./journal-7SNjewV7.mjs";
11
+ import { t as context } from "./local-odic_qV5.mjs";
12
12
  import { t as readVerification } from "./verification-cEb-1z2d.mjs";
13
- import { t as bundle } from "./change-DNLxzdWK.mjs";
14
- import { t as sourceFingerprint } from "./task-snapshot-CNi4Yswc.mjs";
15
- import { n as taskCommand } from "./task-C7oNTNC3.mjs";
13
+ import { t as bundle } from "./change-B3CIaYav.mjs";
14
+ import { n as taskCommand, r as sourceFingerprint } from "./task-dw_E1Rl2.mjs";
16
15
  import { randomUUID } from "node:crypto";
17
16
  import { dirname, join } from "node:path";
18
17
  import { link, lstat, mkdir, open, readdir, rename, unlink } from "node:fs/promises";
@@ -108,6 +107,7 @@ async function preview(root, id) {
108
107
  taskId: t.id,
109
108
  sourceHash: status.sourceHash,
110
109
  eventHash: hash(JSON.stringify(status.events)),
110
+ ...status.binding === "task" ? { inputHash: status.inputHash } : {},
111
111
  events: status.events
112
112
  });
113
113
  }
@@ -28,6 +28,7 @@ const ArchivePlanSchema = Type.Object({
28
28
  }),
29
29
  sourceHash: Hash,
30
30
  eventHash: Hash,
31
+ inputHash: Type.Optional(Hash),
31
32
  events: Type.Array(Type.Unknown(), {
32
33
  minItems: 1,
33
34
  maxItems: 1e4
@@ -73,7 +74,8 @@ const TaskEvidenceSchema = Type.Union([
73
74
  ...base,
74
75
  kind: Type.Literal("start"),
75
76
  authorization: text,
76
- restart: Type.Optional(Type.Boolean())
77
+ restart: Type.Optional(Type.Boolean()),
78
+ binding: Type.Optional(Type.Literal("task"))
77
79
  }, strict),
78
80
  Type.Object({
79
81
  ...bound,
@@ -282,6 +284,96 @@ function acceptTaskEvent(task, events, e, current) {
282
284
  if (e.kind === "review" && challengePolicy(task).level && !state.challenge?.passed) fail("Review requires a passing challenge of the current verification");
283
285
  if (e.kind === "finish" && state.state !== "reviewed") fail("Finish requires current passing verification and review");
284
286
  }
287
+ // ../../packages/workflow/src/binding.ts
288
+ const invalid = (message) => {
289
+ throw new CoreError("INVALID_WORKFLOW_DOCUMENT", message);
290
+ };
291
+ function canonical(value) {
292
+ if (Array.isArray(value)) return "[" + value.map(canonical).join(",") + "]";
293
+ if (value && typeof value === "object") return "{" + Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => JSON.stringify(k) + ":" + canonical(v)).join(",") + "}";
294
+ return JSON.stringify(value);
295
+ }
296
+ /**
297
+ * What an attempt's evidence is bound to. An attempt whose start names task binding
298
+ * answers only for its own task; one that names nothing was started before task
299
+ * binding existed and stays bound to every document of the change. A task with no
300
+ * attempt yet will be started under task binding.
301
+ */
302
+ function taskBinding(events) {
303
+ const start = events.findLast((e) => e.kind === "start");
304
+ return !start || start.binding === "task" ? "task" : "change";
305
+ }
306
+ /**
307
+ * The fingerprint of each task of a change: its own entry in the task list, the
308
+ * wording of the requirements and scenarios it refers to, and the verification maps
309
+ * it refers to. Other tasks, the proposal, the design, requirements it does
310
+ * not refer to and the author's done/pending mark are deliberately left out, so
311
+ * editing them does not disturb evidence already recorded for this task.
312
+ *
313
+ * Expects a change that passes validation; anything else is refused.
314
+ */
315
+ function taskFingerprints(input, parse = inspectWorkflow) {
316
+ const tasks = parse(input.files["tasks.md"] ?? invalid("Expected tasks document"));
317
+ if (tasks.meta.kind !== "tasks") return invalid("Expected tasks document");
318
+ const parsed = /* @__PURE__ */ new Map();
319
+ const once = (key, source) => {
320
+ if (!parsed.has(key)) parsed.set(key, typeof source === "string" ? parse(source) : null);
321
+ return parsed.get(key);
322
+ };
323
+ const text = (doc, block) => (doc.blocks.get(block) ?? "").trim();
324
+ const result = /* @__PURE__ */ new Map();
325
+ for (const task of tasks.meta.tasks) {
326
+ const wanted = new Set(task.scenarios);
327
+ const requirements = task.requirements.map((reference) => {
328
+ const [capability, id] = reference.split("#");
329
+ const delta = once(`delta:${capability}`, input.files[`specs/${capability}.md`]);
330
+ if (!delta || delta.meta.kind !== "delta") return invalid("Expected delta");
331
+ const edit = delta.meta.changes.find((c) => (c.operation === "remove" ? c.requirementId : c.requirement.id) === id);
332
+ if (!edit) return invalid("Requirement is not in the change");
333
+ const scenarios = (edit.operation === "remove" ? edit.scenarios : edit.requirement.scenarios).filter((s) => wanted.has(`${capability}#${s.id}`)).map((s) => ({
334
+ reference: `${capability}#${s.id}`,
335
+ given: text(delta, s.given),
336
+ when: text(delta, s.when),
337
+ then: text(delta, s.then)
338
+ }));
339
+ if (edit.operation !== "remove") return {
340
+ reference,
341
+ operation: edit.operation,
342
+ statement: text(delta, edit.requirement.statement),
343
+ scenarios
344
+ };
345
+ const formal = once(`formal:${capability}`, input.baselines[capability]);
346
+ const original = formal?.meta.kind === "spec" ? formal.meta.requirements.find((r) => r.id === id) : null;
347
+ return {
348
+ reference,
349
+ operation: edit.operation,
350
+ reason: text(delta, edit.reason),
351
+ original: original && formal ? text(formal, original.statement) : null,
352
+ scenarios
353
+ };
354
+ });
355
+ const verification = task.verify.flatMap((step) => {
356
+ if (!step.reference) return [];
357
+ const content = input.verification?.[step.reference.split("#")[0]];
358
+ return [{
359
+ reference: step.reference,
360
+ map: typeof content === "string" ? hash(content) : null
361
+ }];
362
+ });
363
+ const { status: _status, ...entry } = task;
364
+ result.set(task.id, hash(canonical({
365
+ fingerprint: "task",
366
+ version: 1,
367
+ changeId: input.changeId,
368
+ task: entry,
369
+ description: text(tasks, task.description),
370
+ tddReason: task.tddReason ? text(tasks, task.tddReason) : null,
371
+ requirements,
372
+ verification
373
+ })));
374
+ }
375
+ return result;
376
+ }
285
377
  // ../../packages/workflow/src/change.ts
286
378
  const compareText = (a, b) => a < b ? -1 : a > b ? 1 : 0;
287
379
  /** Names never read as task source: environment files and private or vendored directories. */
@@ -577,8 +669,10 @@ function checkedArchivePlan(value) {
577
669
  const meta = inspectWorkflow(p.files["tasks.md"]).meta;
578
670
  if (meta.kind !== "tasks") throw new Error("Expected tasks");
579
671
  if (p.tasks.length !== meta.tasks.length || new Set(p.tasks.map((t) => t.taskId)).size !== p.tasks.length) throw new CoreError("PAYLOAD_UNSUPPORTED", "Archive task coverage mismatch");
672
+ const fingerprints = taskFingerprints(input);
580
673
  for (const entry of p.tasks) {
581
674
  const task = meta.tasks.find((t) => t.id === entry.taskId);
675
+ if (taskBinding(entry.events) === "task" ? entry.inputHash === void 0 || entry.inputHash !== fingerprints.get(entry.taskId) : entry.inputHash !== void 0) throw new CoreError("PAYLOAD_UNSUPPORTED", "Archive task fingerprint mismatch");
582
676
  for (const raw of entry.events) {
583
677
  const e = raw;
584
678
  const { createdAt, inputHash, sourceHash, ...fields } = e;
@@ -600,7 +694,7 @@ function checkedArchivePlan(value) {
600
694
  }
601
695
  }
602
696
  if (!task || hash(JSON.stringify(entry.events)) !== entry.eventHash || taskState(task, entry.events, {
603
- inputHash: p.inputHash,
697
+ inputHash: entry.inputHash ?? p.inputHash,
604
698
  sourceHash: entry.sourceHash
605
699
  }).state !== "done") throw new CoreError("PAYLOAD_UNSUPPORTED", "Archive task evidence is incomplete");
606
700
  }
@@ -629,10 +723,11 @@ function archiveReceipt(plan, operationId, preparedAt) {
629
723
  attemptId: events[start].operationId,
630
724
  sourceHash: t.sourceHash,
631
725
  eventHash: t.eventHash,
726
+ ...t.inputHash === void 0 ? {} : { inputHash: t.inputHash },
632
727
  roundsWithFindings: events.filter((e) => e.kind === "challenge" && e.findings.length).length,
633
728
  evidence: events.slice(start + 1)
634
729
  };
635
730
  })
636
731
  };
637
732
  }
638
- export { validScopePath as a, challengePolicy as c, deniedScopeName as i, taskState as l, checkedArchivePlan as n, validateChange as o, mergeFormal as r, acceptTaskEvent as s, archiveReceipt as t, taskEvidence as u };
733
+ export { validScopePath as a, taskFingerprints as c, taskState as d, taskEvidence as f, deniedScopeName as i, acceptTaskEvent as l, checkedArchivePlan as n, validateChange as o, mergeFormal as r, taskBinding as s, archiveReceipt as t, challengePolicy as u };
@@ -0,0 +1 @@
1
+ export { t as archiveCommand } from "./archive-BDQ_oB6g.mjs";
@@ -2,10 +2,10 @@ import { t as CoreError } from "./src-CRhxwFAN.mjs";
2
2
  import { t as hash } from "./src-DeDtBfdV.mjs";
3
3
  import { n as workflowId } from "./change-DgUPVNsm.mjs";
4
4
  import { n as inspectWorkflow } from "./verification-B4QMPPeA.mjs";
5
- import { c as challengePolicy, o as validateChange } from "./archive-YanRypPH.mjs";
5
+ import { o as validateChange, u as challengePolicy } from "./archive-BEqNOztX.mjs";
6
6
  import { t as findProject } from "./project-directory-w_ITkI7O.mjs";
7
- import { t as bundle } from "./change-DNLxzdWK.mjs";
8
- import { t as sourceFingerprint } from "./task-snapshot-CNi4Yswc.mjs";
7
+ import { t as bundle } from "./change-B3CIaYav.mjs";
8
+ import { n as taskCommand, r as sourceFingerprint } from "./task-dw_E1Rl2.mjs";
9
9
  import { join } from "node:path";
10
10
  // src/commands/challenge-brief.ts
11
11
  const rules = [
@@ -86,8 +86,9 @@ async function challengeBrief(args, project) {
86
86
  };
87
87
  });
88
88
  const { level, roundLimit } = challengePolicy(task);
89
+ const status = await taskCommand("status", [changeId, taskId], project);
89
90
  const again = await capture();
90
- if (again.inputHash !== current.inputHash || again.sourceHash !== current.sourceHash) throw new CoreError("LOCAL_CONFLICT", "Inputs changed while the brief was produced");
91
+ if (again.inputHash !== current.inputHash || again.sourceHash !== current.sourceHash || status.sourceHash !== current.sourceHash) throw new CoreError("LOCAL_CONFLICT", "Inputs changed while the brief was produced");
91
92
  const text = [
92
93
  `# Challenge brief: ${changeId} ${taskId}`,
93
94
  "",
@@ -128,7 +129,7 @@ async function challengeBrief(args, project) {
128
129
  "",
129
130
  "## Content this brief describes",
130
131
  "",
131
- `- Documents: ${current.inputHash}`,
132
+ `- Documents: ${status.inputHash}`,
132
133
  `- Source: ${current.sourceHash}`,
133
134
  "",
134
135
  "A report is only valid for exactly this content. If the source changes, a new brief and a new round are needed.",
@@ -147,7 +148,7 @@ async function challengeBrief(args, project) {
147
148
  level,
148
149
  required: level > 0,
149
150
  roundLimit,
150
- inputHash: current.inputHash,
151
+ inputHash: status.inputHash,
151
152
  sourceHash: current.sourceHash,
152
153
  scope: task.scope,
153
154
  requirements,
@@ -2,11 +2,11 @@ import { t as CoreError } from "./src-CRhxwFAN.mjs";
2
2
  import { t as hash } from "./src-DeDtBfdV.mjs";
3
3
  import { n as workflowId } from "./change-DgUPVNsm.mjs";
4
4
  import { n as inspectWorkflow, r as workflowMarkdown } from "./verification-B4QMPPeA.mjs";
5
- import { o as validateChange } from "./archive-YanRypPH.mjs";
5
+ import { o as validateChange } from "./archive-BEqNOztX.mjs";
6
6
  import { t as readBounded } from "./files-Ca24RKdp.mjs";
7
7
  import { n as withLocks } from "./locks-C4XYFwbg.mjs";
8
8
  import { t as findProject } from "./project-directory-w_ITkI7O.mjs";
9
- import { i as assertNoArchiveIntent, n as openJournal } from "./journal-Da95Qqey.mjs";
9
+ import { i as assertNoArchiveIntent, n as openJournal } from "./journal-7SNjewV7.mjs";
10
10
  import { t as readVerification } from "./verification-cEb-1z2d.mjs";
11
11
  import { randomUUID } from "node:crypto";
12
12
  import { join } from "node:path";
@@ -0,0 +1 @@
1
+ export { n as changeCommand } from "./change-B3CIaYav.mjs";
@@ -10,7 +10,7 @@
10
10
  supekku change archive-plan demo --project /path/to/project --json
11
11
  ```
12
12
 
13
- 預覽不建立 DB。回傳 `ready`、`blockers`,可封存時另有 `planHash` 和 `plan`,包含原文件、基準與目標內容、各任務 sourceHash 和事件指紋。Agent 應檢視前後差異,確認 scope 已包含相關程式、測試與設定;工具不證明 scope 完整,也不證明 Agent 的測試陳述真實。
13
+ 預覽不建立 DB。回傳 `ready`、`blockers`,可封存時另有 `planHash` 和 `plan`,包含原文件、基準與目標內容、各任務 sourceHash 和事件指紋;綁定任務指紋的任務另有它的 inputHash(任務指紋)。封存凍結的仍是整份 change:任務完成之後修改其他任務或 proposal 不妨礙封存,只要每個任務依自己的指紋仍是 done。Agent 應檢視前後差異,確認 scope 已包含相關程式、測試與設定;工具不證明 scope 完整,也不證明 Agent 的測試陳述真實。
14
14
 
15
15
  計畫與完成紀錄各有64MiB上限,預覽會先檢查,超過時不建立封存操作。
16
16
 
@@ -39,7 +39,7 @@ completion.json 的 receiptVersion 為1,包含:
39
39
 
40
40
  - operationId、changeId、preparedAt(操作準備時間)、planHash、inputHash。
41
41
  - 每份正式檔案的相對路徑、beforeHash(新檔為null)與 afterHash。
42
- - 每個任務的 taskId、attemptId、sourceHash、eventHash、roundsWithFindings(這個任務所有 attempt 中含有確認發現的挑戰輪數)與該 attempt 的 TDD/Verify/Challenge/Review/finish 事件。較早版本寫下的完成紀錄沒有 roundsWithFindings。
42
+ - 每個任務的 taskId、attemptId、sourceHash、eventHash、inputHash(任務指紋;只有綁定任務指紋的任務才有,完成紀錄不保留 start 事件,所以這個欄位也是判斷綁定方式的依據。沒有這個欄位的任務,證據綁定最上層的 inputHash,也就是整份 change)、roundsWithFindings(這個任務所有 attempt 中含有確認發現的挑戰輪數)與該 attempt 的 TDD/Verify/Challenge/Review/finish 事件。較早版本寫下的完成紀錄沒有 roundsWithFindings。
43
43
  - attestationOnly=true:這是當時 Agent 陳述與內容對應的歷史紀錄,不是防偽憑證或新 checkout 的執行權限。
44
44
 
45
45
  此檔可進 Git;不包含 start 的授權文字,但其他事件的 command、summary、reviewer 與 findings 會保存,Agent 提交時必須去除敏感資訊。完整凍結計畫與事件仍保存在 `.supekku/.local/operations.sqlite`,不進 Git。
@@ -1,5 +1,5 @@
1
1
  import { t as CoreError } from "./src-CRhxwFAN.mjs";
2
- import { n as directoryPresence, s as projectObservation } from "./project-CTKghH7_.mjs";
2
+ import { n as directoryPresence, s as projectObservation } from "./project-CMFCxtKO.mjs";
3
3
  import { t as nodeSupported } from "./package-Ci4aNmkW.mjs";
4
4
  import { a as targetPath, i as skillStatus } from "./skills-DcxDoyH7.mjs";
5
5
  import { join } from "node:path";
@@ -0,0 +1 @@
1
+ export { t as doctor } from "./doctor-CKgYDYGQ.mjs";
package/dist/index.mjs CHANGED
@@ -652,7 +652,7 @@ try {
652
652
  let data;
653
653
  if (command === "status") {
654
654
  const { packageIdentity } = await import("./package-Dg68Av6x.mjs");
655
- const { projectSummary } = await import("./status-DSbw584b.mjs");
655
+ const { projectSummary } = await import("./status-DKLbxPPK.mjs");
656
656
  const remoteCheck = parsed.reportRemote ? async (root) => {
657
657
  const { projectStatus, readBinding } = await import("./project-BMl3DPyE.mjs");
658
658
  if (!(await readBinding(root)).binding) return { remote: { state: "unbound" } };
@@ -663,7 +663,7 @@ try {
663
663
  if (!data.complete) process.exitCode = 2;
664
664
  } else if (command === "init" && parsed.initOptions) {
665
665
  const { packageIdentity } = await import("./package-Dg68Av6x.mjs");
666
- const { selectTarget, initProject } = await import("./init-BJ9BXQf-.mjs");
666
+ const { selectTarget, initProject } = await import("./init-DL-jiGgQ.mjs");
667
667
  const { withLockOptions } = await import("./locks-ePa5rQ2P.mjs");
668
668
  const target = await selectTarget(parsed.initOptions, !json && !!process.stdin.isTTY && !!process.stderr.isTTY);
669
669
  const identity = await packageIdentity();
@@ -683,27 +683,27 @@ try {
683
683
  const { packageIdentity } = await import("./package-Dg68Av6x.mjs");
684
684
  const identity = await packageIdentity();
685
685
  if (command === "doctor") {
686
- const { doctor } = await import("./doctor-CdPqyaCC.mjs");
686
+ const { doctor } = await import("./doctor-DxcQvrCD.mjs");
687
687
  data = await doctor(parsed.project ?? process.cwd(), args[0], identity);
688
688
  if (!data.ready) process.exitCode = 2;
689
689
  } else {
690
- const { initializedProject, nativeProject } = await import("./project-CWpJQSO5.mjs");
690
+ const { initializedProject, nativeProject } = await import("./project-3tknDiOf.mjs");
691
691
  const root = await (command === "skills install" ? initializedProject : nativeProject)(parsed.project ?? process.cwd());
692
692
  const { installSkills, skillStatus } = await import("./skills-YRZw153S.mjs");
693
693
  data = command === "skills install" ? await installSkills(root, args[0], identity) : await skillStatus(root, args[0], identity);
694
694
  }
695
695
  } else if (command.startsWith("change archive")) {
696
- const { archiveCommand } = await import("./archive-CpcY2BcO.mjs");
696
+ const { archiveCommand } = await import("./archive-F8QO5Uzt.mjs");
697
697
  data = await archiveCommand(command.slice(7), args, parsed.project ?? process.cwd());
698
698
  if (command === "change archive-plan" && !data.ready) process.exitCode = 2;
699
699
  } else if (command === "records publish") {
700
- const { publishRecords } = await import("./records-DzVfCcPk.mjs");
700
+ const { publishRecords } = await import("./records-DZFyxxNq.mjs");
701
701
  data = await publishRecords(parsed.project ?? process.cwd(), args);
702
702
  } else if (command === "task brief") {
703
- const { challengeBrief } = await import("./challenge-brief--2-bDO8A.mjs");
703
+ const { challengeBrief } = await import("./challenge-brief-D6e2atsF.mjs");
704
704
  data = await challengeBrief(args, parsed.project ?? process.cwd());
705
705
  } else if (command.startsWith("task ")) {
706
- const { taskCommand, readTaskInput } = await import("./task-DfJ5t8aZ.mjs");
706
+ const { taskCommand, readTaskInput } = await import("./task-JlFSBhEW.mjs");
707
707
  const action = command.slice(5);
708
708
  data = await taskCommand(action, args, parsed.project ?? process.cwd(), ["status", "snapshot"].includes(action) ? void 0 : await readTaskInput());
709
709
  } else if (command.startsWith("verification ")) {
@@ -711,7 +711,7 @@ try {
711
711
  data = await verificationCommand(command.slice(13), args, parsed.project ?? process.cwd());
712
712
  if (command === "verification validate" && !data.valid) process.exitCode = 2;
713
713
  } else if (command.startsWith("change ") || command.startsWith("spec ")) {
714
- const { changeCommand } = await import("./change-Crv0O1j3.mjs");
714
+ const { changeCommand } = await import("./change-Ueo8V0d5.mjs");
715
715
  data = await changeCommand(command, args, parsed.project ?? process.cwd());
716
716
  if (command === "change validate" && !data.valid) process.exitCode = 2;
717
717
  } else if (command === "connect" && parsed.connectOptions) {
@@ -778,14 +778,14 @@ try {
778
778
  signal: controller.signal
779
779
  }, async () => {
780
780
  if (command === "local init") {
781
- const { initializeProject } = await import("./project-CWpJQSO5.mjs");
781
+ const { initializeProject } = await import("./project-3tknDiOf.mjs");
782
782
  return initializeProject(parsed.project ?? process.cwd(), "independent" in parsed && parsed.independent);
783
783
  }
784
784
  if (command === "operation show" || command === "operation list") {
785
- const local = await import("./local-PdPue5jY.mjs");
785
+ const local = await import("./local-Dz8Zbwnw.mjs");
786
786
  return command === "operation show" ? local.showOperation(process.cwd(), args[0]) : local.listOperations(process.cwd());
787
787
  }
788
- const m = await import("./maintenance-BHKtYJIT.mjs");
788
+ const m = await import("./maintenance-wIhESufF.mjs");
789
789
  if (command === "local db upgrade") return m.upgradeLocal(process.cwd());
790
790
  if (command === "local db backup") return m.backupLocal(process.cwd());
791
791
  if (command === "local db backups") return m.listBackups(process.cwd());
@@ -1,8 +1,8 @@
1
1
  import { o as normalizeError, t as CoreError } from "./src-CRhxwFAN.mjs";
2
- import { i as initializeProject, r as initializationObservation } from "./project-CTKghH7_.mjs";
2
+ import { i as initializeProject, r as initializationObservation } from "./project-CMFCxtKO.mjs";
3
3
  import { t as nodeSupported } from "./package-Ci4aNmkW.mjs";
4
4
  import { i as skillStatus, n as checkSkillResults, r as installSkills } from "./skills-DcxDoyH7.mjs";
5
- import { t as doctor } from "./doctor-CK0Ny6ct.mjs";
5
+ import { t as doctor } from "./doctor-CKgYDYGQ.mjs";
6
6
  import { createInterface } from "node:readline/promises";
7
7
  // src/onboarding/init.ts
8
8
  const targets = {
@@ -1,7 +1,7 @@
1
1
  import { a as freeze, s as planPayload, t as CoreError } from "./src-CRhxwFAN.mjs";
2
2
  import { r as plan, t as hash } from "./src-DeDtBfdV.mjs";
3
3
  import { n as workflowId } from "./change-DgUPVNsm.mjs";
4
- import { n as checkedArchivePlan, u as taskEvidence } from "./archive-YanRypPH.mjs";
4
+ import { f as taskEvidence, n as checkedArchivePlan } from "./archive-BEqNOztX.mjs";
5
5
  import { randomUUID } from "node:crypto";
6
6
  import { dirname, join } from "node:path";
7
7
  import { chmodSync, existsSync, lstatSync, readFileSync, realpathSync } from "node:fs";
@@ -1 +1 @@
1
- export { n as initialize, r as listOperations, i as showOperation } from "./local-DyZAVffW.mjs";
1
+ export { n as initialize, r as listOperations, i as showOperation } from "./local-odic_qV5.mjs";
@@ -2,7 +2,7 @@ import { t as CoreError } from "./src-CRhxwFAN.mjs";
2
2
  import "./files-DphxaLNK.mjs";
3
3
  import { n as withLocks } from "./locks-C4XYFwbg.mjs";
4
4
  import { i as requireCurrentDirectory } from "./project-directory-w_ITkI7O.mjs";
5
- import { n as openJournal } from "./journal-Da95Qqey.mjs";
5
+ import { n as openJournal } from "./journal-7SNjewV7.mjs";
6
6
  import { join } from "node:path";
7
7
  import { lstat, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
8
8
  // src/local/index.ts
@@ -2,8 +2,8 @@ import { t as CoreError } from "./src-CRhxwFAN.mjs";
2
2
  import { t as hash } from "./src-DeDtBfdV.mjs";
3
3
  import { n as documentPath, r as readMarkdown } from "./files-DphxaLNK.mjs";
4
4
  import { n as withLocks } from "./locks-C4XYFwbg.mjs";
5
- import { a as assertNoRestore, c as inspectDatabase, d as newIdentity, i as assertNoArchiveIntent, l as meta, o as assertRegular, r as CLI_VERSION, s as connect, u as migrate } from "./journal-Da95Qqey.mjs";
6
- import { t as context } from "./local-DyZAVffW.mjs";
5
+ import { a as assertNoRestore, c as inspectDatabase, d as newIdentity, i as assertNoArchiveIntent, l as meta, o as assertRegular, r as CLI_VERSION, s as connect, u as migrate } from "./journal-7SNjewV7.mjs";
6
+ import { t as context } from "./local-odic_qV5.mjs";
7
7
  import { createHash, randomUUID } from "node:crypto";
8
8
  import { join } from "node:path";
9
9
  import { chmod, copyFile, lstat, mkdir, open, readFile, readdir, rename, statfs, unlink } from "node:fs/promises";
@@ -1 +1 @@
1
- export { i as initializeProject, a as initializedProject, o as nativeProject } from "./project-CTKghH7_.mjs";
1
+ export { i as initializeProject, a as initializedProject, o as nativeProject } from "./project-CMFCxtKO.mjs";
@@ -87,7 +87,7 @@ async function initializeProject(start, independent = false) {
87
87
  } catch (error) {
88
88
  if (error.code !== "ENOENT") throw error;
89
89
  }
90
- const { initialize } = await import("./local-PdPue5jY.mjs");
90
+ const { initialize } = await import("./local-Dz8Zbwnw.mjs");
91
91
  await initialize(observed.root);
92
92
  return {
93
93
  initialized: true,
@@ -2,7 +2,7 @@ import { l as Check, n as Hash, t as CoreError, u as Type } from "./src-CRhxwFAN
2
2
  import { t as hash } from "./src-DeDtBfdV.mjs";
3
3
  import { t as WorkflowId } from "./change-DgUPVNsm.mjs";
4
4
  import { n as inspectWorkflow } from "./verification-B4QMPPeA.mjs";
5
- import { c as challengePolicy, l as taskState, r as mergeFormal, s as acceptTaskEvent, u as taskEvidence } from "./archive-YanRypPH.mjs";
5
+ import { c as taskFingerprints, d as taskState, f as taskEvidence, l as acceptTaskEvent, r as mergeFormal, u as challengePolicy } from "./archive-BEqNOztX.mjs";
6
6
  import { t as findProject } from "./project-directory-w_ITkI7O.mjs";
7
7
  import { join } from "node:path";
8
8
  import { lstat, open, readdir } from "node:fs/promises";
@@ -56,6 +56,7 @@ const CompletionSchema = Type.Object({
56
56
  attemptId: uuid$1,
57
57
  sourceHash: Hash,
58
58
  eventHash: Hash,
59
+ inputHash: Type.Optional(Hash),
59
60
  roundsWithFindings: Type.Optional(Type.Integer({
60
61
  minimum: 0,
61
62
  maximum: 1e4
@@ -247,7 +248,7 @@ const findingRounds = (events) => events.filter((e) => e.kind === "challenge" &&
247
248
  * record hold together.
248
249
  */
249
250
  function replay(task, entry, completion) {
250
- const { inputHash } = completion;
251
+ const inputHash = entry.inputHash ?? completion.inputHash;
251
252
  let previous = "";
252
253
  const evidence = entry.evidence.map((raw) => {
253
254
  const e = raw;
@@ -269,6 +270,7 @@ function replay(task, entry, completion) {
269
270
  evidenceVersion: 1,
270
271
  operationId: entry.attemptId,
271
272
  authorization: "Not kept in the receipt",
273
+ ...entry.inputHash === void 0 ? {} : { binding: "task" },
272
274
  inputHash,
273
275
  sourceHash: entry.sourceHash,
274
276
  createdAt: evidence[0].createdAt
@@ -433,6 +435,18 @@ function replayed(snapshot) {
433
435
  for (const source of [...Object.values(input.files), ...Object.values(input.baselines)]) read += source === null ? 0 : source.length;
434
436
  if (read > recordsLimits.replayLength) refuse$1("History is too large to replay");
435
437
  if (hash(JSON.stringify(input)) !== c.change.completion.inputHash) refuse$1("Archived documents do not carry the fingerprint their record is bound to");
438
+ const stated = c.change.completion.tasks.filter((t) => t.inputHash !== void 0);
439
+ if (stated.length) {
440
+ const known = /* @__PURE__ */ new Map([[input.files["tasks.md"], c.tasks]]);
441
+ for (const [capability, delta] of c.deltas) known.set(input.files[`specs/${capability}.md`], delta);
442
+ let fingerprints;
443
+ try {
444
+ fingerprints = taskFingerprints(input, (source) => known.get(source) ?? inspectWorkflow(source));
445
+ } catch {
446
+ return refuse$1("Archived task fingerprints cannot be computed");
447
+ }
448
+ for (const t of stated) if (fingerprints.get(t.taskId) !== t.inputHash) refuse$1("Archived task does not carry the fingerprint its evidence is bound to");
449
+ }
436
450
  for (const target of mergeFormal(input)) {
437
451
  const receipt = receiptFor(c, target.capability);
438
452
  if (receipt.beforeHash !== (target.before === null ? null : hash(target.before)) || receipt.afterHash !== hash(target.after)) refuse$1("Archived change does not produce the result its record states");
@@ -10,7 +10,7 @@
10
10
  supekku change archive-plan demo --project /path/to/project --json
11
11
  ```
12
12
 
13
- 預覽不建立 DB。回傳 `ready`、`blockers`,可封存時另有 `planHash` 和 `plan`,包含原文件、基準與目標內容、各任務 sourceHash 和事件指紋。Agent 應檢視前後差異,確認 scope 已包含相關程式、測試與設定;工具不證明 scope 完整,也不證明 Agent 的測試陳述真實。
13
+ 預覽不建立 DB。回傳 `ready`、`blockers`,可封存時另有 `planHash` 和 `plan`,包含原文件、基準與目標內容、各任務 sourceHash 和事件指紋;綁定任務指紋的任務另有它的 inputHash(任務指紋)。封存凍結的仍是整份 change:任務完成之後修改其他任務或 proposal 不妨礙封存,只要每個任務依自己的指紋仍是 done。Agent 應檢視前後差異,確認 scope 已包含相關程式、測試與設定;工具不證明 scope 完整,也不證明 Agent 的測試陳述真實。
14
14
 
15
15
  計畫與完成紀錄各有64MiB上限,預覽會先檢查,超過時不建立封存操作。
16
16
 
@@ -39,7 +39,7 @@ completion.json 的 receiptVersion 為1,包含:
39
39
 
40
40
  - operationId、changeId、preparedAt(操作準備時間)、planHash、inputHash。
41
41
  - 每份正式檔案的相對路徑、beforeHash(新檔為null)與 afterHash。
42
- - 每個任務的 taskId、attemptId、sourceHash、eventHash、roundsWithFindings(這個任務所有 attempt 中含有確認發現的挑戰輪數)與該 attempt 的 TDD/Verify/Challenge/Review/finish 事件。較早版本寫下的完成紀錄沒有 roundsWithFindings。
42
+ - 每個任務的 taskId、attemptId、sourceHash、eventHash、inputHash(任務指紋;只有綁定任務指紋的任務才有,完成紀錄不保留 start 事件,所以這個欄位也是判斷綁定方式的依據。沒有這個欄位的任務,證據綁定最上層的 inputHash,也就是整份 change)、roundsWithFindings(這個任務所有 attempt 中含有確認發現的挑戰輪數)與該 attempt 的 TDD/Verify/Challenge/Review/finish 事件。較早版本寫下的完成紀錄沒有 roundsWithFindings。
43
43
  - attestationOnly=true:這是當時 Agent 陳述與內容對應的歷史紀錄,不是防偽憑證或新 checkout 的執行權限。
44
44
 
45
45
  此檔可進 Git;不包含 start 的授權文字,但其他事件的 command、summary、reviewer 與 findings 會保存,Agent 提交時必須去除敏感資訊。完整凍結計畫與事件仍保存在 `.supekku/.local/operations.sqlite`,不進 Git。
@@ -44,7 +44,7 @@ Start 範例:
44
44
  }
45
45
  ```
46
46
 
47
- 既有 attempt 重新開始時加 `restart:true`。Start 的 operationId 是 attemptId。所有其他事件加上 `attemptId`、`inputHash`、`sourceHash`;後兩者取自**執行測試/review 前**的 snapshot。提交時 CLI 重算比對,不能在測試後取得新 hash 冒充已測內容。
47
+ 既有 attempt 重新開始時加 `restart:true`。Start 的 operationId 是 attemptId。CLI 會在保存的 start 事件上加註 `binding:"task"`,表示這個 attempt 的證據綁定任務指紋(見「狀態與失效」);這個欄位由 CLI 填寫,提交時不必附上,附上相同的值也接受。所有其他事件加上 `attemptId`、`inputHash`、`sourceHash`;後兩者取自**執行測試/review 前**的 snapshot。提交時 CLI 重算比對,不能在測試後取得新 hash 冒充已測內容。
48
48
 
49
49
  | kind/指令 | 額外欄位 |
50
50
  | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -74,7 +74,7 @@ Tasks 的每個任務可用 `challenge` 宣告 0 到 3 的挑戰等級,未宣
74
74
  supekku task brief demo TASK-001 --project /path/to/project --json
75
75
  ```
76
76
 
77
- 這是唯讀指令,不讀取標準輸入,不需要也不建立本機日誌。回傳 `level`、`required`、`roundLimit`、`inputHash`、`sourceHash`、`scope`、`requirements`(需求與情境原文)、`rules`、`report`(回報格式),以及把這些組成一份可直接交付的 `text`。它不含任何已記錄的證據、摘要或 Review 結論,也不含 Tasks 中實作者的任務描述。等級 0 的任務也能取得說明,`required` 為 false。
77
+ 這是唯讀指令,不讀取標準輸入,不需要也不建立本機日誌;日誌存在時只讀取它,以取得目前 attempt 所綁定的指紋。回傳 `level`、`required`、`roundLimit`、`inputHash`、`sourceHash`、`scope`、`requirements`(需求與情境原文)、`rules`、`report`(回報格式),以及把這些組成一份可直接交付的 `text`。它不含任何已記錄的證據、摘要或 Review 結論,也不含 Tasks 中實作者的任務描述。等級 0 的任務也能取得說明,`required` 為 false。
78
78
 
79
79
  2. 把 `text` 原樣交給挑戰者,不要附上自己的測試結果或推論。挑戰者依規則回報一個 JSON 物件。
80
80
  3. 將回報記為 `challenge` 事件:填入 `verifyId`、取得說明時的 `inputHash`/`sourceHash` 與 `attemptId`。說明之後若原始碼有變動,指紋不符會被拒絕,需重新 Verify 並重新挑戰。
@@ -96,7 +96,9 @@ Tasks 的每個任務可用 `challenge` 宣告 0 到 3 的挑戰等級,未宣
96
96
 
97
97
  pending → running → verified → reviewed → done;可 block/resume,指紋改變時為 stale。Tasks Markdown 的 pending/done 僅為舊有作者宣告,不控制執行紀錄;不用回寫它。
98
98
 
99
- - `inputHash` 涵蓋整份 change(包含其他 Tasks)及參照的正式基準。內容變動必須明確 restart;新 attempt 保留舊 events。
99
+ - `inputHash` 是**任務指紋**,只涵蓋這個任務自己的定義:它在 Tasks 中的項目(描述、引用的需求與情境、依賴、scope、verify、tdd 與理由、挑戰等級)、它引用的需求與情境在本 change 中的內文(移除的需求另含正式規格的原文),以及它引用的驗證地圖(整份地圖的內容,不只是被引用的那一項)。其他任務的項目、proposal 與 design 的內文、沒有被引用的需求,以及 Tasks 上的 pending/done 標記都不在其中;修改它們不使這個任務的任何證據失效。任務指紋改變時必須明確 restart;新 attempt 保留舊 events。
100
+ - 任務指紋不偵測沒有寫進文件的關係:proposal 改了方向卻沒有改到任務引用的需求,或兩個任務實際互相影響卻沒有以依賴或共同引用的需求表達時,工具不會要求 restart,要由人判斷。
101
+ - 加入任務指紋之前開始的 attempt(start 事件沒有 `binding`)維持原本的綁定:`inputHash` 涵蓋整份 change 及參照的正式基準,任何文件變動都要 restart。restart 之後的新 attempt 才改綁任務指紋。升級 CLI 本身不會讓進行中的任務失效。
100
102
  - `sourceHash` 涵蓋 task.scope 中檔案的內容、名稱、存在狀態和目錄。修改後 Green/Verify/Challenge/Review/Done 失效,Red 歷史保留。重新提交新證據可繼續同一 attempt。
101
103
  - 新 Red/Green 使舊 Verify/Challenge/Review 不再有效;新 Verify 必須重新 Challenge(等級 1 以上)與 Review;failed 結果不沿用舊 pass。block/resume 清除目前 gates,但保留歷史。
102
104
  - 依賴任務必須目前有效 done。後續任務若修改了前一任務 scope,先刷新前一任務證據,才能完成依賴它的任務。
@@ -104,11 +106,11 @@ pending → running → verified → reviewed → done;可 block/resume,
104
106
  - `.env`、所有 `.env.*`(含 example)、`.git`、`node_modules`、`.supekku`、legacy `supekku` 目錄不讀。直接指定拒絕,遞迴遇到排除;symlink/特殊檔案拒絕。單檔4MiB、總計64MiB、最多10000項、深度64。
105
107
  - 未列入 scope 的檔案、工具版本與外部環境不能自動偵測。內容改回相同 bytes 會再次符合指紋;不提供惡意並行修改的防護或執行結果防偽。
106
108
 
107
- status/snapshot 回傳 state、attemptId、reason、inputHash、sourceHash、files(hash 或 missing/directory)、dependencies、events 與 `attestationOnly:true`。mutation 回傳保存事件,含 CLI 時間 createdAt。標準外層為 outputVersion/command/ok/data;stale/blocked 狀態本身是成功查詢,不是 CLI 錯誤。mutation 衝突為 `LOCAL_CONFLICT`(exit6);非法證據 `INVALID_ARGUMENT`(2);未初始化、需升級或新 schema 則使用既有 journal 錯誤代碼。
109
+ status/snapshot 回傳 state、attemptId、reason、binding(`task` 或 `change`,目前 attempt 的綁定方式;尚未開始的任務為 `task`)、inputHash(依綁定方式為任務指紋或整份 change 的指紋)、sourceHash、files(hash 或 missing/directory)、dependencies、events 與 `attestationOnly:true`。mutation 回傳保存事件,含 CLI 時間 createdAt。標準外層為 outputVersion/command/ok/data;stale/blocked 狀態本身是成功查詢,不是 CLI 錯誤。mutation 衝突為 `LOCAL_CONFLICT`(exit6);非法證據 `INVALID_ARGUMENT`(2);未初始化、需升級或新 schema 則使用既有 journal 錯誤代碼。
108
110
 
109
111
  ## 持久化、安裝與限制
110
112
 
111
- 紀錄在 `.supekku/.local/operations.sqlite` 的 task_events。schema4 新增 archive migration(task_events 自 schema3 引入),既有 SQL 不變。舊 journal 需明確 upgrade,升級前備份;舊 CLI 見新 schema 拒絕。DB 還原只還原紀錄,不還原程式;還原後先依既有 local db reconcile 流程解除限制,再檢查 task status。備份之後的新任務事件不會出現在還原後 DB,需以保留的還原前備份追查;不可假定還原後的舊紀錄代表目前工作。
113
+ 紀錄在 `.supekku/.local/operations.sqlite` 的 task_events。schema4 新增 archive migration(task_events 自 schema3 引入),既有 SQL 不變。任務指紋沒有新增 migration;但 0.1.0-alpha.8 及更早的 CLI 不認得 start 事件上的 `binding`,遇到含有它的日誌會整個拒絕開啟(`PAYLOAD_UNSUPPORTED`),不會把這些 attempt 誤判為有效,也不會改動日誌;換回新版 CLI 即可繼續。舊 journal 需明確 upgrade,升級前備份;舊 CLI 見新 schema 拒絕。DB 還原只還原紀錄,不還原程式;還原後先依既有 local db reconcile 流程解除限制,再檢查 task status。備份之後的新任務事件不會出現在還原後 DB,需以保留的還原前備份追查;不可假定還原後的舊紀錄代表目前工作。
112
114
 
113
115
  套件包含 `dist/skills/supekku-development/`,整個資料夾可由使用者複製到 Agent 支援的 skills 目錄。套件不自動安裝全域 skill。skill 的 references 包含本指南與 native 文件格式。正式規格合併與封存使用獨立的 change archive 指令,見 [封存指南](change-archive.md)。task finish 不授權封存、Git commit 或部署。
114
116
 
@@ -116,4 +118,4 @@ status/snapshot 回傳 state、attemptId、reason、inputHash、sourceHash、fil
116
118
 
117
119
  ## 功能驗證引用
118
120
 
119
- Tasks.verify 可選 reference 串接功能驗證地圖;仍以原 checks 格式記錄結果。引用地圖納入 inputHash,修改後需重新 attempt;封存保留原文。參閱 [驗證地圖與 Git 原則](verification-map.md)。
121
+ Tasks.verify 可選 reference 串接功能驗證地圖;仍以原 checks 格式記錄結果。任務引用的地圖整份納入該任務的 inputHash,地圖的任何修改都需重新 attempt;封存保留原文。參閱 [驗證地圖與 Git 原則](verification-map.md)。
@@ -37,7 +37,7 @@ supekku records publish --operation-id <UUID> --json
37
37
 
38
38
  1. 每份文件都是對應種類的流程文件,數量與大小在上限內(每份 1 MiB、全部 8 MiB、100 份規格、500 個變更)。
39
39
  2. 依封存時間,從空白開始**重播整段正式規格的歷史**:每個變更以它當時的基準執行完整度驗證與合併,文件加基準的指紋必須等於完成紀錄與證據所綁定的指紋,合併結果必須等於完成紀錄記載的結果。
40
- 3. 每個任務的證據以執行與封存時相同的規則重播,包含獨立挑戰的關卡。
40
+ 3. 每個任務的證據以執行與封存時相同的規則重播,包含獨立挑戰的關卡。完成紀錄為任務載明任務指紋時,檢查的一方由上傳的文件自行重新計算,與記載不符即拒絕;沒有載明的任務照舊以整份變更的指紋檢查,所以較早封存的紀錄不需要改動。
41
41
  4. 識別碼不重複,事件時間依序且不晚於完成紀錄的 `preparedAt`(封存操作準備的時間)。
42
42
 
43
43
  這套檢查另有兩個運算量上的上限,超過時同樣整份拒絕:重播歷史時讀取的文件與基準合計不得超過約 800 萬個字元;被多條需求或多個任務共用的文字,展開後合計不得超過 8 MiB。
@@ -1,10 +1,10 @@
1
1
  import { o as normalizeError } from "./src-CRhxwFAN.mjs";
2
2
  import { n as inspectWorkflow } from "./verification-B4QMPPeA.mjs";
3
- import { n as changeCommand } from "./change-DNLxzdWK.mjs";
4
- import { n as taskCommand } from "./task-C7oNTNC3.mjs";
5
- import { t as archiveCommand } from "./archive-fnLRBLHD.mjs";
3
+ import { n as changeCommand } from "./change-B3CIaYav.mjs";
4
+ import { n as taskCommand } from "./task-dw_E1Rl2.mjs";
5
+ import { t as archiveCommand } from "./archive-BDQ_oB6g.mjs";
6
6
  import { n as pendingPublications } from "./status-B7GWMROT.mjs";
7
- import { t as doctor } from "./doctor-CK0Ny6ct.mjs";
7
+ import { t as doctor } from "./doctor-CKgYDYGQ.mjs";
8
8
  // src/onboarding/status.ts
9
9
  function errorOf(cause) {
10
10
  const e = normalizeError(cause);
@@ -0,0 +1 @@
1
+ export { t as readTaskInput, n as taskCommand } from "./task-dw_E1Rl2.mjs";
@@ -2,15 +2,77 @@ import { t as CoreError } from "./src-CRhxwFAN.mjs";
2
2
  import { t as hash } from "./src-DeDtBfdV.mjs";
3
3
  import { n as workflowId } from "./change-DgUPVNsm.mjs";
4
4
  import { n as inspectWorkflow } from "./verification-B4QMPPeA.mjs";
5
- import { l as taskState, o as validateChange, s as acceptTaskEvent, u as taskEvidence } from "./archive-YanRypPH.mjs";
5
+ import { a as validScopePath, c as taskFingerprints, d as taskState, f as taskEvidence, i as deniedScopeName, l as acceptTaskEvent, o as validateChange, s as taskBinding } from "./archive-BEqNOztX.mjs";
6
6
  import { n as withLocks } from "./locks-C4XYFwbg.mjs";
7
7
  import { t as findProject } from "./project-directory-w_ITkI7O.mjs";
8
- import { n as openJournal } from "./journal-Da95Qqey.mjs";
9
- import { t as context } from "./local-DyZAVffW.mjs";
10
- import { t as bundle } from "./change-DNLxzdWK.mjs";
11
- import { t as sourceFingerprint } from "./task-snapshot-CNi4Yswc.mjs";
8
+ import { n as openJournal } from "./journal-7SNjewV7.mjs";
9
+ import { t as context } from "./local-odic_qV5.mjs";
10
+ import { t as bundle } from "./change-B3CIaYav.mjs";
11
+ import { createHash } from "node:crypto";
12
12
  import { join } from "node:path";
13
- import { existsSync } from "node:fs";
13
+ import { lstat, open, readdir } from "node:fs/promises";
14
+ import { constants, existsSync } from "node:fs";
15
+ // src/commands/task-snapshot.ts
16
+ const denied = deniedScopeName;
17
+ const invalid = () => {
18
+ throw new CoreError("INVALID_PATH", "Task scope must contain bounded regular project-relative source paths, excluding environment and private files");
19
+ };
20
+ const digest = (s) => createHash("sha256").update(s).digest("hex");
21
+ const fileLimit = 4 * 1024 ** 2;
22
+ async function readSource(full, expected) {
23
+ const file = await open(full, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => invalid());
24
+ try {
25
+ const s = await file.stat();
26
+ if (!s.isFile() || s.ino !== expected.ino || s.dev !== expected.dev || s.size > fileLimit) invalid();
27
+ const data = await file.readFile();
28
+ if (data.length !== s.size || data.length > fileLimit) throw new CoreError("LOCAL_CONFLICT", "Source changed while it was being read");
29
+ return data;
30
+ } finally {
31
+ await file.close();
32
+ }
33
+ }
34
+ async function sourceFingerprint(root, scope) {
35
+ const entries = /* @__PURE__ */ new Map();
36
+ let total = 0, count = 0;
37
+ async function visit(path, depth = 0) {
38
+ if (++count > 1e4 || depth > 64) invalid();
39
+ let full = root;
40
+ for (const part of path.split("/")) {
41
+ full = join(full, part);
42
+ const s = await lstat(full).catch((e) => {
43
+ if (e.code === "ENOENT" || e.code === "ENOTDIR") return null;
44
+ if (e.code === "ENAMETOOLONG") return invalid();
45
+ throw e;
46
+ });
47
+ if (!s) {
48
+ entries.set(path, "missing");
49
+ return;
50
+ }
51
+ if (s.isSymbolicLink()) invalid();
52
+ }
53
+ const s = await lstat(full);
54
+ if (s.isDirectory()) {
55
+ entries.set(path, "directory");
56
+ const children = await readdir(full);
57
+ if (children.length > 1e4) invalid();
58
+ for (const name of children.sort()) if (!denied(name)) await visit(path + "/" + name, depth + 1);
59
+ } else {
60
+ if (!s.isFile() || s.size > fileLimit) invalid();
61
+ total += s.size;
62
+ if (total > 64 * 1024 ** 2) invalid();
63
+ entries.set(path, digest(await readSource(full, s)));
64
+ }
65
+ }
66
+ for (const path of [...new Set(scope)].sort()) {
67
+ if (!validScopePath(path)) invalid();
68
+ await visit(path);
69
+ }
70
+ const files = Object.fromEntries([...entries].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
71
+ return {
72
+ sourceHash: digest(JSON.stringify(files)),
73
+ files
74
+ };
75
+ }
14
76
  // src/commands/task.ts
15
77
  async function readTaskInput() {
16
78
  if (process.stdin.isTTY) throw new CoreError("INVALID_ARGUMENT", "Provide task evidence JSON on stdin");
@@ -48,7 +110,11 @@ async function taskCommand(action, args, project, payload) {
48
110
  workflowId(changeId);
49
111
  if (!/^TASK-[0-9]{3,}$/.test(taskId) || taskId.length > 64) throw new CoreError("INVALID_ARGUMENT", "Invalid task ID");
50
112
  const readOnly = ["status", "snapshot"].includes(action);
51
- const evidence = readOnly ? null : taskEvidence(payload);
113
+ const submitted = readOnly ? null : taskEvidence(payload);
114
+ const evidence = submitted?.kind === "start" ? {
115
+ ...submitted,
116
+ binding: "task"
117
+ } : submitted;
52
118
  if (evidence && !(action === "record" ? [
53
119
  "red",
54
120
  "green",
@@ -65,7 +131,8 @@ async function taskCommand(action, args, project, payload) {
65
131
  if (!task) throw new CoreError("NOT_FOUND", "Task not found");
66
132
  const source = await sourceFingerprint(root, task.scope);
67
133
  return {
68
- inputHash: hash(JSON.stringify(input)),
134
+ changeHash: hash(JSON.stringify(input)),
135
+ taskHashes: validation.valid ? Object.fromEntries(taskFingerprints(input)) : null,
69
136
  ...source,
70
137
  task,
71
138
  tasks: meta.tasks,
@@ -75,10 +142,23 @@ async function taskCommand(action, args, project, payload) {
75
142
  async function execute(journal) {
76
143
  if (evidence && journal) {
77
144
  journal.assertWritable();
78
- const retry = journal.taskRetry(evidence.operationId, changeId, taskId, canonical(evidence));
145
+ const recorded = (request) => journal.taskRetry(evidence.operationId, changeId, taskId, canonical(request));
146
+ let retry;
147
+ try {
148
+ retry = recorded(evidence);
149
+ } catch (e) {
150
+ if (submitted?.kind !== "start" || submitted.binding) throw e;
151
+ retry = recorded(submitted);
152
+ }
79
153
  if (retry) return retry;
80
154
  }
81
155
  const current = await capture(), events = journal?.taskEvents(changeId, taskId) ?? [];
156
+ const boundHash = (id, binding) => binding === "task" ? current.taskHashes?.[id] ?? current.changeHash : current.changeHash;
157
+ const binding = evidence?.kind === "start" ? "task" : taskBinding(events);
158
+ const fingerprint = {
159
+ inputHash: boundHash(taskId, binding),
160
+ sourceHash: current.sourceHash
161
+ };
82
162
  const memo = /* @__PURE__ */ new Map();
83
163
  async function stateFor(id, visiting = /* @__PURE__ */ new Set()) {
84
164
  if (memo.has(id)) return memo.get(id);
@@ -87,8 +167,9 @@ async function taskCommand(action, args, project, payload) {
87
167
  const t = current.tasks.find((t) => t.id === id);
88
168
  if (!t) return "blocked";
89
169
  const source = id === taskId ? current : await sourceFingerprint(root, t.scope);
90
- let state = taskState(t, journal?.taskEvents(changeId, id) ?? [], {
91
- inputHash: current.inputHash,
170
+ const recorded = journal?.taskEvents(changeId, id) ?? [];
171
+ let state = taskState(t, recorded, {
172
+ inputHash: boundHash(id, taskBinding(recorded)),
92
173
  sourceHash: source.sourceHash
93
174
  }).state;
94
175
  for (const dep of t.dependsOn) if (await stateFor(dep, new Set(visiting)) !== "done") state = "blocked";
@@ -102,7 +183,7 @@ async function taskCommand(action, args, project, payload) {
102
183
  });
103
184
  const blocked = dependencies.some((d) => d.state !== "done");
104
185
  if (!evidence) {
105
- const state = taskState(current.task, events, current);
186
+ const state = taskState(current.task, events, fingerprint);
106
187
  if (JSON.stringify(await capture()) !== JSON.stringify(current)) throw new CoreError("LOCAL_CONFLICT", "Inputs changed during inspection");
107
188
  return {
108
189
  ...state,
@@ -113,7 +194,8 @@ async function taskCommand(action, args, project, payload) {
113
194
  state: "blocked",
114
195
  reason: "Dependency is not currently done"
115
196
  } : {},
116
- inputHash: current.inputHash,
197
+ binding,
198
+ inputHash: fingerprint.inputHash,
117
199
  sourceHash: current.sourceHash,
118
200
  files: current.files,
119
201
  dependencies,
@@ -124,14 +206,14 @@ async function taskCommand(action, args, project, payload) {
124
206
  if (!journal) throw new CoreError("NOT_INITIALIZED", "Run local init first");
125
207
  if (!current.validation.valid) throw new CoreError("INVALID_WORKFLOW_DOCUMENT", "Complete and validate the change before recording execution");
126
208
  if (blocked) throw new CoreError("LOCAL_CONFLICT", "Dependencies must be currently done");
127
- acceptTaskEvent(current.task, events, evidence, current);
209
+ acceptTaskEvent(current.task, events, evidence, fingerprint);
128
210
  const next = await capture();
129
211
  if (JSON.stringify(next) !== JSON.stringify(current)) throw new CoreError("LOCAL_CONFLICT", "Inputs changed before journal write");
130
212
  memo.clear();
131
213
  for (const dep of current.task.dependsOn) if (await stateFor(dep) !== "done") throw new CoreError("LOCAL_CONFLICT", "Dependency changed");
132
214
  const event = {
133
215
  ...evidence,
134
- inputHash: current.inputHash,
216
+ inputHash: fingerprint.inputHash,
135
217
  sourceHash: current.sourceHash,
136
218
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
137
219
  };
@@ -151,4 +233,4 @@ async function taskCommand(action, args, project, payload) {
151
233
  }
152
234
  });
153
235
  }
154
- export { taskCommand as n, readTaskInput as t };
236
+ export { taskCommand as n, sourceFingerprint as r, readTaskInput as t };
@@ -44,7 +44,7 @@ Start 範例:
44
44
  }
45
45
  ```
46
46
 
47
- 既有 attempt 重新開始時加 `restart:true`。Start 的 operationId 是 attemptId。所有其他事件加上 `attemptId`、`inputHash`、`sourceHash`;後兩者取自**執行測試/review 前**的 snapshot。提交時 CLI 重算比對,不能在測試後取得新 hash 冒充已測內容。
47
+ 既有 attempt 重新開始時加 `restart:true`。Start 的 operationId 是 attemptId。CLI 會在保存的 start 事件上加註 `binding:"task"`,表示這個 attempt 的證據綁定任務指紋(見「狀態與失效」);這個欄位由 CLI 填寫,提交時不必附上,附上相同的值也接受。所有其他事件加上 `attemptId`、`inputHash`、`sourceHash`;後兩者取自**執行測試/review 前**的 snapshot。提交時 CLI 重算比對,不能在測試後取得新 hash 冒充已測內容。
48
48
 
49
49
  | kind/指令 | 額外欄位 |
50
50
  | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -74,7 +74,7 @@ Tasks 的每個任務可用 `challenge` 宣告 0 到 3 的挑戰等級,未宣
74
74
  supekku task brief demo TASK-001 --project /path/to/project --json
75
75
  ```
76
76
 
77
- 這是唯讀指令,不讀取標準輸入,不需要也不建立本機日誌。回傳 `level`、`required`、`roundLimit`、`inputHash`、`sourceHash`、`scope`、`requirements`(需求與情境原文)、`rules`、`report`(回報格式),以及把這些組成一份可直接交付的 `text`。它不含任何已記錄的證據、摘要或 Review 結論,也不含 Tasks 中實作者的任務描述。等級 0 的任務也能取得說明,`required` 為 false。
77
+ 這是唯讀指令,不讀取標準輸入,不需要也不建立本機日誌;日誌存在時只讀取它,以取得目前 attempt 所綁定的指紋。回傳 `level`、`required`、`roundLimit`、`inputHash`、`sourceHash`、`scope`、`requirements`(需求與情境原文)、`rules`、`report`(回報格式),以及把這些組成一份可直接交付的 `text`。它不含任何已記錄的證據、摘要或 Review 結論,也不含 Tasks 中實作者的任務描述。等級 0 的任務也能取得說明,`required` 為 false。
78
78
 
79
79
  2. 把 `text` 原樣交給挑戰者,不要附上自己的測試結果或推論。挑戰者依規則回報一個 JSON 物件。
80
80
  3. 將回報記為 `challenge` 事件:填入 `verifyId`、取得說明時的 `inputHash`/`sourceHash` 與 `attemptId`。說明之後若原始碼有變動,指紋不符會被拒絕,需重新 Verify 並重新挑戰。
@@ -96,7 +96,9 @@ Tasks 的每個任務可用 `challenge` 宣告 0 到 3 的挑戰等級,未宣
96
96
 
97
97
  pending → running → verified → reviewed → done;可 block/resume,指紋改變時為 stale。Tasks Markdown 的 pending/done 僅為舊有作者宣告,不控制執行紀錄;不用回寫它。
98
98
 
99
- - `inputHash` 涵蓋整份 change(包含其他 Tasks)及參照的正式基準。內容變動必須明確 restart;新 attempt 保留舊 events。
99
+ - `inputHash` 是**任務指紋**,只涵蓋這個任務自己的定義:它在 Tasks 中的項目(描述、引用的需求與情境、依賴、scope、verify、tdd 與理由、挑戰等級)、它引用的需求與情境在本 change 中的內文(移除的需求另含正式規格的原文),以及它引用的驗證地圖(整份地圖的內容,不只是被引用的那一項)。其他任務的項目、proposal 與 design 的內文、沒有被引用的需求,以及 Tasks 上的 pending/done 標記都不在其中;修改它們不使這個任務的任何證據失效。任務指紋改變時必須明確 restart;新 attempt 保留舊 events。
100
+ - 任務指紋不偵測沒有寫進文件的關係:proposal 改了方向卻沒有改到任務引用的需求,或兩個任務實際互相影響卻沒有以依賴或共同引用的需求表達時,工具不會要求 restart,要由人判斷。
101
+ - 加入任務指紋之前開始的 attempt(start 事件沒有 `binding`)維持原本的綁定:`inputHash` 涵蓋整份 change 及參照的正式基準,任何文件變動都要 restart。restart 之後的新 attempt 才改綁任務指紋。升級 CLI 本身不會讓進行中的任務失效。
100
102
  - `sourceHash` 涵蓋 task.scope 中檔案的內容、名稱、存在狀態和目錄。修改後 Green/Verify/Challenge/Review/Done 失效,Red 歷史保留。重新提交新證據可繼續同一 attempt。
101
103
  - 新 Red/Green 使舊 Verify/Challenge/Review 不再有效;新 Verify 必須重新 Challenge(等級 1 以上)與 Review;failed 結果不沿用舊 pass。block/resume 清除目前 gates,但保留歷史。
102
104
  - 依賴任務必須目前有效 done。後續任務若修改了前一任務 scope,先刷新前一任務證據,才能完成依賴它的任務。
@@ -104,11 +106,11 @@ pending → running → verified → reviewed → done;可 block/resume,
104
106
  - `.env`、所有 `.env.*`(含 example)、`.git`、`node_modules`、`.supekku`、legacy `supekku` 目錄不讀。直接指定拒絕,遞迴遇到排除;symlink/特殊檔案拒絕。單檔4MiB、總計64MiB、最多10000項、深度64。
105
107
  - 未列入 scope 的檔案、工具版本與外部環境不能自動偵測。內容改回相同 bytes 會再次符合指紋;不提供惡意並行修改的防護或執行結果防偽。
106
108
 
107
- status/snapshot 回傳 state、attemptId、reason、inputHash、sourceHash、files(hash 或 missing/directory)、dependencies、events 與 `attestationOnly:true`。mutation 回傳保存事件,含 CLI 時間 createdAt。標準外層為 outputVersion/command/ok/data;stale/blocked 狀態本身是成功查詢,不是 CLI 錯誤。mutation 衝突為 `LOCAL_CONFLICT`(exit6);非法證據 `INVALID_ARGUMENT`(2);未初始化、需升級或新 schema 則使用既有 journal 錯誤代碼。
109
+ status/snapshot 回傳 state、attemptId、reason、binding(`task` 或 `change`,目前 attempt 的綁定方式;尚未開始的任務為 `task`)、inputHash(依綁定方式為任務指紋或整份 change 的指紋)、sourceHash、files(hash 或 missing/directory)、dependencies、events 與 `attestationOnly:true`。mutation 回傳保存事件,含 CLI 時間 createdAt。標準外層為 outputVersion/command/ok/data;stale/blocked 狀態本身是成功查詢,不是 CLI 錯誤。mutation 衝突為 `LOCAL_CONFLICT`(exit6);非法證據 `INVALID_ARGUMENT`(2);未初始化、需升級或新 schema 則使用既有 journal 錯誤代碼。
108
110
 
109
111
  ## 持久化、安裝與限制
110
112
 
111
- 紀錄在 `.supekku/.local/operations.sqlite` 的 task_events。schema4 新增 archive migration(task_events 自 schema3 引入),既有 SQL 不變。舊 journal 需明確 upgrade,升級前備份;舊 CLI 見新 schema 拒絕。DB 還原只還原紀錄,不還原程式;還原後先依既有 local db reconcile 流程解除限制,再檢查 task status。備份之後的新任務事件不會出現在還原後 DB,需以保留的還原前備份追查;不可假定還原後的舊紀錄代表目前工作。
113
+ 紀錄在 `.supekku/.local/operations.sqlite` 的 task_events。schema4 新增 archive migration(task_events 自 schema3 引入),既有 SQL 不變。任務指紋沒有新增 migration;但 0.1.0-alpha.8 及更早的 CLI 不認得 start 事件上的 `binding`,遇到含有它的日誌會整個拒絕開啟(`PAYLOAD_UNSUPPORTED`),不會把這些 attempt 誤判為有效,也不會改動日誌;換回新版 CLI 即可繼續。舊 journal 需明確 upgrade,升級前備份;舊 CLI 見新 schema 拒絕。DB 還原只還原紀錄,不還原程式;還原後先依既有 local db reconcile 流程解除限制,再檢查 task status。備份之後的新任務事件不會出現在還原後 DB,需以保留的還原前備份追查;不可假定還原後的舊紀錄代表目前工作。
112
114
 
113
115
  套件包含 `dist/skills/supekku-development/`,整個資料夾可由使用者複製到 Agent 支援的 skills 目錄。套件不自動安裝全域 skill。skill 的 references 包含本指南與 native 文件格式。正式規格合併與封存使用獨立的 change archive 指令,見 [封存指南](change-archive.md)。task finish 不授權封存、Git commit 或部署。
114
116
 
@@ -116,4 +118,4 @@ status/snapshot 回傳 state、attemptId、reason、inputHash、sourceHash、fil
116
118
 
117
119
  ## 功能驗證引用
118
120
 
119
- Tasks.verify 可選 reference 串接功能驗證地圖;仍以原 checks 格式記錄結果。引用地圖納入 inputHash,修改後需重新 attempt;封存保留原文。參閱 [驗證地圖與 Git 原則](verification-map.md)。
121
+ Tasks.verify 可選 reference 串接功能驗證地圖;仍以原 checks 格式記錄結果。任務引用的地圖整份納入該任務的 inputHash,地圖的任何修改都需重新 attempt;封存保留原文。參閱 [驗證地圖與 Git 原則](verification-map.md)。
@@ -37,7 +37,7 @@ supekku records publish --operation-id <UUID> --json
37
37
 
38
38
  1. 每份文件都是對應種類的流程文件,數量與大小在上限內(每份 1 MiB、全部 8 MiB、100 份規格、500 個變更)。
39
39
  2. 依封存時間,從空白開始**重播整段正式規格的歷史**:每個變更以它當時的基準執行完整度驗證與合併,文件加基準的指紋必須等於完成紀錄與證據所綁定的指紋,合併結果必須等於完成紀錄記載的結果。
40
- 3. 每個任務的證據以執行與封存時相同的規則重播,包含獨立挑戰的關卡。
40
+ 3. 每個任務的證據以執行與封存時相同的規則重播,包含獨立挑戰的關卡。完成紀錄為任務載明任務指紋時,檢查的一方由上傳的文件自行重新計算,與記載不符即拒絕;沒有載明的任務照舊以整份變更的指紋檢查,所以較早封存的紀錄不需要改動。
41
41
  4. 識別碼不重複,事件時間依序且不晚於完成紀錄的 `preparedAt`(封存操作準備的時間)。
42
42
 
43
43
  這套檢查另有兩個運算量上的上限,超過時同樣整份拒絕:重播歷史時讀取的文件與基準合計不得超過約 800 萬個字元;被多條需求或多個任務共用的文字,展開後合計不得超過 8 MiB。
package/package.json CHANGED
@@ -1,6 +1,16 @@
1
1
  {
2
2
  "name": "@kenkyou/supekku",
3
- "version": "0.1.0-alpha.8",
3
+ "version": "0.1.0-alpha.9",
4
+ "description": "Spec-driven development workflows and optional Artifact collaboration for AI agents.",
5
+ "keywords": [
6
+ "ai-agent",
7
+ "artifacts",
8
+ "cli",
9
+ "spec-driven",
10
+ "supekku"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "kenkyou",
4
14
  "bin": {
5
15
  "supekku": "dist/index.mjs"
6
16
  },
@@ -8,6 +18,11 @@
8
18
  "dist"
9
19
  ],
10
20
  "type": "module",
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org/",
24
+ "tag": "next"
25
+ },
11
26
  "dependencies": {
12
27
  "@napi-rs/keyring": "2.1.2",
13
28
  "acorn": "^8.19.0",
@@ -32,21 +47,6 @@
32
47
  "engines": {
33
48
  "node": ">=24.22.1"
34
49
  },
35
- "description": "Spec-driven development workflows and optional Artifact collaboration for AI agents.",
36
- "author": "kenkyou",
37
- "keywords": [
38
- "supekku",
39
- "cli",
40
- "spec-driven",
41
- "ai-agent",
42
- "artifacts"
43
- ],
44
- "publishConfig": {
45
- "access": "public",
46
- "tag": "next",
47
- "registry": "https://registry.npmjs.org/"
48
- },
49
- "license": "MIT",
50
50
  "scripts": {
51
51
  "build": "pnpm --filter @supekku/web build:local && vp pack && node --import tsx scripts/export-schema.ts && node scripts/copy-assets.mjs && node scripts/third-party-notices.mjs"
52
52
  }
@@ -1 +0,0 @@
1
- export { t as archiveCommand } from "./archive-fnLRBLHD.mjs";
@@ -1 +0,0 @@
1
- export { n as changeCommand } from "./change-DNLxzdWK.mjs";
@@ -1 +0,0 @@
1
- export { t as doctor } from "./doctor-CK0Ny6ct.mjs";
@@ -1 +0,0 @@
1
- export { t as readTaskInput, n as taskCommand } from "./task-C7oNTNC3.mjs";
@@ -1,68 +0,0 @@
1
- import { t as CoreError } from "./src-CRhxwFAN.mjs";
2
- import { a as validScopePath, i as deniedScopeName } from "./archive-YanRypPH.mjs";
3
- import { createHash } from "node:crypto";
4
- import { join } from "node:path";
5
- import { lstat, open, readdir } from "node:fs/promises";
6
- import { constants } from "node:fs";
7
- // src/commands/task-snapshot.ts
8
- const denied = deniedScopeName;
9
- const invalid = () => {
10
- throw new CoreError("INVALID_PATH", "Task scope must contain bounded regular project-relative source paths, excluding environment and private files");
11
- };
12
- const digest = (s) => createHash("sha256").update(s).digest("hex");
13
- const fileLimit = 4 * 1024 ** 2;
14
- async function readSource(full, expected) {
15
- const file = await open(full, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => invalid());
16
- try {
17
- const s = await file.stat();
18
- if (!s.isFile() || s.ino !== expected.ino || s.dev !== expected.dev || s.size > fileLimit) invalid();
19
- const data = await file.readFile();
20
- if (data.length !== s.size || data.length > fileLimit) throw new CoreError("LOCAL_CONFLICT", "Source changed while it was being read");
21
- return data;
22
- } finally {
23
- await file.close();
24
- }
25
- }
26
- async function sourceFingerprint(root, scope) {
27
- const entries = /* @__PURE__ */ new Map();
28
- let total = 0, count = 0;
29
- async function visit(path, depth = 0) {
30
- if (++count > 1e4 || depth > 64) invalid();
31
- let full = root;
32
- for (const part of path.split("/")) {
33
- full = join(full, part);
34
- const s = await lstat(full).catch((e) => {
35
- if (e.code === "ENOENT" || e.code === "ENOTDIR") return null;
36
- if (e.code === "ENAMETOOLONG") return invalid();
37
- throw e;
38
- });
39
- if (!s) {
40
- entries.set(path, "missing");
41
- return;
42
- }
43
- if (s.isSymbolicLink()) invalid();
44
- }
45
- const s = await lstat(full);
46
- if (s.isDirectory()) {
47
- entries.set(path, "directory");
48
- const children = await readdir(full);
49
- if (children.length > 1e4) invalid();
50
- for (const name of children.sort()) if (!denied(name)) await visit(path + "/" + name, depth + 1);
51
- } else {
52
- if (!s.isFile() || s.size > fileLimit) invalid();
53
- total += s.size;
54
- if (total > 64 * 1024 ** 2) invalid();
55
- entries.set(path, digest(await readSource(full, s)));
56
- }
57
- }
58
- for (const path of [...new Set(scope)].sort()) {
59
- if (!validScopePath(path)) invalid();
60
- await visit(path);
61
- }
62
- const files = Object.fromEntries([...entries].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
63
- return {
64
- sourceHash: digest(JSON.stringify(files)),
65
- files
66
- };
67
- }
68
- export { sourceFingerprint as t };