@planu/cli 8.3.0 → 8.4.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 +7 -0
- package/README.md +61 -2
- package/dist/sdd-engine/contracts.d.ts +5 -3
- package/dist/sdd-engine/contracts.js +23 -10
- package/dist/sdd-engine/feature-manifest.d.ts +2 -5
- package/dist/sdd-engine/feature-manifest.js +109 -184
- package/dist/sdd-engine/host-rule-pack.d.ts +5 -0
- package/dist/sdd-engine/host-rule-pack.js +102 -43
- package/dist/sdd-engine/host-skill-reader.d.ts +6 -0
- package/dist/sdd-engine/host-skill-reader.js +187 -0
- package/dist/sdd-engine/lock-integrity.d.ts +1 -0
- package/dist/sdd-engine/lock-integrity.js +25 -17
- package/dist/sdd-engine/receipt-assessment.d.ts +12 -0
- package/dist/sdd-engine/receipt-assessment.js +223 -0
- package/dist/sdd-engine/server.js +2 -4
- package/dist/sdd-engine/task-content.d.ts +11 -0
- package/dist/sdd-engine/task-content.js +28 -0
- package/dist/sdd-engine/task-window.d.ts +1 -0
- package/dist/sdd-engine/task-window.js +8 -1
- package/dist/sdd-engine/tools/execution-tools.d.ts +1 -11
- package/dist/sdd-engine/tools/execution-tools.js +5 -29
- package/dist/sdd-engine/tools/workspace-tools.d.ts +1 -1
- package/dist/sdd-engine/tools/workspace-tools.js +17 -9
- package/dist/sdd-engine/tools.d.ts +2 -1
- package/dist/sdd-engine/tools.js +4 -2
- package/dist/sdd-engine/trinity-structure.d.ts +25 -0
- package/dist/sdd-engine/trinity-structure.js +317 -0
- package/dist/sdd-engine/verification-preflight.d.ts +4 -0
- package/dist/sdd-engine/verification-preflight.js +271 -0
- package/dist/sdd-engine/verification-receipts.d.ts +2 -10
- package/dist/sdd-engine/verification-receipts.js +2 -169
- package/dist/sdd-engine/workspace-root.d.ts +1 -0
- package/dist/sdd-engine/workspace-root.js +1 -0
- package/dist/types/completion.d.ts +9 -2
- package/dist/types/sdd-engine.d.ts +71 -0
- package/package.json +1 -1
- package/templates/AGENTS.md +8 -0
- package/templates/host/planu-sdd.md +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [8.4.0] - 2026-11-07
|
|
2
|
+
|
|
3
|
+
- Diagnose installed host roles through `sdd_list_features`: fixed paths, concrete causes, bundled reference version and safe next action. The host catalogue remains unverified.
|
|
4
|
+
- Add artifact, stable rule and exact 1-based source locations to trinity rejection issues where a location exists, preserving rejection codes, legacy details and lock bytes on rejection.
|
|
5
|
+
- Add the explicit `verification_preflight` view to `sdd_get_active_task`, with optional signed receipts, per-gate evidence states, blockers and next action. It runs no command, writes no artifact and keeps integration `not_run`; readiness permits an attempt, not a runtime or integration claim.
|
|
6
|
+
- Preserve the nine tools, ordinary active-task response, dependencies and verification authority. Synchronize shipped guidance and EN/ES/PT website facts.
|
|
7
|
+
|
|
1
8
|
## [8.3.0] - 2026-11-06
|
|
2
9
|
|
|
3
10
|
- Opted-in tasks can require reusable Ed25519 receipts for locally verified gates. Planu binds the evidence to the active task, workspace, lock, candidate files, and reviewed dependencies before running the integration command.
|
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ After the one-time client registration above, ask your agent:
|
|
|
112
112
|
|
|
113
113
|
> Set up Planu in this project and tell me the next step.
|
|
114
114
|
|
|
115
|
-
The guided route starts with `sdd_list_features`.
|
|
115
|
+
The guided route starts with `sdd_list_features`. Inspect `hostSkills` for installed role issues. When project setup is authorized and the installed pack needs repair, use `sdd_init_workspace(scope=project)` without `force` for the identified project. The setup request already supplies that project's setup intent; `catalog: "unverified"` alone does not establish a file problem or authorize setup. Keep the MCP server bound to the project through roots or cwd, rather than `$HOME`.
|
|
116
116
|
|
|
117
117
|
Immediately after init, use the canonical `sdd_read_file_slice` tool to read `.agents/skills/planu-preflight-guardian/SKILL.md` and the installed role for the next action, such as `.agents/skills/planu-spec-architect/SKILL.md` for planning. Init installs role files; native discovery in the client's skill catalog may require a client reload or a new session. That catalog reload is separate from restarting MCP. The instructions guide an agent; the server cannot guarantee that a host has loaded a role or that a model follows it.
|
|
118
118
|
|
|
@@ -136,6 +136,65 @@ There is no timeout tool argument. The nine tool names are unchanged. The option
|
|
|
136
136
|
|
|
137
137
|
The reviewed operator procedure is in the repository guide `docs/verification-budget.md`: finite local-build fingerprint, exact policy schema, per-process Node 24.22.1 PATH, SDK request budget of 660000 ms, one-use launch and safe disable/reconciliation. The grant is not a global registration or a cache replacement. Barbuno acceptance remains a separate handoff.
|
|
138
138
|
|
|
139
|
+
## Read-only diagnostics
|
|
140
|
+
|
|
141
|
+
The existing nine tools expose additive diagnostics in 8.4.0; an ordinary `sdd_get_active_task` request keeps its previous response shape.
|
|
142
|
+
|
|
143
|
+
`sdd_list_features` includes `hostSkills`. For example, a missing installed role can produce this field (other installed files match the available bundled reference):
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"version": 1,
|
|
148
|
+
"bundledVersion": "8.4.0",
|
|
149
|
+
"baseline": "available",
|
|
150
|
+
"catalog": "unverified",
|
|
151
|
+
"issues": [{
|
|
152
|
+
"path": ".agents/skills/planu-spec-executor/SKILL.md",
|
|
153
|
+
"status": "missing",
|
|
154
|
+
"cause": "not_found"
|
|
155
|
+
}],
|
|
156
|
+
"nextAction": "review_project_setup"
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Issues use the fixed workspace-relative paths of the nine roles across four hosts and concrete causes such as `content_mismatch`, `access_denied` or `unsafe_path`. `bundledVersion` identifies the shipped reference, not the installed role or client. An unavailable reference reports `baseline: "unavailable"` and `inspect_installation` rather than inferring project mismatches. Inspect unsafe paths before setup; use the explicit project setup route for repair only when authorized. A matching pack still leaves `catalog: "unverified"`; client catalogue reload and MCP restart remain separate actions.
|
|
161
|
+
|
|
162
|
+
`sdd_lock_spec` keeps existing rejection codes and legacy details, adding bounded `error.details.issues`. For a protected manifest declaration on the fifth source line, the diagnostic includes:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"artifact": "plan.md",
|
|
167
|
+
"rule": "protected_write",
|
|
168
|
+
"line": 5
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
That structural rejection keeps `ERR_TRINITY_INCOMPLETE`. Lines are 1-based original source locations. Missing sections and ambiguous cross-declaration failures omit `line`; errors do not echo the manifest path or source text. A rejected initial lock or relock writes no lock. Diagnostics do not authorize automatic relocking.
|
|
173
|
+
|
|
174
|
+
Request preflight explicitly through `sdd_get_active_task`:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{"feature_id":"FEAT-EXAMPLE","view":"verification_preflight"}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Optionally supply `verification_receipts` with the signed receipt array described below. Receipts require this view. For an opted-in task with one required gate named `contents`, no supplied receipts and otherwise available inputs, `data.verificationPreflight` is:
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"version": 1,
|
|
185
|
+
"taskId": "TASK-1",
|
|
186
|
+
"status": "blocked",
|
|
187
|
+
"gates": [{"gateId":"contents","state":"receipt_missing","reason":"receipt_missing"}],
|
|
188
|
+
"blockers": [],
|
|
189
|
+
"integration": "not_run",
|
|
190
|
+
"nextAction": "obtain_receipts"
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Check `version: 1` on the requested response: an older server may ignore optional arguments. Inspect both per-gate states and aggregate blockers. Preflight can identify rejected evidence, unavailable inputs, changed observed baselines, missing commands, unsupported platforms or matching scoped receipt grants, and lock/guard problems. Follow `nextAction`; a changed observed baseline requires restoring the input or the existing reviewed relock route. An ordinary task rejects supplied receipts with `receipt_not_configured`.
|
|
195
|
+
|
|
196
|
+
`ready_to_attempt` with `attempt_integration` means these read-only checks passed for the current candidate. Runtime prerequisites, write access and integration remain unverified. `not_applicable` means a locked feature has no active task. Preflight runs no command, consumes no grant, writes no artifact and issues no certificate; setup, relock and completion remain explicit actions.
|
|
197
|
+
|
|
139
198
|
## Reusable verification receipts
|
|
140
199
|
|
|
141
200
|
Opt in by adding a level-two `Verification Receipts v1` heading to the locked plan, followed by a single JSON fence with the policy formatted using `JSON.stringify(policy, null, 2)`. It contains:
|
|
@@ -270,7 +329,7 @@ See the [Planu Proprietary Free-Use License](LICENSE) and [planu.dev/license](ht
|
|
|
270
329
|
"mcpServers": {
|
|
271
330
|
"planu": {
|
|
272
331
|
"command": "npx",
|
|
273
|
-
"args": ["-y", "@planu/cli@8.
|
|
332
|
+
"args": ["-y", "@planu/cli@8.4.0"],
|
|
274
333
|
"cwd": ".",
|
|
275
334
|
"env": {
|
|
276
335
|
"PLANU_WORKSPACE": "."
|
|
@@ -66,15 +66,17 @@ export declare const ReadFileSliceInputSchema: z.ZodObject<{
|
|
|
66
66
|
start_line: z.ZodNumber;
|
|
67
67
|
end_line: z.ZodNumber;
|
|
68
68
|
}, z.core.$strip>;
|
|
69
|
-
export declare const GetActiveTaskInputSchema: z.ZodObject<{
|
|
70
|
-
feature_id: z.ZodString;
|
|
71
|
-
}, z.core.$strip>;
|
|
72
69
|
export declare const ApplyFilePatchInputSchema: z.ZodObject<{
|
|
73
70
|
feature_id: z.ZodString;
|
|
74
71
|
path: z.ZodString;
|
|
75
72
|
search_content: z.ZodString;
|
|
76
73
|
replace_content: z.ZodString;
|
|
77
74
|
}, z.core.$strip>;
|
|
75
|
+
export declare const GetActiveTaskInputSchema: z.ZodObject<{
|
|
76
|
+
feature_id: z.ZodString;
|
|
77
|
+
view: z.ZodOptional<z.ZodLiteral<"verification_preflight">>;
|
|
78
|
+
verification_receipts: z.ZodOptional<z.ZodArray<z.ZodPreprocess<z.ZodObject<{}, z.core.$loose>, unknown>>>;
|
|
79
|
+
}, z.core.$strip>;
|
|
78
80
|
export declare const CompleteTaskInputSchema: z.ZodObject<{
|
|
79
81
|
feature_id: z.ZodString;
|
|
80
82
|
task_id: z.ZodString;
|
|
@@ -49,9 +49,6 @@ export const ReadFileSliceInputSchema = z.object({
|
|
|
49
49
|
start_line: z.number().int().min(1),
|
|
50
50
|
end_line: z.number().int().min(1),
|
|
51
51
|
});
|
|
52
|
-
export const GetActiveTaskInputSchema = z.object({
|
|
53
|
-
feature_id: FeatureIdSchema,
|
|
54
|
-
});
|
|
55
52
|
export const ApplyFilePatchInputSchema = z.object({
|
|
56
53
|
feature_id: FeatureIdSchema,
|
|
57
54
|
path: z.string().min(1),
|
|
@@ -65,16 +62,32 @@ const VerificationReceiptInputSchema = z.preprocess((input, context) => {
|
|
|
65
62
|
}
|
|
66
63
|
return input;
|
|
67
64
|
}, z.looseObject({}, { error: 'Invalid verification receipt element.' }));
|
|
65
|
+
const VerificationReceiptsInputSchema = z
|
|
66
|
+
.array(VerificationReceiptInputSchema, {
|
|
67
|
+
error: 'Invalid verification receipt array.',
|
|
68
|
+
})
|
|
69
|
+
.min(1, { error: 'Invalid verification receipt array length.' })
|
|
70
|
+
.max(32, { error: 'Invalid verification receipt array length.' })
|
|
71
|
+
.optional();
|
|
72
|
+
export const GetActiveTaskInputSchema = z
|
|
73
|
+
.object({
|
|
74
|
+
feature_id: FeatureIdSchema,
|
|
75
|
+
view: z.literal('verification_preflight', { error: 'Invalid active task view.' }).optional(),
|
|
76
|
+
verification_receipts: VerificationReceiptsInputSchema,
|
|
77
|
+
})
|
|
78
|
+
.superRefine((input, context) => {
|
|
79
|
+
if (input.verification_receipts !== undefined && input.view !== 'verification_preflight') {
|
|
80
|
+
context.addIssue({
|
|
81
|
+
code: 'custom',
|
|
82
|
+
message: 'Verification receipts require the verification_preflight view.',
|
|
83
|
+
path: ['verification_receipts'],
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
68
87
|
export const CompleteTaskInputSchema = z.object({
|
|
69
88
|
feature_id: FeatureIdSchema,
|
|
70
89
|
task_id: z.string().min(1),
|
|
71
90
|
verification_output: z.string().min(1).optional(),
|
|
72
|
-
verification_receipts:
|
|
73
|
-
.array(VerificationReceiptInputSchema, {
|
|
74
|
-
error: 'Invalid verification receipt array.',
|
|
75
|
-
})
|
|
76
|
-
.min(1, { error: 'Invalid verification receipt array length.' })
|
|
77
|
-
.max(32, { error: 'Invalid verification receipt array length.' })
|
|
78
|
-
.optional(),
|
|
91
|
+
verification_receipts: VerificationReceiptsInputSchema,
|
|
79
92
|
});
|
|
80
93
|
//# sourceMappingURL=contracts.js.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function assessTrinityCompleteness(specContent: string, planContent: string, tasksContent: string): TrinityCompleteness;
|
|
4
|
-
export declare function parseManifestContent(content: string): ParsedManifest;
|
|
5
|
-
export declare function toPosixPath(value: string): string;
|
|
1
|
+
import type { ReceiptPolicyResult, ReceiptSealFailure } from '../types/sdd-engine.js';
|
|
2
|
+
export { assessTrinityCompleteness, parseManifestContent, toPosixPath, } from './trinity-structure.js';
|
|
6
3
|
export declare function parseVerificationReceiptPolicy(featureId: string, plan: string, taskText: string): ReceiptPolicyResult;
|
|
7
4
|
export declare function receiptSealFailure(featureId: string, plan: string, tasks: string): ReceiptSealFailure | undefined;
|
|
8
5
|
//# sourceMappingURL=feature-manifest.d.ts.map
|
|
@@ -1,127 +1,9 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
1
|
import { z } from 'zod';
|
|
3
|
-
import { countTaskIds, dueTaskOrdinals, hasReceiptDirective,
|
|
2
|
+
import { countTaskIds, dueTaskOrdinals, hasReceiptDirective, receiptCommand, taskBlocks, } from './task-content.js';
|
|
4
3
|
import { featureIdPattern, gateIdPattern, importReceiptPublicKey, maxVerificationReceipts, sha256Schema, taskIdPattern, } from './verification-receipts.js';
|
|
5
4
|
import { disjointPaths, isEvidencePath } from './feature-authority.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export function assessTrinityCompleteness(specContent, planContent, tasksContent) {
|
|
9
|
-
const missing = [];
|
|
10
|
-
if (!hasHeading(specContent, 'Out-of-Scope')) {
|
|
11
|
-
missing.push('out_of_scope');
|
|
12
|
-
}
|
|
13
|
-
if (!hasHeading(specContent, 'Error Matrix')) {
|
|
14
|
-
missing.push('error_matrix');
|
|
15
|
-
}
|
|
16
|
-
if (!BDD_KEYWORDS.every((keyword) => keyword.test(specContent))) {
|
|
17
|
-
missing.push('bdd');
|
|
18
|
-
}
|
|
19
|
-
if (!hasHeading(planContent, 'Frozen Dependencies')) {
|
|
20
|
-
missing.push('frozen_dependencies');
|
|
21
|
-
}
|
|
22
|
-
const hasTask = tasksContent.split('\n').some((line) => CHECKBOX_TASK.test(line.trim()));
|
|
23
|
-
const manifest = scanManifest(planContent);
|
|
24
|
-
if (!manifest.hasPath) {
|
|
25
|
-
missing.push('manifest_path');
|
|
26
|
-
}
|
|
27
|
-
if (!hasTask) {
|
|
28
|
-
missing.push('checkbox_task');
|
|
29
|
-
}
|
|
30
|
-
if (manifest.globDelete) {
|
|
31
|
-
return {
|
|
32
|
-
ok: false,
|
|
33
|
-
code: 'ERR_TRINITY_INCOMPLETE',
|
|
34
|
-
message: 'DELETE File Manifest entries must be exact paths, not globs.',
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
if (manifest.protectedWrite !== null) {
|
|
38
|
-
return {
|
|
39
|
-
ok: false,
|
|
40
|
-
code: 'ERR_TRINITY_INCOMPLETE',
|
|
41
|
-
message: `File Manifest cannot grant writes on protected root path '${manifest.protectedWrite}' (.sdd, .git, planu/specs).`,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if (missing.length === 0) {
|
|
45
|
-
return { ok: true };
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
ok: false,
|
|
49
|
-
code: 'ERR_TRINITY_INCOMPLETE',
|
|
50
|
-
message: 'Lock requires Out-of-Scope, Error Matrix, GIVEN/WHEN/THEN acceptance criteria, Frozen Dependencies, a File Manifest path, and at least one checkbox task.',
|
|
51
|
-
details: { missing },
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function hasHeading(content, needle) {
|
|
55
|
-
const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
56
|
-
return new RegExp(`^#{1,3}\\s+.*${escaped}`, 'imu').test(content);
|
|
57
|
-
}
|
|
58
|
-
const PROTECTED_ROOTS = ['.sdd', '.git', 'planu/specs'];
|
|
59
|
-
function scanManifest(planContent) {
|
|
60
|
-
const { allowedFiles } = parseManifestContent(planContent);
|
|
61
|
-
let globDelete = false;
|
|
62
|
-
let protectedWrite = null;
|
|
63
|
-
for (const [entryPath, permission] of allowedFiles) {
|
|
64
|
-
if (permission === 'DELETE' && entryPath.includes('*')) {
|
|
65
|
-
globDelete = true;
|
|
66
|
-
}
|
|
67
|
-
const normalized = path.posix.normalize(entryPath).toLowerCase();
|
|
68
|
-
if (permission !== 'READ_ONLY' &&
|
|
69
|
-
protectedWrite === null &&
|
|
70
|
-
PROTECTED_ROOTS.some((root) => normalized === root || normalized.startsWith(`${root}/`))) {
|
|
71
|
-
protectedWrite = entryPath;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return { hasPath: allowedFiles.size > 0, globDelete, protectedWrite };
|
|
75
|
-
}
|
|
76
|
-
export function parseManifestContent(content) {
|
|
77
|
-
const allowedFiles = new Map();
|
|
78
|
-
for (const { rawPath, permission } of manifestEntries(content)) {
|
|
79
|
-
allowedFiles.set(toPosixPath(rawPath), permission);
|
|
80
|
-
}
|
|
81
|
-
return { allowedFiles };
|
|
82
|
-
}
|
|
83
|
-
function manifestEntries(content) {
|
|
84
|
-
const entries = [];
|
|
85
|
-
let inManifestSection = false;
|
|
86
|
-
for (const rawLine of content.split('\n')) {
|
|
87
|
-
const line = rawLine.trim();
|
|
88
|
-
if (/^#{1,3}\s+/.test(line)) {
|
|
89
|
-
inManifestSection = /^#{1,3}\s+.*file\s+manifest/i.test(line);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (inManifestSection && /^[-*]\s+/.test(line)) {
|
|
93
|
-
const entry = parseManifestLine(line);
|
|
94
|
-
if (entry && toPosixPath(entry.rawPath).toLowerCase() !== 'none') {
|
|
95
|
-
entries.push(entry);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return entries;
|
|
100
|
-
}
|
|
101
|
-
function parseManifestLine(rawLine) {
|
|
102
|
-
const item = rawLine.replace(/^[-*]\s+/, '').trim();
|
|
103
|
-
const prefix = /^(CREATE|MODIFY|READ_ONLY|DELETE):\s*`?([^`\s#]+)`?\s*$/i.exec(item);
|
|
104
|
-
if (prefix?.[1] && prefix[2]) {
|
|
105
|
-
return { rawPath: prefix[2], permission: prefix[1].toUpperCase() };
|
|
106
|
-
}
|
|
107
|
-
const postfix = /^`?([^`\s:#]+)`?:\s*(CREATE|MODIFY|READ_ONLY|DELETE)\s*$/i.exec(item);
|
|
108
|
-
if (postfix?.[1] && postfix[2]) {
|
|
109
|
-
return { rawPath: postfix[1], permission: postfix[2].toUpperCase() };
|
|
110
|
-
}
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
export function toPosixPath(value) {
|
|
114
|
-
const posix = value.replaceAll('\\', '/');
|
|
115
|
-
const absolute = posix.startsWith('/');
|
|
116
|
-
const joined = posix
|
|
117
|
-
.split('/')
|
|
118
|
-
.filter((part) => part !== '' && part !== '.')
|
|
119
|
-
.join('/');
|
|
120
|
-
return absolute ? `/${joined}` : joined;
|
|
121
|
-
}
|
|
122
|
-
const POLICY_LIMIT = 65_536;
|
|
123
|
-
const RECEIPT_HEADING = /^#{1,6}\s+Verification\s+Receipts(?:\s*$|\s*v[0-9])/iu;
|
|
124
|
-
const FENCE = String.fromCharCode(96).repeat(3);
|
|
5
|
+
import { candidateCreationIssue, invalidTask, invalidCandidate, candidateIssue, manifestEntries, policyIssueLine, policyText, toPosixPath, } from './trinity-structure.js';
|
|
6
|
+
export { assessTrinityCompleteness, parseManifestContent, toPosixPath, } from './trinity-structure.js';
|
|
125
7
|
const policySchema = z.strictObject({
|
|
126
8
|
publicKey: z.string().max(128),
|
|
127
9
|
tasks: z
|
|
@@ -148,63 +30,41 @@ const policySchema = z.strictObject({
|
|
|
148
30
|
.max(64),
|
|
149
31
|
});
|
|
150
32
|
const INVALID_POLICY = { status: 'invalid' };
|
|
151
|
-
function
|
|
152
|
-
const lines = plan.replaceAll('\r\n', '\n').split('\n');
|
|
153
|
-
const headings = lines.flatMap((line, index) => RECEIPT_HEADING.test(line.trim()) ? [index] : []);
|
|
154
|
-
if (headings.length === 0) {
|
|
155
|
-
return undefined;
|
|
156
|
-
}
|
|
157
|
-
const start = headings[0];
|
|
158
|
-
if (start === undefined ||
|
|
159
|
-
headings.length !== 1 ||
|
|
160
|
-
insideMarkdownBlock(lines.slice(0, start)) ||
|
|
161
|
-
lines[start]?.trim() !== '## Verification Receipts v1') {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
const after = lines.findIndex((line, index) => index > start && /^#{1,2}\s/u.test(line.trim()));
|
|
165
|
-
const section = lines
|
|
166
|
-
.slice(start + 1, after < 0 ? undefined : after)
|
|
167
|
-
.join('\n')
|
|
168
|
-
.trim();
|
|
169
|
-
const prefix = FENCE + 'json\n';
|
|
170
|
-
const suffix = '\n' + FENCE;
|
|
171
|
-
if (!section.startsWith(prefix) || !section.endsWith(suffix)) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
const payload = section.slice(prefix.length, -suffix.length);
|
|
175
|
-
return Buffer.byteLength(payload) <= POLICY_LIMIT ? payload.trim() : null;
|
|
176
|
-
}
|
|
177
|
-
function readPolicy(text) {
|
|
33
|
+
function readPolicy(text, locations) {
|
|
178
34
|
try {
|
|
179
35
|
const value = JSON.parse(text);
|
|
180
36
|
if (JSON.stringify(value, null, 2) !== text) {
|
|
181
|
-
return
|
|
37
|
+
return {};
|
|
182
38
|
}
|
|
183
39
|
const parsed = policySchema.safeParse(value);
|
|
184
|
-
|
|
40
|
+
if (parsed.success) {
|
|
41
|
+
return { value: parsed.data };
|
|
42
|
+
}
|
|
43
|
+
const first = parsed.error.issues[0];
|
|
44
|
+
return { line: first ? policyIssueLine(first, locations) : undefined };
|
|
185
45
|
}
|
|
186
46
|
catch {
|
|
187
|
-
return
|
|
47
|
+
return {};
|
|
188
48
|
}
|
|
189
49
|
}
|
|
190
|
-
function
|
|
191
|
-
const id = block.explicitId ?? block.id;
|
|
192
|
-
return taskIdPattern.test(id) ? { status: 'invalid', taskId: id } : INVALID_POLICY;
|
|
193
|
-
}
|
|
194
|
-
function parseCandidates(plan, creates, dueTasks) {
|
|
50
|
+
function parseCandidates(plan, creates, dueTasks, locations) {
|
|
195
51
|
const entries = manifestEntries(plan);
|
|
196
52
|
const writable = entries.filter(({ permission }) => permission !== 'READ_ONLY');
|
|
53
|
+
if (writable.length > 64) {
|
|
54
|
+
return candidateIssue(writable[64]);
|
|
55
|
+
}
|
|
197
56
|
const paths = writable.map(({ rawPath }) => rawPath);
|
|
198
57
|
if (writable.length < 1 ||
|
|
199
|
-
writable.length > 64 ||
|
|
200
58
|
!paths.every(isEvidencePath) ||
|
|
201
59
|
!disjointPaths(paths) ||
|
|
202
60
|
writable.some(({ permission }) => permission === 'DELETE')) {
|
|
203
|
-
|
|
61
|
+
const bad = invalidCandidate(writable, paths);
|
|
62
|
+
return candidateIssue(bad);
|
|
204
63
|
}
|
|
205
64
|
const writes = new Set(paths.map((item) => item.toLowerCase()));
|
|
206
|
-
|
|
207
|
-
|
|
65
|
+
const shadow = entries.find(({ rawPath, permission }) => permission === 'READ_ONLY' && writes.has(toPosixPath(rawPath).toLowerCase()));
|
|
66
|
+
if (shadow) {
|
|
67
|
+
return candidateIssue(undefined);
|
|
208
68
|
}
|
|
209
69
|
const mappings = new Map(creates.map(({ path: candidatePath, requiredFromTaskId }) => [
|
|
210
70
|
candidatePath,
|
|
@@ -215,39 +75,70 @@ function parseCandidates(plan, creates, dueTasks) {
|
|
|
215
75
|
return undefined;
|
|
216
76
|
}
|
|
217
77
|
const candidates = [];
|
|
218
|
-
for (const
|
|
78
|
+
for (const entry of writable) {
|
|
79
|
+
const { rawPath, permission } = entry;
|
|
219
80
|
const due = mappings.get(rawPath);
|
|
220
81
|
const requiredFrom = permission === 'CREATE' && due !== undefined ? dueTasks.get(due) : 1;
|
|
221
82
|
if (requiredFrom === undefined ||
|
|
222
83
|
(permission === 'CREATE' ? due === undefined : due !== undefined)) {
|
|
223
|
-
return
|
|
84
|
+
return candidateCreationIssue(rawPath, creates, requiredFrom, locations);
|
|
224
85
|
}
|
|
225
86
|
candidates.push({ path: rawPath, requiredFrom });
|
|
226
87
|
}
|
|
227
88
|
return candidates;
|
|
228
89
|
}
|
|
229
|
-
function
|
|
90
|
+
function planPolicyIssue(line) {
|
|
91
|
+
return {
|
|
92
|
+
artifact: 'plan.md',
|
|
93
|
+
rule: 'receipt_policy_invalid',
|
|
94
|
+
...(line === undefined ? {} : { line }),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function receiptTaskIssue(task, candidatePaths, index, locations) {
|
|
98
|
+
const prefix = 'tasks/' + String(index);
|
|
99
|
+
const duplicate = task.gates.findIndex(({ id }, gate) => task.gates.slice(0, gate).some((prior) => prior.id === id));
|
|
100
|
+
if (duplicate >= 0) {
|
|
101
|
+
return planPolicyIssue(locations.get(prefix + '/gates/' + String(duplicate) + '/id'));
|
|
102
|
+
}
|
|
103
|
+
const unsafe = task.observed.findIndex((item) => !isEvidencePath(item));
|
|
104
|
+
if (unsafe >= 0) {
|
|
105
|
+
return planPolicyIssue(locations.get(prefix + '/observed/' + String(unsafe)));
|
|
106
|
+
}
|
|
107
|
+
return disjointPaths([...candidatePaths, ...task.observed]) ? undefined : planPolicyIssue();
|
|
108
|
+
}
|
|
109
|
+
function bindReceiptTask(block, task, count) {
|
|
230
110
|
const command = receiptCommand(block);
|
|
231
|
-
if (!task ||
|
|
232
|
-
block.explicitId !== task.taskId ||
|
|
233
|
-
count !== 1 ||
|
|
234
|
-
!command ||
|
|
235
|
-
new Set(task.gates.map(({ id }) => id)).size !== task.gates.length ||
|
|
236
|
-
!task.observed.every(isEvidencePath) ||
|
|
237
|
-
!disjointPaths([...candidatePaths, ...task.observed])) {
|
|
111
|
+
if (!task || block.explicitId !== task.taskId || count !== 1 || !command) {
|
|
238
112
|
return undefined;
|
|
239
113
|
}
|
|
240
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
...task,
|
|
116
|
+
command,
|
|
117
|
+
ordinal: block.ordinal,
|
|
118
|
+
lineIndex: block.lineIndex,
|
|
119
|
+
};
|
|
241
120
|
}
|
|
242
|
-
function readBindings(taskText, policy, plan, publicKey) {
|
|
121
|
+
function readBindings(taskText, policy, plan, publicKey, locations) {
|
|
243
122
|
const blocks = taskBlocks(taskText);
|
|
244
123
|
const byId = new Map(policy.tasks.map((task) => [task.taskId, task]));
|
|
245
124
|
const counts = countTaskIds(blocks);
|
|
246
|
-
const candidates = parseCandidates(plan, policy.candidateCreates, dueTaskOrdinals(blocks, counts));
|
|
125
|
+
const candidates = parseCandidates(plan, policy.candidateCreates, dueTaskOrdinals(blocks, counts), locations);
|
|
126
|
+
if (candidates && !Array.isArray(candidates)) {
|
|
127
|
+
return { ...INVALID_POLICY, issue: candidates };
|
|
128
|
+
}
|
|
247
129
|
const preamble = taskText.split('\n').slice(0, blocks[0]?.lineIndex);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
130
|
+
const directive = preamble.findIndex(hasReceiptDirective);
|
|
131
|
+
if (directive >= 0) {
|
|
132
|
+
return {
|
|
133
|
+
...INVALID_POLICY,
|
|
134
|
+
issue: {
|
|
135
|
+
artifact: 'tasks.md',
|
|
136
|
+
rule: 'receipt_policy_invalid',
|
|
137
|
+
line: directive + 1,
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (!candidates || byId.size !== policy.tasks.length) {
|
|
251
142
|
return INVALID_POLICY;
|
|
252
143
|
}
|
|
253
144
|
const paths = candidates.map(({ path: candidatePath }) => candidatePath);
|
|
@@ -257,9 +148,16 @@ function readBindings(taskText, policy, plan, publicKey) {
|
|
|
257
148
|
if (!task && !block.lines.some((line) => hasReceiptDirective(line))) {
|
|
258
149
|
continue;
|
|
259
150
|
}
|
|
260
|
-
const binding = bindReceiptTask(block, task, counts.get(block.id)
|
|
151
|
+
const binding = bindReceiptTask(block, task, counts.get(block.id));
|
|
261
152
|
if (!binding) {
|
|
262
|
-
|
|
153
|
+
const duplicate = task
|
|
154
|
+
? blocks.find((item) => item.id === block.id && item.lineIndex > block.lineIndex)
|
|
155
|
+
: undefined;
|
|
156
|
+
return invalidTask(block, duplicate?.lineIndex);
|
|
157
|
+
}
|
|
158
|
+
const issue = receiptTaskIssue(binding, paths, policy.tasks.findIndex((item) => item.taskId === block.id), locations);
|
|
159
|
+
if (issue) {
|
|
160
|
+
return { ...invalidTask(block), issue };
|
|
263
161
|
}
|
|
264
162
|
tasks.set(binding.taskId, binding);
|
|
265
163
|
}
|
|
@@ -268,23 +166,49 @@ function readBindings(taskText, policy, plan, publicKey) {
|
|
|
268
166
|
: INVALID_POLICY;
|
|
269
167
|
}
|
|
270
168
|
export function parseVerificationReceiptPolicy(featureId, plan, taskText) {
|
|
271
|
-
const
|
|
169
|
+
const source = policyText(plan);
|
|
170
|
+
const { text } = source;
|
|
171
|
+
const invalid = {
|
|
172
|
+
...INVALID_POLICY,
|
|
173
|
+
issue: {
|
|
174
|
+
artifact: 'plan.md',
|
|
175
|
+
rule: 'receipt_policy_invalid',
|
|
176
|
+
...(source.line === undefined ? {} : { line: source.line }),
|
|
177
|
+
},
|
|
178
|
+
};
|
|
272
179
|
if (text === undefined) {
|
|
273
180
|
if (!taskText.split('\n').some((line) => hasReceiptDirective(line))) {
|
|
274
181
|
return { status: 'none' };
|
|
275
182
|
}
|
|
276
183
|
const block = taskBlocks(taskText).find(({ lines }) => lines.some((line) => hasReceiptDirective(line)));
|
|
277
|
-
return block
|
|
184
|
+
return block
|
|
185
|
+
? invalidTask(block)
|
|
186
|
+
: {
|
|
187
|
+
...INVALID_POLICY,
|
|
188
|
+
issue: {
|
|
189
|
+
artifact: 'tasks.md',
|
|
190
|
+
rule: 'receipt_policy_invalid',
|
|
191
|
+
line: taskText.split('\n').findIndex(hasReceiptDirective) + 1,
|
|
192
|
+
},
|
|
193
|
+
};
|
|
278
194
|
}
|
|
279
195
|
if (text === null || !featureIdPattern.test(featureId)) {
|
|
280
|
-
return
|
|
196
|
+
return invalid;
|
|
281
197
|
}
|
|
282
|
-
const
|
|
198
|
+
const locations = source.locations ?? new Map();
|
|
199
|
+
const parsed = readPolicy(text, locations);
|
|
200
|
+
const policy = parsed.value;
|
|
283
201
|
if (!policy) {
|
|
284
|
-
return
|
|
202
|
+
return { ...invalid, issue: planPolicyIssue(parsed.line) };
|
|
285
203
|
}
|
|
286
204
|
const publicKey = importReceiptPublicKey(policy.publicKey);
|
|
287
|
-
|
|
205
|
+
if (!publicKey) {
|
|
206
|
+
return { ...invalid, issue: planPolicyIssue(locations.get('publicKey')) };
|
|
207
|
+
}
|
|
208
|
+
const result = readBindings(taskText, policy, plan, publicKey, locations);
|
|
209
|
+
return result.status === 'invalid' && !result.issue
|
|
210
|
+
? { ...result, issue: invalid.issue }
|
|
211
|
+
: result;
|
|
288
212
|
}
|
|
289
213
|
export function receiptSealFailure(featureId, plan, tasks) {
|
|
290
214
|
const policy = parseVerificationReceiptPolicy(featureId, plan, tasks);
|
|
@@ -295,6 +219,7 @@ export function receiptSealFailure(featureId, plan, tasks) {
|
|
|
295
219
|
message: 'The receipt verification policy or task directive is invalid.',
|
|
296
220
|
details: {
|
|
297
221
|
reason: 'receipt_policy_invalid',
|
|
222
|
+
issues: policy.issue ? [policy.issue] : [],
|
|
298
223
|
...(policy.taskId ? { taskId: policy.taskId } : {}),
|
|
299
224
|
},
|
|
300
225
|
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import type { HostSkillDiagnostics } from '../types/sdd-engine.js';
|
|
1
2
|
export declare function isStaleV6HostDoc(content: string): boolean;
|
|
2
3
|
export declare function copyGlobalRules(workspaceRoot: string, force?: boolean): Promise<'preserved' | 'replaced' | 'created'>;
|
|
3
4
|
export declare function inspectHostSkillPack(workspaceRoot: string): Promise<string | undefined>;
|
|
5
|
+
export declare function inspectHostSkillPackDetailed(workspaceRoot: string, bundledVersion: string): Promise<{
|
|
6
|
+
hostSkills: HostSkillDiagnostics;
|
|
7
|
+
hint?: string;
|
|
8
|
+
}>;
|
|
4
9
|
export declare function installHostSkillPack(workspaceRoot: string): Promise<string[]>;
|
|
5
10
|
export declare function installCursorGuard(workspaceRoot: string): Promise<string[]>;
|
|
6
11
|
export declare function installHostRulePack(workspaceRoot: string): Promise<string[]>;
|