pi-daddy 0.49.5 → 0.51.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 +57 -1
- package/README.md +231 -27
- package/dist/governance/initiative-coordinator.d.ts +63 -0
- package/dist/governance/initiative-coordinator.d.ts.map +1 -0
- package/dist/governance/initiative-coordinator.js +364 -0
- package/dist/governance/initiative-coordinator.js.map +1 -0
- package/dist/governance/initiative-effects.d.ts +20 -0
- package/dist/governance/initiative-effects.d.ts.map +1 -0
- package/dist/governance/initiative-effects.js +108 -0
- package/dist/governance/initiative-effects.js.map +1 -0
- package/dist/governance/initiative-state.d.ts +13 -0
- package/dist/governance/initiative-state.d.ts.map +1 -0
- package/dist/governance/initiative-state.js +122 -0
- package/dist/governance/initiative-state.js.map +1 -0
- package/dist/governance/operation-artifact-io.d.ts +8 -0
- package/dist/governance/operation-artifact-io.d.ts.map +1 -0
- package/dist/governance/operation-artifact-io.js +95 -0
- package/dist/governance/operation-artifact-io.js.map +1 -0
- package/dist/governance/operation-artifact-scan.d.ts +13 -0
- package/dist/governance/operation-artifact-scan.d.ts.map +1 -0
- package/dist/governance/operation-artifact-scan.js +71 -0
- package/dist/governance/operation-artifact-scan.js.map +1 -0
- package/dist/governance/operation-artifacts.d.ts +53 -0
- package/dist/governance/operation-artifacts.d.ts.map +1 -0
- package/dist/governance/operation-artifacts.js +309 -0
- package/dist/governance/operation-artifacts.js.map +1 -0
- package/dist/governance/runtime-settlement.d.ts +2 -0
- package/dist/governance/runtime-settlement.d.ts.map +1 -1
- package/dist/governance/runtime-settlement.js +26 -0
- package/dist/governance/runtime-settlement.js.map +1 -1
- package/dist/governance/workspace-acceptance.d.ts +5 -0
- package/dist/governance/workspace-acceptance.d.ts.map +1 -1
- package/dist/governance/workspace-acceptance.js +16 -0
- package/dist/governance/workspace-acceptance.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/kernel/dashboard-observation.d.ts +76 -0
- package/dist/kernel/dashboard-observation.d.ts.map +1 -0
- package/dist/kernel/dashboard-observation.js +49 -0
- package/dist/kernel/dashboard-observation.js.map +1 -0
- package/dist/kernel/dispatch-operation.d.ts +2 -0
- package/dist/kernel/dispatch-operation.d.ts.map +1 -1
- package/dist/kernel/dispatch-operation.js.map +1 -1
- package/dist/kernel/initiative.d.ts +94 -0
- package/dist/kernel/initiative.d.ts.map +1 -0
- package/dist/kernel/initiative.js +38 -0
- package/dist/kernel/initiative.js.map +1 -0
- package/dist/kernel/operation-artifact.d.ts +49 -0
- package/dist/kernel/operation-artifact.d.ts.map +1 -0
- package/dist/kernel/operation-artifact.js +4 -0
- package/dist/kernel/operation-artifact.js.map +1 -0
- package/dist/kernel/principal-binding.d.ts +4 -0
- package/dist/kernel/principal-binding.d.ts.map +1 -0
- package/dist/kernel/principal-binding.js +94 -0
- package/dist/kernel/principal-binding.js.map +1 -0
- package/dist/kernel/project-paths.d.ts +6 -0
- package/dist/kernel/project-paths.d.ts.map +1 -1
- package/dist/kernel/project-paths.js +12 -0
- package/dist/kernel/project-paths.js.map +1 -1
- package/dist/kernel/selected-definitions.d.ts.map +1 -1
- package/dist/kernel/selected-definitions.js +5 -91
- package/dist/kernel/selected-definitions.js.map +1 -1
- package/dist/kernel/workspace-diagnostics.d.ts +24 -0
- package/dist/kernel/workspace-diagnostics.d.ts.map +1 -0
- package/dist/kernel/workspace-diagnostics.js +81 -0
- package/dist/kernel/workspace-diagnostics.js.map +1 -0
- package/dist/products/activity-storage.d.ts +2 -0
- package/dist/products/activity-storage.d.ts.map +1 -0
- package/dist/products/activity-storage.js +119 -0
- package/dist/products/activity-storage.js.map +1 -0
- package/dist/products/activity-timeline.d.ts +4 -0
- package/dist/products/activity-timeline.d.ts.map +1 -1
- package/dist/products/activity-timeline.js +12 -0
- package/dist/products/activity-timeline.js.map +1 -1
- package/dist/products/dashboard-cli.d.ts +2 -0
- package/dist/products/dashboard-cli.d.ts.map +1 -1
- package/dist/products/dashboard-cli.js +50 -10
- package/dist/products/dashboard-cli.js.map +1 -1
- package/dist/products/dashboard-display-controls.d.ts.map +1 -1
- package/dist/products/dashboard-display-controls.js +72 -2
- package/dist/products/dashboard-display-controls.js.map +1 -1
- package/dist/products/dashboard-file-cache.d.ts +10 -0
- package/dist/products/dashboard-file-cache.d.ts.map +1 -0
- package/dist/products/dashboard-file-cache.js +38 -0
- package/dist/products/dashboard-file-cache.js.map +1 -0
- package/dist/products/dashboard-layout.d.ts +6 -0
- package/dist/products/dashboard-layout.d.ts.map +1 -0
- package/dist/products/dashboard-layout.js +45 -0
- package/dist/products/dashboard-layout.js.map +1 -0
- package/dist/products/dashboard-panels.d.ts +10 -0
- package/dist/products/dashboard-panels.d.ts.map +1 -0
- package/dist/products/dashboard-panels.js +319 -0
- package/dist/products/dashboard-panels.js.map +1 -0
- package/dist/products/dashboard-recap.d.ts +4 -0
- package/dist/products/dashboard-recap.d.ts.map +1 -0
- package/dist/products/dashboard-recap.js +47 -0
- package/dist/products/dashboard-recap.js.map +1 -0
- package/dist/products/dashboard-screen.d.ts +14 -1
- package/dist/products/dashboard-screen.d.ts.map +1 -1
- package/dist/products/dashboard-screen.js +217 -40
- package/dist/products/dashboard-screen.js.map +1 -1
- package/dist/products/dashboard-session-client.d.ts +16 -2
- package/dist/products/dashboard-session-client.d.ts.map +1 -1
- package/dist/products/dashboard-session-client.js +64 -11
- package/dist/products/dashboard-session-client.js.map +1 -1
- package/dist/products/dashboard-settings.d.ts.map +1 -1
- package/dist/products/dashboard-settings.js +4 -6
- package/dist/products/dashboard-settings.js.map +1 -1
- package/dist/products/ecosystem-versions.d.ts +1 -1
- package/dist/products/ecosystem-versions.d.ts.map +1 -1
- package/extensions/activity-timeline.ts +3 -1
- package/extensions/artifact-bridge.ts +130 -0
- package/extensions/dashboard-live.ts +63 -0
- package/extensions/dashboard-observation.ts +39 -0
- package/extensions/dashboard-session-server.ts +45 -3
- package/extensions/dashboard-sources.ts +124 -0
- package/extensions/delegation-artifacts.ts +133 -0
- package/extensions/delegation-operations.ts +42 -13
- package/extensions/ecosystem-versions.ts +12 -5
- package/extensions/grants-command.ts +34 -6
- package/extensions/grants.ts +9 -20
- package/extensions/initiative-dashboard.ts +143 -0
- package/extensions/initiative-handoff.ts +59 -0
- package/extensions/initiative-runtime.ts +444 -0
- package/extensions/runtime-snapshot.ts +118 -2
- package/extensions/session-environment.ts +13 -1
- package/extensions/session.ts +28 -10
- package/extensions/workspace-diagnostics.ts +90 -0
- package/package.json +1 -1
- package/src/governance/initiative-coordinator.ts +416 -0
- package/src/governance/initiative-effects.ts +146 -0
- package/src/governance/initiative-state.ts +144 -0
- package/src/governance/operation-artifact-io.ts +103 -0
- package/src/governance/operation-artifact-scan.ts +77 -0
- package/src/governance/operation-artifacts.ts +363 -0
- package/src/governance/runtime-settlement.ts +28 -0
- package/src/governance/workspace-acceptance.ts +18 -0
- package/src/index.ts +13 -0
- package/src/kernel/dashboard-observation.ts +109 -0
- package/src/kernel/dispatch-operation.ts +2 -0
- package/src/kernel/initiative.ts +126 -0
- package/src/kernel/operation-artifact.ts +46 -0
- package/src/kernel/principal-binding.ts +104 -0
- package/src/kernel/project-paths.ts +16 -0
- package/src/kernel/selected-definitions.ts +5 -100
- package/src/kernel/workspace-diagnostics.ts +110 -0
- package/src/products/activity-storage.ts +128 -0
- package/src/products/activity-timeline.ts +11 -0
- package/src/products/dashboard-cli.ts +53 -10
- package/src/products/dashboard-display-controls.ts +63 -2
- package/src/products/dashboard-file-cache.ts +38 -0
- package/src/products/dashboard-layout.ts +50 -0
- package/src/products/dashboard-panels.ts +379 -0
- package/src/products/dashboard-recap.ts +48 -0
- package/src/products/dashboard-screen.ts +266 -43
- package/src/products/dashboard-session-client.ts +78 -14
- package/src/products/dashboard-settings.ts +4 -6
- package/src/products/ecosystem-versions.ts +2 -1
package/extensions/session.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { InitiativeOperationBinding } from "./initiative-runtime.ts";
|
|
2
|
+
import type { DashboardSourceSnapshot, DashboardContribution } from "../src/kernel/dashboard-observation.ts";
|
|
3
|
+
import type { OperationArtifactRef } from "../src/kernel/operation-artifact.ts";
|
|
4
|
+
import type { DashboardOwnerObservation } from "../src/kernel/dashboard-observation.ts";
|
|
1
5
|
import type { EcosystemVersions } from "../src/products/ecosystem-versions.ts";
|
|
2
6
|
import type { AutoModeReader } from "../src/kernel/auto-mode.ts";
|
|
3
7
|
/**
|
|
@@ -143,7 +147,13 @@ export function activityChildEnv(activity: { rootId: string; path: string; taskI
|
|
|
143
147
|
}
|
|
144
148
|
/** Keep each child's pane after it finishes, for inspection. Off by default: fan-out would flood it. */
|
|
145
149
|
export interface GrantsSession extends NativeSessionHost {
|
|
150
|
+
initiativeOperations?: InitiativeOperationBinding;
|
|
151
|
+
dashboardInitiative?: () => DashboardSourceSnapshot | undefined;
|
|
152
|
+
refreshInitiative?: () => void;
|
|
146
153
|
ecosystemVersions?: () => EcosystemVersions;
|
|
154
|
+
dashboardLive?: () => { turn?: DashboardContribution; activity: DashboardContribution[] };
|
|
155
|
+
dashboardArtifacts?: OperationArtifactRef[];
|
|
156
|
+
dashboardObservations?: () => Omit<DashboardOwnerObservation, "version" | "resources" | "capture"> | undefined;
|
|
147
157
|
autoMode?: AutoModeReader;
|
|
148
158
|
autoModeFailure?: string;
|
|
149
159
|
/** Reconciled from the actual owner root on reload; captured call owners stay immutable. */
|
|
@@ -193,7 +203,7 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
193
203
|
/** Results from pi's synchronous model catalogue, shared by every delegation in this session. */
|
|
194
204
|
readonly modelResolutionCache: Map<string, boolean>;
|
|
195
205
|
/** Committed per-definition and global child runtime defaults. */
|
|
196
|
-
|
|
206
|
+
definitionRuntimeSettings: DefinitionRuntimeSettings;
|
|
197
207
|
/** PD-7's future session controls write here; deliberately empty in this commit. */
|
|
198
208
|
currentThinking?: () => string;
|
|
199
209
|
readonly definitionRuntimeOverrides: Map<string, DefinitionRuntimeChoice>;
|
|
@@ -295,11 +305,10 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
295
305
|
* prompted the human. A value scoped to one specific child is never written to this global channel.
|
|
296
306
|
*/
|
|
297
307
|
publishChildEnv(): void;
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
readonly storeCwd: string;
|
|
308
|
+
/** Exact selected directory whose stored grant was read; provisional process.cwd() before owner binding. */
|
|
309
|
+
storeCwd: string;
|
|
310
|
+
/** Observed provenance only. Explicit/inherited environment always takes precedence over a root store. */
|
|
311
|
+
grantSource?: "environment" | "stored" | "default" | "invalid-store" | "missing-inherited" | "operator-init";
|
|
303
312
|
/** Invalid stored state fails closed and is reported/ledgered during session_start. */
|
|
304
313
|
grantStoreRefusal?: { reason: GrantStoreRefusalReason; path: string };
|
|
305
314
|
/**
|
|
@@ -314,7 +323,7 @@ export interface GrantsSession extends NativeSessionHost {
|
|
|
314
323
|
* widen its own session's ceiling by calling something.
|
|
315
324
|
*/
|
|
316
325
|
adoptGrant(grant: Capability[], projectLedger?: string): void;
|
|
317
|
-
reconcileEnvironment(environment: NodeJS.ProcessEnv, lifecycle: ReloadLifecycle): void;
|
|
326
|
+
reconcileEnvironment(environment: NodeJS.ProcessEnv, lifecycle: ReloadLifecycle, cwd?: string): void;
|
|
318
327
|
}
|
|
319
328
|
/**
|
|
320
329
|
* Parse the environment once and build the session every other module reads through.
|
|
@@ -578,10 +587,11 @@ export function createGrantsSession(
|
|
|
578
587
|
// Local governance is on unless PI_DADDY_GOVERNANCE opts out; explicit inherited grants still win.
|
|
579
588
|
// The factory precedes ctx, so its cwd/store identity is reconciled at session_start.
|
|
580
589
|
const grantRaw = environment[ENV_GRANT];
|
|
590
|
+
const bounds = depthConfig(environment[ENV_DEPTH], environment[ENV_MAX_DEPTH]);
|
|
581
591
|
const storeCwd = process.cwd();
|
|
582
592
|
// One root-only store read supplies both decisions made by `/grants init`. A child always has ENV_GRANT,
|
|
583
593
|
// so it cannot activate a ledger merely because its routed cwd happens to have a v2 store (ADR-0037).
|
|
584
|
-
const storedState = storedGrantSessionState(grantRaw, storeCwd);
|
|
594
|
+
const storedState = storedGrantSessionState(grantRaw ?? (bounds.depth > 0 ? "" : undefined), storeCwd);
|
|
585
595
|
const governanceOff = environment[ENV_GOVERNANCE]?.trim() === "off" || environment[ENV_GOVERNANCE]?.trim() === "0";
|
|
586
596
|
const governed = governanceOff ? false : true;
|
|
587
597
|
const inherited = governanceOff ? storedState.inherited : storedState.governed ? storedState.inherited : [WILDCARD];
|
|
@@ -593,7 +603,6 @@ export function createGrantsSession(
|
|
|
593
603
|
const storedLedger = storedState.defaultLedger;
|
|
594
604
|
// G7 / A-S4 + B-I4: strict, three-way parsing that fails CLOSED. A malformed bound used to yield
|
|
595
605
|
// `NaN`, and every comparison against `NaN` is false, so depth limiting switched itself off.
|
|
596
|
-
const bounds = depthConfig(environment[ENV_DEPTH], environment[ENV_MAX_DEPTH]);
|
|
597
606
|
const runtimeConfig = projectDefinitionRuntimeConfiguration(storeCwd);
|
|
598
607
|
const depth = bounds.depth;
|
|
599
608
|
const maxDepth = runtimeConfig.malformed ? 0 : bounds.maxDepth;
|
|
@@ -709,6 +718,8 @@ export function createGrantsSession(
|
|
|
709
718
|
// enforcer, which is the defect R-28 is named for.
|
|
710
719
|
session.governed = true;
|
|
711
720
|
session.ownGrant = grant;
|
|
721
|
+
session.grantSource = "operator-init";
|
|
722
|
+
session.storeCwd = session.cwd;
|
|
712
723
|
// An environment ledger remains the explicit answer. Otherwise init's v2 choice becomes live now,
|
|
713
724
|
// before publishChildEnv gives the same absolute path to descendants.
|
|
714
725
|
if (!session.ledgerFromEnvironment && projectLedger !== undefined) {
|
|
@@ -716,7 +727,9 @@ export function createGrantsSession(
|
|
|
716
727
|
}
|
|
717
728
|
session.publishChildEnv();
|
|
718
729
|
},
|
|
719
|
-
reconcileEnvironment: (environment, lifecycle) => {
|
|
730
|
+
reconcileEnvironment: (environment, lifecycle, cwd = session.cwd) => {
|
|
731
|
+
const runtimeConfig = projectDefinitionRuntimeConfiguration(cwd);
|
|
732
|
+
session.storeCwd = cwd;
|
|
720
733
|
const evidenceDirectory = environment[ENV_PUBLIC_EVIDENCE_DIR];
|
|
721
734
|
if (session.reloadLifecycle !== lifecycle || session.publicEvidence?.directory !== evidenceDirectory)
|
|
722
735
|
session.publicEvidence = createPublicEvidenceOwner(evidenceDirectory);
|
|
@@ -726,6 +739,11 @@ export function createGrantsSession(
|
|
|
726
739
|
session.discoveryCleanupFailure = lifecycle.discoveryCleanupFailure;
|
|
727
740
|
}
|
|
728
741
|
reconcileSessionEnvironment(session, environment, lifecycle);
|
|
742
|
+
session.definitionRuntimeSettings = runtimeConfig.settings;
|
|
743
|
+
if (runtimeConfig.malformed) {
|
|
744
|
+
session.maxDepth = 0;
|
|
745
|
+
session.malformedBounds.push(runtimeConfig.malformed);
|
|
746
|
+
}
|
|
729
747
|
},
|
|
730
748
|
publishChildEnv: () => {
|
|
731
749
|
const env = childEnv({
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** Explicit owner inspection, cached for display only. Never refresh authority or scan during a redraw. */
|
|
2
|
+
import { inspectWorkspaceRouting, type WorkspaceRoutingObservation } from "../src/kernel/workspace-diagnostics.ts";
|
|
3
|
+
import { loadWorkspaceRegistry, ENV_WORKSPACE_REGISTRY } from "../src/kernel/workspace.ts";
|
|
4
|
+
import { inspectAcceptedWorkspaces } from "../src/governance/workspace-acceptance.ts";
|
|
5
|
+
import type { DashboardSourceSnapshot } from "../src/kernel/dashboard-observation.ts";
|
|
6
|
+
import type { GrantsSession } from "./session.ts";
|
|
7
|
+
const cached = new WeakMap<GrantsSession, { lifecycle: object; signature: string; value: DashboardSourceSnapshot }>();
|
|
8
|
+
const signature = (s: GrantsSession) =>
|
|
9
|
+
JSON.stringify([
|
|
10
|
+
s.cwd,
|
|
11
|
+
s.storeCwd,
|
|
12
|
+
s.grantSource,
|
|
13
|
+
s.depth,
|
|
14
|
+
s.ownGrant,
|
|
15
|
+
[...(s.workspacePin ?? [])],
|
|
16
|
+
process.env[ENV_WORKSPACE_REGISTRY],
|
|
17
|
+
]);
|
|
18
|
+
const clip = (s: string) => s.replace(/[\x00-\x1f\x7f-\x9f]/g, " ").slice(0, 240);
|
|
19
|
+
export function workspaceDiagnosticSnapshot(session: GrantsSession): DashboardSourceSnapshot | undefined {
|
|
20
|
+
const prior = cached.get(session);
|
|
21
|
+
if (!prior || prior.lifecycle !== session.reloadLifecycle || prior.signature !== signature(session)) return undefined;
|
|
22
|
+
return structuredClone(prior.value);
|
|
23
|
+
}
|
|
24
|
+
export async function inspectSessionWorkspace(session: GrantsSession, workspaceId: string): Promise<string> {
|
|
25
|
+
const lifecycle = session.reloadLifecycle,
|
|
26
|
+
before = signature(session),
|
|
27
|
+
registryPath = process.env[ENV_WORKSPACE_REGISTRY];
|
|
28
|
+
const source = `Grant source: ${session.grantSource ?? "unobserved"}; selected store directory: ${session.storeCwd}`;
|
|
29
|
+
let lines: string[],
|
|
30
|
+
state: WorkspaceRoutingObservation["state"] = "unavailable";
|
|
31
|
+
try {
|
|
32
|
+
if (!session.ownerBound) throw Error("session owner is not bound");
|
|
33
|
+
if (!registryPath) throw Error(`${ENV_WORKSPACE_REGISTRY} is not configured`);
|
|
34
|
+
const registry = await loadWorkspaceRegistry(registryPath);
|
|
35
|
+
const acceptance = await inspectAcceptedWorkspaces(registryPath);
|
|
36
|
+
const result = await inspectWorkspaceRouting({
|
|
37
|
+
workspaceId,
|
|
38
|
+
registry,
|
|
39
|
+
accepted: acceptance.state === "recorded" ? acceptance.accepted.includes(workspaceId) : null,
|
|
40
|
+
ownGrant: [...session.ownGrant],
|
|
41
|
+
pins: session.workspacePin ? new Map(session.workspacePin) : undefined,
|
|
42
|
+
depth: session.depth,
|
|
43
|
+
});
|
|
44
|
+
state = result.state;
|
|
45
|
+
lines = [
|
|
46
|
+
`Workspace ${workspaceId}: ${state}`,
|
|
47
|
+
source,
|
|
48
|
+
`Registry: ${registryPath}`,
|
|
49
|
+
`Known acceptance: ${result.accepted === null ? acceptance.state : result.accepted ? "accepted" : "not in current accepted set"}; capability: ${result.capability}; pin: ${result.pin}`,
|
|
50
|
+
...(result.canonicalRoot ? [`Canonical root: ${result.canonicalRoot}`] : []),
|
|
51
|
+
result.reason,
|
|
52
|
+
result.recovery,
|
|
53
|
+
result.dispatchChecks,
|
|
54
|
+
];
|
|
55
|
+
} catch (error) {
|
|
56
|
+
lines = [
|
|
57
|
+
`Workspace ${workspaceId}: unavailable`,
|
|
58
|
+
source,
|
|
59
|
+
String(error),
|
|
60
|
+
"Correct the named configuration or unavailable source, then inspect again. No state was changed.",
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
if (session.reloadLifecycle !== lifecycle || signature(session) !== before)
|
|
64
|
+
throw Error("Workspace inspection owner or authority changed; inspect again.");
|
|
65
|
+
const previous = cached.get(session),
|
|
66
|
+
observedAt = new Date().toISOString();
|
|
67
|
+
cached.set(session, {
|
|
68
|
+
lifecycle,
|
|
69
|
+
signature: before,
|
|
70
|
+
value: {
|
|
71
|
+
producer: "workspace-routing",
|
|
72
|
+
producerVersion: "1",
|
|
73
|
+
generation: `workspace:${session.episodeId}`,
|
|
74
|
+
sequence: (previous?.value.sequence ?? -1) + 1,
|
|
75
|
+
observedAt,
|
|
76
|
+
staleAfterMs: 120_000,
|
|
77
|
+
availability: "observed",
|
|
78
|
+
items: [
|
|
79
|
+
{
|
|
80
|
+
id: "workspace-routing",
|
|
81
|
+
kind: "status",
|
|
82
|
+
label: clip(`Workspace ${workspaceId}: ${state}`),
|
|
83
|
+
state: state === "active" ? "observed" : "unavailable",
|
|
84
|
+
details: [clip(`Last explicit inspection: ${observedAt}`), clip(source), ...lines.slice(-3).map(clip)],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
return lines.join("\n");
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-daddy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Capability governance for pi sub-agents: spawn Agent Skills (SKILL.md) definitions whose allowed-tools becomes a grant that can only narrow going down a delegation tree, enforced by pi's own --tools allowlist, with an append-only ledger.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/** One coordinator per local initiative. Reuses OS-held ownership; ordinary dispatch still owns grants and writer leases. */
|
|
2
|
+
import { realpathSync, existsSync } from "node:fs";
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import type { OperationArtifactOwner } from "../kernel/operation-artifact.ts";
|
|
5
|
+
import type { OperationRequest } from "../kernel/dispatch-operation.ts";
|
|
6
|
+
import { validOperationId } from "../kernel/dispatch-operation.ts";
|
|
7
|
+
import {
|
|
8
|
+
validInitiativeTask,
|
|
9
|
+
sameEffectTarget,
|
|
10
|
+
type InitiativeTask,
|
|
11
|
+
type InitiativeTaskIdentity,
|
|
12
|
+
type InitiativeRecord,
|
|
13
|
+
type InitiativeObservation,
|
|
14
|
+
type InitiativeEffectReconciliation,
|
|
15
|
+
} from "../kernel/initiative.ts";
|
|
16
|
+
import {
|
|
17
|
+
effectCurrent,
|
|
18
|
+
assertTaskPriorSettled,
|
|
19
|
+
currentEffectReceipt,
|
|
20
|
+
receiptResolves,
|
|
21
|
+
effectObservation,
|
|
22
|
+
effectIdentity,
|
|
23
|
+
exactEffect,
|
|
24
|
+
settledInitiative,
|
|
25
|
+
type InitiativeResolution,
|
|
26
|
+
} from "./initiative-effects.ts";
|
|
27
|
+
import { lockRuntimeSettlement } from "./runtime-settlement-lock.ts";
|
|
28
|
+
import { publishArtifact } from "./operation-artifact-io.ts";
|
|
29
|
+
import { initiativeLocation, initiativeRevision, readInitiativeState, saveInitiative } from "./initiative-state.ts";
|
|
30
|
+
export interface InitiativeCoordinatorOptions extends InitiativeResolution {
|
|
31
|
+
assertAuthority(): void | Promise<void>;
|
|
32
|
+
/** Optional read permission for exact owner facts; never substitutes for mutation or task-readiness authority. */
|
|
33
|
+
assertObservationAuthority?(): void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export interface AcquireInitiative {
|
|
36
|
+
initiativeId: string;
|
|
37
|
+
owner: OperationArtifactOwner;
|
|
38
|
+
expectedRevision: string | null;
|
|
39
|
+
recoveryOnly?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export async function acquireInitiativeCoordinator(
|
|
42
|
+
directory: string,
|
|
43
|
+
request: AcquireInitiative,
|
|
44
|
+
options: InitiativeCoordinatorOptions,
|
|
45
|
+
) {
|
|
46
|
+
directory = realpathSync(directory);
|
|
47
|
+
request = {
|
|
48
|
+
initiativeId: request.initiativeId,
|
|
49
|
+
expectedRevision: request.expectedRevision,
|
|
50
|
+
recoveryOnly: request.recoveryOnly === true,
|
|
51
|
+
owner: { sessionId: request.owner.sessionId, cwd: request.owner.cwd },
|
|
52
|
+
};
|
|
53
|
+
if (
|
|
54
|
+
!request.owner.sessionId ||
|
|
55
|
+
request.owner.sessionId.length > 512 ||
|
|
56
|
+
request.owner.cwd !== realpathSync(request.owner.cwd)
|
|
57
|
+
)
|
|
58
|
+
throw Error("initiative owner identity unavailable");
|
|
59
|
+
await options.assertAuthority();
|
|
60
|
+
const { root, path } = initiativeLocation(directory, request.initiativeId, !request.recoveryOnly);
|
|
61
|
+
const lock = await lockRuntimeSettlement(path + ".lock");
|
|
62
|
+
let closed = false,
|
|
63
|
+
failed = false;
|
|
64
|
+
try {
|
|
65
|
+
await options.assertAuthority();
|
|
66
|
+
const old = readInitiativeState(directory, request.initiativeId);
|
|
67
|
+
if ((old?.revision ?? null) !== request.expectedRevision) throw Error("initiative revision conflict");
|
|
68
|
+
const marker = basename(path) + ".initialized";
|
|
69
|
+
if (!old && existsSync(path + ".initialized")) throw Error("initiative state missing; restore trusted state");
|
|
70
|
+
const settled = (record: InitiativeRecord) => settledInitiative(record, options);
|
|
71
|
+
if (request.recoveryOnly && !old) throw Error("no retained initiative to recover");
|
|
72
|
+
if (!request.recoveryOnly && old && !(await settled(old.record)))
|
|
73
|
+
throw Error("initiative reconciliation required; prior attempt or effects unresolved");
|
|
74
|
+
await options.assertAuthority();
|
|
75
|
+
if (!lock.healthy()) throw Error("initiative ownership lock lost");
|
|
76
|
+
if ((readInitiativeState(directory, request.initiativeId)?.revision ?? null) !== request.expectedRevision)
|
|
77
|
+
throw Error("initiative changed before takeover");
|
|
78
|
+
if (!old)
|
|
79
|
+
publishArtifact(root, marker, JSON.stringify({ version: 1, initiativeId: request.initiativeId }) + "\n", false);
|
|
80
|
+
const record: InitiativeRecord = request.recoveryOnly
|
|
81
|
+
? structuredClone(old!.record)
|
|
82
|
+
: {
|
|
83
|
+
version: 1,
|
|
84
|
+
initiativeId: request.initiativeId,
|
|
85
|
+
generation: (old?.record.generation ?? 0) + 1,
|
|
86
|
+
owner: { ...request.owner },
|
|
87
|
+
state: "owned",
|
|
88
|
+
tasks: structuredClone(old?.record.tasks ?? []),
|
|
89
|
+
};
|
|
90
|
+
if (!Number.isSafeInteger(record.generation)) throw Error("initiative generation exhausted");
|
|
91
|
+
let revision = initiativeRevision(record);
|
|
92
|
+
if (!request.recoveryOnly) saveInitiative(path, root, record);
|
|
93
|
+
let tail = Promise.resolve();
|
|
94
|
+
const currentGuard = (authority: () => void | Promise<void>) => async () => {
|
|
95
|
+
if (closed || failed || !lock.healthy()) throw Error("initiative coordinator is no longer current");
|
|
96
|
+
await authority();
|
|
97
|
+
if (
|
|
98
|
+
closed ||
|
|
99
|
+
failed ||
|
|
100
|
+
!lock.healthy() ||
|
|
101
|
+
readInitiativeState(directory, request.initiativeId)?.revision !== revision
|
|
102
|
+
)
|
|
103
|
+
throw Error("initiative coordinator generation or state changed");
|
|
104
|
+
};
|
|
105
|
+
const assertCurrent = currentGuard(() => options.assertAuthority());
|
|
106
|
+
const assertObservationCurrent = currentGuard(() =>
|
|
107
|
+
options.assertObservationAuthority ? options.assertObservationAuthority() : options.assertAuthority(),
|
|
108
|
+
);
|
|
109
|
+
const change = <T>(work: () => Promise<T>): Promise<T> => {
|
|
110
|
+
const next = tail.then(work);
|
|
111
|
+
tail = next.then(
|
|
112
|
+
() => undefined,
|
|
113
|
+
() => undefined,
|
|
114
|
+
);
|
|
115
|
+
return next;
|
|
116
|
+
};
|
|
117
|
+
const save = () => {
|
|
118
|
+
try {
|
|
119
|
+
saveInitiative(path, root, record);
|
|
120
|
+
revision = initiativeRevision(record);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
failed = true;
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const observeAttempts = async (task: InitiativeRecord["tasks"][number] | undefined) => {
|
|
127
|
+
const states: Awaited<ReturnType<InitiativeResolution["resolveAttempt"]>>[] = [];
|
|
128
|
+
const effects = [],
|
|
129
|
+
receipts = [];
|
|
130
|
+
// Retained attempts are bounded; never fan all historical filesystem checks out at once.
|
|
131
|
+
for (const attempt of task?.attempts ?? []) {
|
|
132
|
+
states.push(await options.resolveAttempt(structuredClone(attempt)));
|
|
133
|
+
const receipt = await currentEffectReceipt(record.initiativeId, task!, attempt, options);
|
|
134
|
+
receipts.push(receipt);
|
|
135
|
+
effects.push(receiptResolves(task!, receipt));
|
|
136
|
+
}
|
|
137
|
+
return { states, effects, receipts };
|
|
138
|
+
};
|
|
139
|
+
const taskAt = (task: InitiativeTask) => {
|
|
140
|
+
if (!validInitiativeTask(task)) throw Error("invalid initiative task");
|
|
141
|
+
const found = record.tasks.find((t) => t.taskId === task.taskId && t.taskRevision === task.taskRevision);
|
|
142
|
+
if (found && (found.effectScope !== task.effectScope || !sameEffectTarget(found.effectTarget, task.effectTarget)))
|
|
143
|
+
throw Error("task effect scope or target changed without revision");
|
|
144
|
+
return found;
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
generation: record.generation,
|
|
148
|
+
recoveryOnly: request.recoveryOnly === true,
|
|
149
|
+
revision: () => revision,
|
|
150
|
+
metadata: () => ({
|
|
151
|
+
initiativeId: record.initiativeId,
|
|
152
|
+
generation: record.generation,
|
|
153
|
+
knownSessions: new Set([
|
|
154
|
+
record.owner.sessionId,
|
|
155
|
+
...record.tasks.flatMap((t) => t.attempts.map((a) => a.owner.sessionId)),
|
|
156
|
+
]).size,
|
|
157
|
+
recordedTasks: record.tasks.length,
|
|
158
|
+
recordedAttempts: record.tasks.reduce((n, t) => n + t.attempts.length, 0),
|
|
159
|
+
}),
|
|
160
|
+
assertCurrent,
|
|
161
|
+
assertObservationCurrent,
|
|
162
|
+
claim(task: InitiativeTask) {
|
|
163
|
+
task = structuredClone(task);
|
|
164
|
+
return change(async () => {
|
|
165
|
+
await assertCurrent();
|
|
166
|
+
if (request.recoveryOnly) throw Error("recovery-only owner cannot claim or dispatch");
|
|
167
|
+
if (taskAt(task)?.generation === record.generation) return;
|
|
168
|
+
const prior = record.tasks.filter((t) => t.taskId === task.taskId);
|
|
169
|
+
if (!(await settled({ ...record, tasks: prior }))) throw Error("task prior attempts need reconciliation");
|
|
170
|
+
await assertCurrent();
|
|
171
|
+
const found = taskAt(task);
|
|
172
|
+
if (found) found.generation = record.generation;
|
|
173
|
+
else record.tasks.push({ ...structuredClone(task), generation: record.generation, attempts: [] });
|
|
174
|
+
save();
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
begin(task: InitiativeTask, operation: OperationRequest) {
|
|
178
|
+
task = structuredClone(task);
|
|
179
|
+
return change(async () => {
|
|
180
|
+
await assertCurrent();
|
|
181
|
+
if (request.recoveryOnly) throw Error("recovery-only owner cannot claim or dispatch");
|
|
182
|
+
const found = taskAt(task);
|
|
183
|
+
if (!found || found.generation !== record.generation || !validOperationId(operation.operationId))
|
|
184
|
+
throw Error("initiative task is not claimed by current generation");
|
|
185
|
+
await assertTaskPriorSettled(record, task, options);
|
|
186
|
+
await assertCurrent();
|
|
187
|
+
const all = record.tasks.flatMap((t) => t.attempts);
|
|
188
|
+
if (
|
|
189
|
+
all.some(
|
|
190
|
+
(a) =>
|
|
191
|
+
a.owner.sessionId === request.owner.sessionId &&
|
|
192
|
+
a.owner.cwd === request.owner.cwd &&
|
|
193
|
+
a.operationId === operation.operationId,
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
throw Error("initiative operation already associated");
|
|
197
|
+
found.attempts.push({
|
|
198
|
+
owner: { ...request.owner },
|
|
199
|
+
operationId: operation.operationId,
|
|
200
|
+
executionId: operation.executionId,
|
|
201
|
+
requestDigest: operation.requestDigest,
|
|
202
|
+
state: "pending",
|
|
203
|
+
});
|
|
204
|
+
save();
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
async assertPriorAttemptsSettled(task: InitiativeTask, operation: OperationRequest) {
|
|
208
|
+
task = structuredClone(task);
|
|
209
|
+
operation = { ...operation };
|
|
210
|
+
const captured = revision;
|
|
211
|
+
await assertCurrent();
|
|
212
|
+
const found = taskAt(task);
|
|
213
|
+
const attempt = found?.attempts.find(
|
|
214
|
+
(a) =>
|
|
215
|
+
a.owner.sessionId === request.owner.sessionId &&
|
|
216
|
+
a.owner.cwd === request.owner.cwd &&
|
|
217
|
+
a.operationId === operation.operationId &&
|
|
218
|
+
a.executionId === operation.executionId &&
|
|
219
|
+
a.requestDigest === operation.requestDigest,
|
|
220
|
+
);
|
|
221
|
+
if (
|
|
222
|
+
request.recoveryOnly ||
|
|
223
|
+
!found ||
|
|
224
|
+
found.generation !== record.generation ||
|
|
225
|
+
!attempt ||
|
|
226
|
+
attempt.state === "not-admitted"
|
|
227
|
+
)
|
|
228
|
+
throw Error("exact admitted initiative attempt required before start");
|
|
229
|
+
await assertTaskPriorSettled(record, task, options, attempt);
|
|
230
|
+
await assertCurrent();
|
|
231
|
+
if (revision !== captured) throw Error("initiative changed before start");
|
|
232
|
+
},
|
|
233
|
+
notAdmitted(operation: OperationRequest) {
|
|
234
|
+
return change(async () => {
|
|
235
|
+
await assertCurrent();
|
|
236
|
+
const a = record.tasks
|
|
237
|
+
.flatMap((t) => t.attempts)
|
|
238
|
+
.find(
|
|
239
|
+
(a) =>
|
|
240
|
+
a.owner.sessionId === request.owner.sessionId &&
|
|
241
|
+
a.owner.cwd === request.owner.cwd &&
|
|
242
|
+
a.operationId === operation.operationId &&
|
|
243
|
+
a.executionId === operation.executionId,
|
|
244
|
+
);
|
|
245
|
+
if (!a) throw Error("initiative attempt missing");
|
|
246
|
+
a.state = "not-admitted";
|
|
247
|
+
save();
|
|
248
|
+
});
|
|
249
|
+
},
|
|
250
|
+
async observe(
|
|
251
|
+
input: InitiativeTaskIdentity,
|
|
252
|
+
selectedTask?: InitiativeTask,
|
|
253
|
+
): Promise<InitiativeObservation | { status: "unavailable" }> {
|
|
254
|
+
input = structuredClone(input);
|
|
255
|
+
selectedTask = selectedTask ? structuredClone(selectedTask) : undefined;
|
|
256
|
+
if (input.initiativeId !== record.initiativeId) return { status: "unavailable" };
|
|
257
|
+
const captured = revision;
|
|
258
|
+
await assertObservationCurrent();
|
|
259
|
+
const task = record.tasks.find((t) => t.taskId === input.taskId && t.taskRevision === input.taskRevision);
|
|
260
|
+
if (!task && !selectedTask && record.tasks.some((t) => t.taskId === input.taskId))
|
|
261
|
+
return { status: "unavailable" };
|
|
262
|
+
if (
|
|
263
|
+
selectedTask &&
|
|
264
|
+
(!validInitiativeTask(selectedTask) ||
|
|
265
|
+
selectedTask.taskId !== input.taskId ||
|
|
266
|
+
selectedTask.taskRevision !== input.taskRevision ||
|
|
267
|
+
(task &&
|
|
268
|
+
(task.effectScope !== selectedTask.effectScope ||
|
|
269
|
+
!sameEffectTarget(task.effectTarget, selectedTask.effectTarget))))
|
|
270
|
+
)
|
|
271
|
+
return { status: "unavailable" };
|
|
272
|
+
const { states, effects, receipts } = await observeAttempts(task);
|
|
273
|
+
const prior = record.tasks.filter((t) => t.taskId === input.taskId && t !== task);
|
|
274
|
+
const priorCurrent = await settled({ ...record, tasks: prior });
|
|
275
|
+
const target = task?.effectTarget ?? selectedTask?.effectTarget;
|
|
276
|
+
const observedEffect = effectObservation(target, task?.attempts.at(-1), states.at(-1), receipts.at(-1));
|
|
277
|
+
await assertObservationCurrent();
|
|
278
|
+
if (captured !== revision) return { status: "unavailable" };
|
|
279
|
+
const unresolved =
|
|
280
|
+
!priorCurrent ||
|
|
281
|
+
states.some((status, i) => status === "unknown" || (status !== "not-started" && !effects[i]));
|
|
282
|
+
return {
|
|
283
|
+
status: "observed",
|
|
284
|
+
...input,
|
|
285
|
+
ownerGeneration: record.generation,
|
|
286
|
+
claim: unresolved
|
|
287
|
+
? "uncertain"
|
|
288
|
+
: !task || (!request.recoveryOnly && task.generation !== record.generation && !states.includes("running"))
|
|
289
|
+
? "unclaimed"
|
|
290
|
+
: !request.recoveryOnly && task.generation === record.generation
|
|
291
|
+
? "owned"
|
|
292
|
+
: "other-owner",
|
|
293
|
+
execution: states.includes("unknown")
|
|
294
|
+
? "unknown"
|
|
295
|
+
: states.includes("running")
|
|
296
|
+
? "running"
|
|
297
|
+
: states.length
|
|
298
|
+
? "settled"
|
|
299
|
+
: "none",
|
|
300
|
+
reconciliationRequired: unresolved,
|
|
301
|
+
...(observedEffect ? { effectObservation: observedEffect } : {}),
|
|
302
|
+
async assertCurrent() {
|
|
303
|
+
await assertObservationCurrent();
|
|
304
|
+
const {
|
|
305
|
+
states: currentStates,
|
|
306
|
+
effects: currentEffects,
|
|
307
|
+
receipts: currentReceipts,
|
|
308
|
+
} = await observeAttempts(task);
|
|
309
|
+
const currentEffect = effectObservation(
|
|
310
|
+
target,
|
|
311
|
+
task?.attempts.at(-1),
|
|
312
|
+
currentStates.at(-1),
|
|
313
|
+
currentReceipts.at(-1),
|
|
314
|
+
);
|
|
315
|
+
const priorStillCurrent = await settled({ ...record, tasks: prior });
|
|
316
|
+
await assertObservationCurrent();
|
|
317
|
+
if (
|
|
318
|
+
revision !== captured ||
|
|
319
|
+
priorStillCurrent !== priorCurrent ||
|
|
320
|
+
JSON.stringify(currentStates) !== JSON.stringify(states) ||
|
|
321
|
+
JSON.stringify(currentEffects) !== JSON.stringify(effects) ||
|
|
322
|
+
JSON.stringify(currentEffect) !== JSON.stringify(observedEffect)
|
|
323
|
+
)
|
|
324
|
+
throw Error("initiative observation changed");
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
},
|
|
328
|
+
/** Bind a final to the only admitted attempt for this exact selected task revision. */
|
|
329
|
+
async handoffAttempt(identity: InitiativeTaskIdentity, selectedTask: InitiativeTask) {
|
|
330
|
+
if (request.recoveryOnly || identity.initiativeId !== record.initiativeId) return;
|
|
331
|
+
const observation = await this.observe(identity, selectedTask);
|
|
332
|
+
if (
|
|
333
|
+
observation.status !== "observed" ||
|
|
334
|
+
observation.execution !== "settled" ||
|
|
335
|
+
observation.reconciliationRequired
|
|
336
|
+
)
|
|
337
|
+
return;
|
|
338
|
+
const attempts = taskAt(selectedTask)?.attempts.filter((attempt) => attempt.state !== "not-admitted");
|
|
339
|
+
// A task with several admitted operations needs an explicit output choice.
|
|
340
|
+
if (attempts?.length !== 1) return;
|
|
341
|
+
await observation.assertCurrent();
|
|
342
|
+
return { attempt: structuredClone(attempts[0]!), assertCurrent: observation.assertCurrent };
|
|
343
|
+
},
|
|
344
|
+
async pendingEffects() {
|
|
345
|
+
const captured = revision;
|
|
346
|
+
await assertCurrent();
|
|
347
|
+
const pending = [];
|
|
348
|
+
for (const task of record.tasks)
|
|
349
|
+
for (const attempt of task.attempts) {
|
|
350
|
+
if (task.effectScope === "local") continue;
|
|
351
|
+
const execution = await options.resolveAttempt(structuredClone(attempt));
|
|
352
|
+
if (execution !== "not-started" && !(await effectCurrent(record.initiativeId, task, attempt, options)))
|
|
353
|
+
pending.push({
|
|
354
|
+
...effectIdentity(record.initiativeId, task, attempt),
|
|
355
|
+
execution,
|
|
356
|
+
...(task.effectTarget ? { effectTarget: structuredClone(task.effectTarget) } : {}),
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
await assertCurrent();
|
|
360
|
+
if (captured !== revision) throw Error("initiative observation changed");
|
|
361
|
+
return pending;
|
|
362
|
+
},
|
|
363
|
+
reconcileEffect(input: InitiativeEffectReconciliation) {
|
|
364
|
+
input = structuredClone(input);
|
|
365
|
+
return change(async () => {
|
|
366
|
+
await assertCurrent();
|
|
367
|
+
const { task, attempt } = exactEffect(record, input);
|
|
368
|
+
if (!options.assertEffectReconciled) throw Error("trusted receipt verifier unavailable");
|
|
369
|
+
if ((await options.resolveAttempt(structuredClone(attempt))) !== "settled")
|
|
370
|
+
throw Error("native attempt settlement required");
|
|
371
|
+
await options.assertEffectReconciled({
|
|
372
|
+
...effectIdentity(record.initiativeId, task, attempt),
|
|
373
|
+
receipt: structuredClone(input.receipt),
|
|
374
|
+
});
|
|
375
|
+
await assertCurrent();
|
|
376
|
+
if ((await options.resolveAttempt(structuredClone(attempt))) !== "settled")
|
|
377
|
+
throw Error("native attempt settlement changed");
|
|
378
|
+
await options.assertEffectReconciled({
|
|
379
|
+
...effectIdentity(record.initiativeId, task, attempt),
|
|
380
|
+
receipt: structuredClone(input.receipt),
|
|
381
|
+
});
|
|
382
|
+
await assertCurrent();
|
|
383
|
+
attempt.effectReceipt = structuredClone(input.receipt);
|
|
384
|
+
save();
|
|
385
|
+
const observed = effectObservation(task.effectTarget, attempt, "settled", input.receipt);
|
|
386
|
+
return {
|
|
387
|
+
reconciled: receiptResolves(task, input.receipt),
|
|
388
|
+
taskAccepted: false,
|
|
389
|
+
executionAuthorized: false,
|
|
390
|
+
...(observed ? { effectObservation: observed } : {}),
|
|
391
|
+
};
|
|
392
|
+
});
|
|
393
|
+
},
|
|
394
|
+
release() {
|
|
395
|
+
return change(async () => {
|
|
396
|
+
await assertCurrent();
|
|
397
|
+
if (!(await settled(record))) throw Error("initiative reconciliation required before release");
|
|
398
|
+
await assertCurrent();
|
|
399
|
+
record.state = "released";
|
|
400
|
+
save();
|
|
401
|
+
closed = true;
|
|
402
|
+
await lock.release();
|
|
403
|
+
});
|
|
404
|
+
},
|
|
405
|
+
/** Abandon only cooperative ownership; unresolved attempts remain durable and block takeover. */
|
|
406
|
+
async close() {
|
|
407
|
+
closed = true;
|
|
408
|
+
await lock.release();
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
} catch (error) {
|
|
412
|
+
await lock.release();
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
export type InitiativeCoordinator = Awaited<ReturnType<typeof acquireInitiativeCoordinator>>;
|