@quantiya/codevibe-core 2.0.7 → 2.0.9

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 (128) hide show
  1. package/dist/appsync/__tests__/dispose-watcher-socket.test.d.ts +1 -0
  2. package/dist/appsync/__tests__/refresh-open-prompt-ttl-chunk.test.d.ts +1 -0
  3. package/dist/appsync/appsync-client.d.ts +232 -30
  4. package/dist/appsync/queries.d.ts +2 -0
  5. package/dist/auth/__tests__/keychain-cli-nudge.test.d.ts +1 -0
  6. package/dist/auth/__tests__/keychain-cli.test.d.ts +1 -0
  7. package/dist/auth/keychain-cli.d.ts +14 -0
  8. package/dist/companion-mode/index.d.ts +14 -0
  9. package/dist/credential-broker/oauth-account-lock.d.ts +47 -1
  10. package/dist/crypto/__tests__/open-prompt-id.test.d.ts +1 -0
  11. package/dist/crypto/index.d.ts +1 -0
  12. package/dist/crypto/open-prompt-id.d.ts +36 -0
  13. package/dist/e1/__tests__/prompt-raise.test.d.ts +1 -0
  14. package/dist/e1/index.d.ts +2 -0
  15. package/dist/e1/prompt-raise.d.ts +65 -0
  16. package/dist/index.d.ts +4 -1
  17. package/dist/index.js +4652 -252
  18. package/dist/keychain/__tests__/keychain-manager.test.d.ts +1 -0
  19. package/dist/keychain/__tests__/keychain-migrate.test.d.ts +1 -0
  20. package/dist/keychain/__tests__/migrate-nudge.test.d.ts +1 -0
  21. package/dist/keychain/keychain-backend.d.ts +105 -0
  22. package/dist/keychain/keychain-manager.d.ts +17 -3
  23. package/dist/keychain/keychain-migrate.d.ts +63 -0
  24. package/dist/keychain/migrate-nudge.d.ts +38 -0
  25. package/dist/local-executor/__tests__/anchored-fs.test.d.ts +1 -0
  26. package/dist/local-executor/__tests__/bounded-directory.test.d.ts +1 -0
  27. package/dist/local-executor/__tests__/bounded-output.test.d.ts +1 -0
  28. package/dist/local-executor/__tests__/durable-directory.test.d.ts +1 -0
  29. package/dist/local-executor/__tests__/hosted-class-a-sink.test.d.ts +1 -0
  30. package/dist/local-executor/__tests__/process-identity.test.d.ts +1 -0
  31. package/dist/local-executor/__tests__/process-tree.test.d.ts +1 -0
  32. package/dist/local-executor/__tests__/protocol-backlog-wiring.test.d.ts +1 -0
  33. package/dist/local-executor/__tests__/protocol-backlog.test.d.ts +1 -0
  34. package/dist/local-executor/__tests__/publication-authority-capability.test.d.ts +1 -0
  35. package/dist/local-executor/__tests__/snapshot-merge.test.d.ts +1 -0
  36. package/dist/local-executor/__tests__/workspace-authority-fixture.d.ts +3 -0
  37. package/dist/local-executor/__tests__/workspace-authority.test.d.ts +1 -0
  38. package/dist/local-executor/__tests__/workspace-cleanup-audit.test.d.ts +1 -0
  39. package/dist/local-executor/__tests__/workspace-materializer.test.d.ts +1 -0
  40. package/dist/local-executor/agentic-disposable-repo.d.ts +23 -6
  41. package/dist/local-executor/agentic-resolve.d.ts +16 -0
  42. package/dist/local-executor/anchored-fs.d.ts +250 -0
  43. package/dist/local-executor/bounded-directory.d.ts +78 -0
  44. package/dist/local-executor/bounded-helper.d.ts +22 -0
  45. package/dist/local-executor/bounded-output.d.ts +11 -0
  46. package/dist/local-executor/class-a-emit.d.ts +13 -1
  47. package/dist/local-executor/durable-directory.d.ts +25 -0
  48. package/dist/local-executor/durable-store.d.ts +217 -25
  49. package/dist/local-executor/hosted-class-a-sink.d.ts +27 -0
  50. package/dist/local-executor/index.d.ts +3 -2
  51. package/dist/local-executor/local-executor-impl.d.ts +159 -69
  52. package/dist/local-executor/process-identity.d.ts +46 -0
  53. package/dist/local-executor/process-tree.d.ts +123 -0
  54. package/dist/local-executor/protocol-backlog.d.ts +62 -0
  55. package/dist/local-executor/revert-reconcile.d.ts +4 -0
  56. package/dist/local-executor/revert-runner.d.ts +14 -1
  57. package/dist/local-executor/snapshot-merge.d.ts +124 -0
  58. package/dist/local-executor/task-group-types.d.ts +7 -6
  59. package/dist/local-executor/team-execution-flag.d.ts +2 -2
  60. package/dist/local-executor/track-registry.d.ts +2 -0
  61. package/dist/local-executor/types.d.ts +33 -2
  62. package/dist/local-executor/verification-gates/build.d.ts +5 -0
  63. package/dist/local-executor/verification-gates/deploy-preflight.d.ts +2 -0
  64. package/dist/local-executor/verification-gates/diff-sanity.d.ts +12 -0
  65. package/dist/local-executor/verification-gates/hostile-grep.d.ts +2 -0
  66. package/dist/local-executor/verification-gates/lint.d.ts +2 -0
  67. package/dist/local-executor/verification-gates/shell-runner.d.ts +5 -0
  68. package/dist/local-executor/verification-gates/source-traceability.d.ts +2 -0
  69. package/dist/local-executor/verification-gates/tests.d.ts +3 -0
  70. package/dist/local-executor/verification-gates/typecheck.d.ts +3 -0
  71. package/dist/local-executor/verification-runner.d.ts +6 -0
  72. package/dist/local-executor/workspace-authority.d.ts +45 -0
  73. package/dist/local-executor/workspace-cleanup-audit.d.ts +3 -0
  74. package/dist/local-executor/workspace-materializer.d.ts +48 -0
  75. package/dist/local-executor/workspace-shadow.d.ts +380 -85
  76. package/dist/orchestration-shell/__tests__/advisory-attachment-journal.test.d.ts +1 -0
  77. package/dist/orchestration-shell/__tests__/direct-file-delete.test.d.ts +1 -0
  78. package/dist/orchestration-shell/__tests__/flag-command.test.d.ts +1 -0
  79. package/dist/orchestration-shell/__tests__/halt-message-wire-content.test.d.ts +1 -0
  80. package/dist/orchestration-shell/__tests__/planner-offer-e1.test.d.ts +1 -0
  81. package/dist/orchestration-shell/__tests__/workspace-shutdown.test.d.ts +1 -0
  82. package/dist/orchestration-shell/advisory-attachment-journal.d.ts +165 -0
  83. package/dist/orchestration-shell/attachments.d.ts +47 -58
  84. package/dist/orchestration-shell/audit-browser.d.ts +54 -1
  85. package/dist/orchestration-shell/bounded-shutdown.d.ts +6 -0
  86. package/dist/orchestration-shell/cli.d.ts +10 -0
  87. package/dist/orchestration-shell/cli.js +38355 -27300
  88. package/dist/orchestration-shell/context-items.d.ts +3 -0
  89. package/dist/orchestration-shell/declared-test-runner.d.ts +21 -2
  90. package/dist/orchestration-shell/direct-file-delete.d.ts +22 -0
  91. package/dist/orchestration-shell/emit-shell-event.d.ts +7 -0
  92. package/dist/orchestration-shell/explicit-tty-exit.d.ts +1 -2
  93. package/dist/orchestration-shell/flag-command.d.ts +81 -0
  94. package/dist/orchestration-shell/gate-decision-submit.d.ts +11 -0
  95. package/dist/orchestration-shell/gate-prompts.d.ts +116 -0
  96. package/dist/orchestration-shell/index.d.ts +34 -6
  97. package/dist/orchestration-shell/planner-offer-e1.d.ts +97 -0
  98. package/dist/orchestration-shell/quorum-loop.d.ts +312 -61
  99. package/dist/orchestration-shell/reducer.d.ts +9 -0
  100. package/dist/orchestration-shell/task-progress.d.ts +18 -4
  101. package/dist/orchestration-shell/team-decompose.d.ts +10 -10
  102. package/dist/orchestration-shell/types.d.ts +90 -2
  103. package/dist/orchestration-shell/workspace-shutdown.d.ts +47 -0
  104. package/dist/reviewer/output-parser.d.ts +19 -0
  105. package/dist/reviewer/providers/codex.d.ts +5 -3
  106. package/dist/reviewer/token-usage.d.ts +41 -12
  107. package/dist/reviewer/types.d.ts +6 -0
  108. package/dist/reviewer/verdict-classifier.d.ts +1 -0
  109. package/dist/session/session-rekey.d.ts +4 -3
  110. package/dist/substrate/__tests__/command-runner.test.d.ts +1 -0
  111. package/dist/substrate/command-runner.d.ts +2 -0
  112. package/dist/substrate/docker.d.ts +7 -32
  113. package/dist/substrate/index.d.ts +0 -1
  114. package/dist/substrate/sandbox-exec.d.ts +0 -13
  115. package/dist/substrate/types.d.ts +15 -2
  116. package/dist/substrate-launch/__tests__/reviewer-credential-preflight.test.d.ts +1 -0
  117. package/dist/substrate-launch/engage-substrate.d.ts +3 -0
  118. package/dist/substrate-launch/index.d.ts +2 -0
  119. package/dist/substrate-launch/reviewer-credential-preflight.d.ts +50 -0
  120. package/dist/test-publication-authority-setup.d.ts +1 -0
  121. package/dist/tool-activity/replay-cursor.d.ts +42 -8
  122. package/dist/track-presentation.d.ts +2 -0
  123. package/dist/track-presentation.test.d.ts +1 -0
  124. package/dist/types/encryption.d.ts +5 -0
  125. package/dist/types/events.d.ts +5 -0
  126. package/package.json +3 -3
  127. package/dist/substrate/git-proxy.d.ts +0 -35
  128. /package/dist/{substrate/__tests__/git-proxy.test.d.ts → appsync/__tests__/appsync-client-flag-locator.test.d.ts} +0 -0
