@warpgogol/forge 9.2.3 → 9.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/CHANGELOG.md +25 -0
- package/bin/cli.ts +3 -2
- package/dist/bin/cli.js +3 -2
- package/dist/bin/cli.js.map +1 -1
- package/dist/os/adr/handlers/implement-stamp.d.ts +6 -0
- package/dist/os/adr/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/adr/handlers/implement-stamp.js +23 -15
- package/dist/os/adr/handlers/implement-stamp.js.map +1 -1
- package/dist/os/checks/handlers/counters-journal.d.ts.map +1 -1
- package/dist/os/checks/handlers/counters-journal.js +9 -1
- package/dist/os/checks/handlers/counters-journal.js.map +1 -1
- package/dist/os/core/core.module.d.ts.map +1 -1
- package/dist/os/core/core.module.js +27 -36
- package/dist/os/core/core.module.js.map +1 -1
- package/dist/os/core/lock-holder.d.ts +32 -0
- package/dist/os/core/lock-holder.d.ts.map +1 -0
- package/dist/os/core/lock-holder.js +81 -0
- package/dist/os/core/lock-holder.js.map +1 -0
- package/dist/os/core/stamp-lock.d.ts +30 -0
- package/dist/os/core/stamp-lock.d.ts.map +1 -0
- package/dist/os/core/stamp-lock.js +112 -0
- package/dist/os/core/stamp-lock.js.map +1 -0
- package/dist/os/flow/digest.d.ts +19 -0
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +33 -4
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +61 -6
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/handlers/flow-cut.d.ts +8 -0
- package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-cut.js +91 -5
- package/dist/os/flow/handlers/flow-cut.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +6 -0
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-discard.js +17 -13
- package/dist/os/flow/handlers/flow-discard.js.map +1 -1
- package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-fix.js +99 -10
- package/dist/os/flow/handlers/flow-fix.js.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +32 -15
- package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
- package/dist/os/flow/handlers/flow-publication-retire.d.ts +17 -0
- package/dist/os/flow/handlers/flow-publication-retire.d.ts.map +1 -0
- package/dist/os/flow/handlers/flow-publication-retire.js +132 -0
- package/dist/os/flow/handlers/flow-publication-retire.js.map +1 -0
- package/dist/os/flow/handlers/flow-push.d.ts +7 -0
- package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-push.js +106 -15
- package/dist/os/flow/handlers/flow-push.js.map +1 -1
- package/dist/os/flow/locks.d.ts +6 -1
- package/dist/os/flow/locks.d.ts.map +1 -1
- package/dist/os/flow/locks.js +53 -23
- package/dist/os/flow/locks.js.map +1 -1
- package/dist/os/flow/publication-order.d.ts +25 -0
- package/dist/os/flow/publication-order.d.ts.map +1 -0
- package/dist/os/flow/publication-order.js +75 -0
- package/dist/os/flow/publication-order.js.map +1 -0
- package/dist/os/flow/publish.d.ts +18 -0
- package/dist/os/flow/publish.d.ts.map +1 -1
- package/dist/os/flow/publish.js +58 -2
- package/dist/os/flow/publish.js.map +1 -1
- package/dist/os/flow/registry.d.ts +1 -1
- package/dist/os/flow/registry.d.ts.map +1 -1
- package/dist/os/flow/registry.js +2 -1
- package/dist/os/flow/registry.js.map +1 -1
- package/dist/os/flow/release-tags.d.ts +1 -0
- package/dist/os/flow/release-tags.d.ts.map +1 -1
- package/dist/os/flow/release-tags.js +5 -4
- package/dist/os/flow/release-tags.js.map +1 -1
- package/dist/os/flow/scripts.d.ts +1 -1
- package/dist/os/flow/scripts.d.ts.map +1 -1
- package/dist/os/flow/scripts.js +1 -0
- package/dist/os/flow/scripts.js.map +1 -1
- package/dist/os/flow/task-files.d.ts +11 -0
- package/dist/os/flow/task-files.d.ts.map +1 -0
- package/dist/os/flow/task-files.js +51 -0
- package/dist/os/flow/task-files.js.map +1 -0
- package/dist/os/flow/tests/helpers.d.ts +4 -1
- package/dist/os/flow/tests/helpers.d.ts.map +1 -1
- package/dist/os/flow/tests/helpers.js +9 -5
- package/dist/os/flow/tests/helpers.js.map +1 -1
- package/dist/os/mission/handlers/archive.d.ts.map +1 -1
- package/dist/os/mission/handlers/archive.js +30 -74
- package/dist/os/mission/handlers/archive.js.map +1 -1
- package/dist/os/mission/lockfile.d.ts +21 -0
- package/dist/os/mission/lockfile.d.ts.map +1 -0
- package/dist/os/mission/lockfile.js +76 -0
- package/dist/os/mission/lockfile.js.map +1 -0
- package/dist/os/mission/mission.module.d.ts.map +1 -1
- package/dist/os/mission/mission.module.js +2 -1
- package/dist/os/mission/mission.module.js.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.d.ts +6 -0
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +24 -19
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/system/handlers/outbox-validate.d.ts +8 -0
- package/dist/os/system/handlers/outbox-validate.d.ts.map +1 -0
- package/dist/os/system/handlers/outbox-validate.js +102 -0
- package/dist/os/system/handlers/outbox-validate.js.map +1 -0
- package/dist/os/system/handlers/system-map-validate.d.ts +13 -0
- package/dist/os/system/handlers/system-map-validate.d.ts.map +1 -0
- package/dist/os/system/handlers/system-map-validate.js +78 -0
- package/dist/os/system/handlers/system-map-validate.js.map +1 -0
- package/dist/os/system/handlers/system-outbox-scan.d.ts +10 -0
- package/dist/os/system/handlers/system-outbox-scan.d.ts.map +1 -0
- package/dist/os/system/handlers/system-outbox-scan.js +195 -0
- package/dist/os/system/handlers/system-outbox-scan.js.map +1 -0
- package/dist/os/system/handlers/system-task-collect.d.ts +13 -0
- package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-collect.js +238 -0
- package/dist/os/system/handlers/system-task-collect.js.map +1 -0
- package/dist/os/system/handlers/system-task-create.d.ts +32 -0
- package/dist/os/system/handlers/system-task-create.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-create.js +216 -0
- package/dist/os/system/handlers/system-task-create.js.map +1 -0
- package/dist/os/system/handlers/system-task-dispatch.d.ts +14 -0
- package/dist/os/system/handlers/system-task-dispatch.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-dispatch.js +290 -0
- package/dist/os/system/handlers/system-task-dispatch.js.map +1 -0
- package/dist/os/system/handlers/system-task-move.d.ts +12 -0
- package/dist/os/system/handlers/system-task-move.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-move.js +217 -0
- package/dist/os/system/handlers/system-task-move.js.map +1 -0
- package/dist/os/system/handlers/system-task-status.d.ts +20 -0
- package/dist/os/system/handlers/system-task-status.d.ts.map +1 -0
- package/dist/os/system/handlers/system-task-status.js +139 -0
- package/dist/os/system/handlers/system-task-status.js.map +1 -0
- package/dist/os/system/handlers/system-versionset-record.d.ts +12 -0
- package/dist/os/system/handlers/system-versionset-record.d.ts.map +1 -0
- package/dist/os/system/handlers/system-versionset-record.js +332 -0
- package/dist/os/system/handlers/system-versionset-record.js.map +1 -0
- package/dist/os/system/index.d.ts +6 -0
- package/dist/os/system/index.d.ts.map +1 -0
- package/dist/os/system/index.js +18 -0
- package/dist/os/system/index.js.map +1 -0
- package/dist/os/system/outbox-schema.d.ts +30 -0
- package/dist/os/system/outbox-schema.d.ts.map +1 -0
- package/dist/os/system/outbox-schema.js +29 -0
- package/dist/os/system/outbox-schema.js.map +1 -0
- package/dist/os/system/repo.d.ts +64 -0
- package/dist/os/system/repo.d.ts.map +1 -0
- package/dist/os/system/repo.js +364 -0
- package/dist/os/system/repo.js.map +1 -0
- package/dist/os/system/scenario-schemas.d.ts +26 -0
- package/dist/os/system/scenario-schemas.d.ts.map +1 -0
- package/dist/os/system/scenario-schemas.js +53 -0
- package/dist/os/system/scenario-schemas.js.map +1 -0
- package/dist/os/system/schemas.d.ts +63 -0
- package/dist/os/system/schemas.d.ts.map +1 -0
- package/dist/os/system/schemas.js +83 -0
- package/dist/os/system/schemas.js.map +1 -0
- package/dist/os/system/system.module.d.ts +3 -0
- package/dist/os/system/system.module.d.ts.map +1 -0
- package/dist/os/system/system.module.js +429 -0
- package/dist/os/system/system.module.js.map +1 -0
- package/dist/os/system/task-schemas.d.ts +108 -0
- package/dist/os/system/task-schemas.d.ts.map +1 -0
- package/dist/os/system/task-schemas.js +152 -0
- package/dist/os/system/task-schemas.js.map +1 -0
- package/dist/os/system/task-store.d.ts +41 -0
- package/dist/os/system/task-store.d.ts.map +1 -0
- package/dist/os/system/task-store.js +142 -0
- package/dist/os/system/task-store.js.map +1 -0
- package/dist/os/system/tests/helpers.d.ts +30 -0
- package/dist/os/system/tests/helpers.d.ts.map +1 -0
- package/dist/os/system/tests/helpers.js +178 -0
- package/dist/os/system/tests/helpers.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -4
- package/dist/src/index.js.map +1 -1
- package/os/adr/handlers/implement-stamp-lock.test.ts +90 -0
- package/os/adr/handlers/implement-stamp.ts +29 -20
- package/os/checks/handlers/counters-journal.test.ts +10 -0
- package/os/checks/handlers/counters-journal.ts +8 -1
- package/os/core/core.module.ts +32 -36
- package/os/core/lock-holder.ts +88 -0
- package/os/core/stamp-lock.ts +142 -0
- package/os/flow/digest.ts +46 -4
- package/os/flow/flow.module.ts +62 -6
- package/os/flow/handlers/flow-cut.ts +118 -5
- package/os/flow/handlers/flow-digest.ts +6 -0
- package/os/flow/handlers/flow-discard.ts +22 -13
- package/os/flow/handlers/flow-fix.ts +116 -10
- package/os/flow/handlers/flow-integrate.ts +31 -15
- package/os/flow/handlers/flow-publication-retire.ts +156 -0
- package/os/flow/handlers/flow-push.ts +128 -13
- package/os/flow/locks.ts +75 -25
- package/os/flow/publication-order.ts +99 -0
- package/os/flow/publish.ts +73 -2
- package/os/flow/registry.ts +5 -2
- package/os/flow/release-tags.ts +5 -4
- package/os/flow/scripts.ts +2 -0
- package/os/flow/task-files.ts +59 -0
- package/os/flow/tests/flow-cut-prepare.test.ts +298 -0
- package/os/flow/tests/flow-cut.test.ts +5 -1
- package/os/flow/tests/flow-publication-retire.test.ts +191 -0
- package/os/flow/tests/flow-push-supersede.test.ts +221 -0
- package/os/flow/tests/flow-task-files.test.ts +59 -0
- package/os/flow/tests/helpers.ts +9 -5
- package/os/flow/tests/locks.test.ts +219 -0
- package/os/flow/tests/publication-order.test.ts +102 -0
- package/os/mission/handlers/archive.test.ts +97 -52
- package/os/mission/handlers/archive.ts +31 -76
- package/os/mission/lockfile.ts +84 -0
- package/os/mission/mission.module.ts +2 -1
- package/os/rfc/handlers/implement-stamp-lock.test.ts +133 -0
- package/os/rfc/handlers/implement-stamp.ts +30 -24
- package/os/system/handlers/outbox-validate.ts +120 -0
- package/os/system/handlers/system-map-validate.ts +107 -0
- package/os/system/handlers/system-outbox-scan.ts +320 -0
- package/os/system/handlers/system-task-collect.ts +305 -0
- package/os/system/handlers/system-task-create.ts +271 -0
- package/os/system/handlers/system-task-dispatch.ts +387 -0
- package/os/system/handlers/system-task-move.ts +353 -0
- package/os/system/handlers/system-task-status.ts +176 -0
- package/os/system/handlers/system-versionset-record.ts +476 -0
- package/os/system/index.ts +47 -0
- package/os/system/outbox-schema.ts +47 -0
- package/os/system/repo.ts +451 -0
- package/os/system/scenario-schemas.ts +62 -0
- package/os/system/schemas.ts +102 -0
- package/os/system/system.module.ts +449 -0
- package/os/system/task-schemas.ts +190 -0
- package/os/system/task-store.ts +184 -0
- package/os/system/tests/helpers.ts +189 -0
- package/os/system/tests/outbox-validate.test.ts +92 -0
- package/os/system/tests/system-map-validate.test.ts +321 -0
- package/os/system/tests/system-outbox-scan.test.ts +273 -0
- package/os/system/tests/system-profile.test.ts +90 -0
- package/os/system/tests/system-task-collect.test.ts +293 -0
- package/os/system/tests/system-task-dispatch.test.ts +279 -0
- package/os/system/tests/system-task-status.test.ts +153 -0
- package/os/system/tests/system-task.test.ts +330 -0
- package/os/system/tests/system-versionset.test.ts +314 -0
- package/package.json +33 -1
- package/profiles/system.yaml +650 -0
- package/skills/fo/fo-outbox/SKILL.md +71 -0
- package/skills/fo/fo-system-dispatch/SKILL.md +65 -0
- package/skills/fo/fo-task-run/SKILL.md +75 -0
- package/src/index.ts +11 -4
- package/src/tests/fixtures/agents-generate-business-before.txt +6 -0
- package/src/tests/profile-schema.test.ts +2 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>system.task.collect (RFC-1509) — gather the product session's task
|
|
4
|
+
report. Reads .forge/task/report.yaml from the dispatch worktree, falling back
|
|
5
|
+
to the preserved copy under <common>/forge/tasks/<id>/ when the
|
|
6
|
+
worktree is gone; missing report refuses with SYSTEM-TASK-07 (unless
|
|
7
|
+
--mark-failed --reason), schema/task-id mismatch refuses with SYSTEM-TASK-08.
|
|
8
|
+
A validated report is copied to queue/reports/; outcome done|needs-decision →
|
|
9
|
+
reported, blocked → failed. A journal `integrate` event for dispatch.branch
|
|
10
|
+
then advances reported → integrated with integratedCommit from the journal
|
|
11
|
+
sha — never from report commit ids. One call may apply dispatched → reported
|
|
12
|
+
→ integrated and record both history rows.</purpose>
|
|
13
|
+
<non-goals>
|
|
14
|
+
<item>No product-side mutations — collect only reads the product repo.</item>
|
|
15
|
+
</non-goals>
|
|
16
|
+
</MODULE_CONTRACT>
|
|
17
|
+
<CHANGE_SUMMARY>
|
|
18
|
+
<item>RFC-1509: step 3 — system.task.collect handler</item>
|
|
19
|
+
<item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
|
|
20
|
+
<item>RFC-1509: close RFC-1509 review r1 findings — mark-failed escape, open-error refusal, dry-run coverage</item>
|
|
21
|
+
<item>RFC-1509: address RFC-1509 review r2 — mark-failed without product, journal-read warning, status map diagnostics, V-49 deviations</item>
|
|
22
|
+
</CHANGE_SUMMARY>
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import YAML from "yaml";
|
|
27
|
+
|
|
28
|
+
import { resolveIo } from "../../../src/utils/io.ts";
|
|
29
|
+
import type {
|
|
30
|
+
Diagnostic,
|
|
31
|
+
ForgeCommandInput,
|
|
32
|
+
ForgeCommandResult,
|
|
33
|
+
ForgeRuntimeContext,
|
|
34
|
+
WorkspaceIO,
|
|
35
|
+
} from "../../../src/types.ts";
|
|
36
|
+
import { commonGitDir, readJournal } from "../../flow/registry.ts";
|
|
37
|
+
import { assertSystemRepository, loadSystemMap, type SystemMap } from "../repo.ts";
|
|
38
|
+
import { taskReportSchema, type SystemTask } from "../task-schemas.ts";
|
|
39
|
+
import { readTask, reportFilePath, writeTask } from "../task-store.ts";
|
|
40
|
+
|
|
41
|
+
export interface SystemTaskCollectResult {
|
|
42
|
+
command: "system.task.collect";
|
|
43
|
+
task: string | null;
|
|
44
|
+
state: SystemTask["state"] | null;
|
|
45
|
+
reportFound: boolean;
|
|
46
|
+
reportFile: string | null;
|
|
47
|
+
integratedCommit: string | null;
|
|
48
|
+
diagnostics: Diagnostic[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function refusal(ruleId: string, message: string, fixHint?: string): Diagnostic {
|
|
52
|
+
return { ruleId, severity: "error", message, ...(fixHint ? { fixHint } : {}) };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function flagString(input: ForgeCommandInput, name: string): string | null {
|
|
56
|
+
const v = input.flags[name];
|
|
57
|
+
return typeof v === "string" && v.length > 0 ? v : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function historyRow(
|
|
61
|
+
task: SystemTask,
|
|
62
|
+
to: SystemTask["state"],
|
|
63
|
+
by: string,
|
|
64
|
+
reason?: string,
|
|
65
|
+
): SystemTask {
|
|
66
|
+
return {
|
|
67
|
+
...task,
|
|
68
|
+
state: to,
|
|
69
|
+
history: [
|
|
70
|
+
...task.history,
|
|
71
|
+
{
|
|
72
|
+
at: new Date().toISOString(),
|
|
73
|
+
from: task.state,
|
|
74
|
+
to,
|
|
75
|
+
by,
|
|
76
|
+
...(reason ? { reason } : {}),
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Find report.yaml — worktree first, then the preserved copy in the common dir. */
|
|
83
|
+
async function locateReport(
|
|
84
|
+
io: WorkspaceIO,
|
|
85
|
+
task: SystemTask,
|
|
86
|
+
productCommon: string | null,
|
|
87
|
+
): Promise<{ file: string; content: string } | null> {
|
|
88
|
+
const worktree = task.dispatch?.worktree ?? null;
|
|
89
|
+
if (worktree !== null) {
|
|
90
|
+
const candidate = path.join(worktree, ".forge", "task", "report.yaml");
|
|
91
|
+
if (await io.exists(candidate)) {
|
|
92
|
+
return { file: candidate, content: await io.readFile(candidate) };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (productCommon !== null) {
|
|
96
|
+
const preserved = path.join(productCommon, "forge", "tasks", task.id, "report.yaml");
|
|
97
|
+
if (await io.exists(preserved)) {
|
|
98
|
+
return { file: preserved, content: await io.readFile(preserved) };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function runSystemTaskCollect(
|
|
105
|
+
input: ForgeCommandInput,
|
|
106
|
+
context: ForgeRuntimeContext,
|
|
107
|
+
): Promise<ForgeCommandResult<SystemTaskCollectResult>> {
|
|
108
|
+
const io = resolveIo(context.io);
|
|
109
|
+
const root = context.workspaceRoot;
|
|
110
|
+
const diagnostics: Diagnostic[] = [];
|
|
111
|
+
const dryRun = context.dryRun || input.flags["dry-run"] === true;
|
|
112
|
+
const reason = flagString(input, "reason");
|
|
113
|
+
|
|
114
|
+
const refusalDiag = await assertSystemRepository(root, io);
|
|
115
|
+
if (refusalDiag) diagnostics.push(refusalDiag);
|
|
116
|
+
|
|
117
|
+
const id = flagString(input, "task");
|
|
118
|
+
if (id === null) {
|
|
119
|
+
diagnostics.push(refusal("SYSTEM-TASK-01", "--task is required"));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let map: SystemMap | null = null;
|
|
123
|
+
let task: SystemTask | null = null;
|
|
124
|
+
if (diagnostics.every((d) => d.severity !== "error")) {
|
|
125
|
+
const loaded = await loadSystemMap(root, io);
|
|
126
|
+
diagnostics.push(...loaded.diagnostics.filter((d) => d.ruleId === "SYSTEM-MAP-01"));
|
|
127
|
+
map = loaded.map;
|
|
128
|
+
const read = await readTask(root, io, id!);
|
|
129
|
+
if (read.diagnostic) diagnostics.push(read.diagnostic);
|
|
130
|
+
task = read.task;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (task !== null && task.state !== "dispatched" && task.state !== "reported") {
|
|
134
|
+
diagnostics.push(
|
|
135
|
+
refusal(
|
|
136
|
+
"SYSTEM-TASK-02",
|
|
137
|
+
`${task.id} is ${task.state} — collect owns only dispatched → reported/failed and reported → integrated`,
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Resolve the product's common git dir for preserved reports + journal.
|
|
143
|
+
// --mark-failed needs no product checkout — the failure escape must stay
|
|
144
|
+
// reachable even after the folder is unmapped or deleted.
|
|
145
|
+
const canMarkFailed =
|
|
146
|
+
input.flags["mark-failed"] === true && reason !== null && reason.trim() !== "";
|
|
147
|
+
let productRoot: string | null = null;
|
|
148
|
+
let productCommon: string | null = null;
|
|
149
|
+
if (task !== null && map !== null && (diagnostics.every((d) => d.severity !== "error") || canMarkFailed)) {
|
|
150
|
+
const folder = Object.prototype.hasOwnProperty.call(map.local?.folders ?? {}, task.product)
|
|
151
|
+
? map.local!.folders[task.product]
|
|
152
|
+
: undefined;
|
|
153
|
+
if (folder === undefined && task.state === "dispatched" && !canMarkFailed) {
|
|
154
|
+
diagnostics.push(
|
|
155
|
+
refusal(
|
|
156
|
+
"SYSTEM-TASK-05",
|
|
157
|
+
`product '${task.product}' has no folder in system/products.local.yaml`,
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
} else if (folder !== undefined) {
|
|
161
|
+
productRoot = path.isAbsolute(folder) ? folder : path.resolve(root, folder);
|
|
162
|
+
try {
|
|
163
|
+
productCommon = await commonGitDir(io, productRoot);
|
|
164
|
+
} catch {
|
|
165
|
+
productCommon = null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// A reported task whose product git dir cannot be read would stall
|
|
169
|
+
// silently — surface the reason instead of reporting a frozen state.
|
|
170
|
+
if (task !== null && task.state === "reported" && productCommon === null) {
|
|
171
|
+
diagnostics.push({
|
|
172
|
+
ruleId: "SYSTEM-TASK-05",
|
|
173
|
+
severity: "warning",
|
|
174
|
+
message: `${task.id} is reported but the product checkout for '${task.product}' is unresolvable — the reported → integrated check is skipped this run`,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let reportFile: string | null = null;
|
|
180
|
+
if (task !== null && diagnostics.every((d) => d.severity !== "error")) {
|
|
181
|
+
const located = task.state === "dispatched" ? await locateReport(io, task, productCommon) : null;
|
|
182
|
+
if (task.state === "dispatched" && located === null) {
|
|
183
|
+
if (canMarkFailed) {
|
|
184
|
+
if (!dryRun) {
|
|
185
|
+
task = historyRow(task, "failed", "operator", reason!);
|
|
186
|
+
await writeTask(root, io, task);
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
diagnostics.push(
|
|
190
|
+
refusal(
|
|
191
|
+
"SYSTEM-TASK-07",
|
|
192
|
+
`no task report for ${task.id} — checked ${task.dispatch?.worktree ?? "(no worktree)"} and the preserved copy`,
|
|
193
|
+
"finish the product session or re-run with --mark-failed --reason <why>",
|
|
194
|
+
),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
} else if (task.state === "dispatched" && canMarkFailed) {
|
|
198
|
+
// --mark-failed deliberately discards a present report — the escape
|
|
199
|
+
// hatch SYSTEM-TASK-08's fixHint prescribes for a wedged report.
|
|
200
|
+
if (!dryRun) {
|
|
201
|
+
task = historyRow(task, "failed", "operator", reason!);
|
|
202
|
+
await writeTask(root, io, task);
|
|
203
|
+
}
|
|
204
|
+
} else if (located !== null) {
|
|
205
|
+
reportFile = located.file;
|
|
206
|
+
let raw: unknown = null;
|
|
207
|
+
let parseError: string | null = null;
|
|
208
|
+
try {
|
|
209
|
+
raw = YAML.parse(located.content);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
parseError = error instanceof Error ? error.message : String(error);
|
|
212
|
+
}
|
|
213
|
+
const parsed = parseError === null ? taskReportSchema.safeParse(raw) : null;
|
|
214
|
+
if (parsed === null || !parsed.success) {
|
|
215
|
+
const detail =
|
|
216
|
+
parseError ??
|
|
217
|
+
(parsed && !parsed.success
|
|
218
|
+
? parsed.error.issues
|
|
219
|
+
.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`)
|
|
220
|
+
.join("; ")
|
|
221
|
+
: "");
|
|
222
|
+
diagnostics.push(
|
|
223
|
+
refusal(
|
|
224
|
+
"SYSTEM-TASK-08",
|
|
225
|
+
`task report at ${located.file} is not valid forge/task-report@1 — ${detail}`,
|
|
226
|
+
"fix the report in the product session or --mark-failed --reason <why>",
|
|
227
|
+
),
|
|
228
|
+
);
|
|
229
|
+
} else if (parsed.data.task !== task.id) {
|
|
230
|
+
diagnostics.push(
|
|
231
|
+
refusal(
|
|
232
|
+
"SYSTEM-TASK-08",
|
|
233
|
+
`report at ${located.file} names task ${parsed.data.task}, expected ${task.id}`,
|
|
234
|
+
"the report belongs to a different task",
|
|
235
|
+
),
|
|
236
|
+
);
|
|
237
|
+
} else if (!dryRun) {
|
|
238
|
+
// Copy the validated report into the system queue.
|
|
239
|
+
const dst = reportFilePath(root, task.id);
|
|
240
|
+
await io.mkdir(path.dirname(dst));
|
|
241
|
+
await io.writeFile(dst, located.content);
|
|
242
|
+
const next: SystemTask = { ...task, report: path.posix.join("queue/reports", `${task.id}.yaml`) };
|
|
243
|
+
const outcome = parsed.data.outcome;
|
|
244
|
+
const target = outcome === "blocked" ? "failed" : "reported";
|
|
245
|
+
task = historyRow(next, target, "collect");
|
|
246
|
+
await writeTask(root, io, task);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Journal check — reported → integrated when the product integrated dispatch.branch.
|
|
252
|
+
if (
|
|
253
|
+
task !== null &&
|
|
254
|
+
task.state === "reported" &&
|
|
255
|
+
task.dispatch !== null &&
|
|
256
|
+
productCommon !== null &&
|
|
257
|
+
diagnostics.every((d) => d.severity !== "error")
|
|
258
|
+
) {
|
|
259
|
+
try {
|
|
260
|
+
const events = await readJournal(io, productCommon);
|
|
261
|
+
const integrated = events.find(
|
|
262
|
+
(e) => e.event === "integrate" && e.branch === task!.dispatch!.branch,
|
|
263
|
+
);
|
|
264
|
+
if (integrated && !dryRun) {
|
|
265
|
+
const next: SystemTask = { ...task, integratedCommit: integrated.sha };
|
|
266
|
+
task = historyRow(next, "integrated", "collect");
|
|
267
|
+
await writeTask(root, io, task);
|
|
268
|
+
} else if (integrated && dryRun) {
|
|
269
|
+
task = { ...task, integratedCommit: integrated.sha };
|
|
270
|
+
}
|
|
271
|
+
} catch (error) {
|
|
272
|
+
diagnostics.push({
|
|
273
|
+
ruleId: "SYSTEM-TASK-05",
|
|
274
|
+
severity: "warning",
|
|
275
|
+
message: `${task.id} is reported but the product journal could not be read: ${error instanceof Error ? error.message : String(error)} — the reported → integrated check is skipped this run`,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const errors = diagnostics.filter((d) => d.severity === "error").length;
|
|
281
|
+
return {
|
|
282
|
+
data: {
|
|
283
|
+
command: "system.task.collect",
|
|
284
|
+
task: task?.id ?? id,
|
|
285
|
+
state: task?.state ?? null,
|
|
286
|
+
reportFound: reportFile !== null,
|
|
287
|
+
reportFile,
|
|
288
|
+
integratedCommit: task?.integratedCommit ?? null,
|
|
289
|
+
diagnostics,
|
|
290
|
+
},
|
|
291
|
+
exitCode: errors > 0 ? 1 : 0,
|
|
292
|
+
summary:
|
|
293
|
+
task === null
|
|
294
|
+
? `system.task.collect refused (${errors} error(s))`
|
|
295
|
+
: dryRun
|
|
296
|
+
? `system.task.collect would process ${task.id} (state ${task.state})`
|
|
297
|
+
: `system.task.collect: ${task.id} is now ${task.state}${task.integratedCommit ? ` (integrated ${task.integratedCommit.slice(0, 9)})` : ""}`,
|
|
298
|
+
nextSteps:
|
|
299
|
+
task?.state === "reported"
|
|
300
|
+
? [{ action: "integrate the product branch, then re-run system.task.collect", kind: "optional" }]
|
|
301
|
+
: task?.state === "integrated"
|
|
302
|
+
? [{ action: `system.task.move --task ${task.id} --to verified --version-set <id>`, kind: "optional" }]
|
|
303
|
+
: [],
|
|
304
|
+
};
|
|
305
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>system.task.create (RFC-1509) — allocate the next T-NNNN id, write
|
|
4
|
+
queue/tasks/<id>.yaml (forge/system-task@1, state proposed) and a brief
|
|
5
|
+
scaffold at queue/briefs/<id>.md (forge/dispatch-brief@1 frontmatter
|
|
6
|
+
with a placeholder goal). Writes files only — the session commits.</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>No dispatch/collect logic — move owns readiness checks.</item>
|
|
9
|
+
</non-goals>
|
|
10
|
+
</MODULE_CONTRACT>
|
|
11
|
+
<CHANGE_SUMMARY>
|
|
12
|
+
<item>RFC-1509: step 3 — system.task.create handler</item>
|
|
13
|
+
<item>RFC-1509: implement RFC-1509 — system task queue, dispatch briefs and task reports</item>
|
|
14
|
+
<item>RFC-1510: implement RFC-1510 — product outbox for dependency-contract requests</item>
|
|
15
|
+
</CHANGE_SUMMARY>
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { resolveIo } from "../../../src/utils/io.ts";
|
|
19
|
+
import type {
|
|
20
|
+
Diagnostic,
|
|
21
|
+
ForgeCommandInput,
|
|
22
|
+
ForgeCommandResult,
|
|
23
|
+
ForgeRuntimeContext,
|
|
24
|
+
WorkspaceIO,
|
|
25
|
+
} from "../../../src/types.ts";
|
|
26
|
+
import { assertSystemRepository, loadSystemMap } from "../repo.ts";
|
|
27
|
+
import { TASK_KINDS, type SystemTask } from "../task-schemas.ts";
|
|
28
|
+
import {
|
|
29
|
+
briefFilePath,
|
|
30
|
+
nextTaskId,
|
|
31
|
+
taskFilePath,
|
|
32
|
+
writeTask,
|
|
33
|
+
} from "../task-store.ts";
|
|
34
|
+
import path from "node:path";
|
|
35
|
+
|
|
36
|
+
export const BRIEF_GOAL_PLACEHOLDER = "TODO: describe the task goal";
|
|
37
|
+
|
|
38
|
+
export interface SystemTaskCreateResult {
|
|
39
|
+
command: "system.task.create";
|
|
40
|
+
created: boolean;
|
|
41
|
+
task: string | null;
|
|
42
|
+
files: string[];
|
|
43
|
+
diagnostics: Diagnostic[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function flagString(input: ForgeCommandInput, name: string): string | null {
|
|
47
|
+
const v = input.flags[name];
|
|
48
|
+
return typeof v === "string" && v.length > 0 ? v : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function flagList(input: ForgeCommandInput, name: string): string[] {
|
|
52
|
+
const v = input.flags[name];
|
|
53
|
+
if (Array.isArray(v)) return v.filter((s): s is string => typeof s === "string");
|
|
54
|
+
return typeof v === "string" && v.length > 0 ? [v] : [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `--origin` grammar: `<kind>` or `<kind>:<ref>` (ref may itself contain colons). */
|
|
58
|
+
function parseOrigin(
|
|
59
|
+
raw: string | null,
|
|
60
|
+
): { kind: "operator" | "outbox" | "decision" | "scenario"; ref: string | null } | null {
|
|
61
|
+
if (raw === null) return { kind: "operator", ref: null };
|
|
62
|
+
const idx = raw.indexOf(":");
|
|
63
|
+
const kind = idx === -1 ? raw : raw.slice(0, idx);
|
|
64
|
+
const ref = idx === -1 ? null : raw.slice(idx + 1);
|
|
65
|
+
if (kind !== "operator" && kind !== "outbox" && kind !== "decision" && kind !== "scenario") {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
return { kind, ref: ref === "" ? null : ref };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function briefScaffold(id: string, product: string): string {
|
|
72
|
+
return `---
|
|
73
|
+
schema: forge/dispatch-brief@1
|
|
74
|
+
task: ${id}
|
|
75
|
+
product: ${product}
|
|
76
|
+
goal: "${BRIEF_GOAL_PLACEHOLDER}"
|
|
77
|
+
acceptance:
|
|
78
|
+
- claim: "TODO: the claim this task must prove"
|
|
79
|
+
check: "TODO: how the product session verifies it"
|
|
80
|
+
constraints: []
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
# ${id}
|
|
84
|
+
|
|
85
|
+
${BRIEF_GOAL_PLACEHOLDER}
|
|
86
|
+
`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Build a proposed-state task plus its brief-scaffold files — the same write
|
|
91
|
+
* set system.task.create performs. Shared with system.outbox.scan --create
|
|
92
|
+
* (RFC-1510) so every task origin writes an identical record.
|
|
93
|
+
*/
|
|
94
|
+
export async function createTask(
|
|
95
|
+
root: string,
|
|
96
|
+
io: WorkspaceIO,
|
|
97
|
+
spec: {
|
|
98
|
+
product: string;
|
|
99
|
+
slug: string;
|
|
100
|
+
title: string;
|
|
101
|
+
kind: SystemTask["kind"];
|
|
102
|
+
contracts: string[];
|
|
103
|
+
dependsOn?: string[];
|
|
104
|
+
origin: SystemTask["origin"];
|
|
105
|
+
reason?: string;
|
|
106
|
+
},
|
|
107
|
+
): Promise<{ task: SystemTask; files: string[] }> {
|
|
108
|
+
const id = await nextTaskId(root, io);
|
|
109
|
+
const task: SystemTask = {
|
|
110
|
+
schema: "forge/system-task@1",
|
|
111
|
+
id,
|
|
112
|
+
title: spec.title,
|
|
113
|
+
product: spec.product,
|
|
114
|
+
slug: spec.slug,
|
|
115
|
+
kind: spec.kind,
|
|
116
|
+
state: "proposed",
|
|
117
|
+
origin: spec.origin,
|
|
118
|
+
contracts: spec.contracts,
|
|
119
|
+
dependsOn: spec.dependsOn ?? [],
|
|
120
|
+
brief: path.posix.join("queue/briefs", `${id}.md`),
|
|
121
|
+
briefSha256: null,
|
|
122
|
+
dispatch: null,
|
|
123
|
+
report: null,
|
|
124
|
+
integratedCommit: null,
|
|
125
|
+
history: [
|
|
126
|
+
{
|
|
127
|
+
at: new Date().toISOString(),
|
|
128
|
+
from: "none",
|
|
129
|
+
to: "proposed",
|
|
130
|
+
by: "operator",
|
|
131
|
+
...(spec.reason ? { reason: spec.reason } : {}),
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
return { task, files: [taskFilePath(root, id), briefFilePath(root, id)] };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Write a task created by createTask plus its brief scaffold. */
|
|
139
|
+
export async function writeTaskWithBrief(
|
|
140
|
+
root: string,
|
|
141
|
+
io: WorkspaceIO,
|
|
142
|
+
task: SystemTask,
|
|
143
|
+
): Promise<void> {
|
|
144
|
+
await writeTask(root, io, task);
|
|
145
|
+
const brief = briefFilePath(root, task.id);
|
|
146
|
+
await io.mkdir(path.dirname(brief));
|
|
147
|
+
await io.writeFile(brief, briefScaffold(task.id, task.product));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function runSystemTaskCreate(
|
|
151
|
+
input: ForgeCommandInput,
|
|
152
|
+
context: ForgeRuntimeContext,
|
|
153
|
+
): Promise<ForgeCommandResult<SystemTaskCreateResult>> {
|
|
154
|
+
const io = resolveIo(context.io);
|
|
155
|
+
const root = context.workspaceRoot;
|
|
156
|
+
const diagnostics: Diagnostic[] = [];
|
|
157
|
+
const dryRun = context.dryRun || input.flags["dry-run"] === true;
|
|
158
|
+
|
|
159
|
+
const refusal = await assertSystemRepository(root, io);
|
|
160
|
+
if (refusal) diagnostics.push(refusal);
|
|
161
|
+
|
|
162
|
+
const product = flagString(input, "product");
|
|
163
|
+
const slug = flagString(input, "slug");
|
|
164
|
+
const title = flagString(input, "title");
|
|
165
|
+
const kind = flagString(input, "kind");
|
|
166
|
+
const contracts = flagList(input, "contracts");
|
|
167
|
+
const dependsOn = flagList(input, "depends-on");
|
|
168
|
+
const origin = parseOrigin(flagString(input, "origin"));
|
|
169
|
+
|
|
170
|
+
if (product === null || slug === null || title === null || kind === null) {
|
|
171
|
+
diagnostics.push({
|
|
172
|
+
ruleId: "SYSTEM-TASK-01",
|
|
173
|
+
severity: "error",
|
|
174
|
+
message: "--product, --slug, --title and --kind are required",
|
|
175
|
+
fixHint: "see forge system.task.create --help",
|
|
176
|
+
});
|
|
177
|
+
} else if (!(TASK_KINDS as readonly string[]).includes(kind)) {
|
|
178
|
+
diagnostics.push({
|
|
179
|
+
ruleId: "SYSTEM-TASK-01",
|
|
180
|
+
severity: "error",
|
|
181
|
+
message: `invalid --kind '${kind}' — one of ${TASK_KINDS.join(", ")}`,
|
|
182
|
+
fixHint: "pick a declared task kind",
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (origin === null) {
|
|
186
|
+
diagnostics.push({
|
|
187
|
+
ruleId: "SYSTEM-TASK-01",
|
|
188
|
+
severity: "error",
|
|
189
|
+
message: `--origin must start with operator|outbox|decision|scenario (e.g. outbox:werkstatt:OB-0003)`,
|
|
190
|
+
fixHint: "pass --origin <kind>:<ref> or omit it",
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
for (const dep of dependsOn) {
|
|
194
|
+
if (!/^T-\d{4}$/.test(dep)) {
|
|
195
|
+
diagnostics.push({
|
|
196
|
+
ruleId: "SYSTEM-TASK-01",
|
|
197
|
+
severity: "error",
|
|
198
|
+
message: `--depends-on '${dep}' is not a task id (T-NNNN)`,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// The product must exist in the map — SYSTEM-TASK-05.
|
|
204
|
+
if (diagnostics.length === 0) {
|
|
205
|
+
const loaded = await loadSystemMap(root, io);
|
|
206
|
+
diagnostics.push(...loaded.diagnostics.filter((d) => d.ruleId === "SYSTEM-MAP-01"));
|
|
207
|
+
if (loaded.map) {
|
|
208
|
+
const known = loaded.map.products.products.some((p) => p.id === product);
|
|
209
|
+
if (!known) {
|
|
210
|
+
diagnostics.push({
|
|
211
|
+
ruleId: "SYSTEM-TASK-05",
|
|
212
|
+
severity: "error",
|
|
213
|
+
message: `product '${product}' is not declared in system/products.yaml`,
|
|
214
|
+
fixHint: "add the product to system/products.yaml or fix --product",
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let id: string | null = null;
|
|
221
|
+
let task: SystemTask | null = null;
|
|
222
|
+
const files: string[] = [];
|
|
223
|
+
if (diagnostics.every((d) => d.severity !== "error")) {
|
|
224
|
+
const created = await createTask(root, io, {
|
|
225
|
+
product: product!,
|
|
226
|
+
slug: slug!,
|
|
227
|
+
title: title!,
|
|
228
|
+
kind: kind as SystemTask["kind"],
|
|
229
|
+
contracts,
|
|
230
|
+
dependsOn,
|
|
231
|
+
origin: origin!,
|
|
232
|
+
...(flagString(input, "reason") ? { reason: flagString(input, "reason")! } : {}),
|
|
233
|
+
});
|
|
234
|
+
task = created.task;
|
|
235
|
+
id = task.id;
|
|
236
|
+
files.push(...created.files);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (task && !dryRun) {
|
|
240
|
+
await writeTaskWithBrief(root, io, task);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const errors = diagnostics.filter((d) => d.severity === "error").length;
|
|
244
|
+
return {
|
|
245
|
+
data: {
|
|
246
|
+
command: "system.task.create",
|
|
247
|
+
created: task !== null && !dryRun,
|
|
248
|
+
task: id,
|
|
249
|
+
files: dryRun ? files : files.filter((f) => f !== null),
|
|
250
|
+
diagnostics,
|
|
251
|
+
},
|
|
252
|
+
exitCode: errors > 0 ? 1 : 0,
|
|
253
|
+
summary:
|
|
254
|
+
task === null
|
|
255
|
+
? `system.task.create refused (${errors} error(s))`
|
|
256
|
+
: dryRun
|
|
257
|
+
? `system.task.create would write ${id} (task + brief scaffold)`
|
|
258
|
+
: `system.task.create wrote ${id} at queue/tasks/${id}.yaml + queue/briefs/${id}.md`,
|
|
259
|
+
nextSteps:
|
|
260
|
+
task === null
|
|
261
|
+
? [{ action: "Fix the error diagnostics and re-run system.task.create", kind: "required" }]
|
|
262
|
+
: dryRun
|
|
263
|
+
? []
|
|
264
|
+
: [
|
|
265
|
+
{
|
|
266
|
+
action: `Edit queue/briefs/${id}.md — fill goal and acceptance, then system.task.move --task ${id} --to ready`,
|
|
267
|
+
kind: "required",
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
}
|