@quolu/lattice 0.85.2 → 0.85.4
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/bin/lattice.mjs +5 -3
- package/docs/schemas/lattice.plan_revise_input.v1.schema.json +1 -1
- package/docs/schemas/lattice.plan_scope_review.v1.schema.json +3 -3
- package/docs/schemas/lattice.todo_witness_draft.v2.schema.json +86 -0
- package/docs/schemas/lattice.todo_witness_set.v5.schema.json +400 -0
- package/package.json +3 -1
- package/src/cli-help.mjs +16 -4
- package/src/cli-refusal-guidance.mjs +88 -4
- package/src/plan-revise.mjs +43 -3
- package/src/plan-scope-review.mjs +37 -12
- package/src/runtime-front-end.mjs +45 -42
- package/src/seat-identity.mjs +10 -2
- package/src/todo-audit-pending.mjs +6 -3
- package/src/todo-authoring-input.mjs +10 -3
- package/src/todo-cli.mjs +134 -36
- package/src/todo-independence-guidance.mjs +3 -2
- package/src/todo-readiness.mjs +18 -2
- package/src/todo-status.mjs +2 -1
- package/src/todo-store.mjs +66 -18
- package/src/witness-scaffold.mjs +78 -21
package/src/witness-scaffold.mjs
CHANGED
|
@@ -51,28 +51,85 @@ function reject(reasons) {
|
|
|
51
51
|
return { witnessSet: null, queries: [], reasons: sortedUnique(reasons) };
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
54
|
+
const DRAFT_TOP_LEVEL_KEYS = Object.freeze(['schema', 'project_id', 'plan_key', 'capacity', 'tasks']);
|
|
55
|
+
const plainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
56
|
+
const refList = (value) => value === undefined || (Array.isArray(value) && value.every(isTodoRef));
|
|
57
|
+
|
|
58
|
+
/** 1 taskの下書きの最初の違反(相対path)、無ければnull。validateWitnessDraftと同じ規則。 */
|
|
59
|
+
function explainDraftTask(task, schema) {
|
|
60
|
+
if (!plainObject(task)) return { reason: 'not_an_object', path: '' };
|
|
61
|
+
if (draftOwnEntries(task, schema) === null) return { reason: 'invalid_owns', path: '/owns' };
|
|
62
|
+
for (const key of ['reads', 'writes']) {
|
|
63
|
+
if (!refList(task[key])) return { reason: 'invalid_repo_relative_paths', path: `/${key}` };
|
|
64
|
+
}
|
|
65
|
+
if (task.unknowns !== undefined && !(Array.isArray(task.unknowns) && task.unknowns.every((entry) => plainObject(entry)
|
|
66
|
+
&& isTodoIdentifier(entry.kind) && typeof entry.ref === 'string' && entry.ref.length > 0))) {
|
|
67
|
+
return { reason: 'invalid_unknowns', path: '/unknowns' };
|
|
68
|
+
}
|
|
69
|
+
if (task.concern_anchors !== undefined && !(Array.isArray(task.concern_anchors)
|
|
70
|
+
&& task.concern_anchors.every((anchor) => plainObject(anchor) && isTodoRef(anchor.within)
|
|
71
|
+
&& Array.isArray(anchor.symbols) && anchor.symbols.length > 0 && anchor.symbols.every(isTodoIdentifier)))) {
|
|
72
|
+
return { reason: 'invalid_concern_anchors', path: '/concern_anchors' };
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 下書きの形。AIが書く欄だけを持ち、観測で埋まる欄は持たない。
|
|
79
|
+
* a32: 拒否は最初に落ちた欄(JSON pointer)と理由、topの欠けたkeyを名指す。
|
|
80
|
+
*/
|
|
81
|
+
export function explainWitnessDraft(value) {
|
|
82
|
+
const reject = (reason, at, extra = {}) => ({ valid: false, reason, path: at, ...extra });
|
|
83
|
+
if (!plainObject(value)) return reject('not_an_object', '/');
|
|
84
|
+
const missing = DRAFT_TOP_LEVEL_KEYS.filter((key) => !Object.hasOwn(value, key));
|
|
85
|
+
if (missing.length > 0) return reject('missing_top_level_keys', '/', { missing_keys: missing });
|
|
86
|
+
if (!DRAFT_SCHEMAS.includes(value.schema)) return reject('schema_mismatch', '/schema', { expected: DRAFT_SCHEMAS });
|
|
87
|
+
if (!isTodoIdentifier(value.project_id)) return reject('invalid_identifier', '/project_id');
|
|
88
|
+
if (!isTodoIdentifier(value.plan_key)) return reject('invalid_identifier', '/plan_key');
|
|
89
|
+
if (!plainObject(value.capacity) || !Number.isSafeInteger(value.capacity.executors) || value.capacity.executors < 1) {
|
|
90
|
+
return reject('invalid_capacity', '/capacity/executors');
|
|
91
|
+
}
|
|
92
|
+
if (!plainObject(value.tasks)) return reject('not_an_object', '/tasks');
|
|
62
93
|
const entries = Object.entries(value.tasks);
|
|
63
|
-
if (entries.length === 0) return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
94
|
+
if (entries.length === 0) return reject('empty_tasks', '/tasks');
|
|
95
|
+
for (const [taskId, task] of entries) {
|
|
96
|
+
if (!isTodoIdentifier(taskId)) return reject('invalid_identifier', `/tasks/${taskId}`);
|
|
97
|
+
const failure = explainDraftTask(task, value.schema);
|
|
98
|
+
if (failure !== null) return reject(failure.reason, `/tasks/${taskId}${failure.path}`);
|
|
99
|
+
}
|
|
100
|
+
return { valid: true };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function validateWitnessDraft(value) {
|
|
104
|
+
return explainWitnessDraft(value).valid;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* a32: the starting draft for a plan: every task still to do.
|
|
109
|
+
* a35: a task the recorded witness set already declares starts from that declaration (the inverse of
|
|
110
|
+
* buildWitnessSet: owns back to draft entries, writes without the owned paths it adds), so adding one
|
|
111
|
+
* task after a revision does not mean rewriting the others.
|
|
112
|
+
*/
|
|
113
|
+
export function witnessDraftTemplate({ projectId, planKey, taskIds, witnessSet = null }) {
|
|
114
|
+
const recorded = witnessSet?.plan_key === planKey ? witnessSet.manual_witness : {};
|
|
115
|
+
const draftTask = (witness) => {
|
|
116
|
+
if (witness === undefined) return { owns: [], reads: [], writes: [] };
|
|
117
|
+
const owned = new Set(witness.owns.map(({ target }) => target));
|
|
118
|
+
return {
|
|
119
|
+
owns: witness.owns.map(({ target, creates }) => (creates ? { path: target, creates: true } : target)),
|
|
120
|
+
reads: [...witness.reads],
|
|
121
|
+
writes: witness.writes.filter((target) => !owned.has(target)),
|
|
122
|
+
...(witness.unknowns.length > 0 ? { unknowns: witness.unknowns.map(({ kind, ref }) => ({ kind, ref })) } : {}),
|
|
123
|
+
...(witness.concern_anchors?.length > 0 ? {
|
|
124
|
+
concern_anchors: witness.concern_anchors.map(({ within, symbols }) => ({ within: within.target, symbols: [...symbols] })),
|
|
125
|
+
} : {}),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
schema: WITNESS_DRAFT_SCHEMA_V2, project_id: projectId, plan_key: planKey,
|
|
130
|
+
capacity: { executors: witnessSet?.plan_key === planKey ? witnessSet.capacity.executors : 1 },
|
|
131
|
+
tasks: Object.fromEntries([...taskIds].sort(compareText).map((taskId) => [taskId, draftTask(recorded[taskId])])),
|
|
132
|
+
};
|
|
76
133
|
}
|
|
77
134
|
|
|
78
135
|
function queryIdFor(index) {
|