@pellux/goodvibes-sdk 0.36.0 → 0.37.1
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/dist/contracts/artifacts/operator-contract.json +1 -1
- package/dist/platform/core/compaction-sections.d.ts +8 -0
- package/dist/platform/core/compaction-sections.d.ts.map +1 -1
- package/dist/platform/core/compaction-sections.js +71 -2
- package/dist/platform/core/context-compaction.d.ts +13 -0
- package/dist/platform/core/context-compaction.d.ts.map +1 -1
- package/dist/platform/core/context-compaction.js +24 -2
- package/dist/platform/core/orchestrator-context-runtime.d.ts.map +1 -1
- package/dist/platform/core/orchestrator-context-runtime.js +1 -2
- package/dist/platform/core/orchestrator-tool-runtime.d.ts.map +1 -1
- package/dist/platform/core/orchestrator-tool-runtime.js +30 -2
- package/dist/platform/permissions/manager.d.ts.map +1 -1
- package/dist/platform/permissions/manager.js +3 -2
- package/dist/platform/permissions/prompt.d.ts +8 -1
- package/dist/platform/permissions/prompt.d.ts.map +1 -1
- package/dist/platform/permissions/types.d.ts +6 -0
- package/dist/platform/permissions/types.d.ts.map +1 -1
- package/dist/platform/runtime/services.d.ts +2 -0
- package/dist/platform/runtime/services.d.ts.map +1 -1
- package/dist/platform/runtime/services.js +15 -0
- package/dist/platform/tools/index.d.ts +1 -0
- package/dist/platform/tools/index.d.ts.map +1 -1
- package/dist/platform/version.js +1 -1
- package/dist/platform/workspace/checkpoint/index.d.ts +9 -0
- package/dist/platform/workspace/checkpoint/index.d.ts.map +1 -0
- package/dist/platform/workspace/checkpoint/index.js +7 -0
- package/dist/platform/workspace/checkpoint/manager.d.ts +214 -0
- package/dist/platform/workspace/checkpoint/manager.d.ts.map +1 -0
- package/dist/platform/workspace/checkpoint/manager.js +543 -0
- package/dist/platform/workspace/checkpoint/side-git.d.ts +130 -0
- package/dist/platform/workspace/checkpoint/side-git.d.ts.map +1 -0
- package/dist/platform/workspace/checkpoint/side-git.js +264 -0
- package/dist/platform/workspace/checkpoint/types.d.ts +96 -0
- package/dist/platform/workspace/checkpoint/types.d.ts.map +1 -0
- package/dist/platform/workspace/checkpoint/types.js +20 -0
- package/dist/platform/workspace/index.d.ts +1 -0
- package/dist/platform/workspace/index.d.ts.map +1 -1
- package/dist/platform/workspace/index.js +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* manager.ts
|
|
3
|
+
*
|
|
4
|
+
* WorkspaceCheckpointManager — the coarse, whole-workspace rewind layer.
|
|
5
|
+
*
|
|
6
|
+
* Complements (does not replace) FileUndoManager (../../state/file-undo.ts),
|
|
7
|
+
* which stays as the fine-grained, in-memory, per-file /undo layer. This
|
|
8
|
+
* manager persists across sessions, snapshots the ENTIRE workspace tree, and
|
|
9
|
+
* survives process restarts (backed by git objects + a JSON manifest on
|
|
10
|
+
* disk), which is the wrong shape for FileUndoManager but exactly the shape
|
|
11
|
+
* needed for "revert everything turn N did" or "restore the workspace to how
|
|
12
|
+
* it looked an hour ago".
|
|
13
|
+
*
|
|
14
|
+
* Storage layout (workspace-local, see side-git.ts for the git mechanics):
|
|
15
|
+
* <workspaceRoot>/.goodvibes/checkpoints/git — side GIT_DIR
|
|
16
|
+
* <workspaceRoot>/.goodvibes/checkpoints/index.json — manifest (JsonFileStore)
|
|
17
|
+
*
|
|
18
|
+
* Checkpoint refs live at refs/goodvibes/checkpoints/<id> inside the side
|
|
19
|
+
* repo, entirely separate from the user's real git refs and from compaction's
|
|
20
|
+
* `cpt_` boundary commits (which are conversation snapshots, not filesystem
|
|
21
|
+
* snapshots, and are not stored in git at all — see types.ts's header comment
|
|
22
|
+
* for the full disambiguation).
|
|
23
|
+
*
|
|
24
|
+
* Automatic snapshots subscribe to EXISTING runtime bus events
|
|
25
|
+
* (TURN_COMPLETED / TURN_ERROR / TURN_CANCEL / AGENT_COMPLETED) — no new
|
|
26
|
+
* event contract is introduced by this module.
|
|
27
|
+
*/
|
|
28
|
+
import type { RuntimeEventBus } from '../../runtime/events/index.js';
|
|
29
|
+
import { type RetentionConfig, type RetentionClass, type PruneResult } from '../../runtime/retention/index.js';
|
|
30
|
+
import type { WorkspaceCheckpoint, CheckpointKind, CheckpointDiff, RestoreResult } from './types.js';
|
|
31
|
+
export interface CreateCheckpointOptions {
|
|
32
|
+
readonly kind: CheckpointKind;
|
|
33
|
+
readonly label?: string | undefined;
|
|
34
|
+
readonly retentionClass?: RetentionClass | undefined;
|
|
35
|
+
readonly turnId?: string | undefined;
|
|
36
|
+
readonly agentId?: string | undefined;
|
|
37
|
+
/** Scope the snapshot to these paths instead of sweeping the whole workspace. */
|
|
38
|
+
readonly paths?: string[] | undefined;
|
|
39
|
+
}
|
|
40
|
+
export interface RestoreOptions {
|
|
41
|
+
/** Restrict restore to these paths instead of the whole workspace. */
|
|
42
|
+
readonly paths?: string[] | undefined;
|
|
43
|
+
/** Take a safety checkpoint of the current state before restoring. Defaults to true. */
|
|
44
|
+
readonly safetyCheckpoint?: boolean | undefined;
|
|
45
|
+
}
|
|
46
|
+
export interface ListCheckpointsFilter {
|
|
47
|
+
readonly kind?: CheckpointKind | undefined;
|
|
48
|
+
readonly since?: number | undefined;
|
|
49
|
+
readonly limit?: number | undefined;
|
|
50
|
+
}
|
|
51
|
+
export interface WorkspaceCheckpointManagerOptions {
|
|
52
|
+
readonly workspaceRoot: string;
|
|
53
|
+
/** Override the side repo's GIT_DIR. Defaults to `<workspaceRoot>/.goodvibes/checkpoints/git`. */
|
|
54
|
+
readonly checkpointDir?: string | undefined;
|
|
55
|
+
/** When provided, the manager subscribes to TURN_COMPLETED/TURN_ERROR/TURN_CANCEL/AGENT_COMPLETED for automatic snapshots. */
|
|
56
|
+
readonly runtimeBus?: RuntimeEventBus | undefined;
|
|
57
|
+
readonly retention?: Partial<RetentionConfig> | undefined;
|
|
58
|
+
/** Clock override for deterministic tests. */
|
|
59
|
+
readonly now?: (() => number) | undefined;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* WorkspaceCheckpointManager — create/list/diff/restore/gc for whole-workspace
|
|
63
|
+
* git-backed snapshots, plus automatic snapshotting on existing turn/agent
|
|
64
|
+
* lifecycle events.
|
|
65
|
+
*/
|
|
66
|
+
export declare class WorkspaceCheckpointManager {
|
|
67
|
+
readonly workspaceRoot: string;
|
|
68
|
+
private readonly checkpointRootDir;
|
|
69
|
+
private readonly sideGit;
|
|
70
|
+
private readonly manifestStore;
|
|
71
|
+
private readonly retentionPolicy;
|
|
72
|
+
private readonly now;
|
|
73
|
+
private readonly runtimeBus;
|
|
74
|
+
private readonly unsubscribers;
|
|
75
|
+
private checkpoints;
|
|
76
|
+
private initialized;
|
|
77
|
+
private initPromise;
|
|
78
|
+
/**
|
|
79
|
+
* Promise-chain mutex serializing every public operation that touches the
|
|
80
|
+
* side repo's shared index or shared object store: `create`, `restore`,
|
|
81
|
+
* `gc`, and `diff` (see each method's `*Internal` body below). Without
|
|
82
|
+
* this, an auto-snapshot `create()` firing on a bus event (TURN_COMPLETED,
|
|
83
|
+
* TURN_ERROR, TURN_CANCEL, or AGENT_COMPLETED) could run its `git add -A`
|
|
84
|
+
* in between `restore()`'s
|
|
85
|
+
* `read-tree --reset` and `checkout-index -a -f`, silently corrupting the
|
|
86
|
+
* restore; two concurrent `create()` calls share the same hazard on the
|
|
87
|
+
* index, and a same-tick `gc()` could treat a not-yet-ref'd loose commit
|
|
88
|
+
* from an in-flight `create()` as unreachable and prune it out from under
|
|
89
|
+
* it. `diff()` is included too: the single-argument `git diff <tree-ish>`
|
|
90
|
+
* form (diffing a checkpoint against the live working tree) refreshes the
|
|
91
|
+
* index's stat cache as a side effect, which is itself a write.
|
|
92
|
+
*
|
|
93
|
+
* Each public method below only does `await this.init()` (idempotent, safe
|
|
94
|
+
* to race) before calling `withLock`; the actual git-touching work lives in
|
|
95
|
+
* a same-named `*Internal` method. Internal callers that need another
|
|
96
|
+
* locked operation's behavior (e.g. `restore()`'s safety checkpoint) call
|
|
97
|
+
* the `*Internal` method directly — never the public wrapper — so a single
|
|
98
|
+
* logical operation never tries to re-enter its own lock.
|
|
99
|
+
*/
|
|
100
|
+
private lockChain;
|
|
101
|
+
private withLock;
|
|
102
|
+
constructor(opts: WorkspaceCheckpointManagerOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Idempotent setup: init the side repo, load the manifest (re-hydrating the
|
|
105
|
+
* in-memory RetentionPolicy so retention state survives process restarts),
|
|
106
|
+
* and subscribe to automatic-snapshot events if a runtime bus was provided.
|
|
107
|
+
* Safe to call multiple times; concurrent callers share one in-flight init.
|
|
108
|
+
*/
|
|
109
|
+
init(): Promise<void>;
|
|
110
|
+
private _init;
|
|
111
|
+
/**
|
|
112
|
+
* Subscribes to the EXISTING turn/agent lifecycle events — no new event
|
|
113
|
+
* types are introduced. A snapshot is taken at the boundary AFTER each
|
|
114
|
+
* turn/agent-run finishes, meaning "revert everything turn N did" means
|
|
115
|
+
* restoring the checkpoint captured BEFORE turn N, i.e. checkpoint[N-1] in
|
|
116
|
+
* `list()`'s (newest-first) ordering — an intentional off-by-one, documented
|
|
117
|
+
* here rather than hidden: this module always snapshots "where things ended
|
|
118
|
+
* up", never "where things started".
|
|
119
|
+
*
|
|
120
|
+
* Listener bodies are wrapped so a failure NEVER throws back into the bus:
|
|
121
|
+
* `RuntimeEventBus.emit()` only catches synchronous throws from a listener,
|
|
122
|
+
* not rejections from a returned (but un-awaited) promise, so every
|
|
123
|
+
* auto-snapshot call here is deliberately `.catch()`-guarded.
|
|
124
|
+
*/
|
|
125
|
+
private subscribeToAutomaticSnapshots;
|
|
126
|
+
/**
|
|
127
|
+
* Create a new checkpoint. Returns `null` (a cheap no-op) when the current
|
|
128
|
+
* workspace tree is identical to the parent checkpoint's tree — no commit,
|
|
129
|
+
* no ref, no manifest entry is created in that case.
|
|
130
|
+
*
|
|
131
|
+
* Serialized against every other index-touching operation on this manager
|
|
132
|
+
* — see `withLock`.
|
|
133
|
+
*/
|
|
134
|
+
create(opts: CreateCheckpointOptions): Promise<WorkspaceCheckpoint | null>;
|
|
135
|
+
private createInternal;
|
|
136
|
+
/** List checkpoints, newest-first. `list()[0]` is always the most recent checkpoint. */
|
|
137
|
+
list(filter?: ListCheckpointsFilter): Promise<WorkspaceCheckpoint[]>;
|
|
138
|
+
/**
|
|
139
|
+
* Diff two checkpoints, or a checkpoint against the live working tree when
|
|
140
|
+
* `b` is omitted.
|
|
141
|
+
*
|
|
142
|
+
* Serialized against every other index-touching operation on this manager
|
|
143
|
+
* — see `withLock`. The single-argument form (`b` omitted, diffing against
|
|
144
|
+
* the live working tree) refreshes the side index's stat cache as a side
|
|
145
|
+
* effect, so it is not purely read-only.
|
|
146
|
+
*/
|
|
147
|
+
diff(a: string, b?: string): Promise<CheckpointDiff>;
|
|
148
|
+
private diffInternal;
|
|
149
|
+
/**
|
|
150
|
+
* Restore the workspace to the state captured by checkpoint `id`.
|
|
151
|
+
*
|
|
152
|
+
* By default (`safetyCheckpoint: true`) takes a checkpoint of the CURRENT
|
|
153
|
+
* state first, so a restore is itself undoable via another restore.
|
|
154
|
+
*
|
|
155
|
+
* Whole-workspace restore (no `opts.paths`):
|
|
156
|
+
* 1. Snapshot the current tracked-file set (via the safety checkpoint, or
|
|
157
|
+
* a transient write-tree when `safetyCheckpoint: false`) — this is the
|
|
158
|
+
* "before" set.
|
|
159
|
+
* 2. Reset the side index to the target checkpoint's tree and check every
|
|
160
|
+
* file in it out to disk (re-creates anything the checkpoint had that
|
|
161
|
+
* is currently missing or modified).
|
|
162
|
+
* 3. Remove exactly the files that were in the "before" set but are NOT
|
|
163
|
+
* in the target checkpoint's tree (files created/tracked after the
|
|
164
|
+
* checkpoint). Anything NOT in the "before" set — i.e. any untracked
|
|
165
|
+
* path outside what this engine has ever snapshotted — is never
|
|
166
|
+
* touched, by construction: it never appears in either set.
|
|
167
|
+
*
|
|
168
|
+
* Scoped restore (`opts.paths` provided) only checks out those paths from
|
|
169
|
+
* the target tree; it never removes files outside the given paths.
|
|
170
|
+
*
|
|
171
|
+
* Serialized against every other index-touching operation on this manager
|
|
172
|
+
* — see `withLock`. Without this, an auto-snapshot `create()` firing on a
|
|
173
|
+
* bus event could run its `git add -A` in between the `read-tree --reset`
|
|
174
|
+
* and `checkout-index -a -f` calls below, silently corrupting the restore.
|
|
175
|
+
*/
|
|
176
|
+
restore(id: string, opts?: RestoreOptions): Promise<RestoreResult>;
|
|
177
|
+
private restoreInternal;
|
|
178
|
+
/**
|
|
179
|
+
* Apply retention limits: `RetentionPolicy` selects prune candidates,
|
|
180
|
+
* `WorkspaceCheckpointPruner` deletes their refs, then (only if anything
|
|
181
|
+
* was actually deleted) a single `git gc --prune=now` reclaims the now-
|
|
182
|
+
* unreachable objects. This never touches compaction's boundary commits —
|
|
183
|
+
* they are tracked in an entirely separate `RetentionPolicy` instance
|
|
184
|
+
* (../../runtime/compaction) with no shared state.
|
|
185
|
+
*
|
|
186
|
+
* Reclamation only works because checkpoint commits are parentless (see
|
|
187
|
+
* `SideGitRunner.commitTree`): a pruned ref's commit has no descendant
|
|
188
|
+
* keeping it reachable via a git parent pointer, so once its ref is
|
|
189
|
+
* deleted it is genuinely unreachable and `--prune=now` frees it.
|
|
190
|
+
*
|
|
191
|
+
* Serialized against every other index/object-store-touching operation on
|
|
192
|
+
* this manager — see `withLock`. Without this, a `create()` racing this
|
|
193
|
+
* method could write a loose commit object that isn't ref'd yet at the
|
|
194
|
+
* moment `--prune=now` runs, and lose it.
|
|
195
|
+
*/
|
|
196
|
+
gc(): Promise<PruneResult>;
|
|
197
|
+
private gcInternal;
|
|
198
|
+
/** Unsubscribe from the runtime bus. Does not touch anything on disk. */
|
|
199
|
+
dispose(): void;
|
|
200
|
+
private mostRecentCheckpoint;
|
|
201
|
+
private requireCheckpoint;
|
|
202
|
+
private defaultLabel;
|
|
203
|
+
/**
|
|
204
|
+
* Approximate incremental bytes introduced by a checkpoint: sum of on-disk
|
|
205
|
+
* sizes of the changed paths, read immediately after they were staged and
|
|
206
|
+
* committed (so they still reflect exactly the content just captured).
|
|
207
|
+
* Deleted paths (no longer on disk) contribute 0. This is deliberately not
|
|
208
|
+
* exact git object-store accounting — it exists for retention's `maxSizeBytes`
|
|
209
|
+
* bookkeeping, not for a byte-perfect audit.
|
|
210
|
+
*/
|
|
211
|
+
private computeSizeBytes;
|
|
212
|
+
private persistManifest;
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/platform/workspace/checkpoint/manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AASH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGrE,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EAGnB,KAAK,WAAW,EAEjB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAuFrG,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,iFAAiF;IACjF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACvC;AAED,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACtC,wFAAwF;IACxF,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,GAAG,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