@@ -1,4 +1,19 @@
1
+ import { type AnchoredFsIdentity, type AnchoredPathIdentity } from './anchored-fs';
1
2
  import type { PromoteManifestInput } from './durable-store';
3
+ import { type ProcessCleanupOwner } from './process-tree';
4
+ import { type ProcessIdentity } from './process-identity';
5
+ import { type WorkspaceRootAuthority } from './workspace-authority';
6
+ import { type MaterializationHangStage } from './workspace-materializer';
7
+ export declare const MAX_TRACKED_FILE_LOGICAL_BYTES: number;
8
+ export declare const MAX_TRACKED_WORKSPACE_LOGICAL_BYTES: number;
9
+ /** Metadata is bounded independently of content bytes (zero-byte files still cost memory/inodes). */
10
+ export declare const MAX_TRACKED_FILE_COUNT = 100000;
11
+ export declare const MAX_TRACKED_PATH_BYTES: number;
12
+ /** Reviewed text is intentionally bounded before any whole-file decode/read. */
13
+ export declare const MAX_REVIEW_FILE_BYTES: number;
14
+ export declare const MAX_PROMOTION_PREIMAGE_AGGREGATE_BYTES: number;
15
+ /** Exact UTF-8 ceiling shared by every durable state-marker writer and reader. */
16
+ export declare const MAX_STATE_MARKER_BYTES: number;
2
17
  /** Default TTL after which an orphaned shadow is GC-eligible (#GC-1). */
3
18
  export declare const DEFAULT_SHADOW_TTL_MS: number;
4
19
  /** `change_kind` values mirroring the pinned engine `ExecuteFirstFile` contract. */
