@wrongstack/governance 0.298.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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +172 -0
  3. package/dist/admin-session.d.ts +56 -0
  4. package/dist/attachment-broker-controller.d.ts +73 -0
  5. package/dist/authenticated-project-service.d.ts +18 -0
  6. package/dist/autonomy-envelope.d.ts +40 -0
  7. package/dist/capability-grant.d.ts +122 -0
  8. package/dist/credential-lease-controller.d.ts +85 -0
  9. package/dist/daemon-control.d.ts +48 -0
  10. package/dist/daemon-launcher.d.ts +46 -0
  11. package/dist/daemon-metadata.d.ts +126 -0
  12. package/dist/daemon-protocol.d.ts +59 -0
  13. package/dist/event-store.d.ts +109 -0
  14. package/dist/evidence-candidate.d.ts +95 -0
  15. package/dist/index.d.ts +38 -0
  16. package/dist/index.js +8468 -0
  17. package/dist/ipc-endpoint.d.ts +6 -0
  18. package/dist/ipc-protocol.d.ts +24 -0
  19. package/dist/legacy-shadow-adapter.d.ts +33 -0
  20. package/dist/management-receipt-cache.d.ts +53 -0
  21. package/dist/plan-version.d.ts +91 -0
  22. package/dist/project-client.d.ts +31 -0
  23. package/dist/project-daemon.d.ts +2 -0
  24. package/dist/project-daemon.js +5722 -0
  25. package/dist/project-server.d.ts +48 -0
  26. package/dist/project-service.d.ts +121 -0
  27. package/dist/protocol-decoder.d.ts +16 -0
  28. package/dist/runtime-compatibility.d.ts +99 -0
  29. package/dist/sanitize.d.ts +11 -0
  30. package/dist/service-protocol.d.ts +82 -0
  31. package/dist/task-aggregate.d.ts +92 -0
  32. package/dist/task-contract.d.ts +74 -0
  33. package/dist/transition-engine.d.ts +37 -0
  34. package/dist/verification-check-binding.d.ts +23 -0
  35. package/dist/verification-check-registry.d.ts +43 -0
  36. package/dist/verification-execution-lease.d.ts +76 -0
  37. package/dist/verification-issuance-coordinator.d.ts +110 -0
  38. package/dist/verification-ledger-store.d.ts +20 -0
  39. package/dist/verification-planner.d.ts +76 -0
  40. package/dist/verification-run-contract.d.ts +84 -0
  41. package/dist/verification-tool-gateway.d.ts +74 -0
  42. package/dist/workflow-state.d.ts +5 -0
  43. package/dist/workspace-snapshot-fence.d.ts +20 -0
  44. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ECOSTACK TECHNOLOGY OÜ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,172 @@
