pi-daddy 0.17.0 → 0.18.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 +154 -80
- package/README.md +54 -25
- package/dist/approval-prompt.d.ts +3 -1
- package/dist/approval-prompt.d.ts.map +1 -1
- package/dist/approval-prompt.js +1 -1
- package/dist/approval-prompt.js.map +1 -1
- package/dist/approval-store.d.ts.map +1 -1
- package/dist/approval-store.js +4 -1
- package/dist/approval-store.js.map +1 -1
- package/dist/approval.d.ts +20 -2
- package/dist/approval.d.ts.map +1 -1
- package/dist/approval.js +26 -6
- package/dist/approval.js.map +1 -1
- package/dist/chain.d.ts +6 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +1 -1
- package/dist/chain.js.map +1 -1
- package/dist/check-runner.d.ts +61 -0
- package/dist/check-runner.d.ts.map +1 -0
- package/dist/check-runner.js +237 -0
- package/dist/check-runner.js.map +1 -0
- package/dist/correlation.d.ts +90 -0
- package/dist/correlation.d.ts.map +1 -0
- package/dist/correlation.js +183 -0
- package/dist/correlation.js.map +1 -0
- package/dist/delegate-types.d.ts +140 -0
- package/dist/delegate-types.d.ts.map +1 -0
- package/dist/delegate-types.js +8 -0
- package/dist/delegate-types.js.map +1 -0
- package/dist/delegate.d.ts +4 -128
- package/dist/delegate.d.ts.map +1 -1
- package/dist/delegate.js +68 -72
- package/dist/delegate.js.map +1 -1
- package/dist/delegation-approval.d.ts +36 -0
- package/dist/delegation-approval.d.ts.map +1 -0
- package/dist/delegation-approval.js +67 -0
- package/dist/delegation-approval.js.map +1 -0
- package/dist/git-identity.d.ts +13 -0
- package/dist/git-identity.d.ts.map +1 -0
- package/dist/git-identity.js +44 -0
- package/dist/git-identity.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/lease-record.d.ts +78 -0
- package/dist/lease-record.d.ts.map +1 -0
- package/dist/lease-record.js +52 -0
- package/dist/lease-record.js.map +1 -0
- package/dist/ledger-events.d.ts +87 -0
- package/dist/ledger-events.d.ts.map +1 -0
- package/dist/ledger-events.js +45 -0
- package/dist/ledger-events.js.map +1 -0
- package/dist/ledger-report.d.ts +19 -12
- package/dist/ledger-report.d.ts.map +1 -1
- package/dist/ledger-report.js +81 -1
- package/dist/ledger-report.js.map +1 -1
- package/dist/ledger.d.ts +44 -1
- package/dist/ledger.d.ts.map +1 -1
- package/dist/ledger.js +20 -2
- package/dist/ledger.js.map +1 -1
- package/dist/refusals.d.ts +16 -0
- package/dist/refusals.d.ts.map +1 -0
- package/dist/refusals.js +51 -0
- package/dist/refusals.js.map +1 -0
- package/dist/run-child.d.ts +4 -0
- package/dist/run-child.d.ts.map +1 -1
- package/dist/run-child.js +21 -1
- package/dist/run-child.js.map +1 -1
- package/dist/run-herdr.d.ts +7 -0
- package/dist/run-herdr.d.ts.map +1 -1
- package/dist/run-herdr.js +41 -12
- package/dist/run-herdr.js.map +1 -1
- package/dist/workspace-lease.d.ts +28 -0
- package/dist/workspace-lease.d.ts.map +1 -0
- package/dist/workspace-lease.js +276 -0
- package/dist/workspace-lease.js.map +1 -0
- package/dist/workspace.d.ts +32 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +79 -0
- package/dist/workspace.js.map +1 -0
- package/extensions/approval-banking.ts +66 -0
- package/extensions/approvals.ts +95 -7
- package/extensions/chain-approval-facts.ts +51 -0
- package/extensions/chain-ledger.ts +48 -0
- package/extensions/delegate-chain.ts +115 -81
- package/extensions/delegation.ts +81 -23
- package/extensions/execute-child.ts +289 -0
- package/extensions/fanout-outcome.ts +97 -0
- package/extensions/run-delegation.ts +130 -120
- package/extensions/session.ts +4 -0
- package/extensions/workspace-runtime.ts +165 -0
- package/package.json +17 -1
- package/src/approval-prompt.ts +4 -2
- package/src/approval-store.ts +4 -1
- package/src/approval.ts +47 -14
- package/src/chain.ts +3 -1
- package/src/check-runner.ts +341 -0
- package/src/correlation.ts +260 -0
- package/src/delegate-types.ts +144 -0
- package/src/delegate.ts +80 -179
- package/src/delegation-approval.ts +99 -0
- package/src/git-identity.ts +52 -0
- package/src/index.ts +50 -0
- package/src/lease-record.ts +119 -0
- package/src/ledger-events.ts +138 -0
- package/src/ledger-report.ts +90 -2
- package/src/ledger.ts +68 -3
- package/src/refusals.ts +66 -0
- package/src/run-child.ts +23 -1
- package/src/run-herdr.ts +41 -11
- package/src/workspace-lease.ts +303 -0
- package/src/workspace.ts +135 -0
package/dist/delegate.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Governed delegation
|
|
3
|
-
*
|
|
4
|
-
* The `tool_call` interceptor can only *permit or refuse* a `pi-subagents` spawn, because that package's
|
|
5
|
-
* `Agent` tool has no `tools` parameter. When we do the spawning ourselves the grant becomes an argument,
|
|
6
|
-
* which is what "give them some tools but not others" actually requires.
|
|
7
|
-
*
|
|
8
|
-
* Two properties fall out of owning the spawn:
|
|
9
|
-
*
|
|
10
|
-
* 1. **No propagation race at all.** Each child receives its own explicit `env` object, so nothing is
|
|
11
|
-
* written to the shared `process.env`. The interceptor's constraint (only parent-level facts may be
|
|
12
|
-
* pushed, because the channel is global) does not apply here.
|
|
13
|
-
* 2. **Depth control by capability.** `tool:delegate` is itself a capability. Grant it and the child can
|
|
14
|
-
* sub-delegate; withhold it and the child is a leaf. No separate depth mechanism is required, though
|
|
15
|
-
* `maxDepth` remains as a cheap backstop.
|
|
2
|
+
* Governed delegation planning. Owning the spawn makes the grant an argument; each child receives its own
|
|
3
|
+
* environment, and `tool:delegate` determines whether it is a delegator or a leaf.
|
|
16
4
|
*/
|
|
17
5
|
import { planSpawn } from "./spawn.js";
|
|
18
6
|
import { ceilingForDefinition, digestDefinition } from "./definitions.js";
|
|
19
|
-
import {
|
|
20
|
-
import { AGENT_WILDCARD } from "./resolve.js";
|
|
7
|
+
import { assertNarrowing } from "./resolve.js";
|
|
21
8
|
import { DELEGATE_CAPABILITY, agentCapability, maySpawnDefinition, normaliseCapability } from "./capabilities.js";
|
|
22
9
|
// Re-exported so the split stays internal: `delegate.ts` has been the import site for these since 0.6.0 and
|
|
23
10
|
// four modules plus the test suite name it. Moving the definitions without moving the door would be churn
|
|
24
11
|
// charged to every caller for a line count they did not cause.
|
|
25
12
|
export { DELEGATE_CAPABILITY, agentCapability, maySpawnDefinition, normaliseCapability } from "./capabilities.js";
|
|
26
13
|
import { ENV_APPROVED, ENV_DEPTH, ENV_FANOUT, ENV_GATED, ENV_GRANT, ENV_LEDGER, ENV_MAX_DEPTH, ENV_PARENT_ID } from "./propagation.js";
|
|
27
|
-
import {
|
|
14
|
+
import { inheritApprovals } from "./approval.js";
|
|
28
15
|
import { suggestForUnknown, unknownCapabilities } from "./catalog.js";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* Fails closed on depth, on any requested capability the delegator does not hold, on gated capabilities
|
|
33
|
-
* without approval, and on a grant that cannot narrow (a universal capability slipping through).
|
|
34
|
-
*/
|
|
16
|
+
import { GovernanceRefusal, refusal } from "./refusals.js";
|
|
17
|
+
import { digestTask, normaliseCorrelation, } from "./correlation.js";
|
|
18
|
+
import { resolveDelegationApproval } from "./delegation-approval.js";
|
|
35
19
|
export function planDelegation(request, ctx) {
|
|
36
20
|
const childDepth = ctx.depth + 1;
|
|
21
|
+
const denied = (plan, code) => plan.reason ? { ...plan, refusal: refusal(code, plan.reason) } : plan;
|
|
37
22
|
// G6 / B-I3: every refusal carries a result, including the four below that return before `resolve()`
|
|
38
23
|
// is ever called. The extension guarded its ledger write with `if (ledgerPath && plan.result)`, so
|
|
39
24
|
// those four governance decisions — disabled, too deep, no task, unknown capability — were never
|
|
40
25
|
// audited at all. An empty result is the honest record: nothing was resolved, and that is the fact.
|
|
26
|
+
// Bounded/whitelisted correlation is a REFUSAL, not an exception escaping the planner. It is reachable
|
|
27
|
+
// from a model-facing tool parameter on all three delegation tools, and throwing from here produced a
|
|
28
|
+
// governed refusal with no code and no ledger line at all — the ledger file was never even created
|
|
29
|
+
// (R-112). Caught here so it becomes an ordinary recorded decision.
|
|
30
|
+
let correlation;
|
|
31
|
+
let correlationRefused;
|
|
32
|
+
try {
|
|
33
|
+
correlation = normaliseCorrelation(request.correlation);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
correlationRefused = error instanceof GovernanceRefusal
|
|
37
|
+
? { code: error.code, message: error.message, ...(error.details ? { details: error.details } : {}) }
|
|
38
|
+
: refusal("CORRELATION_INVALID", String(error instanceof Error ? error.message : error));
|
|
39
|
+
}
|
|
40
|
+
const taskDigest = digestTask(request.task ?? "");
|
|
41
41
|
const empty = {
|
|
42
42
|
ok: false,
|
|
43
43
|
args: [],
|
|
@@ -45,15 +45,21 @@ export function planDelegation(request, ctx) {
|
|
|
45
45
|
effective: [],
|
|
46
46
|
childDepth,
|
|
47
47
|
requested: [],
|
|
48
|
+
taskDigest,
|
|
49
|
+
...(correlation ? { correlation } : {}),
|
|
48
50
|
result: { effective: [], denied: [], clipped: [], gatedBlocked: [], universal: [], subsumedBy: [] },
|
|
49
51
|
};
|
|
50
|
-
if (
|
|
51
|
-
return { ...empty, reason:
|
|
52
|
+
if (correlationRefused) {
|
|
53
|
+
return { ...empty, reason: correlationRefused.message, refusal: correlationRefused };
|
|
54
|
+
}
|
|
55
|
+
if (ctx.maxDepth <= 0) {
|
|
56
|
+
return denied({ ...empty, reason: "delegation is disabled (maxDepth 0)" }, "DEPTH_EXCEEDED");
|
|
57
|
+
}
|
|
52
58
|
if (childDepth > ctx.maxDepth) {
|
|
53
|
-
return { ...empty, reason: `delegation depth limit reached (${ctx.maxDepth})` };
|
|
59
|
+
return denied({ ...empty, reason: `delegation depth limit reached (${ctx.maxDepth})` }, "DEPTH_EXCEEDED");
|
|
54
60
|
}
|
|
55
61
|
if (!request.task?.trim())
|
|
56
|
-
return { ...empty, reason: "a delegation needs a task" };
|
|
62
|
+
return denied({ ...empty, reason: "a delegation needs a task" }, "TASK_MISSING");
|
|
57
63
|
// ADR-0016. A named definition replaces the model's tool list with an operator-authored ceiling.
|
|
58
64
|
let requested;
|
|
59
65
|
let systemPrompt;
|
|
@@ -68,11 +74,11 @@ export function planDelegation(request, ctx) {
|
|
|
68
74
|
// here is simply an error.
|
|
69
75
|
if (!definition) {
|
|
70
76
|
const known = [...(ctx.definitions?.keys() ?? [])].sort();
|
|
71
|
-
return {
|
|
77
|
+
return denied({
|
|
72
78
|
...empty,
|
|
73
79
|
reason: `unknown agent "${request.agent}"` +
|
|
74
80
|
(known.length > 0 ? ` — known definitions: ${known.join(", ")}` : " — no definitions were found"),
|
|
75
|
-
};
|
|
81
|
+
}, "UNKNOWN_DEFINITION");
|
|
76
82
|
}
|
|
77
83
|
// ADR-0017: authorisation comes BEFORE anything is said about the file. Which definitions this
|
|
78
84
|
// session may spawn is a governance question about the SESSION; whether the file declares its tools
|
|
@@ -85,7 +91,7 @@ export function planDelegation(request, ctx) {
|
|
|
85
91
|
if (!maySpawnDefinition(ctx.ownGrant, definition.name)) {
|
|
86
92
|
const authorising = agentCapability(definition.name);
|
|
87
93
|
const held = ctx.ownGrant.filter((c) => c.startsWith("agent:")).sort();
|
|
88
|
-
return {
|
|
94
|
+
return denied({
|
|
89
95
|
...empty,
|
|
90
96
|
requested: [authorising],
|
|
91
97
|
result: { ...empty.result, denied: [authorising] },
|
|
@@ -94,7 +100,7 @@ export function planDelegation(request, ctx) {
|
|
|
94
100
|
(held.length > 0
|
|
95
101
|
? `It may spawn: ${held.join(", ")}.`
|
|
96
102
|
: `It may spawn no definitions at all; add ${authorising} to its grant to allow this one.`),
|
|
97
|
-
};
|
|
103
|
+
}, "DEFINITION_NOT_AUTHORIZED");
|
|
98
104
|
}
|
|
99
105
|
// ADR-0018. Recorded from here on — after authorisation, because the digest is a fact about a file
|
|
100
106
|
// this caller was allowed to read, and before every remaining outcome, because a spawn refused for a
|
|
@@ -108,19 +114,19 @@ export function planDelegation(request, ctx) {
|
|
|
108
114
|
Object.assign(empty, { definitionDigest });
|
|
109
115
|
const ceiling = ceilingForDefinition(definition);
|
|
110
116
|
if (ceiling.undeclared) {
|
|
111
|
-
return {
|
|
117
|
+
return denied({
|
|
112
118
|
...empty,
|
|
113
119
|
reason: `agent "${definition.name}" declares no \`allowed-tools\`, so it cannot be spawned — add one ` +
|
|
114
120
|
`to ${definition.source}. An undeclared capability set is treated as NONE, never as everything.`,
|
|
115
|
-
};
|
|
121
|
+
}, "UNDECLARED_TOOLS");
|
|
116
122
|
}
|
|
117
123
|
if (ceiling.patterns.length > 0) {
|
|
118
|
-
return {
|
|
124
|
+
return denied({
|
|
119
125
|
...empty,
|
|
120
126
|
reason: `agent "${definition.name}" restricts a tool with a pattern (${ceiling.patterns.join(", ")}), ` +
|
|
121
127
|
`which pi's --tools cannot express — it matches whole tool names only. Granting the bare tool ` +
|
|
122
128
|
`would widen the declaration and dropping it would silently narrow, so neither is done.`,
|
|
123
|
-
};
|
|
129
|
+
}, "CEILING_PATTERNS_UNRESOLVED");
|
|
124
130
|
}
|
|
125
131
|
requested = ceiling.capabilities;
|
|
126
132
|
systemPrompt = definition.body;
|
|
@@ -144,55 +150,38 @@ export function planDelegation(request, ctx) {
|
|
|
144
150
|
return s === null ? null : `${c} → did you mean ${s}?`;
|
|
145
151
|
})
|
|
146
152
|
.filter((h) => h !== null);
|
|
147
|
-
return {
|
|
153
|
+
return denied({
|
|
148
154
|
...empty,
|
|
149
155
|
requested,
|
|
150
156
|
reason: `unknown capabilit${unknown.length === 1 ? "y" : "ies"}: ${unknown.join(", ")} — not present in ` +
|
|
151
157
|
`this session's catalog (typo, or an uninstalled package?)` +
|
|
152
158
|
(hints.length > 0 ? ` — ${hints.join("; ")}` : ""),
|
|
153
|
-
};
|
|
159
|
+
}, "UNKNOWN_TOOL");
|
|
154
160
|
}
|
|
155
161
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const result = resolve({
|
|
162
|
+
const { result, approvalBinding, bindingMismatch } = resolveDelegationApproval({
|
|
163
|
+
task: request.task,
|
|
164
|
+
agent: request.agent,
|
|
165
|
+
boundWorkspaceId: request.boundWorkspaceId,
|
|
166
|
+
boundContextId: request.boundContextId,
|
|
162
167
|
requested,
|
|
163
168
|
parentGrant: ctx.ownGrant,
|
|
164
169
|
gated: ctx.gated,
|
|
165
|
-
approved:
|
|
170
|
+
approved: ctx.approved,
|
|
171
|
+
spawned,
|
|
172
|
+
definitionDigest,
|
|
173
|
+
correlation,
|
|
174
|
+
parentId: ctx.spawnId ?? `d${ctx.depth}`,
|
|
166
175
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
* `gatedBlocked` is a filter over `requested`, and for a definition spawn `requested` is the definition's
|
|
171
|
-
* CEILING — so the id that authorises it was never a candidate, and `PI_GRANTS_GATED=agent:deploy` did
|
|
172
|
-
* nothing at all on the path an operator writing it means. It half-worked when some *other* definition
|
|
173
|
-
* passed the id down in its own `allowed-tools`, which is worse than not working (R-47, R-25's shape).
|
|
174
|
-
*
|
|
175
|
-
* Evaluated here rather than by adding the id to `requested`, and that is the load-bearing part: a
|
|
176
|
-
* capability in `requested` flows to `effective`, which becomes the CHILD's grant — so the child would
|
|
177
|
-
* hold `agent:deploy` and could spawn `deploy` itself without anyone being asked. This is the parent's
|
|
178
|
-
* authority to run the definition *now*, not something the child receives.
|
|
179
|
-
*
|
|
180
|
-
* `agent:*` in the gate covers every definition, so "ask me before any definition runs" is one variable.
|
|
181
|
-
*/
|
|
182
|
-
if (spawned) {
|
|
183
|
-
const authorising = agentCapability(spawned.name);
|
|
184
|
-
const gatedHere = ctx.gated.includes(authorising) || ctx.gated.includes(AGENT_WILDCARD);
|
|
185
|
-
if (gatedHere && !approvedCapabilities.includes(authorising)) {
|
|
186
|
-
result.gatedBlocked = [...result.gatedBlocked, authorising];
|
|
187
|
-
}
|
|
188
|
-
}
|
|
176
|
+
if (approvalBinding)
|
|
177
|
+
Object.assign(empty, { approvalBinding });
|
|
189
178
|
if (result.denied.length > 0) {
|
|
190
|
-
return {
|
|
179
|
+
return denied({
|
|
191
180
|
...empty,
|
|
192
181
|
requested,
|
|
193
182
|
result,
|
|
194
183
|
reason: `cannot grant ${result.denied.join(", ")} — this session does not hold it (capability escalation blocked)`,
|
|
195
|
-
};
|
|
184
|
+
}, "CAPABILITY_ESCALATION");
|
|
196
185
|
}
|
|
197
186
|
// ADR-0011: narrowing is checked BEFORE the gate, and the order is load-bearing rather than
|
|
198
187
|
// stylistic. `assertNarrowing` refuses regardless of approval, so with the old order this returned
|
|
@@ -203,10 +192,14 @@ export function planDelegation(request, ctx) {
|
|
|
203
192
|
assertNarrowing(result);
|
|
204
193
|
}
|
|
205
194
|
catch (error) {
|
|
206
|
-
|
|
195
|
+
// ADR-0011's narrowing invariant is the hardest rule this package enforces, and it was the one
|
|
196
|
+
// refusal an external controller could not identify by code (R-109).
|
|
197
|
+
return denied({ ...empty, requested, result, reason: String(error instanceof Error ? error.message : error) }, "NARROWING_VIOLATED");
|
|
207
198
|
}
|
|
208
199
|
if (result.gatedBlocked.length > 0) {
|
|
209
|
-
|
|
200
|
+
const code = bindingMismatch ? "APPROVAL_SCOPE_MISMATCH" : "GATED_UNAPPROVED";
|
|
201
|
+
const suffix = bindingMismatch ? " (an approval exists, but its task/workspace/context scope does not match)" : "";
|
|
202
|
+
return denied({ ...empty, requested, result, reason: `${result.gatedBlocked.join(", ")} requires explicit approval${suffix}` }, code);
|
|
210
203
|
}
|
|
211
204
|
const canSubDelegate = result.effective.includes(DELEGATE_CAPABILITY);
|
|
212
205
|
const plan = planSpawn({
|
|
@@ -226,13 +219,13 @@ export function planDelegation(request, ctx) {
|
|
|
226
219
|
// not contain. `unknownCapabilities` above catches names absent from the catalog entirely; this
|
|
227
220
|
// catches one that is known but whose path we could not resolve, which is a different fault.
|
|
228
221
|
if (plan.unresolvedSkills.length > 0) {
|
|
229
|
-
return {
|
|
222
|
+
return denied({
|
|
230
223
|
...empty,
|
|
231
224
|
requested,
|
|
232
225
|
result,
|
|
233
226
|
reason: `cannot locate ${plan.unresolvedSkills.join(", ")} on disk — granted but unresolvable, so the ` +
|
|
234
227
|
`child would silently lack it`,
|
|
235
|
-
};
|
|
228
|
+
}, "DEFINITION_UNREADABLE");
|
|
236
229
|
}
|
|
237
230
|
// A child may only delegate further if it was granted the capability AND has the extension to do it.
|
|
238
231
|
const args = [...plan.args];
|
|
@@ -271,6 +264,9 @@ export function planDelegation(request, ctx) {
|
|
|
271
264
|
childDepth,
|
|
272
265
|
requested,
|
|
273
266
|
childId: ctx.childSpawnId,
|
|
267
|
+
taskDigest,
|
|
268
|
+
...(correlation ? { correlation } : {}),
|
|
269
|
+
...(approvalBinding ? { approvalBinding } : {}),
|
|
274
270
|
...(definitionDigest ? { definitionDigest } : {}),
|
|
275
271
|
};
|
|
276
272
|
}
|
package/dist/delegate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../src/delegate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"delegate.js","sourceRoot":"","sources":["../src/delegate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAA+C,MAAM,kBAAkB,CAAC;AACvH,OAAO,EAAE,eAAe,EAAuC,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAElH,4GAA4G;AAC5G,0GAA0G;AAC1G,+DAA+D;AAC/D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAClH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,UA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AK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/D,+FAA+F;IAC/F,qGAAqG;IACrG,mGAAmG;IACnG,oFAAoF;IACpF,GAAG,CAAC,YAAY,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrF,IAAI,GAAG,CAAC,UAAU;QAAE,GAAG,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC;IAErD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,IAAI;QACJ,GAAG;QACH,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,MAAM;QACN,UAAU;QACV,SAAS;QACT,OAAO,EAAE,GAAG,CAAC,YAAY;QACzB,UAAU;QACV,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/C,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type InheritableApproval } from "./approval.ts";
|
|
2
|
+
import { type ApprovalBinding, type CorrelationMetadata } from "./correlation.ts";
|
|
3
|
+
import type { DefinitionDigest, SkillDefinition } from "./definitions.ts";
|
|
4
|
+
import { type Capability, type ResolveResult } from "./resolve.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the approval half of one delegation after its requested capability set is known.
|
|
7
|
+
*
|
|
8
|
+
* Kept as one function because the ordering is security-relevant: compute the unapproved and potential
|
|
9
|
+
* effective sets first, derive the exact binding from those trusted values, then decide which approvals
|
|
10
|
+
* match. An approval must never define the scope against which it is checked.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveDelegationApproval(input: {
|
|
13
|
+
task: string;
|
|
14
|
+
agent?: string;
|
|
15
|
+
requested: Capability[];
|
|
16
|
+
parentGrant: Capability[];
|
|
17
|
+
gated: Capability[];
|
|
18
|
+
approved?: InheritableApproval[];
|
|
19
|
+
spawned?: SkillDefinition;
|
|
20
|
+
definitionDigest?: DefinitionDigest;
|
|
21
|
+
/**
|
|
22
|
+
* Present iff this call is task-bound. Its VALUES never enter the binding — only its presence selects
|
|
23
|
+
* the exact-bound regime over the legacy subject-scoped one.
|
|
24
|
+
*/
|
|
25
|
+
correlation?: CorrelationMetadata;
|
|
26
|
+
/** Trusted: an id that was resolved against the operator registry and leased. Never a caller claim. */
|
|
27
|
+
boundWorkspaceId?: string;
|
|
28
|
+
/** Caller-declared label. Narrows the binding only; asserts nothing about enforcement. */
|
|
29
|
+
boundContextId?: string;
|
|
30
|
+
parentId: string;
|
|
31
|
+
}): {
|
|
32
|
+
result: ResolveResult;
|
|
33
|
+
approvalBinding?: ApprovalBinding;
|
|
34
|
+
bindingMismatch: boolean;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=delegation-approval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation-approval.d.ts","sourceRoot":"","sources":["../src/delegation-approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAA2B,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5F;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,UAAU,EAAE,CAAC;IACxB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACjC,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;OAGG;IACH,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,uGAAuG;IACvG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0FAA0F;IAC1F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,eAAe,CAAC,EAAE,eAAe,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CA6DzF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { DELEGATE_SUBJECT } from "./approval.js";
|
|
2
|
+
import { agentCapability } from "./capabilities.js";
|
|
3
|
+
import { approvalBindingsEqual, buildApprovalBinding, } from "./correlation.js";
|
|
4
|
+
import { AGENT_WILDCARD, resolve } from "./resolve.js";
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the approval half of one delegation after its requested capability set is known.
|
|
7
|
+
*
|
|
8
|
+
* Kept as one function because the ordering is security-relevant: compute the unapproved and potential
|
|
9
|
+
* effective sets first, derive the exact binding from those trusted values, then decide which approvals
|
|
10
|
+
* match. An approval must never define the scope against which it is checked.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveDelegationApproval(input) {
|
|
13
|
+
const subject = input.agent ?? DELEGATE_SUBJECT;
|
|
14
|
+
const unapproved = resolve({
|
|
15
|
+
requested: input.requested,
|
|
16
|
+
parentGrant: input.parentGrant,
|
|
17
|
+
gated: input.gated,
|
|
18
|
+
approved: [],
|
|
19
|
+
});
|
|
20
|
+
// ADR-0024: a definition's authorising id is gated as the PARENT's authority to run it now. It never
|
|
21
|
+
// joins requested/effective, because that would hand the child authority to recursively spawn itself.
|
|
22
|
+
let authorisingCapability;
|
|
23
|
+
if (input.spawned) {
|
|
24
|
+
const authorising = agentCapability(input.spawned.name);
|
|
25
|
+
if (input.gated.includes(authorising) || input.gated.includes(AGENT_WILDCARD)) {
|
|
26
|
+
authorisingCapability = authorising;
|
|
27
|
+
unapproved.gatedBlocked = [...unapproved.gatedBlocked, authorising];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const potential = resolve({
|
|
31
|
+
requested: input.requested,
|
|
32
|
+
parentGrant: input.parentGrant,
|
|
33
|
+
gated: input.gated,
|
|
34
|
+
// If the definition also declares its own authorising `agent:<name>`, the same approval unblocks
|
|
35
|
+
// that requested child capability too; excluding it here would bind a smaller set than we provision.
|
|
36
|
+
approved: unapproved.gatedBlocked,
|
|
37
|
+
});
|
|
38
|
+
const approvalBinding = input.correlation
|
|
39
|
+
? buildApprovalBinding({
|
|
40
|
+
task: input.task,
|
|
41
|
+
requested: input.requested,
|
|
42
|
+
effective: potential.effective,
|
|
43
|
+
definitionSha256: input.definitionDigest?.sha256,
|
|
44
|
+
parentId: input.parentId,
|
|
45
|
+
workspaceId: input.boundWorkspaceId,
|
|
46
|
+
contextId: input.boundContextId,
|
|
47
|
+
})
|
|
48
|
+
: undefined;
|
|
49
|
+
const forSubject = (input.approved ?? []).filter((approval) => approval.subject === subject);
|
|
50
|
+
const approvedCapabilities = forSubject
|
|
51
|
+
.filter((approval) => approvalBinding
|
|
52
|
+
? approvalBindingsEqual(approval.binding, approvalBinding)
|
|
53
|
+
: approval.binding === undefined)
|
|
54
|
+
.map((approval) => approval.capability);
|
|
55
|
+
const bindingMismatch = approvalBinding !== undefined && forSubject.some((approval) => approval.binding !== undefined && !approvalBindingsEqual(approval.binding, approvalBinding));
|
|
56
|
+
const result = resolve({
|
|
57
|
+
requested: input.requested,
|
|
58
|
+
parentGrant: input.parentGrant,
|
|
59
|
+
gated: input.gated,
|
|
60
|
+
approved: approvedCapabilities,
|
|
61
|
+
});
|
|
62
|
+
if (authorisingCapability && !approvedCapabilities.includes(authorisingCapability)) {
|
|
63
|
+
result.gatedBlocked = [...result.gatedBlocked, authorisingCapability];
|
|
64
|
+
}
|
|
65
|
+
return { result, ...(approvalBinding ? { approvalBinding } : {}), bindingMismatch };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=delegation-approval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation-approval.js","sourceRoot":"","sources":["../src/delegation-approval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA4B,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GAGrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,OAAO,EAAuC,MAAM,cAAc,CAAC;AAE5F;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAmBzC;IACC,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,IAAI,gBAAgB,CAAC;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC;QACzB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,EAAE;KACb,CAAC,CAAC;IAEH,qGAAqG;IACrG,sGAAsG;IACtG,IAAI,qBAA6C,CAAC;IAClD,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACxD,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAA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eAAe,GAAG,eAAe,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,CACtE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,CAC1G,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,CAAC;QACrB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,oBAAoB;KAC/B,CAAC,CAAC;IACH,IAAI,qBAAqB,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACnF,MAAM,CAAC,YAAY,GAAG,CAAC,GAAG,MAAM,CAAC,YAAY,EAAE,qBAAqB,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,eAAe,EAAE,CAAC;AACtF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ValidatedWorkspace } from "./workspace.ts";
|
|
2
|
+
export interface GitCandidateIdentity {
|
|
3
|
+
headSha: string;
|
|
4
|
+
treeSha: string;
|
|
5
|
+
}
|
|
6
|
+
/** Compute HEAD plus NON-IGNORED tracked/untracked candidate content without changing the real index.
|
|
7
|
+
*
|
|
8
|
+
* NOT the exact working tree: `git add -A` honours `.gitignore`, `core.excludesFile` and
|
|
9
|
+
* `$GIT_DIR/info/exclude`, and records only a gitlink for a submodule. And it is not read-only — it writes
|
|
10
|
+
* blob objects into the real `.git/objects`. `docs/SPEC.md` retracted the word "exact"; this comment said
|
|
11
|
+
* it for one more round. */
|
|
12
|
+
export declare function computeGitCandidateIdentity(workspace: ValidatedWorkspace): Promise<GitCandidateIdentity>;
|
|
13
|
+
//# sourceMappingURL=git-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-identity.d.ts","sourceRoot":"","sources":["../src/git-identity.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAIzD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;4BAK4B;AAC5B,wBAAsB,2BAA2B,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8B9G"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { GovernanceRefusal, refusal } from "./refusals.js";
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
/** Compute HEAD plus NON-IGNORED tracked/untracked candidate content without changing the real index.
|
|
9
|
+
*
|
|
10
|
+
* NOT the exact working tree: `git add -A` honours `.gitignore`, `core.excludesFile` and
|
|
11
|
+
* `$GIT_DIR/info/exclude`, and records only a gitlink for a submodule. And it is not read-only — it writes
|
|
12
|
+
* blob objects into the real `.git/objects`. `docs/SPEC.md` retracted the word "exact"; this comment said
|
|
13
|
+
* it for one more round. */
|
|
14
|
+
export async function computeGitCandidateIdentity(workspace) {
|
|
15
|
+
const dir = await mkdtemp(join(tmpdir(), "pi-daddy-index-"));
|
|
16
|
+
const index = join(dir, "index");
|
|
17
|
+
const env = {
|
|
18
|
+
PATH: process.env.PATH,
|
|
19
|
+
HOME: process.env.HOME,
|
|
20
|
+
LANG: process.env.LANG,
|
|
21
|
+
LC_ALL: process.env.LC_ALL,
|
|
22
|
+
TMPDIR: process.env.TMPDIR,
|
|
23
|
+
GIT_INDEX_FILE: index,
|
|
24
|
+
};
|
|
25
|
+
const git = async (args) => (await execFileAsync("git", ["-C", workspace.root, ...args], {
|
|
26
|
+
env, encoding: "utf8", maxBuffer: 16 * 1024 * 1024,
|
|
27
|
+
})).stdout.trim();
|
|
28
|
+
try {
|
|
29
|
+
const headSha = await git(["rev-parse", "HEAD"]);
|
|
30
|
+
await git(["read-tree", "HEAD"]);
|
|
31
|
+
await git(["add", "-A"]);
|
|
32
|
+
const treeSha = await git(["write-tree"]);
|
|
33
|
+
if (!/^[a-f0-9]{40,64}$/i.test(headSha) || !/^[a-f0-9]{40,64}$/i.test(treeSha))
|
|
34
|
+
throw new Error("Git returned an invalid object id");
|
|
35
|
+
return { headSha, treeSha };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
throw new GovernanceRefusal(refusal("CHECK_IDENTITY_UNAVAILABLE", `could not compute exact Git head/candidate-tree identity for workspace ${workspace.workspaceId} (${String(error)})`, { workspace_id: workspace.workspaceId }));
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
await rm(dir, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=git-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-identity.js","sourceRoot":"","sources":["../src/git-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG3D,MAAM,aAAa,GAAG,SAAS,CAAC,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AI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACrI,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,iBAAiB,CAAC,OAAO,CACjC,4BAA4B,EAC5B,0EAA0E,SAAS,CAAC,WAAW,KAAK,MAAM,CAAC,KAAK,CAAC,GAAG,EACpH,EAAE,YAAY,EAAE,SAAS,CAAC,WAAW,EAAE,CACxC,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { resolve, assertNarrowing, toPiToolsAllowlist, UNIVERSAL_CAPABILITIES, type Capability, type ResolveInput, type ResolveResult, } from "./resolve.ts";
|
|
2
|
-
export { appendRecord, buildRecord, isEscalationAttempt, type GrantRecord, type LedgerOptions, } from "./ledger.ts";
|
|
2
|
+
export { appendLedgerEvent, appendRecord, buildChildLifecycleEvent, buildRecord, buildWorkspaceLeaseEvent, isEscalationAttempt, LEDGER_VERSION, type CheckReceiptLedgerEvent, type ChildLifecycleEvent, type GrantRecord, type LedgerOptions, type RuntimeLedgerEvent, type WorkspaceLeaseEvent, type WorkspaceLeaseOutcome, } from "./ledger.ts";
|
|
3
3
|
export { planSpawn, type SpawnPlan, type SpawnPlanInput } from "./spawn.ts";
|
|
4
4
|
export { APPROVAL_TTL_DAYS, DELEGATE_SUBJECT, approvalKey, entryVerdict, expiryFor, inheritApprovals, offeredScopes, resolveApprovals, shouldSeekApproval, type ApprovalEntry, type ApprovalPath, type ApprovalScope, type ApprovalSource, type EntryVerdict, type SubjectSnapshot, } from "./approval.ts";
|
|
5
5
|
export { approvalsPath, loadApprovals, revokeAll, revokeApproval, saveApproval, type DroppedApproval, type SubjectLookup, } from "./approval-store.ts";
|
|
6
|
+
export { approvalBindingDigest, approvalBindingsEqual, buildApprovalBinding, digestCapabilities, digestTask, isApprovalBinding, normaliseCorrelation, type ApprovalBinding, type CorrelationMetadata, type JsonValue, } from "./correlation.ts";
|
|
7
|
+
export { GovernanceRefusal, REFUSAL_CODES, refusal, type RefusalCode, type StructuredRefusal, } from "./refusals.ts";
|
|
8
|
+
export { acquireWorkspaceLease, defaultWorkspaceLeaseDir, loadWorkspaceRegistry, resolveWorkspace, validateRegisteredWorkspace, type ValidatedWorkspace, type WorkspaceAccess, type WorkspaceLease, type WorkspaceRegistryFile, } from "./workspace.ts";
|
|
9
|
+
export { buildCheckEnvironment, runNamedCheck, type CheckDefinition, type CheckReceipt, type CheckRegistry, } from "./check-runner.ts";
|
|
6
10
|
export { createApprovalGate, createApprovalGateProvider, timeoutMsFromEnv, type ApprovalGate, type InFlightApprovals, type ApprovalUI, type PromptOutcome, type PromptOutcomeKind, type PromptRequest, } from "./approval-prompt.ts";
|
|
7
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,KAAK,WAAW,EAChB,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,UAAU,EACf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AAK,cAAc,EACnB,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { resolve, assertNarrowing, toPiToolsAllowlist, UNIVERSAL_CAPABILITIES, } from "./resolve.js";
|
|
2
|
-
export { appendRecord, buildRecord, isEscalationAttempt, } from "./ledger.js";
|
|
2
|
+
export { appendLedgerEvent, appendRecord, buildChildLifecycleEvent, buildRecord, buildWorkspaceLeaseEvent, isEscalationAttempt, LEDGER_VERSION, } from "./ledger.js";
|
|
3
3
|
export { planSpawn } from "./spawn.js";
|
|
4
4
|
export { APPROVAL_TTL_DAYS, DELEGATE_SUBJECT, approvalKey, entryVerdict, expiryFor, inheritApprovals, offeredScopes, resolveApprovals, shouldSeekApproval, } from "./approval.js";
|
|
5
5
|
export { approvalsPath, loadApprovals, revokeAll, revokeApproval, saveApproval, } from "./approval-store.js";
|
|
6
|
+
export { approvalBindingDigest, approvalBindingsEqual, buildApprovalBinding, digestCapabilities, digestTask, isApprovalBinding, normaliseCorrelation, } from "./correlation.js";
|
|
7
|
+
export { GovernanceRefusal, REFUSAL_CODES, refusal, } from "./refusals.js";
|
|
8
|
+
export { acquireWorkspaceLease, defaultWorkspaceLeaseDir, loadWorkspaceRegistry, resolveWorkspace, validateRegisteredWorkspace, } from "./workspace.js";
|
|
9
|
+
export { buildCheckEnvironment, runNamedCheck, } from "./check-runner.js";
|
|
6
10
|
export { createApprovalGate, createApprovalGateProvider, timeoutMsFromEnv, } from "./approval-prompt.js";
|
|
7
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,sBAAsB,GAIvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,YAAY,EACZ,WAAW,EACX,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,eAAe,EACf,kBAAkB,EAClB,sBAAsB,GAIvB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,wBAAwB,EACxB,WAAW,EACX,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,GAQf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,SAAS,EAAuC,MAAM,YAAY,CAAC;AAE5E,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,GAOnB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,aAAa,EACb,aAAa,EACb,SAAS,EACT,cAAc,EACd,YAAY,GAGb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EACjB,oBAAoB,GAIrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,OAAO,GAGR,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,2BAA2B,GAK5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,qBAAqB,EACrB,aAAa,GAId,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,gBAAgB,GAOjB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ValidatedWorkspace, WorkspaceAccess } from "./workspace.ts";
|
|
2
|
+
export interface LeaseMetadata {
|
|
3
|
+
version: 1;
|
|
4
|
+
state: "active" | "released";
|
|
5
|
+
token: string;
|
|
6
|
+
owner_id: string;
|
|
7
|
+
workspace_id: string;
|
|
8
|
+
root: string;
|
|
9
|
+
pid: number;
|
|
10
|
+
acquired_at: string;
|
|
11
|
+
released_at?: string;
|
|
12
|
+
release_reason?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkspaceLease {
|
|
15
|
+
workspace: ValidatedWorkspace;
|
|
16
|
+
access: WorkspaceAccess;
|
|
17
|
+
ownerId: string;
|
|
18
|
+
/**
|
|
19
|
+
* `true` only when the kernel lock was free but metadata said the prior owner never released.
|
|
20
|
+
* `"unknown"` when the prior owner's record could not be read at all — that is not evidence of a
|
|
21
|
+
* clean handover and must not be recorded as one (R-100).
|
|
22
|
+
*/
|
|
23
|
+
recovered: boolean | "unknown";
|
|
24
|
+
/** Attach the governed resource so parent death cleans it before the kernel lock is released. */
|
|
25
|
+
attachProcess(pid: number): void;
|
|
26
|
+
attachHerdrTab(tabId: string): void;
|
|
27
|
+
/** Resolves only when the kernel-lock helper exits before explicit release. */
|
|
28
|
+
lost: Promise<Error>;
|
|
29
|
+
/**
|
|
30
|
+
* NEVER throws. A cleanup function that can throw destroys its caller's return value — a completed
|
|
31
|
+
* child's entire output was discarded this way (R-99) — so the outcome is a VALUE the caller records:
|
|
32
|
+
* `"released"` the kernel lock was handed back and the handover recorded;
|
|
33
|
+
* `"released-unrecorded"` the lock was handed back but the record failed, so the NEXT owner will
|
|
34
|
+
* report a recovery that did not happen unless this is ledgered;
|
|
35
|
+
* `"lost"` the helper was already gone, so this owner never released anything.
|
|
36
|
+
*/
|
|
37
|
+
release(reason?: string): Promise<LeaseReleaseOutcome>;
|
|
38
|
+
/**
|
|
39
|
+
* Record that this lease is being kept deliberately, WITHOUT releasing the kernel lock.
|
|
40
|
+
*
|
|
41
|
+
* Needed because a retained lease never calls `release()`, so the metadata stays `state: "active"` and
|
|
42
|
+
* whoever acquires next reports `recovered: true` — blaming a crash on a known-good path.
|
|
43
|
+
*/
|
|
44
|
+
markRetained(reason?: string): Promise<void>;
|
|
45
|
+
/** Reads the give-up marker the helper leaves when it could not close a herdr writer tab. */
|
|
46
|
+
readCloseFailure(): Promise<{
|
|
47
|
+
reason: string;
|
|
48
|
+
herdr_tab?: string;
|
|
49
|
+
} | null>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* What a release actually did. Five members rather than three, because the first version conflated facts
|
|
53
|
+
* that call for different responses — and one of them is an alarm:
|
|
54
|
+
* `released` the lock went back and THIS owner wrote its own handover;
|
|
55
|
+
* `released-unrecorded` the lock went back and the record does not say so, so the next owner will report
|
|
56
|
+
* a recovery that never happened unless the caller ledgers this. **The alarm.**
|
|
57
|
+
* `released-superseded` the lock went back and a successor already owns the metadata, so we correctly
|
|
58
|
+
* declined to overwrite it. Healthy, and previously indistinguishable from the
|
|
59
|
+
* alarm above;
|
|
60
|
+
* `not-held` a read lease, which never took a kernel lock — recording it as `released`
|
|
61
|
+
* overstated how many handovers the kernel performed, which is R-105 on the
|
|
62
|
+
* release side of the same defect;
|
|
63
|
+
* `lost` the helper was already gone; this owner released nothing.
|
|
64
|
+
*/
|
|
65
|
+
export type LeaseReleaseOutcome = "released" | "released-unrecorded" | "released-superseded" | "not-held" | "lost";
|
|
66
|
+
export declare function leasePaths(leaseDir: string, root: string): {
|
|
67
|
+
lock: string;
|
|
68
|
+
metadata: string;
|
|
69
|
+
marker: string;
|
|
70
|
+
};
|
|
71
|
+
export declare function atomicMetadata(path: string, value: LeaseMetadata): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* `null` means no prior owner was recorded. `"malformed"` means a record exists and cannot be read,
|
|
74
|
+
* which is strictly LESS evidence than a readable "active" one and must never read as a clean handover
|
|
75
|
+
* (R-100). Absent and unreadable are different facts; conflating them silently erases a real recovery.
|
|
76
|
+
*/
|
|
77
|
+
export declare function readMetadata(path: string): Promise<LeaseMetadata | null | "malformed">;
|
|
78
|
+
//# sourceMappingURL=lease-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lease-record.d.ts","sourceRoot":"","sources":["../src/lease-record.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE1E,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,iGAAiG;IACjG,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,+EAA+E;IAC/E,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACrB;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,CAAC,EAAE,MA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