@@ -10,28 +25,141 @@ export interface ShadowDiffFile {
10
25
  change_kind: ShadowChangeKind;
11
26
  /** The captured content (created/modified) or empty for deleted. */
12
27
  content: string;
28
+ /** POSIX permission bits for the reviewed post-image (omitted by legacy records). */
29
+ mode?: number;
30
+ }
31
+ /** A reviewed change plus the exact real-tree pre-image expected at promotion. */
32
+ export interface ReviewedShadowDiffFile extends ShadowDiffFile {
33
+ /** SHA-256 of the pre-task file, or null when the path was absent. */
34
+ base_hash: string | null;
35
+ /** POSIX permission bits of the pre-task file, or null when absent. */
36
+ base_mode?: number | null;
13
37
  }
14
38
  /** Persisted promote-state marker (#PR-4). */
15
- type ShadowPromoteState = 'pending' | 'promoted';
16
- /** Injected for deterministic tests; production uses the real fs/git. */
39
+ type ShadowPromoteState = 'pending' | 'applying' | 'promoted' | 'disposing';
40
+ export type CasHelperCrashStage = 'post-link' | 'post-displacement' | 'post-publication' | 'post-fsync' | 'post-close';
41
+ export interface UnresolvedBundlePublicationRetention {
42
+ taskGroupId: string;
43
+ trackIndex: number;
44
+ }
45
+ interface CasRecoveryAuthority {
46
+ path: string;
47
+ operation: 'replace' | 'delete';
48
+ /** Deterministic from the persisted root/pre/post authority. */
49
+ recoveryName: string;
50
+ /** Deterministic public-entry quarantine used instead of check-then-unlink. */
51
+ quarantineName: string;
52
+ /** Deterministic prepared-byte name for replace/create operations. */
53
+ tempName?: string;
54
+ expectedHash: string | null;
55
+ expectedMode: number | null;
56
+ postHash: string | null;
57
+ postMode: number | null;
58
+ }
59
+ /** Injected for deterministic tests; production uses the real filesystem. */
17
60
  export interface ShadowEnv {
18
- /** Sleep between git-op retries. */
61
+ /** @deprecated Compatibility-only; filesystem snapshots do not use Git retries. */
19
62
  sleep?: (ms: number) => Promise<void>;
20
63
  /** Override the per-task state dir root (default `~/.codevibe/shadow-state`). */
21
64
  stateRootDir?: string;
22
65
  /** Override the shadow temp-dir root (default `os.tmpdir()`). */
23
66
  shadowRootDir?: string;
67
+ /** @internal lower deterministic limit for serialized-marker boundary tests. */
68
+ maxStateMarkerBytes?: number;
24
69
  /** TTL for the GC reaper. */
25
70
  ttlMs?: number;
71
+ /** @internal lower deterministic workspace-authority helper deadline. */
72
+ workspaceAuthorityHelperTimeoutMs?: number;
73
+ /** @internal deterministic root/recovery authority stall seam. */
74
+ testHangWorkspaceAuthorityStage?: (target: string, boundary: string) => 'realpath' | 'lstat' | 'open' | 'stat' | 'close' | undefined;
26
75
  /** Hook to terminate task-spawned children rooted in the shadow before teardown. */
27
76
  killChildrenInShadow?: (shadowDir: string) => Promise<void>;
77
+ /** @internal lower deterministic aggregate quota for tests. */
78
+ maxSessionPhysicalCopyBytes?: number;
79
+ /** @internal lower deterministic aggregate pre-image quota for tests. */
80
+ maxPromotionPreImageAggregateBytes?: number;
81
+ /** Test seam after the stable source handle is opened but before physical streaming. */
82
+ beforePhysicalCopy?: (source: string) => Promise<void>;
83
+ /** @internal force the production helper's bounded physical-copy branch. */
84
+ forcePhysicalMaterialization?: boolean;
85
+ /** @internal lower deterministic materialization-helper deadline for tests. */
86
+ materializationHelperTimeoutMs?: number;
87
+ /** @internal deterministic live-workspace helper stall seam. */
88
+ testHangMaterializationHelperStage?: (source: string) => MaterializationHangStage | undefined;
89
+ /** Test seam after a tracked hash handle opens and before its bounded read. */
90
+ beforeTrackedHashRead?: (filePath: string) => Promise<void>;
91
+ /** Test seam after materialization and before hashing/marker persistence. */
92
+ afterShadowMaterialized?: (shadowDir: string) => Promise<void>;
93
+ /** Test seam immediately before each recovery-byte/directory durability sync. */
94
+ beforeSnapshotDurabilitySync?: (kind: 'file' | 'directory' | 'parent', target: string) => Promise<void> | void;
95
+ /** Test seam after copy and before the final durability seal + atomic exposure. */
96
+ beforeSnapshotExpose?: (stagingDir: string, finalDir: string) => Promise<void> | void;
97
+ /** @internal race seam after rename while the lifecycle fence is still held. */
98
+ afterSnapshotExposeRename?: (finalDir: string) => Promise<void> | void;
99
+ /** Test seam while the lifecycle fence is held, immediately before owner publication. */
100
+ beforeSnapshotOwnerPublish?: (stagingDir: string) => Promise<void> | void;
101
+ /** @internal failure seam after inode capture but before external authority commits. */
102
+ beforeExposureRetentionPublish?: (stagingDir: string, retentionFile: string) => Promise<void> | void;
103
+ /** Test seam after merge planning and before an integration snapshot is created. */
104
+ beforePromotionWrite?: (path: string) => Promise<void>;
105
+ /** Test seam before COMMIT; no live-workspace mutation has occurred yet. */
106
+ beforePromotionCommit?: (path: string) => Promise<void>;
107
+ /** Test seam after a promote temp file is fsynced, immediately before final CAS checks. */
108
+ afterPromotionPrepared?: (path: string) => Promise<void>;
109
+ /** Test seam after final live-parent validation; helper operations stay fd-anchored. */
110
+ afterPromotionParentValidation?: (path: string) => Promise<void>;
111
+ /** @internal lower deterministic CAS-helper deadline for tests. */
112
+ promotionHelperTimeoutMs?: number;
113
+ /** @internal deterministic CAS-helper target-filesystem stall seam. */
114
+ testHangPromotionHelperStage?: (path: string) => 'root' | 'parent' | 'target' | undefined;
115
+ /** @internal deterministic helper-death seam after COMMIT/mutation. */
116
+ testCrashPromotionHelperStage?: (path: string) => CasHelperCrashStage | undefined;
117
+ /** Test seam after the exact target is displaced but before replacement/deletion. */
118
+ afterPromotionTargetDisplaced?: (path: string, recoveryName: string) => Promise<void>;
119
+ /** Test seam immediately before the public target is atomically quarantined. */
120
+ beforePromotionTargetQuarantine?: (path: string, quarantineName: string) => Promise<void>;
121
+ /** Test seam immediately before identity-conditioned promotion quarantine unlink. */
122
+ beforePromotionFinalUnlink?: (path: string, quarantineName: string) => Promise<void>;
123
+ /** Test seam before rollback verifies/reverses a just-promoted path. */
124
+ beforePromotionRollback?: (path: string) => Promise<void>;
125
+ /** Test seam after an anchored marker parent is validated but before commit. */
126
+ beforeMarkerWriteCommit?: (filePath: string) => Promise<void>;
127
+ /** Test seam after marker CAS validation while the cross-process lock is held. */
128
+ afterMarkerWriteValidation?: (filePath: string) => Promise<void>;
129
+ /** @internal inject a post-publication directory-sync failure for a marker write. */
130
+ failMarkerDirectorySync?: (filePath: string) => boolean;
131
+ /** @internal inject a post-publication directory-sync failure for the quota registry. */
132
+ failQuotaRegistryDirectorySync?: boolean;
133
+ /** @internal pause after quota-lock acquisition and before strict state enumeration. */
134
+ beforeQuotaFenceScan?: () => Promise<void>;
135
+ /** @internal fail initial/retry shadow-root durability before acknowledgement. */
136
+ failShadowRootDirectorySyncStage?: 'target-child' | 'target-parent';
137
+ /** @internal fail initial/retry state-root durability before acknowledgement. */
138
+ failStateRootDirectorySyncStage?: 'target-child' | 'target-parent';
139
+ /** Test seam after disposal reads semantic state but before its CAS transition. */
140
+ afterDisposalStateRead?: (state: ShadowPromoteState) => Promise<void>;
141
+ /** Test-only: exercise the cross-process lock without the parent-process queue. */
142
+ disableMarkerWriteProcessLock?: boolean;
143
+ /** Test seam after an anchored snapshot parent is validated but before deletion. */
144
+ beforeShadowDeleteCommit?: (shadowDir: string) => Promise<void>;
145
+ /** Test seam after the owned snapshot was renamed and inode-verified. */
146
+ afterShadowTombstoneRename?: (shadowDir: string, tombstoneDir: string) => Promise<void>;
147
+ /** @internal exact lifecycle-lock release seam after snapshot cleanup. */
148
+ beforeShadowLifecycleFinalRemove?: (artifactPath: string) => Promise<void> | void;
149
+ /** Test seam after snapshot removal but before DISPOSING marker retirement. */
150
+ afterShadowRemovedBeforeMarkerCleanup?: (shadowDir: string) => Promise<void>;
151
+ /** @internal deterministic state-directory replacement before residue cleanup. */
152
+ beforeCrashedStateArtifactCleanup?: (stateDir: string) => Promise<void> | void;
153
+ /** @internal deterministic cleanup-block replacement before exact retirement. */
154
+ beforeCleanupBlockFinalRemove?: (artifactPath: string) => Promise<void> | void;
28
155
  }