1
+ # @wrongstack/governance
2
+
3
+ Deterministic workflow vocabulary and transition policy for WrongStack.
4
+
5
+ This package deliberately has no provider, agent, tool, or UI dependency. Its deterministic core is wrapped
6
+ by isolated SQLite and local IPC adapters. Models remain the primary reasoning and execution resource: they
7
+ can propose plans, transitions, retries, replans, and completion. The transition engine decides whether a
8
+ proposal is inside the approved autonomy envelope and can therefore proceed automatically.
9
+
10
+ The package is not connected to the current runtime yet. Existing Agent, Director, Kanban, SDD, Goal,
11
+ and MCP behavior remains unchanged while the governance contract is introduced incrementally.
12
+
13
+ `TaskContractV1` defines requirements, acceptance criteria, evidence expectations, review dimensions,
14
+ rollback class, path scope, change budgets, and an A0-A4 autonomy envelope. Low-risk work can proceed
15
+ without human prompts; sensitive operations can be explicitly escalated or narrowly pre-authorized by
16
+ project policy.
17
+
18
+ `PlanVersionV1` stores immutable model-generated plan content as a requirement-linked DAG. Replanning
19
+ creates a parent-linked next version instead of rewriting history. Step-level autonomy classification
20
+ keeps ordinary implementation and verification automatic while isolating only the sensitive steps that
21
+ need escalation.
22
+
23
+ The pure task aggregate accepts command envelopes, evaluates trusted deterministic facts outside model
24
+ arguments, emits one immutable event proposal, and rebuilds state by deterministic replay. Persistence,
25
+ daemon ownership, and runtime adapters remain separate from model execution.
26
+
27
+ `SqliteGovernanceEventStore` is an isolated append-only persistence adapter. It commits an accepted event
28
+ and its command receipt in one `BEGIN IMMEDIATE` transaction, records rejected decisions for stable retry
29
+ semantics, rejects reuse of a command id with a different payload, and reconstructs historical results by
30
+ event replay. Trusted decision facts are stored with the receipt for auditability. Production runtime code
31
+ does not open this database yet; the opt-in project daemon remains the only process allowed to own it.
32
+
33
+ `GovernanceProjectService` adds a transport-neutral, project-scoped owner with explicit `task_read`,
34
+ `audit_read`, `command_submit`, and `shadow_observe` capabilities. Capabilities are supplied by trusted
35
+ server context rather than request payloads. Trusted transition facts are resolved by a service-owned policy
36
+ provider and are structurally absent from model command requests. The typed service core is not itself a
37
+ network security boundary; credential binding, unknown-input decoding, IPC election, and process lifecycle
38
+ are enforced by the surrounding local server and daemon adapters.
39
+
40
+ `decodeGovernanceServiceRequest` is the mandatory future wire boundary for unknown JSON. It rejects unknown
41
+ fields at every governed schema level, validates command/contract/plan/observation shapes, applies bounded
42
+ JSON depth and collection limits, and returns a deeply frozen request. Capability and trusted decision-fact
43
+ fields are absent from the accepted wire schema and are rejected if injected.
44
+
45
+ `LegacyGovernanceShadowAdapter` has only `shadow_observe`. It writes idempotent legacy observations to a
46
+ separate append-only ledger and cannot submit governance commands or transition canonical task state. This
47
+ allows compatibility telemetry before any legacy workflow is blocked or replaced.
48
+
49
+ `GovernanceCapabilityGrantRegistry` issues short-lived opaque grants bound to one project and client. Only a
50
+ SHA-256 verifier is retained; raw bearer tokens are returned once, expire inclusively, can be revoked, and
51
+ are intentionally lost when the future daemon restarts. `AuthenticatedGovernanceProjectService` resolves a
52
+ valid grant into an immutable capability set before calling the internal service. The legacy shadow adapter
53
+ uses this authenticated facade instead of constructing its own capabilities.
54
+
55
+ The ephemeral registry is bounded by `maxGrants`. It emits immutable lifecycle records through an injected
56
+ audit sink instead of retaining an unbounded in-memory history; the project server appends those records to
57
+ the persistent evidence ledger.
58
+
59
+ `GovernanceProjectServer` and `GovernanceProjectClient` provide a local IPC skeleton for isolated testing.
60
+ The server binds the deterministic per-project endpoint before opening `.wrongstack/governance/governance.sqlite`,
61
+ so a losing owner never opens a second database connection. Credentials travel in a strict transport
62
+ envelope, separate from the inner request, and only the authenticated facade receives decoded calls. Frames,
63
+ connections, and half-open socket lifetimes are bounded. Capability lifecycle observations require
64
+ `audit_read`; ordinary task readers cannot see them, and shadow writers cannot forge reserved audit events.
65
+
66
+ `launchGovernanceProjectDaemon` is an explicit, opt-in detached-process boundary. The built daemon acquires
67
+ the endpoint before SQLite, then returns one initial client grant over the private parent-child IPC channel.
68
+ The raw token is never placed in argv, inherited environment, or a bootstrap file. The daemon inherits only
69
+ a small operating-system environment allowlist, rejects unknown handshake fields, validates project/client
70
+ identity, and exits instead of silently falling back to a second in-process owner. A competing launch reports
71
+ `owner_conflict` without disturbing the current owner.
72
+
73
+ The daemon publishes strict, secrets-free liveness metadata under `.wrongstack/governance/daemon.json`:
74
+ protocol and schema versions, canonical project identity, endpoint, PID, instance id, and start time. It does
75
+ not persist bearer tokens, client credentials, or capabilities. Metadata is a discovery hint rather than an
76
+ ownership authority: endpoint binding remains authoritative, and the launcher verifies the on-disk instance
77
+ identity before returning a bootstrap credential.
78
+
79
+ `connectGovernanceProjectClient` is a non-starting discovery adapter for callers that already hold an
80
+ ephemeral credential. It requires live metadata, matching project identity, and a successful authenticated
81
+ health response before returning a client. Missing or contradictory state is returned as an explicit result;
82
+ the helper neither launches a daemon nor reads or writes credential material.
83
+
84
+ Daemon startup is serialized by an atomically created project-local lease. A lease held by a live PID is never
85
+ removed, malformed lease data fails loud, and release removes only the exact record owned by that instance.
86
+ After a failed endpoint probe, a dead or missing owner permits stale filesystem-socket cleanup only while the
87
+ lease is held on Unix-like platforms. Windows named pipes are not deleted; contradictory owner/endpoint state
88
+ fails with `endpoint_invalid` instead of guessing. An abrupt Windows process stop can leave stale metadata,
89
+ which the next launch treats as a dead liveness hint and replaces only after it has acquired the endpoint.
90
+
91
+ An explicitly bootstrapped `capability_admin` client can issue short-lived ordinary-client grants, list public
92
+ grant metadata in cursor pages of at most 100 records, rotate active credentials, and revoke grants through the
93
+ authenticated facade. Rotation preserves the target client and exact capability set, replaces the old verifier
94
+ only after one append-only `grant_rotated` audit event succeeds, and never places the replacement token in the
95
+ audit ledger. An administrator can rotate only its own `capability_admin` grant and cannot delegate that
96
+ capability.
97
+ The facade derives `issuedBy` from the authenticated administrator rather than request data, and lifecycle
98
+ events are appended to the audit ledger without storing the returned bearer token. Ordinary model clients
99
+ cannot call grant-management operations unless a trusted launcher deliberately gave them the admin grant.
100
+
101
+ Daemon lifecycle control is a separate `daemon_control` capability; `capability_admin` alone cannot inspect
102
+ or stop the owner process. Like `capability_admin`, it can be bootstrapped only through the trusted launcher
103
+ and cannot be delegated by a service request. Status reports the live PID, instance id, project id, and start
104
+ time from the daemon-owned adapter. Shutdown requests must name the expected instance id, derive the requester
105
+ from the authenticated grant, and append a reserved `daemon_shutdown_requested` audit observation before
106
+ acceptance. The server half-closes the client socket with the complete response and invokes the daemon stop
107
+ callback only after that response is flushed; an audit failure or stale instance id leaves the daemon running.
108
+ Shadow/model observations cannot forge the reserved `daemon_*` evidence namespace.
109
+
110
+ Successful grant issue, rotation, and revocation mutations reserve a bounded in-memory retry receipt before
111
+ changing registry state. Reusing the same administrator credential, `requestId`, and canonical payload within
112
+ 30 seconds replays the exact response instead of repeating the mutation; reusing the id with another payload
113
+ is rejected. This also lets a self-rotating administrator recover its replacement credential with only the exact
114
+ old request. Receipt capacity fails before mutation, entries expire without timers, and the cache is cleared on
115
+ shutdown. Replacement tokens may exist in this bounded process memory during the retry window but are never
116
+ written to daemon metadata, SQLite, argv, environment variables, or audit observations. This is daemon-lifetime
117
+ network retry protection, not durable replay across a process restart.
118
+
119
+ `GovernanceCredentialLeaseController` is an opt-in process-local holder for one self-rotating
120
+ `capability_admin` credential. It schedules renewal before expiry, reuses one request id across a bounded
121
+ three-attempt retry cycle, swaps its internal IPC client only after strict replacement identity validation,
122
+ and serializes ordinary requests behind an in-flight rotation. The controller never exposes the current token
123
+ in its snapshot. Retry exhaustion and expiry are terminal, observable states rather than unbounded healing
124
+ loops; configured timeout and retry windows must fit inside the server's retry-receipt TTL. Failure text is
125
+ bounded and credential-shaped values are redacted. Its referenced scheduler exists only after a trusted caller
126
+ explicitly creates and starts the controller, and `stop()` cancels the pending timer without revoking the
127
+ still-valid grant.
128
+
129
+ `connectGovernanceAdminSessionFromLaunch` and `connectGovernanceAdminSession` compose daemon discovery,
130
+ authenticated health, public self-grant inspection, and the lease controller for a trusted control-plane
131
+ holder. A session is created only when project, daemon instance, grant, client, expiry, and
132
+ `capability_admin` identity agree. `read_own_capability_grant` reveals only the authenticated caller's public
133
+ grant descriptor and never its token. Session snapshots contain daemon and lease status but no credential.
134
+ This admin session must not be passed to a model-facing tool surface; ordinary agents should receive narrowly
135
+ scoped child grants. Session `readDaemonStatus()` and `shutdownDaemon()` require a separately bootstrapped
136
+ `daemon_control` grant. `shutdownDaemon()` binds the request to the verified session metadata and stops lease
137
+ renewal only after the acceptance response arrives. Session `stop()` stops renewal only—it does not terminate
138
+ the detached project daemon or revoke the current grant.
139
+
140
+ `prepareGovernanceCompatibilityRuntime` is an opt-in compatibility factory for gradual runtime adoption. It
141
+ attaches only when the trusted caller supplies an existing admin grant, otherwise inspects ownership and
142
+ launches a new daemon only when the project has no live owner. A live owner without an explicit credential,
143
+ invalid metadata, launch failure, or provisioning failure returns a structured `mode: "legacy"` result; the
144
+ factory never steals the endpoint or silently creates an in-process authority. The current WrongStack runtime
145
+ decides whether to continue through its existing path after observing that result.
146
+
147
+ On success the factory uses the admin session to issue one explicit, short-lived model grant. The caller must
148
+ choose the model capabilities; `capability_admin` and `daemon_control` are rejected before inspection or
149
+ process launch. The returned runtime exposes a `GovernanceModelSession` whose IPC client is held in a native
150
+ private field, while daemon control remains in the trusted runtime wrapper. Model requests are still autonomous
151
+ within their assigned capabilities and remain subject to deterministic server checks. `close()` revokes the
152
+ model grant before stopping the admin lease, and `shutdownDaemon()` revokes it before requesting identity-bound
153
+ daemon shutdown. If a newly launched daemon cannot finish model provisioning, the factory requests graceful
154
+ rollback; it never shuts down an owner to which it merely attached. Snapshots and fallback results contain no
155
+ bearer credentials.
156
+
157
+ The interactive CLI now has one experimental, default-off compatibility callsite. Setting
158
+ `WRONGSTACK_GOVERNANCE=1` after session creation dynamically loads
159
+ `@wrongstack/runtime/governance-bootstrap`; every other value leaves the governance runtime chunk unloaded and
160
+ the existing execution path unchanged. Successful bootstrap publishes only a credential-free snapshot into
161
+ session metadata. Structured fallback or unexpected bootstrap failure is logged and the legacy runtime
162
+ continues. The LLM still uses the existing WrongStack executor and tools in this phase; its governance model
163
+ session is provisioned with `task_read`, `command_submit`, and `shadow_observe` but is not yet the tool-execution
164
+ path. A daemon launched by this compatibility session is shut down when the session ends, while an attached
165
+ owner is only detached. This session-scoped policy avoids trapping later sessions until durable admin
166
+ credential handoff exists.
167
+
168
+ There is still no default-on runtime spawn, idle policy, durable credential discovery, cross-process token
169
+ handoff, or governance-backed tool gateway in a legacy execution callsite.
170
+ The detached daemon currently uses the service's conservative default decision context; a trusted policy
171
+ adapter must be installed before command execution is enabled for production callers. Existing WrongStack
172
+ execution continues unchanged.
@@ -0,0 +1,56 @@
1
+ import type { GovernanceServiceCredential } from './capability-grant.js';
2
+ import { GovernanceCredentialLeaseController, type GovernanceCredentialLeaseSnapshot } from './credential-lease-controller.js';
3
+ import type { GovernanceProjectDaemonLaunch } from './daemon-launcher.js';
4
+ import type { GovernanceDaemonMetadata } from './daemon-metadata.js';
5
+ import { type GovernanceProjectClientOptions } from './project-client.js';
6
+ import type { GovernanceServiceResponse } from './project-service.js';
7
+ export interface GovernanceAdminSessionLeaseOptions extends GovernanceProjectClientOptions {
8
+ readonly rotationTtlMs?: number | undefined;
9
+ readonly renewBeforeMs?: number | undefined;
10
+ readonly retryDelayMs?: number | undefined;
11
+ readonly maxAttempts?: number | undefined;
12
+ readonly startLease?: boolean | undefined;
13
+ }
14
+ export interface ConnectGovernanceAdminSessionOptions extends GovernanceAdminSessionLeaseOptions {
15
+ readonly projectRoot: string;
16
+ readonly projectId: string;
17
+ readonly grantId: string;
18
+ readonly credential: GovernanceServiceCredential;
19
+ }
20
+ export type GovernanceAdminSessionConnectionFailureCode = 'not_running' | 'endpoint_invalid' | 'project_mismatch' | 'credential_mismatch' | 'authentication_failed' | 'service_rejected' | 'admin_required' | 'grant_mismatch';
21
+ export type ConnectGovernanceAdminSessionResult = {
22
+ readonly connected: true;
23
+ readonly session: GovernanceAdminSession;
24
+ } | {
25
+ readonly connected: false;
26
+ readonly code: GovernanceAdminSessionConnectionFailureCode;
27
+ readonly message: string;
28
+ };
29
+ export interface GovernanceAdminSessionSnapshot {
30
+ readonly mode: 'attached' | 'launched';
31
+ readonly daemon: {
32
+ readonly projectRoot: string;
33
+ readonly projectId: string;
34
+ readonly pid: number;
35
+ readonly instanceId: string;
36
+ readonly startedAt: string;
37
+ };
38
+ readonly lease: GovernanceCredentialLeaseSnapshot;
39
+ }
40
+ declare const GOVERNANCE_ADMIN_SESSION_CONSTRUCTION: unique symbol;
41
+ export declare class GovernanceAdminSession {
42
+ readonly mode: 'attached' | 'launched';
43
+ private readonly metadata;
44
+ private readonly lease;
45
+ constructor(construction: typeof GOVERNANCE_ADMIN_SESSION_CONSTRUCTION, mode: 'attached' | 'launched', metadata: GovernanceDaemonMetadata, lease: GovernanceCredentialLeaseController);
46
+ request(input: unknown): Promise<GovernanceServiceResponse>;
47
+ readDaemonStatus(): Promise<GovernanceServiceResponse>;
48
+ shutdownDaemon(reason?: string): Promise<GovernanceServiceResponse>;
49
+ rotateNow(): Promise<GovernanceCredentialLeaseSnapshot>;
50
+ stop(): GovernanceAdminSessionSnapshot;
51
+ snapshot(): GovernanceAdminSessionSnapshot;
52
+ }
53
+ export declare function connectGovernanceAdminSession(options: ConnectGovernanceAdminSessionOptions): Promise<ConnectGovernanceAdminSessionResult>;
54
+ export declare function connectGovernanceAdminSessionFromLaunch(launch: GovernanceProjectDaemonLaunch, options?: GovernanceAdminSessionLeaseOptions): Promise<ConnectGovernanceAdminSessionResult>;
55
+ export {};
56
+ //# sourceMappingURL=admin-session.d.ts.map
@@ -0,0 +1,73 @@
1
+ import type { IssuedGovernanceCapabilityGrant, IssueGovernanceCapabilityGrantOptions } from './capability-grant.js';
2
+ import { type GovernanceDaemonAttachmentBrokerRecord, type GovernanceDaemonMetadata } from './daemon-metadata.js';
3
+ export declare const GOVERNANCE_DAEMON_ATTACHMENT_BROKER_RENEW_BEFORE_MS: number;
4
+ export declare const GOVERNANCE_DAEMON_ATTACHMENT_BROKER_RETRY_MS = 5000;
5
+ export declare const GOVERNANCE_DAEMON_ATTACHMENT_BROKER_DEGRADED_FAILURES = 3;
6
+ export type GovernanceAttachmentBrokerLifecycleEventType = 'published' | 'renewal_failed' | 'degraded' | 'revocation_failed' | 'recovered' | 'stopped';
7
+ export interface GovernanceAttachmentBrokerLifecycleEvent {
8
+ readonly schemaVersion: 1;
9
+ readonly sequence: number;
10
+ readonly type: GovernanceAttachmentBrokerLifecycleEventType;
11
+ readonly projectId: string;
12
+ readonly instanceId: string;
13
+ readonly occurredAt: string;
14
+ readonly state: GovernanceAttachmentBrokerControllerSnapshot['state'];
15
+ readonly health: GovernanceAttachmentBrokerControllerSnapshot['health'];
16
+ readonly grantId: string | null;
17
+ readonly expiresAt: string | null;
18
+ readonly consecutiveFailures: number;
19
+ readonly pendingRevocations: number;
20
+ readonly message?: string | undefined;
21
+ }
22
+ export interface GovernanceAttachmentBrokerScheduler {
23
+ schedule(callback: () => void, delayMs: number): unknown;
24
+ cancel(handle: unknown): void;
25
+ }
26
+ export interface GovernanceAttachmentBrokerControllerSnapshot {
27
+ readonly state: 'idle' | 'active' | 'retry_wait' | 'stopped';
28
+ readonly health: 'initializing' | 'healthy' | 'degraded' | 'stopped';
29
+ readonly grantId: string | null;
30
+ readonly expiresAt: string | null;
31
+ readonly consecutiveFailures: number;
32
+ readonly pendingRevocations: number;
33
+ readonly auditHealthy: boolean;
34
+ readonly nextActionAt?: string | undefined;
35
+ readonly lastFailure?: string | undefined;
36
+ readonly lastAuditFailure?: string | undefined;
37
+ }
38
+ interface GovernanceAttachmentBrokerGrantPort {
39
+ issueGrant(options: IssueGovernanceCapabilityGrantOptions): IssuedGovernanceCapabilityGrant;
40
+ revokeGrant(grantId: string, reason?: string): boolean;
41
+ }
42
+ export interface GovernanceAttachmentBrokerControllerOptions {
43
+ readonly projectRoot: string;
44
+ readonly metadata: GovernanceDaemonMetadata;
45
+ readonly grants: GovernanceAttachmentBrokerGrantPort;
46
+ readonly ttlMs?: number | undefined;
47
+ readonly renewBeforeMs?: number | undefined;
48
+ readonly retryMs?: number | undefined;
49
+ readonly degradedFailureThreshold?: number | undefined;
50
+ readonly now?: (() => number) | undefined;
51
+ readonly scheduler?: GovernanceAttachmentBrokerScheduler | undefined;
52
+ readonly publish?: ((broker: GovernanceDaemonAttachmentBrokerRecord) => Promise<void>) | undefined;
53
+ readonly remove?: (() => Promise<boolean>) | undefined;
54
+ readonly onEvent?: ((event: GovernanceAttachmentBrokerLifecycleEvent) => void) | undefined;
55
+ }
56
+ export declare class GovernanceAttachmentBrokerController {
57
+ #private;
58
+ constructor(options: GovernanceAttachmentBrokerControllerOptions);
59
+ start(): Promise<GovernanceDaemonAttachmentBrokerRecord>;
60
+ rotateNow(): Promise<GovernanceDaemonAttachmentBrokerRecord>;
61
+ stop(): Promise<GovernanceAttachmentBrokerControllerSnapshot>;
62
+ snapshot(): GovernanceAttachmentBrokerControllerSnapshot;
63
+ private rotateOnce;
64
+ private publish;
65
+ private remove;
66
+ private revokePending;
67
+ private health;
68
+ private emit;
69
+ private schedule;
70
+ private cancelTimer;
71
+ }
72
+ export {};
73
+ //# sourceMappingURL=attachment-broker-controller.d.ts.map
@@ -0,0 +1,18 @@
1
+ import type { GovernanceCapabilityGrantRegistry, GovernanceServiceCredential } from './capability-grant.js';
2
+ import type { GovernanceDaemonControlPort } from './daemon-control.js';
3
+ import { GovernanceManagementReceiptCache } from './management-receipt-cache.js';
4
+ import type { GovernanceProjectService, GovernanceServiceResponse } from './project-service.js';
5
+ export declare const GOVERNANCE_RUNTIME_ATTACHMENT_MAX_TTL_MS: number;
6
+ /** External facade for a future IPC transport. Raw capability sets never cross this boundary. */
7
+ export declare class AuthenticatedGovernanceProjectService {
8
+ #private;
9
+ private readonly service;
10
+ private readonly grants;
11
+ private readonly receipts;
12
+ private readonly daemonControl?;
13
+ readonly projectId: string;
14
+ constructor(service: GovernanceProjectService, grants: GovernanceCapabilityGrantRegistry, receipts?: GovernanceManagementReceiptCache, daemonControl?: GovernanceDaemonControlPort | undefined);
15
+ handleUnknown(input: unknown, credential: GovernanceServiceCredential): GovernanceServiceResponse;
16
+ close(): void;
17
+ }
18
+ //# sourceMappingURL=authenticated-project-service.d.ts.map
@@ -0,0 +1,40 @@
1
+ export declare const AUTONOMY_TIERS: readonly ['A0', 'A1', 'A2', 'A3', 'A4'];
2
+ export type AutonomyTier = (typeof AUTONOMY_TIERS)[number];
3
+ export declare const GOVERNED_OPERATIONS: readonly ['repository_read', 'file_edit', 'focused_check', 'shell_restricted', 'subagent_spawn', 'git_local_write', 'shell_arbitrary', 'package_install', 'public_api_change', 'schema_change', 'network_access', 'secret_access', 'git_push', 'publish', 'deploy', 'destructive_external'];
4
+ export type GovernedOperation = (typeof GOVERNED_OPERATIONS)[number];
5
+ export interface ChangeBudget {
6
+ readonly maxChangedFiles: number;
7
+ readonly maxChangedLines: number;
8
+ readonly maxNewDependencies: number;
9
+ readonly maxRetries: number;
10
+ readonly maxReplans: number;
11
+ readonly maxSubagents: number;
12
+ readonly maxWallClockMs: number;
13
+ }
14
+ export interface AutonomyEnvelope {
15
+ readonly tier: AutonomyTier;
16
+ readonly allowedOperations: readonly GovernedOperation[];
17
+ readonly humanApprovalRequiredFor: readonly GovernedOperation[];
18
+ readonly allowedPaths: readonly string[];
19
+ readonly deniedPaths: readonly string[];
20
+ readonly budget: ChangeBudget;
21
+ readonly autoAuthorizePlan: boolean;
22
+ readonly autoReplanLimit: number;
23
+ readonly autoResolveReviewFixes: boolean;
24
+ }
25
+ export type OperationAutonomyDecision = {
26
+ readonly allowed: true;
27
+ readonly requiresHumanApproval: false;
28
+ readonly operation: GovernedOperation;
29
+ readonly minimumTier: AutonomyTier;
30
+ } | {
31
+ readonly allowed: false;
32
+ readonly requiresHumanApproval: true;
33
+ readonly operation: GovernedOperation;
34
+ readonly minimumTier: AutonomyTier;
35
+ readonly reason: 'operation_not_allowed' | 'explicit_approval_required' | 'tier_exceeded';
36
+ };
37
+ export declare const OPERATION_MINIMUM_TIER: Readonly<Record<GovernedOperation, AutonomyTier>>;
38
+ export declare function compareAutonomyTiers(left: AutonomyTier, right: AutonomyTier): number;
39
+ export declare function decideOperationAutonomy(envelope: AutonomyEnvelope, operation: GovernedOperation): OperationAutonomyDecision;
40
+ //# sourceMappingURL=autonomy-envelope.d.ts.map
@@ -0,0 +1,122 @@
1
+ import { type GovernanceServiceCapability, type GovernanceServiceClientContext } from './service-protocol.js';
2
+ export declare const DEFAULT_GOVERNANCE_GRANT_MAX_TTL_MS: number;
3
+ export declare const DEFAULT_GOVERNANCE_MAX_GRANTS = 10000;
4
+ export type GovernanceCapabilityGrantStatus = 'active' | 'expired' | 'revoked';
5
+ export interface GovernanceCapabilityGrant {
6
+ readonly grantId: string;
7
+ readonly projectId: string;
8
+ readonly clientId: string;
9
+ readonly issuedBy: string;
10
+ readonly capabilities: readonly GovernanceServiceCapability[];
11
+ readonly issuedAt: string;
12
+ readonly expiresAt: string;
13
+ readonly status: GovernanceCapabilityGrantStatus;
14
+ readonly revokedAt?: string | undefined;
15
+ readonly revokedBy?: string | undefined;
16
+ readonly revocationReason?: string | undefined;
17
+ }
18
+ export interface IssuedGovernanceCapabilityGrant {
19
+ readonly token: string;
20
+ readonly grant: GovernanceCapabilityGrant;
21
+ }
22
+ export interface IssueGovernanceCapabilityGrantOptions {
23
+ readonly clientId: string;
24
+ readonly issuedBy?: string | undefined;
25
+ readonly capabilities: readonly GovernanceServiceCapability[];
26
+ readonly ttlMs: number;
27
+ }
28
+ export interface RotateGovernanceCapabilityGrantOptions {
29
+ readonly rotatedBy?: string | undefined;
30
+ readonly ttlMs: number;
31
+ readonly reason?: string | undefined;
32
+ }
33
+ export interface GovernanceServiceCredential {
34
+ readonly token: string;
35
+ readonly projectId: string;
36
+ readonly clientId: string;
37
+ }
38
+ export type GovernanceCapabilityAuthenticationFailureCode = 'invalid_token' | 'project_mismatch' | 'client_mismatch' | 'grant_expired' | 'grant_revoked';
39
+ export type GovernanceCapabilityAuthenticationResult = {
40
+ readonly authenticated: true;
41
+ readonly grant: GovernanceCapabilityGrant;
42
+ readonly client: GovernanceServiceClientContext;
43
+ } | {
44
+ readonly authenticated: false;
45
+ readonly code: GovernanceCapabilityAuthenticationFailureCode;
46
+ readonly message: string;
47
+ };
48
+ export type GovernanceGrantAuditEvent = {
49
+ readonly sequence: number;
50
+ readonly type: 'grant_issued';
51
+ readonly grantId: string;
52
+ readonly projectId: string;
53
+ readonly clientId: string;
54
+ readonly issuedBy: string;
55
+ readonly capabilities: readonly GovernanceServiceCapability[];
56
+ readonly occurredAt: string;
57
+ readonly expiresAt: string;
58
+ } | {
59
+ readonly sequence: number;
60
+ readonly type: 'grant_revoked';
61
+ readonly grantId: string;
62
+ readonly projectId: string;
63
+ readonly clientId: string;
64
+ readonly revokedBy: string;
65
+ readonly occurredAt: string;
66
+ readonly reason: string;
67
+ } | {
68
+ readonly sequence: number;
69
+ readonly type: 'grant_expired';
70
+ readonly grantId: string;
71
+ readonly projectId: string;
72
+ readonly clientId: string;
73
+ readonly occurredAt: string;
74
+ readonly reason: string;
75
+ } | {
76
+ readonly sequence: number;
77
+ readonly type: 'grant_rotated';
78
+ readonly grantId: string;
79
+ readonly previousGrantId: string;
80
+ readonly projectId: string;
81
+ readonly clientId: string;
82
+ readonly rotatedBy: string;
83
+ readonly capabilities: readonly GovernanceServiceCapability[];
84
+ readonly occurredAt: string;
85
+ readonly expiresAt: string;
86
+ readonly reason: string;
87
+ };
88
+ export interface GovernanceCapabilityGrantRegistryOptions {
89
+ readonly now?: (() => number) | undefined;
90
+ readonly maxTtlMs?: number | undefined;
91
+ readonly maxGrants?: number | undefined;
92
+ readonly tokenMaterial?: (() => {
93
+ readonly grantId: string;
94
+ readonly secret: string;
95
+ }) | undefined;
96
+ readonly auditSink?: ((event: GovernanceGrantAuditEvent) => void) | undefined;
97
+ }
98
+ export declare class GovernanceCapabilityGrantRegistry {
99
+ readonly projectId: string;
100
+ private readonly records;
101
+ private readonly now;
102
+ private readonly maxTtlMs;
103
+ private readonly maxGrants;
104
+ private readonly tokenMaterial;
105
+ private readonly auditSink;
106
+ private auditSequence;
107
+ constructor(projectId: string, options?: GovernanceCapabilityGrantRegistryOptions);
108
+ issue(options: IssueGovernanceCapabilityGrantOptions): IssuedGovernanceCapabilityGrant;
109
+ rotate(grantId: string, options: RotateGovernanceCapabilityGrantOptions): IssuedGovernanceCapabilityGrant;
110
+ authenticate(credential: GovernanceServiceCredential): GovernanceCapabilityAuthenticationResult;
111
+ revoke(grantId: string, reason?: string, revokedBy?: string): boolean;
112
+ sweepExpired(reason?: string): number;
113
+ getGrant(grantId: string): GovernanceCapabilityGrant | null;
114
+ remainingTtlMs(grantId: string): number | null;
115
+ listGrants(): readonly GovernanceCapabilityGrant[];
116
+ private parseToken;
117
+ private describe;
118
+ private reject;
119
+ private appendAudit;
120
+ private pruneInactive;
121
+ }
122
+ //# sourceMappingURL=capability-grant.d.ts.map
@@ -0,0 +1,85 @@
1
+ import type { GovernanceServiceCredential } from './capability-grant.js';
2
+ import type { GovernanceServiceResponse } from './project-service.js';
3
+ export declare const GOVERNANCE_CREDENTIAL_LEASE_DEFAULT_TTL_MS: number;
4
+ export declare const GOVERNANCE_CREDENTIAL_LEASE_DEFAULT_RENEW_BEFORE_MS: number;
5
+ export declare const GOVERNANCE_CREDENTIAL_LEASE_DEFAULT_RETRY_MS = 1000;
6
+ export declare const GOVERNANCE_CREDENTIAL_LEASE_DEFAULT_MAX_ATTEMPTS = 3;
7
+ export type GovernanceCredentialLeaseState = 'idle' | 'scheduled' | 'rotating' | 'retry_wait' | 'stopped' | 'expired';
8
+ export type GovernanceCredentialLeaseStopReason = 'stopped_by_owner' | 'retry_exhausted' | 'credential_expired';
9
+ export interface GovernanceCredentialLeaseSnapshot {
10
+ readonly state: GovernanceCredentialLeaseState;
11
+ readonly projectId: string;
12
+ readonly clientId: string;
13
+ readonly grantId: string;
14
+ readonly expiresAt: string;
15
+ readonly rotationAttempt: number;
16
+ readonly nextActionAt?: string | undefined;
17
+ readonly stopReason?: GovernanceCredentialLeaseStopReason | undefined;
18
+ readonly lastFailure?: string | undefined;
19
+ }
20
+ export interface GovernanceCredentialLeaseScheduler {
21
+ schedule(callback: () => void, delayMs: number): unknown;
22
+ cancel(handle: unknown): void;
23
+ }
24
+ export interface GovernanceCredentialLeaseClient {
25
+ request(input: unknown): Promise<GovernanceServiceResponse>;
26
+ }
27
+ export interface GovernanceCredentialLeaseControllerOptions {
28
+ readonly projectRoot: string;
29
+ readonly projectId: string;
30
+ readonly grantId: string;
31
+ readonly expiresAt: string;
32
+ readonly credential: GovernanceServiceCredential;
33
+ readonly rotationTtlMs?: number | undefined;
34
+ readonly renewBeforeMs?: number | undefined;
35
+ readonly retryDelayMs?: number | undefined;
36
+ readonly maxAttempts?: number | undefined;
37
+ readonly requestTimeoutMs?: number | undefined;
38
+ readonly now?: (() => number) | undefined;
39
+ readonly scheduler?: GovernanceCredentialLeaseScheduler | undefined;
40
+ readonly requestIdFactory?: (() => string) | undefined;
41
+ readonly clientFactory?: ((credential: GovernanceServiceCredential) => GovernanceCredentialLeaseClient) | undefined;
42
+ }
43
+ /**
44
+ * Opt-in process-local holder for one self-rotating capability_admin credential.
45
+ * It never persists or exposes the current bearer token.
46
+ */
47
+ export declare class GovernanceCredentialLeaseController implements GovernanceCredentialLeaseClient {
48
+ private readonly projectRoot;
49
+ private readonly projectId;
50
+ private readonly clientId;
51
+ private readonly rotationTtlMs;
52
+ private readonly renewBeforeMs;
53
+ private readonly retryDelayMs;
54
+ private readonly maxAttempts;
55
+ private readonly now;
56
+ private readonly scheduler;
57
+ private readonly requestIdFactory;
58
+ private readonly clientFactory;
59
+ private client;
60
+ private credential;
61
+ private grantId;
62
+ private expiresAtMs;
63
+ private state;
64
+ private rotationAttempt;
65
+ private cycleRequestId;
66
+ private timer;
67
+ private nextActionAtMs;
68
+ private stopReason;
69
+ private lastFailure;
70
+ private stopped;
71
+ private inFlight;
72
+ constructor(options: GovernanceCredentialLeaseControllerOptions);
73
+ start(): GovernanceCredentialLeaseSnapshot;
74
+ stop(): GovernanceCredentialLeaseSnapshot;
75
+ request(input: unknown): Promise<GovernanceServiceResponse>;
76
+ rotateNow(): Promise<GovernanceCredentialLeaseSnapshot>;
77
+ snapshot(): GovernanceCredentialLeaseSnapshot;
78
+ private rotateOnce;
79
+ private handleFailure;
80
+ private scheduleRenewal;
81
+ private schedule;
82
+ private clearTimer;
83
+ private expire;
84
+ }
85
+ //# sourceMappingURL=credential-lease-controller.d.ts.map
@@ -0,0 +1,48 @@
1
+ import type { GovernanceAttachmentBrokerControllerSnapshot } from './attachment-broker-controller.js';
2
+ export interface GovernanceDaemonControlStatus {
3
+ readonly projectId: string;
4
+ readonly pid: number;
5
+ readonly instanceId: string;
6
+ readonly startedAt: string;
7
+ readonly attachmentBroker?: GovernanceAttachmentBrokerControllerSnapshot | undefined;
8
+ }
9
+ export type GovernanceDaemonOperatorSignalLevel = 'healthy' | 'notice' | 'warning';
10
+ export interface GovernanceDaemonOperatorAttachmentBrokerStatus {
11
+ readonly state: GovernanceAttachmentBrokerControllerSnapshot['state'];
12
+ readonly health: GovernanceAttachmentBrokerControllerSnapshot['health'];
13
+ readonly expiresAt?: string | undefined;
14
+ readonly nextActionAt?: string | undefined;
15
+ readonly consecutiveFailures: number;
16
+ readonly pendingRevocations: number;
17
+ readonly auditHealthy: boolean;
18
+ }
19
+ export interface GovernanceDaemonOperatorStatus {
20
+ readonly schemaVersion: 1;
21
+ readonly projectId: string;
22
+ readonly pid: number;
23
+ readonly instanceId: string;
24
+ readonly startedAt: string;
25
+ readonly signal: {
26
+ readonly level: GovernanceDaemonOperatorSignalLevel;
27
+ readonly code: 'attachment_broker_healthy' | 'attachment_broker_initializing' | 'attachment_broker_status_unavailable' | 'attachment_broker_degraded' | 'attachment_broker_audit_unhealthy' | 'attachment_broker_revocation_pending' | 'attachment_broker_stopped';
28
+ readonly message: string;
29
+ readonly operatorAction: 'none' | 'observe' | 'investigate';
30
+ readonly executionDisposition: 'continue';
31
+ };
32
+ readonly attachmentBroker: GovernanceDaemonOperatorAttachmentBrokerStatus | null;
33
+ }
34
+ /**
35
+ * Deterministic, credential-free operator projection. A warning is advisory:
36
+ * task and model execution continue until a separate policy gate says otherwise.
37
+ */
38
+ export declare function projectGovernanceDaemonOperatorStatus(status: GovernanceDaemonControlStatus): GovernanceDaemonOperatorStatus;
39
+ export interface GovernanceDaemonControlPort {
40
+ status(): GovernanceDaemonControlStatus;
41
+ }
42
+ export interface GovernanceDaemonShutdownNotice {
43
+ readonly requestId: string;
44
+ readonly expectedInstanceId: string;
45
+ readonly requestedBy: string;
46
+ readonly reason: string;
47
+ }
48
+ //# sourceMappingURL=daemon-control.d.ts.map