@astrosheep/keiyaku 2.9.11 → 2.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -85
- package/build/.tsbuildinfo +1 -1
- package/build/agents/call-terms.js +1 -0
- package/build/agents/providers/claude-agent-sdk/adapter.js +17 -4
- package/build/cli/commands/akuma/akuma/handler.js +2 -1
- package/build/cli/commands/akuma/akuma/meta.js +4 -3
- package/build/cli/commands/akuma/catalog.js +2 -0
- package/build/cli/commands/akuma/list/handler.js +1 -1
- package/build/cli/commands/akuma/list/meta-list.js +12 -0
- package/build/cli/commands/akuma/list/meta-ls.js +2 -2
- package/build/cli/commands/akuma.js +5 -0
- package/build/cli/commands/contract/amend/meta.js +4 -3
- package/build/cli/commands/contract/arc/meta.js +2 -0
- package/build/cli/commands/contract/audit/handler.js +28 -2
- package/build/cli/commands/contract/audit/meta.js +4 -3
- package/build/cli/commands/contract/bind/meta.js +4 -4
- package/build/cli/commands/contract/petition/handler.js +2 -1
- package/build/cli/commands/contract/petition/meta.js +2 -2
- package/build/cli/commands/contract/renew/handler.js +44 -3
- package/build/cli/commands/contract/renew/meta.js +5 -4
- package/build/cli/commands/metadata.js +14 -10
- package/build/cli/commands/projection/call/handler.js +1 -1
- package/build/cli/commands/projection/call/meta.js +1 -1
- package/build/cli/commands/projection/catalog.js +2 -2
- package/build/cli/commands/projection/{revive → fork}/handler.js +10 -5
- package/build/cli/commands/projection/fork/meta.js +12 -0
- package/build/cli/commands/projection/history/handler.js +46 -2
- package/build/cli/commands/projection/history/meta.js +3 -3
- package/build/cli/commands/projection/kill/handler.js +4 -5
- package/build/cli/commands/projection/kill/meta.js +2 -2
- package/build/cli/commands/projection/status/handler.js +29 -13
- package/build/cli/commands/projection/status/meta.js +14 -3
- package/build/cli/commands/projection/tell/handler.js +8 -4
- package/build/cli/commands/projection/tell/meta.js +1 -1
- package/build/cli/commands/projection/wait/handler.js +45 -20
- package/build/cli/commands/projection/wait/meta.js +1 -1
- package/build/cli/commands/shared.js +2 -2
- package/build/cli/commands/system/catalog.js +2 -0
- package/build/cli/commands/task/add/handler.js +28 -12
- package/build/cli/commands/task/add/meta.js +18 -6
- package/build/cli/commands/task/catalog.js +4 -0
- package/build/cli/commands/task/compose/handler.js +18 -0
- package/build/cli/commands/task/compose/meta.js +10 -0
- package/build/cli/commands/task/doctor/handler.js +2 -3
- package/build/cli/commands/task/doctor/meta.js +2 -2
- package/build/cli/commands/task/done/meta.js +2 -2
- package/build/cli/commands/task/drop/handler.js +7 -2
- package/build/cli/commands/task/drop/meta.js +6 -3
- package/build/cli/commands/task/hold/meta.js +2 -2
- package/build/cli/commands/task/log/meta.js +2 -2
- package/build/cli/commands/task/ls/meta.js +2 -2
- package/build/cli/commands/task/note/handler.js +6 -0
- package/build/cli/commands/task/note/meta.js +11 -0
- package/build/cli/commands/task/resume/meta.js +2 -2
- package/build/cli/commands/task/shared.js +29 -15
- package/build/cli/commands/task/show/meta.js +2 -2
- package/build/cli/commands/task/start/meta.js +2 -2
- package/build/cli/commands/task/stop/meta.js +2 -2
- package/build/cli/commands/task/update/meta.js +3 -2
- package/build/cli/commands/verification/handler.js +43 -0
- package/build/cli/commands/verification/meta.js +13 -0
- package/build/cli/completion.js +16 -13
- package/build/cli/flags.js +48 -12
- package/build/cli/help.js +29 -30
- package/build/cli/index.js +14 -8
- package/build/cli/parse-flags.js +60 -21
- package/build/cli/parse-metadata.js +10 -4
- package/build/cli/parse-selectors.js +22 -4
- package/build/cli/parse.js +43 -30
- package/build/cli/projection-address.js +7 -7
- package/build/cli/render/arc.js +12 -3
- package/build/cli/render/audit.js +2 -2
- package/build/cli/render/call.js +4 -4
- package/build/cli/render/kanshi.js +122 -85
- package/build/cli/render/misc.js +2 -2
- package/build/cli/render/petition.js +16 -1
- package/build/cli/render/projection-history.js +17 -4
- package/build/cli/render/shared.js +5 -5
- package/build/cli/render/status-indicator.js +47 -0
- package/build/cli/render/status.js +106 -76
- package/build/cli/render/success-response.js +20 -5
- package/build/cli/render/task.js +33 -5
- package/build/cli/render/tell.js +10 -4
- package/build/cli/render/tool-command-normalization.js +137 -0
- package/build/cli/render/tool-presentation.js +2 -1
- package/build/cli/render/verification.js +23 -0
- package/build/cli/render/wait.js +101 -33
- package/build/cli/types.js +2 -1
- package/build/config/akuma-loader.js +21 -1
- package/build/config/settings/knobs.js +7 -1
- package/build/config/settings/schema.js +10 -5
- package/build/core/addressing.js +3 -3
- package/build/core/amend.js +102 -17
- package/build/core/arc.js +4 -4
- package/build/core/audit/candidate.js +10 -18
- package/build/core/audit/coordinates.js +12 -17
- package/build/core/audit/evidence.js +6 -4
- package/build/core/audit/facade.js +3 -3
- package/build/core/audit/report.js +1 -1
- package/build/core/bind-reconciliation.js +42 -23
- package/build/core/bind.js +182 -81
- package/build/core/call/call.js +6 -7
- package/build/core/call/context.js +46 -33
- package/build/core/call/execution.js +21 -6
- package/build/core/call/prompt.js +11 -42
- package/build/core/contract-carrier-runtime.js +209 -105
- package/build/core/contract-carrier.js +156 -73
- package/build/core/contract-view.js +43 -6
- package/build/core/contract.js +2 -1
- package/build/core/derived-replay.js +168 -35
- package/build/core/draft.js +60 -27
- package/build/core/forfeit.js +1 -1
- package/build/core/lifecycle-history.js +13 -0
- package/build/core/lifecycle-recovery.js +32 -27
- package/build/core/lifecycle-runner.js +14 -14
- package/build/core/log.js +1 -1
- package/build/core/outcome-base.js +2 -2
- package/build/core/projection/akuma-name.js +43 -0
- package/build/core/projection/generation/database.js +141 -79
- package/build/core/projection/generation/ledger.js +91 -0
- package/build/core/projection/generation/model.js +19 -14
- package/build/core/projection/generation/projection-generation-continuation.js +1 -1
- package/build/core/projection/generation/projection-generation-doorbell.js +88 -0
- package/build/core/projection/generation/projection-generation-execution.js +24 -0
- package/build/core/projection/generation/projection-generation-identity.js +4 -0
- package/build/core/projection/generation/projection-generation-launcher.js +72 -138
- package/build/core/projection/generation/projection-generation-process.js +16 -15
- package/build/core/projection/generation/projection-generation-runner.js +132 -76
- package/build/core/projection/generation/projection-generation-runtime.js +10 -61
- package/build/core/projection/generation/protocol.js +68 -0
- package/build/core/projection/generation/store.js +17 -7
- package/build/core/projection/generation/transitions.js +24 -14
- package/build/core/projection/index.js +5 -5
- package/build/core/projection/projection-core.js +6 -2
- package/build/core/projection/projection-execution-observer.js +1 -1
- package/build/core/projection/projection-history.js +8 -8
- package/build/core/projection/projection-kill.js +20 -10
- package/build/core/projection/projection-life-observer.js +8 -8
- package/build/core/projection/projection-mint.js +6 -8
- package/build/core/projection/projection-status-observation.js +77 -8
- package/build/core/projection/projection-status.js +151 -4
- package/build/core/projection/projection-wait.js +48 -29
- package/build/core/projection/projection-wake.js +28 -88
- package/build/core/projection/tell/launch-store.js +1 -1
- package/build/core/projection/tell/store.js +1 -1
- package/build/core/renew-build.js +204 -74
- package/build/core/renew-plan.js +34 -9
- package/build/core/renew-rewrite.js +56 -15
- package/build/core/renew.js +39 -35
- package/build/core/repository-ledger/accepted-fold-read.js +6 -3
- package/build/core/repository-ledger/claim-evidence.js +1 -1
- package/build/core/repository-ledger/codec.js +11 -5
- package/build/core/repository-ledger/current-state-store.js +464 -349
- package/build/core/repository-ledger/fold-repository.js +5 -6
- package/build/core/repository-ledger/identity.js +60 -0
- package/build/core/repository-ledger/inventory.js +3 -3
- package/build/core/repository-ledger/read-model.js +57 -9
- package/build/core/repository-ledger/write-transaction.js +24 -17
- package/build/core/run-control/connection-bound-close.js +41 -0
- package/build/core/run-control/detached-lease-bootstrap.js +208 -0
- package/build/core/run-control/detached-process.js +14 -0
- package/build/core/run-control/index.js +6 -0
- package/build/core/{process-group.js → run-control/process-tree.js} +1 -1
- package/build/core/run-control/runner-lease.js +172 -0
- package/build/core/run-control/sqlite-process-lifetime-lock.js +174 -0
- package/build/core/seal.js +44 -32
- package/build/core/settlement/claim-delivery.js +22 -9
- package/build/core/settlement/claim.js +8 -6
- package/build/core/settlement/petition-claim-gates.js +9 -8
- package/build/core/settlement/petition-head-guard.js +5 -6
- package/build/core/settlement/petition-preview.js +21 -5
- package/build/core/settlement/petition.js +51 -17
- package/build/core/settlement/settlement.js +20 -15
- package/build/core/settlement/verdict.js +2 -2
- package/build/core/settlement/verification.js +492 -364
- package/build/core/status/board.js +184 -75
- package/build/core/status/drift.js +8 -10
- package/build/core/task/board.js +1 -0
- package/build/core/task/commands.js +25 -0
- package/build/core/task/compose.js +328 -0
- package/build/core/task/document.js +102 -39
- package/build/core/task/index.js +4 -3
- package/build/core/task/settlement-git.js +70 -30
- package/build/core/task/settlement-policy.js +27 -14
- package/build/core/task/source-board.js +1 -0
- package/build/core/task/task-bind-preparation.js +59 -9
- package/build/core/task/task-contract.js +2 -2
- package/build/core/task/task-git-store.js +1 -0
- package/build/core/task/task-store-repository.js +2 -0
- package/build/core/task/task.js +2 -2
- package/build/core/transcripts.js +4 -4
- package/build/core/verification-declaration.js +95 -0
- package/build/core/worktree-bootstrap.js +1 -1
- package/build/core/worktree-path.js +7 -11
- package/build/flow-error.js +15 -2
- package/build/generated/version.js +2 -2
- package/build/git/branches.js +41 -70
- package/build/git/commits.js +92 -21
- package/build/git/core.js +9 -161
- package/build/git/diff/preview.js +4 -4
- package/build/git/diff/read.js +4 -4
- package/build/git/diff/structured.js +5 -5
- package/build/git/process.js +229 -0
- package/build/git/refs.js +30 -5
- package/build/git/staging.js +39 -115
- package/build/git/streaming-batch.js +9 -16
- package/build/git/worktree.js +104 -91
- package/build/index.js +7 -0
- package/package.json +2 -2
- package/skills/keiyaku-akuma/SKILL.md +27 -21
- package/skills/keiyaku-task/SKILL.md +61 -5
- package/skills/keiyaku-workflow/SKILL.md +81 -26
- package/build/cli/commands/projection/revive/meta.js +0 -12
- package/build/core/projection/projection-life-protocol.js +0 -115
- package/build/core/projection/projection-runner-lock.js +0 -382
- package/build/core/projection/tell/database.js +0 -127
- package/build/core/settlement/verification-coordination.js +0 -305
- package/build/core/settlement/verification-supervisor.js +0 -275
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { FlowError } from "../../flow-error.js";
|
|
2
|
+
import { taskIdentifierSlug, IdentifierSlugError } from "../identifier-slug.js";
|
|
3
|
+
import { buildTaskBoardFromDocuments, requireHealthy, resolveTaskId } from "./board.js";
|
|
4
|
+
import { formatTaskCoordinate, parseTaskCoordinate } from "./coordinate.js";
|
|
5
|
+
import { advancedTaskUpdatedAt } from "./model.js";
|
|
6
|
+
function atLine(line, message) {
|
|
7
|
+
throw new FlowError("INVALID_TARGET", `task compose line ${line}: ${message}`);
|
|
8
|
+
}
|
|
9
|
+
function parseRelationValues(line, field, value) {
|
|
10
|
+
if (value === "")
|
|
11
|
+
return [];
|
|
12
|
+
const values = value.split(",");
|
|
13
|
+
const references = values.map((entry) => {
|
|
14
|
+
if (!entry.startsWith("@"))
|
|
15
|
+
atLine(line, `${field}= accepts comma-separated @COORDINATE references or an explicit empty assignment`);
|
|
16
|
+
try {
|
|
17
|
+
return parseTaskCoordinate(entry.slice(1), `${field} coordinate`).coordinate;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
if (error instanceof FlowError)
|
|
21
|
+
atLine(line, `${field}= accepts comma-separated @COORDINATE references or an explicit empty assignment`);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (new Set(references).size !== references.length)
|
|
26
|
+
atLine(line, `${field}= cannot repeat a coordinate`);
|
|
27
|
+
return references;
|
|
28
|
+
}
|
|
29
|
+
function parseAssignments(line, tokens) {
|
|
30
|
+
let clearParent = false;
|
|
31
|
+
const relations = {};
|
|
32
|
+
const declared = new Set();
|
|
33
|
+
for (const token of tokens) {
|
|
34
|
+
const match = /^(parent|needs|supersedes|relates)=(.*)$/.exec(token);
|
|
35
|
+
if (!match)
|
|
36
|
+
atLine(line, "inline declarations must use parent=, needs=, supersedes=, or relates=");
|
|
37
|
+
const field = match[1];
|
|
38
|
+
const value = match[2];
|
|
39
|
+
if (declared.has(field))
|
|
40
|
+
atLine(line, `${field}= may appear only once`);
|
|
41
|
+
declared.add(field);
|
|
42
|
+
if (field === "parent") {
|
|
43
|
+
if (value !== "")
|
|
44
|
+
atLine(line, "parent= only clears the parent; use nesting to assign one");
|
|
45
|
+
clearParent = true;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
relations[field] = parseRelationValues(line, field, value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { clearParent, relations };
|
|
52
|
+
}
|
|
53
|
+
function declarationTokens(line, content, kind) {
|
|
54
|
+
if (/\[(?:parent|needs|supersedes|relates)=/.test(content)) {
|
|
55
|
+
atLine(line, "inline declarations use whitespace-separated field=value tokens, not brackets");
|
|
56
|
+
}
|
|
57
|
+
if (kind === "@") {
|
|
58
|
+
const [reference, ...assignments] = content.slice(1).split(/\s+/);
|
|
59
|
+
if (!reference)
|
|
60
|
+
atLine(line, "task references must be exactly @COORDINATE followed only by inline declarations");
|
|
61
|
+
return { reference, ...parseAssignments(line, assignments) };
|
|
62
|
+
}
|
|
63
|
+
const source = content.slice(1).trim();
|
|
64
|
+
if (!source)
|
|
65
|
+
atLine(line, "+ must be followed by a task title");
|
|
66
|
+
const tokens = source.split(/\s+/);
|
|
67
|
+
const assignmentStart = tokens.findIndex((token) => token.includes("="));
|
|
68
|
+
const titleTokens = assignmentStart === -1 ? tokens : tokens.slice(0, assignmentStart);
|
|
69
|
+
if (titleTokens.length === 0)
|
|
70
|
+
atLine(line, "+ must be followed by a task title");
|
|
71
|
+
const assignments = assignmentStart === -1 ? [] : tokens.slice(assignmentStart);
|
|
72
|
+
return { title: titleTokens.join(" "), ...parseAssignments(line, assignments) };
|
|
73
|
+
}
|
|
74
|
+
export function parseTaskCompositionSketch(input) {
|
|
75
|
+
if (!input.trim())
|
|
76
|
+
throw new FlowError("EMPTY_PARAM", "task compose sketch cannot be blank");
|
|
77
|
+
const nodes = [];
|
|
78
|
+
const taskAtDepth = new Map();
|
|
79
|
+
let pendingBodyBlanks;
|
|
80
|
+
let activeBody;
|
|
81
|
+
for (const [offset, raw] of input.split(/\r?\n/).entries()) {
|
|
82
|
+
const line = offset + 1;
|
|
83
|
+
if (/\t/.test(raw))
|
|
84
|
+
atLine(line, "uses spaces only; indentation is two spaces per tree level");
|
|
85
|
+
const indent = /^( *)/.exec(raw)[1].length;
|
|
86
|
+
if (indent % 2 !== 0)
|
|
87
|
+
atLine(line, "indentation must use whole two-space levels");
|
|
88
|
+
const content = raw.slice(indent).trimEnd();
|
|
89
|
+
const depth = indent / 2;
|
|
90
|
+
if (!content) {
|
|
91
|
+
if (activeBody) {
|
|
92
|
+
if (pendingBodyBlanks?.parent === activeBody)
|
|
93
|
+
pendingBodyBlanks.count += 1;
|
|
94
|
+
else
|
|
95
|
+
pendingBodyBlanks = { parent: activeBody, count: 1 };
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
pendingBodyBlanks = undefined;
|
|
99
|
+
}
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (!content.startsWith("+") && !content.startsWith("@")) {
|
|
103
|
+
const parentDepth = [...taskAtDepth.keys()].filter((candidate) => candidate < depth).sort((a, b) => b - a)[0];
|
|
104
|
+
const parent = parentDepth === undefined ? undefined : taskAtDepth.get(parentDepth);
|
|
105
|
+
if (!parent?.title)
|
|
106
|
+
atLine(line, "bare prose is allowed only inside a new + task body");
|
|
107
|
+
if (pendingBodyBlanks?.parent === parent)
|
|
108
|
+
parent.body.push(...Array(pendingBodyBlanks.count).fill(""));
|
|
109
|
+
pendingBodyBlanks = undefined;
|
|
110
|
+
parent.body.push(raw.slice((parent.depth + 1) * 2));
|
|
111
|
+
activeBody = parent;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
pendingBodyBlanks = undefined;
|
|
115
|
+
activeBody = undefined;
|
|
116
|
+
const kind = content.startsWith("+") ? "+" : "@";
|
|
117
|
+
const parsed = declarationTokens(line, content, kind);
|
|
118
|
+
for (const existingDepth of [...taskAtDepth.keys()])
|
|
119
|
+
if (existingDepth >= depth)
|
|
120
|
+
taskAtDepth.delete(existingDepth);
|
|
121
|
+
if (depth > 0 && !taskAtDepth.has(depth - 1))
|
|
122
|
+
atLine(line, "cannot indent below a missing parent task line");
|
|
123
|
+
const node = { line, depth, body: [], ...parsed };
|
|
124
|
+
nodes.push(node);
|
|
125
|
+
taskAtDepth.set(depth, node);
|
|
126
|
+
}
|
|
127
|
+
if (nodes.length === 0)
|
|
128
|
+
throw new FlowError("EMPTY_PARAM", "task compose sketch cannot be blank");
|
|
129
|
+
return nodes;
|
|
130
|
+
}
|
|
131
|
+
function requireHealthyFinalCompositionBoard(board, lines) {
|
|
132
|
+
const disease = board.diseases[0];
|
|
133
|
+
if (!disease)
|
|
134
|
+
return;
|
|
135
|
+
const coordinate = [disease.id, ...(disease.relatedIds ?? [])].find((candidate) => candidate !== undefined && lines.has(candidate));
|
|
136
|
+
if (coordinate !== undefined)
|
|
137
|
+
atLine(lines.get(coordinate), disease.message);
|
|
138
|
+
requireHealthy(board);
|
|
139
|
+
}
|
|
140
|
+
function documentFromView(task) {
|
|
141
|
+
return {
|
|
142
|
+
id: task.id, namespace: task.namespace, coordinate: task.coordinate, title: task.title,
|
|
143
|
+
state: task.state, pri: task.pri, needs: [...task.needs], parent: task.parent,
|
|
144
|
+
from: [...task.from], supersedes: [...task.supersedes], relatesTo: [...task.relatesTo],
|
|
145
|
+
notes: task.notes.map((note) => ({ ...note })),
|
|
146
|
+
createdAt: task.createdAt, ...(task.updatedAt === undefined ? {} : { updatedAt: task.updatedAt }),
|
|
147
|
+
creator: task.creator, ...(task.startedAt === undefined ? {} : { startedAt: task.startedAt }),
|
|
148
|
+
...(task.contractId === undefined ? {} : { contractId: task.contractId }), body: task.body,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function allocateCoordinate(title, namespace, occupied, line) {
|
|
152
|
+
for (let ordinal = 1; Number.isSafeInteger(ordinal); ordinal += 1) {
|
|
153
|
+
try {
|
|
154
|
+
const localId = taskIdentifierSlug(title, ordinal === 1 ? "" : `-${ordinal}`);
|
|
155
|
+
const coordinate = formatTaskCoordinate(namespace, localId);
|
|
156
|
+
if (!occupied.has(coordinate))
|
|
157
|
+
return coordinate;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (error instanceof IdentifierSlugError)
|
|
161
|
+
atLine(line, `task title ${error.message}`);
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
throw new FlowError("INTERNAL_STATE", "task compose allocation exceeded the safe integer range");
|
|
166
|
+
}
|
|
167
|
+
function same(left, right) {
|
|
168
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
169
|
+
}
|
|
170
|
+
function resolvedRelations(board, node) {
|
|
171
|
+
const result = {};
|
|
172
|
+
for (const [name, values] of Object.entries(node.relations)) {
|
|
173
|
+
try {
|
|
174
|
+
const resolved = values.map((value) => resolveTaskId(board, value));
|
|
175
|
+
if (new Set(resolved).size !== resolved.length)
|
|
176
|
+
atLine(node.line, `${name}= resolves the same coordinate more than once`);
|
|
177
|
+
result[name] = resolved;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error instanceof FlowError)
|
|
181
|
+
atLine(node.line, error.message);
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
/** Build the composition entirely from one board observation. Persistence is caller-owned. */
|
|
188
|
+
export function planTaskComposition(board, input) {
|
|
189
|
+
requireHealthy(board);
|
|
190
|
+
const now = input.now();
|
|
191
|
+
const parsed = parseTaskCompositionSketch(input.sketch);
|
|
192
|
+
const occupied = new Set(board.byId.keys());
|
|
193
|
+
const resolved = [];
|
|
194
|
+
const declared = new Set();
|
|
195
|
+
const allocations = [];
|
|
196
|
+
const parents = new Map();
|
|
197
|
+
for (const node of parsed) {
|
|
198
|
+
if (node.depth > 0 && !parents.has(node.depth - 1))
|
|
199
|
+
atLine(node.line, "cannot indent below a missing parent line");
|
|
200
|
+
for (const depth of [...parents.keys()])
|
|
201
|
+
if (depth >= node.depth)
|
|
202
|
+
parents.delete(depth);
|
|
203
|
+
let coordinate;
|
|
204
|
+
let existing;
|
|
205
|
+
if (node.reference) {
|
|
206
|
+
try {
|
|
207
|
+
coordinate = resolveTaskId(board, node.reference);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
if (error instanceof FlowError)
|
|
211
|
+
atLine(node.line, error.message);
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
existing = board.byId.get(coordinate);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
coordinate = allocateCoordinate(node.title, input.namespace, occupied, node.line);
|
|
218
|
+
occupied.add(coordinate);
|
|
219
|
+
allocations.push({ title: node.title, coordinate });
|
|
220
|
+
}
|
|
221
|
+
if (declared.has(coordinate))
|
|
222
|
+
atLine(node.line, `task ${coordinate} is declared more than once`);
|
|
223
|
+
declared.add(coordinate);
|
|
224
|
+
const parent = node.depth > 0 ? parents.get(node.depth - 1) : node.clearParent ? null : undefined;
|
|
225
|
+
if (node.depth > 0 && node.clearParent)
|
|
226
|
+
atLine(node.line, "cannot combine nesting with parent=");
|
|
227
|
+
if (parent === coordinate)
|
|
228
|
+
atLine(node.line, `task ${coordinate} cannot be its own parent`);
|
|
229
|
+
if (parent && (board.byId.get(parent)?.state === "done" || board.byId.get(parent)?.state === "drop")) {
|
|
230
|
+
atLine(node.line, `terminal task ${parent} cannot be a parent target`);
|
|
231
|
+
}
|
|
232
|
+
resolved.push({ ...node, coordinate, existing, parent });
|
|
233
|
+
parents.set(node.depth, coordinate);
|
|
234
|
+
}
|
|
235
|
+
const relationBoard = { ...board, byId: new Map(board.byId) };
|
|
236
|
+
for (const allocation of allocations) {
|
|
237
|
+
const [namespace, id] = allocation.coordinate.includes("/") ? allocation.coordinate.split("/") : [null, allocation.coordinate];
|
|
238
|
+
const node = resolved.find((entry) => entry.coordinate === allocation.coordinate);
|
|
239
|
+
const document = { id, namespace, coordinate: allocation.coordinate, title: allocation.title, state: "open", pri: 2, needs: [], parent: null, from: [], supersedes: [], relatesTo: [], notes: [], createdAt: now.toISOString(), updatedAt: now.toISOString(), creator: input.creator, body: node.body.join("\n") };
|
|
240
|
+
relationBoard.byId.set(allocation.coordinate, { ...document, namespace, coordinate: allocation.coordinate, blocks: [], blocked: false, releasedNeeds: [], supersededBy: [], relatedTasks: [] });
|
|
241
|
+
}
|
|
242
|
+
const replacements = [];
|
|
243
|
+
const deltas = [];
|
|
244
|
+
for (const node of resolved) {
|
|
245
|
+
const current = node.existing;
|
|
246
|
+
const document = current ? documentFromView(current) : (() => {
|
|
247
|
+
const allocation = allocations.find((entry) => entry.coordinate === node.coordinate);
|
|
248
|
+
const [namespace, id] = node.coordinate.includes("/") ? node.coordinate.split("/") : [null, node.coordinate];
|
|
249
|
+
const timestamp = now.toISOString();
|
|
250
|
+
return { id, namespace, coordinate: node.coordinate, title: allocation.title, state: "open", pri: 2, needs: [], parent: null, from: [], supersedes: [], relatesTo: [], notes: [], createdAt: timestamp, updatedAt: timestamp, creator: input.creator, body: node.body.join("\n") };
|
|
251
|
+
})();
|
|
252
|
+
if (node.parent !== undefined)
|
|
253
|
+
document.parent = node.parent;
|
|
254
|
+
const relations = resolvedRelations(relationBoard, node);
|
|
255
|
+
if (relations.needs !== undefined) {
|
|
256
|
+
for (const target of relations.needs) {
|
|
257
|
+
const targetTask = relationBoard.byId.get(target);
|
|
258
|
+
if (targetTask?.state === "done" || targetTask?.state === "drop")
|
|
259
|
+
atLine(node.line, `terminal task ${target} cannot be a needs target`);
|
|
260
|
+
}
|
|
261
|
+
if (relations.needs.includes(document.coordinate))
|
|
262
|
+
atLine(node.line, `task ${document.coordinate} needs must not reference itself`);
|
|
263
|
+
document.needs = relations.needs;
|
|
264
|
+
}
|
|
265
|
+
if (relations.supersedes !== undefined) {
|
|
266
|
+
if (relations.supersedes.includes(document.coordinate))
|
|
267
|
+
atLine(node.line, `task ${document.coordinate} supersedes must not reference itself`);
|
|
268
|
+
document.supersedes = relations.supersedes;
|
|
269
|
+
}
|
|
270
|
+
if (relations.relates !== undefined) {
|
|
271
|
+
if (relations.relates.includes(document.coordinate))
|
|
272
|
+
atLine(node.line, `task ${document.coordinate} relations must not reference itself`);
|
|
273
|
+
document.relatesTo = relations.relates;
|
|
274
|
+
}
|
|
275
|
+
if (document.relatesTo.includes(document.coordinate))
|
|
276
|
+
atLine(node.line, `task ${document.coordinate} relations must not reference itself`);
|
|
277
|
+
const before = current;
|
|
278
|
+
const delta = { coordinate: node.coordinate, allocated: !current };
|
|
279
|
+
if (!before || before.parent !== document.parent)
|
|
280
|
+
delta.parent = { before: before?.parent ?? null, after: document.parent };
|
|
281
|
+
if (!before || !same(before.needs, document.needs))
|
|
282
|
+
delta.needs = { before: before?.needs ?? [], after: document.needs };
|
|
283
|
+
if (!before || !same(before.supersedes, document.supersedes))
|
|
284
|
+
delta.supersedes = { before: before?.supersedes ?? [], after: document.supersedes };
|
|
285
|
+
if (!before || !same(before.relatesTo, document.relatesTo))
|
|
286
|
+
delta.relatesTo = { before: before?.relatesTo ?? [], after: document.relatesTo };
|
|
287
|
+
if (Object.keys(delta).length > 2) {
|
|
288
|
+
if (input.namespace !== null && current && current.namespace !== input.namespace) {
|
|
289
|
+
atLine(node.line, `task ${node.coordinate} is outside compose namespace ${input.namespace}`);
|
|
290
|
+
}
|
|
291
|
+
if (current)
|
|
292
|
+
document.updatedAt = advancedTaskUpdatedAt(current, input.now());
|
|
293
|
+
replacements.push(document);
|
|
294
|
+
deltas.push(delta);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (replacements.length === 0)
|
|
298
|
+
throw new FlowError("EMPTY_PARAM", "task compose sketch makes no changes");
|
|
299
|
+
const replacementByCoordinate = new Map(replacements.map((document) => [document.coordinate, document]));
|
|
300
|
+
const finalBoard = buildTaskBoardFromDocuments(board.tasks.map((task) => replacementByCoordinate.get(task.coordinate) ?? documentFromView(task)).concat(replacements.filter((document) => !board.byId.has(document.coordinate))));
|
|
301
|
+
const mentioned = new Set(resolved.map((node) => node.coordinate));
|
|
302
|
+
requireHealthyFinalCompositionBoard(finalBoard, new Map(resolved.map((node) => [node.coordinate, node.line])));
|
|
303
|
+
const warnings = [];
|
|
304
|
+
for (const task of board.tasks) {
|
|
305
|
+
if (mentioned.has(task.coordinate))
|
|
306
|
+
continue;
|
|
307
|
+
for (const target of [...task.needs, ...(task.parent ? [task.parent] : []), ...task.supersedes, ...task.relatesTo]) {
|
|
308
|
+
if (mentioned.has(target))
|
|
309
|
+
warnings.push({ kind: "external_inbound", coordinate: target, related: task.coordinate });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
for (const node of resolved) {
|
|
313
|
+
const task = finalBoard.byId.get(node.coordinate);
|
|
314
|
+
for (const target of task.supersedes) {
|
|
315
|
+
if (finalBoard.byId.get(target)?.state === "open")
|
|
316
|
+
warnings.push({ kind: "open_superseded", coordinate: task.coordinate, related: target });
|
|
317
|
+
}
|
|
318
|
+
if (task.contractId)
|
|
319
|
+
warnings.push({ kind: "bound_task", coordinate: task.coordinate, related: task.contractId });
|
|
320
|
+
}
|
|
321
|
+
return { allocations, replacements, deltas, warnings };
|
|
322
|
+
}
|
|
323
|
+
export async function composeTasks(repository, input) {
|
|
324
|
+
return repository.mutate((board) => {
|
|
325
|
+
const plan = planTaskComposition(board, input);
|
|
326
|
+
return { replacements: plan.replacements, subject: "Compose tasks", requireCommit: true, select: () => plan };
|
|
327
|
+
});
|
|
328
|
+
}
|
|
@@ -10,6 +10,7 @@ const FIELD_ORDER = [
|
|
|
10
10
|
"from",
|
|
11
11
|
"supersedes",
|
|
12
12
|
"relatesTo",
|
|
13
|
+
"notes",
|
|
13
14
|
"createdAt",
|
|
14
15
|
"updatedAt",
|
|
15
16
|
"creator",
|
|
@@ -17,6 +18,9 @@ const FIELD_ORDER = [
|
|
|
17
18
|
"contractId",
|
|
18
19
|
];
|
|
19
20
|
const FIELD_SET = new Set(FIELD_ORDER);
|
|
21
|
+
const CREATION_INPUT_FIELDS = new Set([
|
|
22
|
+
"title", "pri", "needs", "parent", "from", "supersedes", "relatesTo",
|
|
23
|
+
]);
|
|
20
24
|
function validateNode(node) {
|
|
21
25
|
if (node == null)
|
|
22
26
|
return;
|
|
@@ -60,7 +64,7 @@ function frontMatter(source) {
|
|
|
60
64
|
body: lines.slice(closing + 1).join("\n"),
|
|
61
65
|
};
|
|
62
66
|
}
|
|
63
|
-
|
|
67
|
+
function parseTaskSource(source) {
|
|
64
68
|
const split = frontMatter(source);
|
|
65
69
|
const parsed = parseDocument(split.yaml, {
|
|
66
70
|
merge: false,
|
|
@@ -83,6 +87,10 @@ export function parseTaskDocument(source) {
|
|
|
83
87
|
if (!FIELD_SET.has(key))
|
|
84
88
|
invalid(`unknown task front matter key '${key}'`);
|
|
85
89
|
const value = item.value;
|
|
90
|
+
if (key === "notes") {
|
|
91
|
+
values.set(key, noteArray(value));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
86
94
|
if (isSeq(value)) {
|
|
87
95
|
const items = value.items.map((entry) => {
|
|
88
96
|
if (!isScalar(entry) || typeof entry.value !== "string") {
|
|
@@ -102,6 +110,68 @@ export function parseTaskDocument(source) {
|
|
|
102
110
|
invalid(`task field '${key}' must be a scalar or string array`);
|
|
103
111
|
}
|
|
104
112
|
}
|
|
113
|
+
return { values, body: split.body };
|
|
114
|
+
}
|
|
115
|
+
function noteArray(value) {
|
|
116
|
+
if (!isSeq(value))
|
|
117
|
+
invalid("task field 'notes' must be an array of note objects");
|
|
118
|
+
return value.items.map((item) => {
|
|
119
|
+
if (!isMap(item))
|
|
120
|
+
invalid("task field 'notes' must contain only note objects");
|
|
121
|
+
const values = new Map();
|
|
122
|
+
for (const pair of item.items) {
|
|
123
|
+
if (!isScalar(pair.key) || typeof pair.key.value !== "string") {
|
|
124
|
+
invalid("task note fields must be strings");
|
|
125
|
+
}
|
|
126
|
+
const key = pair.key.value;
|
|
127
|
+
if (key !== "actor" && key !== "timestamp" && key !== "text") {
|
|
128
|
+
invalid(`unknown task note field '${key}'`);
|
|
129
|
+
}
|
|
130
|
+
if (!isScalar(pair.value))
|
|
131
|
+
invalid(`task note field '${key}' must be a string`);
|
|
132
|
+
values.set(key, pair.value.value);
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
actor: nonblank("task note actor", values.get("actor")),
|
|
136
|
+
timestamp: canonicalTimestamp("task note timestamp", values.get("timestamp")),
|
|
137
|
+
text: nonblank("task note text", values.get("text")),
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function taskNotes(values) {
|
|
142
|
+
const value = values.get("notes");
|
|
143
|
+
return value === undefined ? [] : value;
|
|
144
|
+
}
|
|
145
|
+
function stringArray(values, field, required) {
|
|
146
|
+
const value = values.get(field);
|
|
147
|
+
if (value === undefined && !required)
|
|
148
|
+
return [];
|
|
149
|
+
if (!Array.isArray(value))
|
|
150
|
+
invalid(`task field '${field}' must be a string array`);
|
|
151
|
+
const related = value.map((item) => fullId(field, item));
|
|
152
|
+
if (new Set(related).size !== related.length)
|
|
153
|
+
invalid(`task field '${field}' must be unique`);
|
|
154
|
+
return related;
|
|
155
|
+
}
|
|
156
|
+
function priority(values, required) {
|
|
157
|
+
const value = values.get("pri");
|
|
158
|
+
if (value === undefined && !required)
|
|
159
|
+
return undefined;
|
|
160
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 3) {
|
|
161
|
+
invalid("task field 'pri' must be an integer from 0 through 3");
|
|
162
|
+
}
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
function parent(values, required) {
|
|
166
|
+
const value = values.get("parent");
|
|
167
|
+
if (value === undefined && !required)
|
|
168
|
+
return null;
|
|
169
|
+
if (value === null)
|
|
170
|
+
return null;
|
|
171
|
+
return fullId("parent", value);
|
|
172
|
+
}
|
|
173
|
+
export function parseTaskDocument(source) {
|
|
174
|
+
const { values, body } = parseTaskSource(source);
|
|
105
175
|
const id = nonblank("id", values.get("id"));
|
|
106
176
|
if (!isTaskId(id))
|
|
107
177
|
invalid("task field 'id' must be a canonical local task id");
|
|
@@ -110,42 +180,13 @@ export function parseTaskDocument(source) {
|
|
|
110
180
|
if (typeof state !== "string" || !TASK_STATES.has(state)) {
|
|
111
181
|
invalid("task field 'state' must be open, in_progress, on_hold, done, or drop");
|
|
112
182
|
}
|
|
113
|
-
const pri = values
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const needs = needsValue.map((need) => fullId("needs", need));
|
|
121
|
-
if (new Set(needs).size !== needs.length)
|
|
122
|
-
invalid("task field 'needs' must be unique");
|
|
123
|
-
const relationship = (field) => {
|
|
124
|
-
const value = values.get(field);
|
|
125
|
-
if (value === null)
|
|
126
|
-
return null;
|
|
127
|
-
return fullId(field, value);
|
|
128
|
-
};
|
|
129
|
-
const parent = relationship("parent");
|
|
130
|
-
const fromValue = values.get("from");
|
|
131
|
-
if (!Array.isArray(fromValue))
|
|
132
|
-
invalid("task field 'from' must be a string array");
|
|
133
|
-
const from = fromValue.map((related) => fullId("from", related));
|
|
134
|
-
if (new Set(from).size !== from.length)
|
|
135
|
-
invalid("task field 'from' must be unique");
|
|
136
|
-
const relationships = (field) => {
|
|
137
|
-
const value = values.get(field);
|
|
138
|
-
if (value === undefined)
|
|
139
|
-
return [];
|
|
140
|
-
if (!Array.isArray(value))
|
|
141
|
-
invalid(`task field '${field}' must be a string array`);
|
|
142
|
-
const related = value.map((item) => fullId(field, item));
|
|
143
|
-
if (new Set(related).size !== related.length)
|
|
144
|
-
invalid(`task field '${field}' must be unique`);
|
|
145
|
-
return related;
|
|
146
|
-
};
|
|
147
|
-
const supersedes = relationships("supersedes");
|
|
148
|
-
const relatesTo = relationships("relatesTo");
|
|
183
|
+
const pri = priority(values, true);
|
|
184
|
+
const needs = stringArray(values, "needs", true);
|
|
185
|
+
const taskParent = parent(values, true);
|
|
186
|
+
const from = stringArray(values, "from", true);
|
|
187
|
+
const supersedes = stringArray(values, "supersedes", false);
|
|
188
|
+
const relatesTo = stringArray(values, "relatesTo", false);
|
|
189
|
+
const notes = taskNotes(values);
|
|
149
190
|
const createdAt = canonicalTimestamp("createdAt", values.get("createdAt"));
|
|
150
191
|
const updatedValue = values.get("updatedAt");
|
|
151
192
|
const updatedAt = updatedValue === undefined ? undefined : canonicalTimestamp("updatedAt", updatedValue);
|
|
@@ -166,19 +207,40 @@ export function parseTaskDocument(source) {
|
|
|
166
207
|
state: state,
|
|
167
208
|
pri,
|
|
168
209
|
needs,
|
|
169
|
-
parent,
|
|
210
|
+
parent: taskParent,
|
|
170
211
|
from,
|
|
171
212
|
supersedes,
|
|
172
213
|
relatesTo,
|
|
214
|
+
notes,
|
|
173
215
|
createdAt,
|
|
174
216
|
...(updatedAt === undefined ? {} : { updatedAt }),
|
|
175
217
|
creator,
|
|
176
218
|
...(startedAt === undefined ? {} : { startedAt }),
|
|
177
219
|
...(contractId === undefined ? {} : { contractId }),
|
|
178
|
-
body
|
|
220
|
+
body,
|
|
179
221
|
source,
|
|
180
222
|
};
|
|
181
223
|
}
|
|
224
|
+
/** Parse the caller-owned subset of the canonical task document grammar. */
|
|
225
|
+
export function parseTaskCreationDocument(source) {
|
|
226
|
+
const { values, body } = parseTaskSource(source);
|
|
227
|
+
for (const field of values.keys()) {
|
|
228
|
+
if (!CREATION_INPUT_FIELDS.has(field)) {
|
|
229
|
+
invalid(`task creation document field '${field}' is creation-owned and cannot be supplied`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const pri = priority(values, false);
|
|
233
|
+
return {
|
|
234
|
+
title: nonblank("title", values.get("title")),
|
|
235
|
+
body,
|
|
236
|
+
...(pri === undefined ? {} : { pri }),
|
|
237
|
+
needs: stringArray(values, "needs", false),
|
|
238
|
+
parent: parent(values, false),
|
|
239
|
+
from: stringArray(values, "from", false),
|
|
240
|
+
supersedes: stringArray(values, "supersedes", false),
|
|
241
|
+
relatesTo: stringArray(values, "relatesTo", false),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
182
244
|
function validateDocument(document) {
|
|
183
245
|
return parseTaskDocument({ path: `${document.id}.md`, text: serializeUnchecked(document) });
|
|
184
246
|
}
|
|
@@ -193,6 +255,7 @@ function serializeUnchecked(document) {
|
|
|
193
255
|
from: document.from,
|
|
194
256
|
...(document.supersedes.length === 0 ? {} : { supersedes: document.supersedes }),
|
|
195
257
|
...(document.relatesTo.length === 0 ? {} : { relatesTo: document.relatesTo }),
|
|
258
|
+
...(document.notes.length === 0 ? {} : { notes: document.notes.map((note) => ({ ...note })) }),
|
|
196
259
|
createdAt: document.createdAt,
|
|
197
260
|
...(document.updatedAt === undefined ? {} : { updatedAt: document.updatedAt }),
|
|
198
261
|
creator: document.creator,
|
package/build/core/task/index.js
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
* Package-internal modules must import each other directly, not through this file.
|
|
5
5
|
*/
|
|
6
6
|
export { previewTaskBoardForBind, reconcileTaskForfeit, replayClaimTasks, } from "./task-contract.js";
|
|
7
|
-
export { replayPreparedTaskBind, replayPreparedTaskBindLocked, replayCommittedTaskBind, replayCommittedTaskBindForfeit, replayPreparedTaskBindForfeit, withPreparedTaskBind, } from "./task-bind-preparation.js";
|
|
7
|
+
export { replayPreparedTaskBind, replayPreparedTaskBindLocked, replayCommittedTaskBind, replayCommittedTaskBindForfeit, replayPreparedTaskBindForfeit, withPreparedTaskBind, withPreparedTaskBindSnapshot, } from "./task-bind-preparation.js";
|
|
8
8
|
export { readTaskBoardGeneration } from "./task-git-store.js";
|
|
9
9
|
export { resolveTaskCreator } from "./task-git-actor.js";
|
|
10
10
|
export { openTaskCommandRepository, openTaskMutationContext, readTaskDoctor, taskCommandContractId, taskCommandNamespace, } from "./task-git-runtime.js";
|
|
11
11
|
export { openTaskStore, readTaskHistory, readTaskNamespaces } from "./task-git-store.js";
|
|
12
12
|
export { taskRepositoryFromStore } from "./task-store-repository.js";
|
|
13
|
+
export { composeTasks, planTaskComposition, parseTaskCompositionSketch, } from "./compose.js";
|
|
13
14
|
export { isTaskId } from "./validation.js";
|
|
14
|
-
export { isTaskCoordinate, parseTaskCoordinate, taskCoordinateFromSourcePath } from "./coordinate.js";
|
|
15
|
-
export { buildTaskTree, createTask, doneTask, dropTask, parseTaskDocument, readTaskBoard, resolveTaskReadId, serializeTaskDocument, startTask, stopTask, holdTask, resumeTask, updateTask, updateTaskWithReceipt, deriveTaskDisplay, selectTaskList, taskUpdatedAt, advancedTaskUpdatedAt, } from "./task.js";
|
|
15
|
+
export { isTaskCoordinate, parseTaskCoordinate, taskCoordinateFromSourcePath, taskNamespaceFromScope } from "./coordinate.js";
|
|
16
|
+
export { buildTaskTree, createTask, doneTask, dropTask, dropTaskWithNote, appendTaskNote, parseTaskCreationDocument, parseTaskDocument, readTaskBoard, resolveTaskReadId, serializeTaskDocument, startTask, stopTask, holdTask, resumeTask, updateTask, updateTaskWithReceipt, deriveTaskDisplay, selectTaskList, taskUpdatedAt, advancedTaskUpdatedAt, } from "./task.js";
|