29
156
  /**
30
- * CP-14 Wave A (`team.execution=worktree_merge`) — make the shadow worktree a
157
+ * Legacy migration contract from the branch-tip implementation. New creates
158
+ * ignore this option and always use a Git-independent snapshot. Historically it made a worktree a
31
159
  * PERSISTENT track branch instead of a detached HEAD, so the merge-train can
32
160
  * merge the track's committed tip. `baseSha` is the ONE group base pinned BEFORE
33
161
  * the first track shadow is created (so every track roots at the same base — a
34
- * deterministic merge-train input). Git-only: a non-git workspace is ineligible.
162
+ * deterministic merge-train input).
35
163
  */
36
164
  export interface TrackBranchSpec {
37
165
  /** The persistent branch name, e.g. `codevibe/track/<groupId>/<trackIndex>`. */
@@ -51,33 +179,69 @@ export declare class WorkspaceShadow {
51
179
  readonly workingDir: string;
52
180
  /** The shadow dir the implementor spawns in (its cwd). */
53
181
  readonly shadowDir: string;
54
- /** True when the shadow is a `git worktree` (vs a non-git file copy). */
55
- readonly isGit: boolean;
182
+ private readonly shadowDirIdentity;
183
+ private readonly snapshotRootAuthority;
184
+ private readonly workingDirIdentity;
185
+ private readonly workspaceRootAuthority;
186
+ private readonly ownerProcessIdentity;
187
+ private readonly physicalCopyBytes;
188
+ private readonly physicalCopyScope;
56
189
  /**
57
- * CP-14 Wave A — the persistent track branch this shadow worktree sits on
58
- * (`worktree_merge` only); undefined on the legacy detached-HEAD path. When
59
- * set, the seam commits to this branch (see {@link commitTrack}) instead of
60
- * the in-place promote.
190
+ * Legacy marker retained for recovery compatibility. New shadows are always
191
+ * CodeVibe-managed filesystem snapshots, so this is always false.
61
192
  */
62
- readonly trackBranch?: string;
193
+ readonly isGit: boolean;
63
194
  /** Paths (RELATIVE to workingDir) materialized into the shadow — the TRACKED SET. */
64
195
  private trackedSet;
65
196
  /** Pre-task content hash per tracked path (null = absent at create), #PR-2. */
66
197
  private preTaskHashes;
198
+ /** Pre-task POSIX mode per tracked path (null = absent at create). */
199
+ private preTaskModes;
67
200
  /** The per-task durable state dir (under the app-data dir), survives restarts. */
68
201
  private readonly stateDir;
202
+ /** This snapshot instance's marker; sibling restarts never overwrite it. */
203
+ private readonly stateFile;
204
+ /** Original durable state authorities; public pathnames are never re-adopted. */
205
+ private readonly stateRootAuthority;
206
+ private readonly stateDirAuthority;
207
+ private stateFileAuthority?;
208
+ /**
209
+ * Same-instance atomic writes that may have published a replacement inode
210
+ * before their outer promise updates `stateFileAuthority`. A concurrent
211
+ * reader joins this narrow handoff instead of misclassifying our authenticated
212
+ * commit as a pathname replacement.
213
+ */
214
+ private readonly stateFileWriteAdmissions;
215
+ private exposureFileAuthority?;
216
+ private stateResourcesRetiredInProcess;
69
217
  private readonly env;
70
- private readonly sleep;
218
+ private readonly maxStateMarkerBytes;
219
+ private promotedInProcess;
220
+ private cleanupBlocked;
221
+ private cleanupOwners;
222
+ private unresolvedAuthorityRetention?;
71
223
  private constructor();
72
224
  /** @internal — test introspection of the tracked set. */
73
225
  get trackedSetForTests(): ReadonlySet<string>;
226
+ /** Exact user-root instance authenticated into reviewed team bundles. */
227
+ rootAuthorityForBundle(): WorkspaceRootAuthority;
228
+ /** Exact disposable-root incarnation required by every task-scoped consumer. */
229
+ snapshotAuthorityForDispatch(): WorkspaceRootAuthority;
230
+ /**
231
+ * Exact recovery-instance comparator. A task id or pathname alone is not an
232
+ * ownership token: restart races may leave two UUID snapshots for one task,
233
+ * and a hostile pathname replacement may reuse the public name. Recovery and
234
+ * teardown use this full marker/root authority check before installing or
235
+ * reconciling a durable instance.
236
+ */
237
+ matchesRecoveredInstance(recovered: RecoveredShadow): boolean;
74
238
  /**
75
239
  * Create the shadow BEFORE the round-0 spawn + record the TRACKED SET.
76
240
  *
77
- * - git repo → `git worktree add` (PRIMARY: cheap, shared object store, real
78
- * `.git` so the agent's own `npm test`/`git diff` work).
79
- * - non-git → file-copy of `workingDir` excluding `.git`/secrets/gitignored
80
- * + symlink the real `node_modules` (read-through, never a promote target).
241
+ * Every workspace, Git repository or not, is materialized through the same
242
+ * CodeVibe-owned filesystem snapshot. Regular files use copy-on-write clones
243
+ * where the filesystem supports them and fall back to a normal copy only when
244
+ * cloning is unavailable. Git is never probed or invoked on this path.
81
245
  *
82
246
  * Fail-closed (#SR-2): a create failure throws — the caller surfaces it and
83
247
  * does NOT spawn against a half-built shadow.
@@ -94,42 +258,32 @@ export declare class WorkspaceShadow {
94
258
  * shadow (NOT merely "absent from shadow", which would falsely
95
259
  * flag every excluded path → catastrophic-delete).
96
260
  *
97
- * git → `git diff` (already tracked-scoped); non-git → tree-compare bounded to
98
- * the tracked set. Across revise rounds the diff is CUMULATIVE shadow-vs-real.
261
+ * Snapshots use a tree compare bounded to the tracked set. Across revise
262
+ * rounds the diff is CUMULATIVE shadow-vs-real.
99
263
  */
100
264
  captureDiff(): Promise<ShadowDiffFile[]>;
101
- private captureGitDiff;
102
- private captureCopyDiff;
103
265
  /**
104
- * CP-14 Wave A (`worktree_merge`) — commit the shadow worktree's full content
105
- * (the dirty-replay baseline + the implementor's edits + any new untracked
106
- * files) onto the persistent track branch, and return the committed tip SHA
107
- * (the merge-train input). This REPLACES the legacy in-place {@link promote}
108
- * for track shadows: the user tree is NOT touched here — the change lands only
109
- * when the merge gate promotes the integration tip.
110
- *
111
- * Deterministic for recovery-replay stability: pinned bot identity + a pinned
112
- * `@0` author/committer date + hooks/gpg disabled, so a re-run over identical
113
- * content yields an identical SHA. `--allow-empty` so a no-op track still
114
- * produces a real base-rooted tip (no `#EF-1`-style born-halt; the merge-train
115
- * fast-forwards it).
116
- *
117
- * Requires a git track-branch shadow (created with `opts.trackBranch`); throws
118
- * otherwise — a missing tip must FAIL CLOSED upstream, never be silently empty.
119
- *
120
- * REVIEW-INTEGRITY (#598-11 parity, Stage-1 HIGH): the commit is built from the
121
- * REVIEWED, drift-checked `diff` content (the in-memory `ShadowDiffFile[]` the
122
- * caller already validated against the reviewed snapshot) via a THROWAWAY index
123
- * + `git hash-object`/`commit-tree` — the live worktree is NEVER re-read. This
124
- * matches the legacy `promote(diff)`, which applies the captured `diff[].content`
125
- * (not a re-read), so a detached writer that mutates the worktree after the
126
- * drift-check cannot inject UNREVIEWED bytes into the track tip. The branch sits
127
- * at the pinned base (its only commit-to-be) and the diff is "everything vs
128
- * base", so `read-tree base` + apply-diff reconstructs exactly the reviewed tree.
266
+ * Bind a reviewed diff to this shadow's pre-task hashes. Team execution stores
267
+ * these immutable bundles instead of Git commits; the integration gate uses
268
+ * `base_hash` for the same no-clobber check as single-task promotion.
269
+ */
270
+ bindReviewedDiff(diff: readonly ShadowDiffFile[]): ReviewedShadowDiffFile[];
271
+ /**
272
+ * Durably bind the exact artifact submitted for review to this snapshot.
273
+ * The private state marker is fsynced before the caller may submit the
274
+ * artifact to the engine. A revise round atomically replaces the prior
275
+ * authority; completion/discard removes the instance marker with the copy.
129
276
  */
130
- commitTrack(diff: readonly ShadowDiffFile[], opts?: {
131
- message?: string;
132
- }): Promise<string>;
277
+ persistReviewedDiff(diff: readonly ShadowDiffFile[]): Promise<void>;
278
+ /** Read the crash-durable reviewed artifact, or null for an unreviewed snapshot. */
279
+ readReviewedDiff(): Promise<ShadowDiffFile[] | null>;
280
+ /**
281
+ * Apply already-reviewed bytes inside this disposable shadow only. Promotion
282
+ * remains bound to the bundle's reviewed base hash, never to whatever bytes
283
+ * happened to exist when the integration snapshot was created.
284
+ */
285
+ applyDiffToShadow(diff: readonly ReviewedShadowDiffFile[]): Promise<void>;
286
+ private captureCopyDiff;
133
287
  /**
134
288
  * Materialize the changed-file SET over the TRACKED SET ONLY (#PM-1/#PM-2):
135
289
  * copy the shadow's changed files onto the real tree (create/overwrite) +
@@ -169,15 +323,23 @@ export declare class WorkspaceShadow {
169
323
  promoteOrderBase: number;
170
324
  persist: (entries: PromoteManifestInput[]) => Promise<void>;
171
325
  };
326
+ /** Refuse to begin a new real-tree mutation after session cancellation. */
327
+ signal?: AbortSignal;
172
328
  }): Promise<{
173
329
  /**
174
- * Whether this call actually MATERIALIZED files onto the real tree. `false`
175
- * means it was an idempotent no-op (a prior promote already landed via the
176
- * durable `promoted` marker — a packet + recovery double-fire). The caller
177
- * uses this to suppress duplicate `promoting`/`promoted` progress + the
178
- * "Applied N files" milestone on a re-delivered TaskAuthorized packet.
330
+ * Truthful real-tree state at return. `unresolved` means an APPLYING marker
331
+ * still owns one or more possible post-images; callers must retain/re-drive
332
+ * recovery authority and must not report an ordinary failure as terminal.
333
+ */
334
+ mutationState: 'none' | 'applied' | 'unresolved';
335
+ /**
336
+ * On success, whether this call actually materialized files. On failure,
337
+ * `true` means possible post-images remain under APPLYING authority. Callers
338
+ * must inspect `mutationState` before using this for progress suppression.
179
339
  */
180
340
  materialized: boolean;
341
+ /** True when an `applying` crash marker was fully reconciled this call. */
342
+ recovered: boolean;
181
343
  promoted: string[];
182
344
  conflicts: string[];
183
345
  errors: Array<{
@@ -198,37 +360,53 @@ export declare class WorkspaceShadow {
198
360
  * each Halted reason, parser-empty, session-end, crash). Leaves the real tree
199
361
  * byte-identical to its pre-task state (a discard never touched it).
200
362
  *
201
- * git-worktree → `git worktree remove --force` (+ `git worktree prune`),
202
- * NEVER raw `rm -rf` (leaks `.git/worktrees/`, #GC-2). Non-git copy → `rm -rf`
203
- * (the symlinked `node_modules` is unlinked, never follow-delete).
363
+ * Snapshots are ordinary filesystem directories and use recursive removal.
204
364
  *
205
365
  * Before teardown, terminate task-spawned children rooted in the shadow; if
206
366
  * removal still fails (stray watcher), the durable marker is left in place so
207
367
  * the next-startup GC retries (#GC-2 lazy cleanup).
208
368
  *
209
- * `preserveStateDir` (the ORPHAN-teardown mode, restart-race fix 2026-06-11):
210
- * tear down ONLY this instance's uuid-suffixed `shadowDir` and NEVER the
211
- * per-task SHARED `stateDir`. A restart reuses the SAME taskId, so a fresh
212
- * shadow B's durable `pending` marker lives in the same `stateDir`; tearing
213
- * down the orphaned old instance A with a full `discard()` would `fs.rm` that
214
- * SHARED dir and delete B's authorized-but-pending #PR-4 marker (B becomes
215
- * unrecoverable after a crash — a sealed-LOCK violation). The orphan branch in
216
- * QuorumLoop.discardShadow passes `{ preserveStateDir: true }` because the
217
- * shared `stateDir` belongs to the LIVE mapped shadow B, not the orphan.
369
+ * Each instance owns a UUID-suffixed marker. Cleanup removes only that marker,
370
+ * so a replacement instance for the same task remains recoverable. The
371
+ * `preserveStateDir` option remains for source compatibility only.
218
372
  */
219
373
  discard(opts?: {
220
374
  preserveStateDir?: boolean;
375
+ /**
376
+ * The team integration path may retire its per-snapshot APPLYING marker
377
+ * only after the group-level PREPARED journal durably owns the same exact
378
+ * pre/post-image authority. Ordinary single-task/session cleanup must never
379
+ * set this flag.
380
+ */
381
+ applyingAuthorityRetired?: boolean;
221
382
  }): Promise<void>;
383
+ private retainExposureWriteAuthority;
384
+ private runOwnedStateFileWrite;
385
+ private acceptExposureSnapshot;
222
386
  /**
223
- * Orphan-teardown shorthand (restart-race fix 2026-06-11): tear down ONLY this
224
- * instance's `shadowDir` (worktree-aware per #GC-2) and PRESERVE the SHARED
225
- * per-task `stateDir` — used by `QuorumLoop.discardShadow`'s instance-mismatch
226
- * branch when a newer shadow (same taskId) has replaced this one in the map.
387
+ * Prove idempotent terminal cleanup without adopting replacement pathnames.
388
+ * A present original marker/bridge returns false so ordinary disposal can
389
+ * continue. A displaced original state directory is retained fail-closed.
227
390
  */
391
+ private exactStateResourcesAreRetired;
392
+ /** Reclaim a renamed original without ever adopting its public replacement. */
393
+ private discardDisplacedSnapshot;
394
+ private refreshRetainedStateAuthorities;
395
+ /** Orphan teardown is ordinary instance-owned teardown. */
228
396
  discardOrphan(): Promise<void>;
229
- private removeGitWorktree;
397
+ /** Fail-closed preflight used before callers alter their in-memory ownership. */
398
+ assertCanDiscard(): Promise<void>;
399
+ /** Strict disposal guard: malformed/unreadable authority is retained too. */
400
+ private assertDiscardable;
401
+ /**
402
+ * Atomically retire every promotion/review transition before deleting the
403
+ * disposable tree. DISPOSING is intentionally terminal and immutable: cleanup
404
+ * retries may consume it, but no marker writer may replace it.
405
+ */
406
+ private beginDisposal;
230
407
  private writeStateMarker;
231
408
  private readStateMarker;
409
+ private readStateMarkerSnapshot;
232
410
  /**
233
411
  * Read the durable promote-state marker WITHOUT mutating the tree (#PR-4). The
234
412
  * QuorumLoop checks this BEFORE `captureDiff` so a re-delivered TaskAuthorized
@@ -239,11 +417,20 @@ export declare class WorkspaceShadow {
239
417
  * idempotency guard is still the authority).
240
418
  */
241
419
  readPromoteState(): Promise<ShadowPromoteState | null>;
420
+ /** Durably prevent cwd deletion after process-tree verification failed. */
421
+ blockDiscardForUnverifiedChildren(owners?: readonly ProcessCleanupOwner[]): Promise<void>;
422
+ /** Persistently retain reviewed source bytes while bundle publication is unresolved. */
423
+ retainForUnresolvedAuthority(retention: UnresolvedBundlePublicationRetention): Promise<void>;
424
+ unresolvedBundlePublicationForCleanup(): UnresolvedBundlePublicationRetention | null;
425
+ /** Clear retention only after the durable store proves publication is readable/reconciled. */
426
+ clearUnresolvedAuthorityRetention(): Promise<void>;
427
+ /** Retry persisted process-tree quiescence and retire the cleanup block. */
428
+ retryBlockedCleanup(): Promise<boolean>;
429
+ /** Write the independent in-snapshot non-disposable recovery surface. */
430
+ private writeCleanupBlockAnchor;
242
431
  /**
243
- * Reconstruct a `WorkspaceShadow` from a durable marker (a crash lost the
244
- * in-memory tracked set + pre-task hashes). The tracked set is re-derived
245
- * from the live shadow + real tree; promote then re-captures the diff. Used
246
- * ONLY by the recovery/GC paths (`reopenShadow` / `reapOrphanShadows`).
432
+ * Reconstruct from the marker's exact immutable baseline. Recovery never
433
+ * derives overwrite authority from the moving user tree.
247
434
  */
248
435
  static fromRecovered(recovered: RecoveredShadow, env?: ShadowEnv): Promise<WorkspaceShadow>;
249
436
  }
@@ -252,24 +439,69 @@ export interface RecoveredShadow {
252
439
  taskId: string;
253
440
  shadowDir: string;
254
441
  workingDir: string;
255
- isGit: boolean;
442
+ shadowDirIdentity: AnchoredFsIdentity;
443
+ snapshotRootAuthority: WorkspaceRootAuthority;
444
+ workingDirIdentity: AnchoredFsIdentity;
445
+ workspaceRootAuthority: WorkspaceRootAuthority;
446
+ ownerProcessIdentity: ProcessIdentity;
447
+ physicalCopyBytes: number;
448
+ isGit: false;
256
449
  promoteState: ShadowPromoteState;
257
450
  createdAtMs: number;
258
451
  /** The durable state dir for this task (for cleanup). */
259
452
  stateDir: string;
453
+ /** Exact instance marker (sibling restarts use separate files). */
454
+ stateFile: string;
455
+ /** Exact durable state container and marker authorities from the scan. */
456
+ stateRootAuthority: WorkspaceRootAuthority;
457
+ stateDirAuthority: WorkspaceRootAuthority;
458
+ stateFileAuthority: AnchoredPathIdentity;
459
+ /** Scan-time bridge incarnation, when disposal/exposure recovery has one. */
460
+ exposureFileAuthority?: AnchoredPathIdentity;
461
+ /** Immutable tracked paths and pre-task hashes, including deleted/absent paths. */
462
+ baseline: Array<{
463
+ path: string;
464
+ hash: string | null;
465
+ mode?: number | null;
466
+ }>;
467
+ promotePostHashes?: Array<{
468
+ path: string;
469
+ hash: string | null;
470
+ mode?: number | null;
471
+ }>;
472
+ casRecovery?: CasRecoveryAuthority[];
473
+ disposalSnapshotAuthority?: WorkspaceRootAuthority;
474
+ disposalShadowIdentity?: AnchoredFsIdentity;
475
+ /** Exact reviewed artifact persisted before authorization could resolve. */
476
+ reviewedDiff?: ShadowDiffFile[];
477
+ cleanupBlocked?: boolean;
478
+ cleanupOwners?: ProcessCleanupOwner[];
479
+ unresolvedAuthorityRetention?: UnresolvedBundlePublicationRetention;
260
480
  }
481
+ export declare function listRecoverableShadows(env?: ShadowEnv): Promise<RecoveredShadow[]>;
261
482
  /**
262
- * Read every durable per-task shadow marker under the state root. The reconnect/
263
- * startup recovery (#PR-4) reads these to find an authorized-but-pending shadow
264
- * to promote; the GC reaper (#GC-1) reads them to delete orphaned shadows.
483
+ * Join or recover every known atomic writer owned by the supplied task ids
484
+ * before strict teardown inventory. This is a mutating reconciliation step,
485
+ * deliberately separate from `listShadowCleanupResidue`'s read-only audit.
265
486
  */
266
- export declare function listRecoverableShadows(env?: ShadowEnv): Promise<RecoveredShadow[]>;
487
+ export declare function reconcileShadowPublicationAuthority(taskIds: ReadonlySet<string>, env?: ShadowEnv): Promise<void>;
488
+ export interface ShadowCleanupResidue {
489
+ taskId: string;
490
+ path: string;
491
+ kind: 'recoverable-marker' | 'displaced-marker' | 'exposure-marker' | 'unresolved-authority' | 'state-directory' | 'snapshot-directory' | 'private-publication-authority';
492
+ detail?: string;
493
+ }
267
494
  /**
268
- * Reconstruct a `WorkspaceShadow` from a durable marker so the recovery path
269
- * can re-run promote/discard against an already-created shadow. The tracked set
270
- * + pre-task hashes are re-derived from the live shadow vs the real tree (a
271
- * crash lost the in-memory state). For a git worktree this is `git status`; for
272
- * a copy shadow it is a tree-compare. The promote then re-captures the diff.
495
+ * Exhaustive post-drain audit for exact task ids owned by one session. Unlike
496
+ * `listRecoverableShadows`, this intentionally reports non-operational and
497
+ * malformed authorities, empty owned state directories, snapshot/staging
498
+ * directories, and private publication records. Cleanup failures may be
499
+ * suppressed only when this inventory is empty.
500
+ */
501
+ export declare function listShadowCleanupResidue(taskIds: ReadonlySet<string>, env?: ShadowEnv): Promise<ShadowCleanupResidue[]>;
502
+ /**
503
+ * Reconstruct from a validated instance marker so recovery can re-run
504
+ * promote/discard against an already-created filesystem snapshot.
273
505
  */
274
506
  export declare function reopenShadow(recovered: RecoveredShadow, env?: ShadowEnv): Promise<WorkspaceShadow | null>;
275
507
  /**
@@ -287,4 +519,67 @@ export declare function reapOrphanShadows(keepTaskIds: ReadonlySet<string>, env?
287
519
  reaped: string[];
288
520
  retained: string[];
289
521
  }>;
522
+ export declare function assertPathCollectionBounds(paths: readonly string[], label: string): void;
523
+ export interface AcceptedAlternateImage {
524
+ hash: string | null;
525
+ mode: number | null;
526
+ }
527
+ /** Hardened reverse-apply surface shared by promotion and durable revert. */
528
+ export declare function replaceWorkspaceFileIfMatches(args: {
529
+ workingDir: string;
530
+ workspaceRootAuthority: WorkspaceRootAuthority;
531
+ path: string;
532
+ content: string;
533
+ mode: number;
534
+ expectedHash: string | null;
535
+ expectedMode: number | null;
536
+ /** @internal deterministic last-commit race seam. */
537
+ beforeCommit?: () => Promise<void> | undefined;
538
+ /** @internal deterministic post-validation parent-swap seam. */
539
+ afterValidation?: () => Promise<void> | undefined;
540
+ /** @internal deterministic post-displacement recreation seam. */
541
+ afterDisplacement?: (recoveryName: string) => Promise<void> | undefined;
542
+ /** @internal deterministic public-target quarantine race seam. */
543
+ beforeTargetQuarantine?: (quarantineName: string) => Promise<void> | undefined;
544
+ /** @internal deterministic artifact-retirement race seam. */
545
+ beforeFinalUnlink?: (recoveryName: string) => Promise<void> | undefined;
546
+ /** @internal lower deterministic CAS-helper deadline for tests. */
547
+ helperTimeoutMs?: number;
548
+ /** @internal deterministic CAS-helper target-filesystem stall seam. */
549
+ testHangHelperStage?: 'root' | 'parent' | 'target';
550
+ /** @internal deterministic helper death after COMMIT/mutation. */
551
+ testCrashHelperStage?: CasHelperCrashStage;
552
+ /** Re-drive deterministic recovery names owned by an existing durable journal. */
553
+ allowPostImageRecovery?: boolean;
554
+ /** Exact terminal image that authorizes cleanup-only replay for same-path chains. */
555
+ acceptedAlternate?: AcceptedAlternateImage;
556
+ }): Promise<boolean>;
557
+ /** Hardened reverse-delete surface shared by promotion and durable revert. */
558
+ export declare function removeWorkspaceFileIfMatches(args: {
559
+ workingDir: string;
560
+ workspaceRootAuthority: WorkspaceRootAuthority;
561
+ path: string;
562
+ expectedHash: string | null;
563
+ expectedMode: number | null;
564
+ /** @internal deterministic last-commit race seam. */
565
+ beforeCommit?: () => Promise<void> | undefined;
566
+ /** @internal deterministic post-validation parent-swap seam. */
567
+ afterValidation?: () => Promise<void> | undefined;
568
+ /** @internal deterministic post-displacement recreation seam. */
569
+ afterDisplacement?: (recoveryName: string) => Promise<void> | undefined;
570
+ /** @internal deterministic public-target quarantine race seam. */
571
+ beforeTargetQuarantine?: (quarantineName: string) => Promise<void> | undefined;
572
+ /** @internal deterministic artifact-retirement race seam. */
573
+ beforeFinalUnlink?: (recoveryName: string) => Promise<void> | undefined;
574
+ /** @internal lower deterministic CAS-helper deadline for tests. */
575
+ helperTimeoutMs?: number;
576
+ /** @internal deterministic CAS-helper target-filesystem stall seam. */
577
+ testHangHelperStage?: 'root' | 'parent' | 'target';
578
+ /** @internal deterministic helper death after COMMIT/mutation. */
579
+ testCrashHelperStage?: CasHelperCrashStage;
580
+ /** Re-drive deterministic recovery names owned by an existing durable journal. */
581
+ allowPostImageRecovery?: boolean;
582
+ /** Exact terminal image that authorizes cleanup-only replay for same-path chains. */
583
+ acceptedAlternate?: AcceptedAlternateImage;
584
+ }): Promise<boolean>;
290
585
  export {};