sessionlog 0.0.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/LICENSE +21 -0
- package/README.md +388 -0
- package/dist/agent/agents/claude-code.d.ts +76 -0
- package/dist/agent/agents/claude-code.d.ts.map +1 -0
- package/dist/agent/agents/claude-code.js +769 -0
- package/dist/agent/agents/claude-code.js.map +1 -0
- package/dist/agent/agents/cursor.d.ts +35 -0
- package/dist/agent/agents/cursor.d.ts.map +1 -0
- package/dist/agent/agents/cursor.js +294 -0
- package/dist/agent/agents/cursor.js.map +1 -0
- package/dist/agent/agents/gemini-cli.d.ts +62 -0
- package/dist/agent/agents/gemini-cli.d.ts.map +1 -0
- package/dist/agent/agents/gemini-cli.js +474 -0
- package/dist/agent/agents/gemini-cli.js.map +1 -0
- package/dist/agent/agents/opencode.d.ts +100 -0
- package/dist/agent/agents/opencode.d.ts.map +1 -0
- package/dist/agent/agents/opencode.js +423 -0
- package/dist/agent/agents/opencode.js.map +1 -0
- package/dist/agent/registry.d.ts +54 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +123 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/session-types.d.ts +45 -0
- package/dist/agent/session-types.d.ts.map +1 -0
- package/dist/agent/session-types.js +48 -0
- package/dist/agent/session-types.js.map +1 -0
- package/dist/agent/types.d.ts +126 -0
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent/types.js +40 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/cli.d.ts +12 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +425 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/clean.d.ts +30 -0
- package/dist/commands/clean.d.ts.map +1 -0
- package/dist/commands/clean.js +98 -0
- package/dist/commands/clean.js.map +1 -0
- package/dist/commands/disable.d.ts +23 -0
- package/dist/commands/disable.d.ts.map +1 -0
- package/dist/commands/disable.js +57 -0
- package/dist/commands/disable.js.map +1 -0
- package/dist/commands/doctor.d.ts +43 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +97 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/enable.d.ts +37 -0
- package/dist/commands/enable.d.ts.map +1 -0
- package/dist/commands/enable.js +133 -0
- package/dist/commands/enable.js.map +1 -0
- package/dist/commands/explain.d.ts +68 -0
- package/dist/commands/explain.d.ts.map +1 -0
- package/dist/commands/explain.js +182 -0
- package/dist/commands/explain.js.map +1 -0
- package/dist/commands/reset.d.ts +23 -0
- package/dist/commands/reset.d.ts.map +1 -0
- package/dist/commands/reset.js +68 -0
- package/dist/commands/reset.js.map +1 -0
- package/dist/commands/resume.d.ts +42 -0
- package/dist/commands/resume.d.ts.map +1 -0
- package/dist/commands/resume.js +133 -0
- package/dist/commands/resume.js.map +1 -0
- package/dist/commands/rewind.d.ts +34 -0
- package/dist/commands/rewind.d.ts.map +1 -0
- package/dist/commands/rewind.js +155 -0
- package/dist/commands/rewind.js.map +1 -0
- package/dist/commands/status.d.ts +51 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +112 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config.d.ts +40 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- package/dist/git-operations.d.ts +191 -0
- package/dist/git-operations.d.ts.map +1 -0
- package/dist/git-operations.js +462 -0
- package/dist/git-operations.js.map +1 -0
- package/dist/hooks/git-hooks.d.ts +22 -0
- package/dist/hooks/git-hooks.d.ts.map +1 -0
- package/dist/hooks/git-hooks.js +139 -0
- package/dist/hooks/git-hooks.js.map +1 -0
- package/dist/hooks/lifecycle.d.ts +21 -0
- package/dist/hooks/lifecycle.d.ts.map +1 -0
- package/dist/hooks/lifecycle.js +179 -0
- package/dist/hooks/lifecycle.js.map +1 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +166 -0
- package/dist/index.js.map +1 -0
- package/dist/security/redaction.d.ts +35 -0
- package/dist/security/redaction.d.ts.map +1 -0
- package/dist/security/redaction.js +239 -0
- package/dist/security/redaction.js.map +1 -0
- package/dist/session/state-machine.d.ts +90 -0
- package/dist/session/state-machine.d.ts.map +1 -0
- package/dist/session/state-machine.js +345 -0
- package/dist/session/state-machine.js.map +1 -0
- package/dist/store/checkpoint-store.d.ts +59 -0
- package/dist/store/checkpoint-store.d.ts.map +1 -0
- package/dist/store/checkpoint-store.js +321 -0
- package/dist/store/checkpoint-store.js.map +1 -0
- package/dist/store/native-store.d.ts +14 -0
- package/dist/store/native-store.d.ts.map +1 -0
- package/dist/store/native-store.js +159 -0
- package/dist/store/native-store.js.map +1 -0
- package/dist/store/provider-types.d.ts +78 -0
- package/dist/store/provider-types.d.ts.map +1 -0
- package/dist/store/provider-types.js +12 -0
- package/dist/store/provider-types.js.map +1 -0
- package/dist/store/session-store.d.ts +36 -0
- package/dist/store/session-store.d.ts.map +1 -0
- package/dist/store/session-store.js +193 -0
- package/dist/store/session-store.js.map +1 -0
- package/dist/strategy/attribution.d.ts +39 -0
- package/dist/strategy/attribution.d.ts.map +1 -0
- package/dist/strategy/attribution.js +225 -0
- package/dist/strategy/attribution.js.map +1 -0
- package/dist/strategy/common.d.ts +57 -0
- package/dist/strategy/common.d.ts.map +1 -0
- package/dist/strategy/common.js +156 -0
- package/dist/strategy/common.js.map +1 -0
- package/dist/strategy/content-overlap.d.ts +33 -0
- package/dist/strategy/content-overlap.d.ts.map +1 -0
- package/dist/strategy/content-overlap.js +176 -0
- package/dist/strategy/content-overlap.js.map +1 -0
- package/dist/strategy/manual-commit.d.ts +36 -0
- package/dist/strategy/manual-commit.d.ts.map +1 -0
- package/dist/strategy/manual-commit.js +717 -0
- package/dist/strategy/manual-commit.js.map +1 -0
- package/dist/strategy/types.d.ts +163 -0
- package/dist/strategy/types.d.ts.map +1 -0
- package/dist/strategy/types.js +48 -0
- package/dist/strategy/types.js.map +1 -0
- package/dist/summarize/claude-generator.d.ts +25 -0
- package/dist/summarize/claude-generator.d.ts.map +1 -0
- package/dist/summarize/claude-generator.js +87 -0
- package/dist/summarize/claude-generator.js.map +1 -0
- package/dist/summarize/summarize.d.ts +52 -0
- package/dist/summarize/summarize.d.ts.map +1 -0
- package/dist/summarize/summarize.js +335 -0
- package/dist/summarize/summarize.js.map +1 -0
- package/dist/types.d.ts +293 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +94 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/chunk-files.d.ts +25 -0
- package/dist/utils/chunk-files.d.ts.map +1 -0
- package/dist/utils/chunk-files.js +47 -0
- package/dist/utils/chunk-files.js.map +1 -0
- package/dist/utils/commit-message.d.ts +11 -0
- package/dist/utils/commit-message.d.ts.map +1 -0
- package/dist/utils/commit-message.js +54 -0
- package/dist/utils/commit-message.js.map +1 -0
- package/dist/utils/detect-agent.d.ts +19 -0
- package/dist/utils/detect-agent.d.ts.map +1 -0
- package/dist/utils/detect-agent.js +34 -0
- package/dist/utils/detect-agent.js.map +1 -0
- package/dist/utils/hook-managers.d.ts +24 -0
- package/dist/utils/hook-managers.d.ts.map +1 -0
- package/dist/utils/hook-managers.js +96 -0
- package/dist/utils/hook-managers.js.map +1 -0
- package/dist/utils/ide-tags.d.ts +12 -0
- package/dist/utils/ide-tags.d.ts.map +1 -0
- package/dist/utils/ide-tags.js +30 -0
- package/dist/utils/ide-tags.js.map +1 -0
- package/dist/utils/paths.d.ts +32 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +55 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/preview-rewind.d.ts +23 -0
- package/dist/utils/preview-rewind.d.ts.map +1 -0
- package/dist/utils/preview-rewind.js +63 -0
- package/dist/utils/preview-rewind.js.map +1 -0
- package/dist/utils/rewind-conflict.d.ts +52 -0
- package/dist/utils/rewind-conflict.d.ts.map +1 -0
- package/dist/utils/rewind-conflict.js +79 -0
- package/dist/utils/rewind-conflict.js.map +1 -0
- package/dist/utils/shadow-branch.d.ts +44 -0
- package/dist/utils/shadow-branch.d.ts.map +1 -0
- package/dist/utils/shadow-branch.js +93 -0
- package/dist/utils/shadow-branch.js.map +1 -0
- package/dist/utils/string-utils.d.ts +24 -0
- package/dist/utils/string-utils.d.ts.map +1 -0
- package/dist/utils/string-utils.js +47 -0
- package/dist/utils/string-utils.js.map +1 -0
- package/dist/utils/todo-extract.d.ts +52 -0
- package/dist/utils/todo-extract.d.ts.map +1 -0
- package/dist/utils/todo-extract.js +167 -0
- package/dist/utils/todo-extract.js.map +1 -0
- package/dist/utils/trailers.d.ts +36 -0
- package/dist/utils/trailers.d.ts.map +1 -0
- package/dist/utils/trailers.js +148 -0
- package/dist/utils/trailers.js.map +1 -0
- package/dist/utils/transcript-parse.d.ts +57 -0
- package/dist/utils/transcript-parse.d.ts.map +1 -0
- package/dist/utils/transcript-parse.js +126 -0
- package/dist/utils/transcript-parse.js.map +1 -0
- package/dist/utils/transcript-timestamp.d.ts +22 -0
- package/dist/utils/transcript-timestamp.d.ts.map +1 -0
- package/dist/utils/transcript-timestamp.js +56 -0
- package/dist/utils/transcript-timestamp.js.map +1 -0
- package/dist/utils/tree-ops.d.ts +47 -0
- package/dist/utils/tree-ops.d.ts.map +1 -0
- package/dist/utils/tree-ops.js +145 -0
- package/dist/utils/tree-ops.js.map +1 -0
- package/dist/utils/tty.d.ts +25 -0
- package/dist/utils/tty.d.ts.map +1 -0
- package/dist/utils/tty.js +70 -0
- package/dist/utils/tty.js.map +1 -0
- package/dist/utils/validation.d.ts +31 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +59 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/worktree.d.ts +16 -0
- package/dist/utils/worktree.d.ts.map +1 -0
- package/dist/utils/worktree.js +50 -0
- package/dist/utils/worktree.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Store
|
|
3
|
+
*
|
|
4
|
+
* Manages session state files in .git/entire-sessions/.
|
|
5
|
+
* Each active session has a JSON state file that tracks
|
|
6
|
+
* its lifecycle, files touched, checkpoints, and token usage.
|
|
7
|
+
*/
|
|
8
|
+
import { type SessionState } from '../types.js';
|
|
9
|
+
export interface SessionStore {
|
|
10
|
+
/** Load a session state by ID */
|
|
11
|
+
load(sessionID: string): Promise<SessionState | null>;
|
|
12
|
+
/** List all session states */
|
|
13
|
+
list(): Promise<SessionState[]>;
|
|
14
|
+
/** Save a session state */
|
|
15
|
+
save(state: SessionState): Promise<void>;
|
|
16
|
+
/** Delete a session state */
|
|
17
|
+
delete(sessionID: string): Promise<void>;
|
|
18
|
+
/** Get the sessions directory path */
|
|
19
|
+
getDir(): Promise<string>;
|
|
20
|
+
/** Check if a session exists */
|
|
21
|
+
exists(sessionID: string): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a session store.
|
|
25
|
+
*
|
|
26
|
+
* @param cwd - The project working directory (used to locate .git/entire-sessions/)
|
|
27
|
+
* @param sessionsDir - Optional explicit directory for session state files.
|
|
28
|
+
* When provided, session files are stored here instead of .git/entire-sessions/.
|
|
29
|
+
* This is used when a separate session repo is configured.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createSessionStore(cwd?: string, sessionsDir?: string): SessionStore;
|
|
32
|
+
/**
|
|
33
|
+
* Normalize raw JSON data into a SessionState, handling field name variations
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeSessionState(id: string, data: Record<string, unknown>): SessionState;
|
|
36
|
+
//# sourceMappingURL=session-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/store/session-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EACL,KAAK,YAAY,EAIlB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAEtD,8BAA8B;IAC9B,IAAI,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAEhC,2BAA2B;IAC3B,IAAI,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC,6BAA6B;IAC7B,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC,sCAAsC;IACtC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAE1B,gCAAgC;IAChC,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7C;AAMD;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,CAsHnF;AAMD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAkC7F"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Store
|
|
3
|
+
*
|
|
4
|
+
* Manages session state files in .git/entire-sessions/.
|
|
5
|
+
* Each active session has a JSON state file that tracks
|
|
6
|
+
* its lifecycle, files touched, checkpoints, and token usage.
|
|
7
|
+
*/
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import { STALE_SESSION_DAYS, } from '../types.js';
|
|
11
|
+
import { getSessionsDir, atomicWriteFile } from '../git-operations.js';
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Filesystem Session Store
|
|
14
|
+
// ============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Create a session store.
|
|
17
|
+
*
|
|
18
|
+
* @param cwd - The project working directory (used to locate .git/entire-sessions/)
|
|
19
|
+
* @param sessionsDir - Optional explicit directory for session state files.
|
|
20
|
+
* When provided, session files are stored here instead of .git/entire-sessions/.
|
|
21
|
+
* This is used when a separate session repo is configured.
|
|
22
|
+
*/
|
|
23
|
+
export function createSessionStore(cwd, sessionsDir) {
|
|
24
|
+
let sessionsDirCache = sessionsDir ?? null;
|
|
25
|
+
async function getDir() {
|
|
26
|
+
if (sessionsDirCache)
|
|
27
|
+
return sessionsDirCache;
|
|
28
|
+
sessionsDirCache = await getSessionsDir(cwd);
|
|
29
|
+
return sessionsDirCache;
|
|
30
|
+
}
|
|
31
|
+
function sessionFilePath(dir, sessionID) {
|
|
32
|
+
return path.join(dir, `${sessionID}.json`);
|
|
33
|
+
}
|
|
34
|
+
function parseSessionFile(filePath) {
|
|
35
|
+
try {
|
|
36
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
37
|
+
const data = JSON.parse(content);
|
|
38
|
+
const id = path.basename(filePath, '.json');
|
|
39
|
+
return normalizeSessionState(id, data);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isStale(state) {
|
|
46
|
+
if (state.phase !== 'ended' || !state.endedAt)
|
|
47
|
+
return false;
|
|
48
|
+
const endedAt = new Date(state.endedAt);
|
|
49
|
+
const staleThreshold = Date.now() - STALE_SESSION_DAYS * 24 * 60 * 60 * 1000;
|
|
50
|
+
return endedAt.getTime() < staleThreshold;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
async load(sessionID) {
|
|
54
|
+
const dir = await getDir();
|
|
55
|
+
const filePath = sessionFilePath(dir, sessionID);
|
|
56
|
+
const state = parseSessionFile(filePath);
|
|
57
|
+
if (!state)
|
|
58
|
+
return null;
|
|
59
|
+
// Auto-delete stale sessions
|
|
60
|
+
if (isStale(state)) {
|
|
61
|
+
try {
|
|
62
|
+
await fs.promises.unlink(filePath);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Ignore deletion errors
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return state;
|
|
70
|
+
},
|
|
71
|
+
async list() {
|
|
72
|
+
const dir = await getDir();
|
|
73
|
+
try {
|
|
74
|
+
const files = await fs.promises.readdir(dir);
|
|
75
|
+
const states = [];
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
if (!file.endsWith('.json'))
|
|
78
|
+
continue;
|
|
79
|
+
const filePath = path.join(dir, file);
|
|
80
|
+
const state = parseSessionFile(filePath);
|
|
81
|
+
if (!state)
|
|
82
|
+
continue;
|
|
83
|
+
// Auto-delete stale sessions
|
|
84
|
+
if (isStale(state)) {
|
|
85
|
+
try {
|
|
86
|
+
await fs.promises.unlink(filePath);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Ignore
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
states.push(state);
|
|
94
|
+
}
|
|
95
|
+
return states;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
async save(state) {
|
|
102
|
+
const dir = await getDir();
|
|
103
|
+
const filePath = sessionFilePath(dir, state.sessionID);
|
|
104
|
+
const content = JSON.stringify(serializeSessionState(state), null, 2);
|
|
105
|
+
await atomicWriteFile(filePath, content);
|
|
106
|
+
},
|
|
107
|
+
async delete(sessionID) {
|
|
108
|
+
const dir = await getDir();
|
|
109
|
+
const filePath = sessionFilePath(dir, sessionID);
|
|
110
|
+
try {
|
|
111
|
+
await fs.promises.unlink(filePath);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Ignore if already deleted
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
async getDir() {
|
|
118
|
+
return getDir();
|
|
119
|
+
},
|
|
120
|
+
async exists(sessionID) {
|
|
121
|
+
const dir = await getDir();
|
|
122
|
+
const filePath = sessionFilePath(dir, sessionID);
|
|
123
|
+
try {
|
|
124
|
+
await fs.promises.access(filePath);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// ============================================================================
|
|
134
|
+
// Normalization
|
|
135
|
+
// ============================================================================
|
|
136
|
+
/**
|
|
137
|
+
* Normalize raw JSON data into a SessionState, handling field name variations
|
|
138
|
+
*/
|
|
139
|
+
export function normalizeSessionState(id, data) {
|
|
140
|
+
return {
|
|
141
|
+
sessionID: String(data.sessionID ?? data.session_id ?? id),
|
|
142
|
+
cliVersion: data.cliVersion,
|
|
143
|
+
baseCommit: String(data.baseCommit ?? data.base_commit ?? ''),
|
|
144
|
+
attributionBaseCommit: data.attributionBaseCommit,
|
|
145
|
+
worktreePath: data.worktreePath,
|
|
146
|
+
worktreeID: data.worktreeID,
|
|
147
|
+
startedAt: String(data.startedAt ?? data.started_at ?? new Date().toISOString()),
|
|
148
|
+
endedAt: (data.endedAt ?? data.ended_at),
|
|
149
|
+
phase: normalizePhase(String(data.phase ?? data.state ?? 'idle')),
|
|
150
|
+
turnID: data.turnID,
|
|
151
|
+
turnCheckpointIDs: Array.isArray(data.turnCheckpointIDs)
|
|
152
|
+
? data.turnCheckpointIDs.map(String)
|
|
153
|
+
: [],
|
|
154
|
+
lastInteractionTime: (data.lastInteractionTime ?? data.last_interaction_time),
|
|
155
|
+
stepCount: Number(data.stepCount ?? data.step_count ?? 0),
|
|
156
|
+
checkpointTranscriptStart: Number(data.checkpointTranscriptStart ?? 0),
|
|
157
|
+
untrackedFilesAtStart: Array.isArray(data.untrackedFilesAtStart)
|
|
158
|
+
? data.untrackedFilesAtStart.map(String)
|
|
159
|
+
: [],
|
|
160
|
+
filesTouched: Array.isArray(data.filesTouched) ? data.filesTouched.map(String) : [],
|
|
161
|
+
lastCheckpointID: data.lastCheckpointID,
|
|
162
|
+
agentType: String(data.agentType ?? data.agent ?? data.agent_type ?? 'Agent'),
|
|
163
|
+
tokenUsage: data.tokenUsage,
|
|
164
|
+
transcriptIdentifierAtStart: data.transcriptIdentifierAtStart,
|
|
165
|
+
transcriptPath: data.transcriptPath,
|
|
166
|
+
firstPrompt: data.firstPrompt,
|
|
167
|
+
promptAttributions: data.promptAttributions,
|
|
168
|
+
pendingPromptAttribution: data.pendingPromptAttribution,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function normalizePhase(phase) {
|
|
172
|
+
const lower = phase.toLowerCase();
|
|
173
|
+
if (lower === 'active')
|
|
174
|
+
return 'active';
|
|
175
|
+
if (lower === 'idle')
|
|
176
|
+
return 'idle';
|
|
177
|
+
if (lower === 'ended')
|
|
178
|
+
return 'ended';
|
|
179
|
+
return 'idle';
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Serialize a SessionState for writing to disk
|
|
183
|
+
*/
|
|
184
|
+
function serializeSessionState(state) {
|
|
185
|
+
const result = { ...state };
|
|
186
|
+
// Remove undefined values
|
|
187
|
+
for (const [key, value] of Object.entries(result)) {
|
|
188
|
+
if (value === undefined)
|
|
189
|
+
delete result[key];
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=session-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../src/store/session-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAIL,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA0BvE,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/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,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attribution Logic
|
|
3
|
+
*
|
|
4
|
+
* Computes line-level attribution between agent-generated and human-edited code.
|
|
5
|
+
* Uses diff-based analysis to track who wrote which lines.
|
|
6
|
+
*/
|
|
7
|
+
import type { InitialAttribution } from '../types.js';
|
|
8
|
+
import type { PromptAttribution } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Compare two strings and return line-level diff stats.
|
|
11
|
+
* Returns [unchanged, added, removed] line counts.
|
|
12
|
+
*
|
|
13
|
+
* Uses a simple line-by-line comparison. For production-grade diffing,
|
|
14
|
+
* we compare line sets since we only need counts, not actual patches.
|
|
15
|
+
*/
|
|
16
|
+
export declare function diffLines(oldContent: string, newContent: string): [unchanged: number, added: number, removed: number];
|
|
17
|
+
/**
|
|
18
|
+
* Get all changed files between two sets of file contents.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAllChangedFiles(tree1: Map<string, string>, tree2: Map<string, string>): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Calculate attribution with accumulated prompt data.
|
|
23
|
+
*
|
|
24
|
+
* This provides more accurate attribution than tree-only comparison because
|
|
25
|
+
* it captures user edits between checkpoints.
|
|
26
|
+
*
|
|
27
|
+
* @param baseFiles - File contents at session start
|
|
28
|
+
* @param shadowFiles - File contents at last checkpoint
|
|
29
|
+
* @param headFiles - File contents at commit time (HEAD)
|
|
30
|
+
* @param filesTouched - Files the agent modified
|
|
31
|
+
* @param promptAttributions - Per-prompt user edit tracking
|
|
32
|
+
*/
|
|
33
|
+
export declare function calculateAttributionWithAccumulated(baseFiles: Map<string, string>, shadowFiles: Map<string, string>, headFiles: Map<string, string>, filesTouched: string[], promptAttributions: PromptAttribution[]): InitialAttribution | null;
|
|
34
|
+
/**
|
|
35
|
+
* Calculate prompt attribution at the start of a prompt.
|
|
36
|
+
* Captures user edits since the last checkpoint BEFORE the agent makes changes.
|
|
37
|
+
*/
|
|
38
|
+
export declare function calculatePromptAttribution(baseFiles: Map<string, string>, lastCheckpointFiles: Map<string, string> | null, worktreeFiles: Map<string, string>, checkpointNumber: number): PromptAttribution;
|
|
39
|
+
//# sourceMappingURL=attribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.d.ts","sourceRoot":"","sources":["../../src/strategy/attribution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMpD;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CA6CrD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC1B,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzB,MAAM,EAAE,CAiBV;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mCAAmC,CACjD,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAChC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,YAAY,EAAE,MAAM,EAAE,EACtB,kBAAkB,EAAE,iBAAiB,EAAE,GACtC,kBAAkB,GAAG,IAAI,CAoH3B;AAkBD;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,EAC/C,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,gBAAgB,EAAE,MAAM,GACvB,iBAAiB,CAqCnB"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attribution Logic
|
|
3
|
+
*
|
|
4
|
+
* Computes line-level attribution between agent-generated and human-edited code.
|
|
5
|
+
* Uses diff-based analysis to track who wrote which lines.
|
|
6
|
+
*/
|
|
7
|
+
import { countLines } from '../utils/string-utils.js';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Diff-based Attribution
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Compare two strings and return line-level diff stats.
|
|
13
|
+
* Returns [unchanged, added, removed] line counts.
|
|
14
|
+
*
|
|
15
|
+
* Uses a simple line-by-line comparison. For production-grade diffing,
|
|
16
|
+
* we compare line sets since we only need counts, not actual patches.
|
|
17
|
+
*/
|
|
18
|
+
export function diffLines(oldContent, newContent) {
|
|
19
|
+
if (oldContent === newContent) {
|
|
20
|
+
return [countLines(newContent), 0, 0];
|
|
21
|
+
}
|
|
22
|
+
if (oldContent === '') {
|
|
23
|
+
return [0, countLines(newContent), 0];
|
|
24
|
+
}
|
|
25
|
+
if (newContent === '') {
|
|
26
|
+
return [0, 0, countLines(oldContent)];
|
|
27
|
+
}
|
|
28
|
+
// Line-by-line LCS-based diff for accurate counting
|
|
29
|
+
const oldLines = oldContent.split('\n');
|
|
30
|
+
const newLines = newContent.split('\n');
|
|
31
|
+
// Remove trailing empty string from split if content ends with newline
|
|
32
|
+
if (oldLines[oldLines.length - 1] === '' && oldContent.endsWith('\n')) {
|
|
33
|
+
oldLines.pop();
|
|
34
|
+
}
|
|
35
|
+
if (newLines[newLines.length - 1] === '' && newContent.endsWith('\n')) {
|
|
36
|
+
newLines.pop();
|
|
37
|
+
}
|
|
38
|
+
// Build a set-based approximation for line counts
|
|
39
|
+
// This is simpler than full LCS but gives good accuracy for attribution
|
|
40
|
+
const oldSet = new Map();
|
|
41
|
+
for (const line of oldLines) {
|
|
42
|
+
oldSet.set(line, (oldSet.get(line) ?? 0) + 1);
|
|
43
|
+
}
|
|
44
|
+
let unchanged = 0;
|
|
45
|
+
const matchedOld = new Map();
|
|
46
|
+
for (const line of newLines) {
|
|
47
|
+
const available = (oldSet.get(line) ?? 0) - (matchedOld.get(line) ?? 0);
|
|
48
|
+
if (available > 0) {
|
|
49
|
+
unchanged++;
|
|
50
|
+
matchedOld.set(line, (matchedOld.get(line) ?? 0) + 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const removed = oldLines.length - unchanged;
|
|
54
|
+
const added = newLines.length - unchanged;
|
|
55
|
+
return [unchanged, added, removed];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get all changed files between two sets of file contents.
|
|
59
|
+
*/
|
|
60
|
+
export function getAllChangedFiles(tree1, tree2) {
|
|
61
|
+
const changed = new Set();
|
|
62
|
+
for (const [path, hash1] of tree1) {
|
|
63
|
+
const hash2 = tree2.get(path);
|
|
64
|
+
if (hash2 === undefined || hash1 !== hash2) {
|
|
65
|
+
changed.add(path);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const path of tree2.keys()) {
|
|
69
|
+
if (!tree1.has(path)) {
|
|
70
|
+
changed.add(path);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return Array.from(changed);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Calculate attribution with accumulated prompt data.
|
|
77
|
+
*
|
|
78
|
+
* This provides more accurate attribution than tree-only comparison because
|
|
79
|
+
* it captures user edits between checkpoints.
|
|
80
|
+
*
|
|
81
|
+
* @param baseFiles - File contents at session start
|
|
82
|
+
* @param shadowFiles - File contents at last checkpoint
|
|
83
|
+
* @param headFiles - File contents at commit time (HEAD)
|
|
84
|
+
* @param filesTouched - Files the agent modified
|
|
85
|
+
* @param promptAttributions - Per-prompt user edit tracking
|
|
86
|
+
*/
|
|
87
|
+
export function calculateAttributionWithAccumulated(baseFiles, shadowFiles, headFiles, filesTouched, promptAttributions) {
|
|
88
|
+
if (filesTouched.length === 0)
|
|
89
|
+
return null;
|
|
90
|
+
// Sum accumulated user lines from prompt attributions
|
|
91
|
+
let accumulatedUserRemoved = 0;
|
|
92
|
+
const accumulatedUserAddedPerFile = new Map();
|
|
93
|
+
for (const pa of promptAttributions) {
|
|
94
|
+
accumulatedUserRemoved += pa.userLinesRemoved;
|
|
95
|
+
for (const [filePath, added] of Object.entries(pa.userAddedPerFile)) {
|
|
96
|
+
accumulatedUserAddedPerFile.set(filePath, (accumulatedUserAddedPerFile.get(filePath) ?? 0) + added);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Calculate for agent-touched files
|
|
100
|
+
let totalAgentAndUserWork = 0;
|
|
101
|
+
let postCheckpointUserAdded = 0;
|
|
102
|
+
let postCheckpointUserRemoved = 0;
|
|
103
|
+
const postCheckpointUserRemovedPerFile = new Map();
|
|
104
|
+
for (const filePath of filesTouched) {
|
|
105
|
+
const baseContent = baseFiles.get(filePath) ?? '';
|
|
106
|
+
const shadowContent = shadowFiles.get(filePath) ?? '';
|
|
107
|
+
const headContent = headFiles.get(filePath) ?? '';
|
|
108
|
+
// Total work in shadow: base → shadow
|
|
109
|
+
const [, workAdded] = diffLines(baseContent, shadowContent);
|
|
110
|
+
totalAgentAndUserWork += workAdded;
|
|
111
|
+
// Post-checkpoint user edits: shadow → head
|
|
112
|
+
const [, postUserAdded, postUserRemoved] = diffLines(shadowContent, headContent);
|
|
113
|
+
postCheckpointUserAdded += postUserAdded;
|
|
114
|
+
postCheckpointUserRemoved += postUserRemoved;
|
|
115
|
+
if (postUserRemoved > 0) {
|
|
116
|
+
postCheckpointUserRemovedPerFile.set(filePath, postUserRemoved);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// User edits to non-agent files
|
|
120
|
+
const nonAgentFiles = getAllChangedFiles(baseFiles, headFiles);
|
|
121
|
+
const touchedSet = new Set(filesTouched);
|
|
122
|
+
let allUserEditsToNonAgentFiles = 0;
|
|
123
|
+
for (const filePath of nonAgentFiles) {
|
|
124
|
+
if (touchedSet.has(filePath))
|
|
125
|
+
continue;
|
|
126
|
+
const baseContent = baseFiles.get(filePath) ?? '';
|
|
127
|
+
const headContent = headFiles.get(filePath) ?? '';
|
|
128
|
+
const [, userAdded] = diffLines(baseContent, headContent);
|
|
129
|
+
allUserEditsToNonAgentFiles += userAdded;
|
|
130
|
+
}
|
|
131
|
+
// Separate accumulated edits by file type
|
|
132
|
+
const committedNonAgentSet = new Set(nonAgentFiles.filter((f) => !touchedSet.has(f)));
|
|
133
|
+
let accumulatedToAgentFiles = 0;
|
|
134
|
+
let accumulatedToCommittedNonAgentFiles = 0;
|
|
135
|
+
for (const [filePath, added] of accumulatedUserAddedPerFile) {
|
|
136
|
+
if (touchedSet.has(filePath)) {
|
|
137
|
+
accumulatedToAgentFiles += added;
|
|
138
|
+
}
|
|
139
|
+
else if (committedNonAgentSet.has(filePath)) {
|
|
140
|
+
accumulatedToCommittedNonAgentFiles += added;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Agent work = (base→shadow for agent files) - (accumulated user edits to agent files)
|
|
144
|
+
const totalAgentAdded = Math.max(0, totalAgentAndUserWork - accumulatedToAgentFiles);
|
|
145
|
+
// Post-checkpoint edits to non-agent files
|
|
146
|
+
const postToNonAgentFiles = Math.max(0, allUserEditsToNonAgentFiles - accumulatedToCommittedNonAgentFiles);
|
|
147
|
+
// Total user contribution
|
|
148
|
+
const relevantAccumulatedUser = accumulatedToAgentFiles + accumulatedToCommittedNonAgentFiles;
|
|
149
|
+
const totalUserAdded = relevantAccumulatedUser + postCheckpointUserAdded + postToNonAgentFiles;
|
|
150
|
+
const totalUserRemoved = accumulatedUserRemoved + postCheckpointUserRemoved;
|
|
151
|
+
// Estimate modified lines
|
|
152
|
+
const totalHumanModified = Math.min(totalUserAdded, totalUserRemoved);
|
|
153
|
+
// Estimate user self-modifications
|
|
154
|
+
const userSelfModified = estimateUserSelfModifications(accumulatedUserAddedPerFile, postCheckpointUserRemovedPerFile);
|
|
155
|
+
const humanModifiedAgent = Math.max(0, totalHumanModified - userSelfModified);
|
|
156
|
+
const pureUserAdded = totalUserAdded - totalHumanModified;
|
|
157
|
+
const pureUserRemoved = totalUserRemoved - totalHumanModified;
|
|
158
|
+
let totalCommitted = totalAgentAdded + pureUserAdded - pureUserRemoved;
|
|
159
|
+
if (totalCommitted <= 0) {
|
|
160
|
+
totalCommitted = Math.max(0, totalAgentAdded);
|
|
161
|
+
}
|
|
162
|
+
const agentLinesInCommit = Math.max(0, totalAgentAdded - pureUserRemoved - humanModifiedAgent);
|
|
163
|
+
let agentPercentage = 0;
|
|
164
|
+
if (totalCommitted > 0) {
|
|
165
|
+
agentPercentage = (agentLinesInCommit / totalCommitted) * 100;
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
calculatedAt: new Date().toISOString(),
|
|
169
|
+
agentLines: agentLinesInCommit,
|
|
170
|
+
humanAdded: pureUserAdded,
|
|
171
|
+
humanModified: totalHumanModified,
|
|
172
|
+
humanRemoved: pureUserRemoved,
|
|
173
|
+
totalCommitted,
|
|
174
|
+
agentPercentage,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Estimate how many removed lines were the user's own additions.
|
|
179
|
+
* Uses LIFO assumption: user removes their own recent additions first.
|
|
180
|
+
*/
|
|
181
|
+
function estimateUserSelfModifications(accumulatedUserAddedPerFile, postCheckpointUserRemovedPerFile) {
|
|
182
|
+
let selfModified = 0;
|
|
183
|
+
for (const [filePath, removed] of postCheckpointUserRemovedPerFile) {
|
|
184
|
+
const userAddedToFile = accumulatedUserAddedPerFile.get(filePath) ?? 0;
|
|
185
|
+
selfModified += Math.min(removed, userAddedToFile);
|
|
186
|
+
}
|
|
187
|
+
return selfModified;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Calculate prompt attribution at the start of a prompt.
|
|
191
|
+
* Captures user edits since the last checkpoint BEFORE the agent makes changes.
|
|
192
|
+
*/
|
|
193
|
+
export function calculatePromptAttribution(baseFiles, lastCheckpointFiles, worktreeFiles, checkpointNumber) {
|
|
194
|
+
const result = {
|
|
195
|
+
checkpointNumber,
|
|
196
|
+
userLinesAdded: 0,
|
|
197
|
+
userLinesRemoved: 0,
|
|
198
|
+
agentLinesAdded: 0,
|
|
199
|
+
agentLinesRemoved: 0,
|
|
200
|
+
userAddedPerFile: {},
|
|
201
|
+
};
|
|
202
|
+
if (worktreeFiles.size === 0)
|
|
203
|
+
return result;
|
|
204
|
+
const referenceFiles = lastCheckpointFiles ?? baseFiles;
|
|
205
|
+
for (const [filePath, worktreeContent] of worktreeFiles) {
|
|
206
|
+
const referenceContent = referenceFiles.get(filePath) ?? '';
|
|
207
|
+
const baseContent = baseFiles.get(filePath) ?? '';
|
|
208
|
+
// User changes: diff(reference, worktree)
|
|
209
|
+
const [, userAdded, userRemoved] = diffLines(referenceContent, worktreeContent);
|
|
210
|
+
result.userLinesAdded += userAdded;
|
|
211
|
+
result.userLinesRemoved += userRemoved;
|
|
212
|
+
if (userAdded > 0) {
|
|
213
|
+
result.userAddedPerFile[filePath] = userAdded;
|
|
214
|
+
}
|
|
215
|
+
// Agent lines so far: diff(base, lastCheckpoint)
|
|
216
|
+
if (lastCheckpointFiles) {
|
|
217
|
+
const checkpointContent = lastCheckpointFiles.get(filePath) ?? '';
|
|
218
|
+
const [, agentAdded, agentRemoved] = diffLines(baseContent, checkpointContent);
|
|
219
|
+
result.agentLinesAdded += agentAdded;
|
|
220
|
+
result.agentLinesRemoved += agentRemoved;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=attribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribution.js","sourceRoot":"","sources":["../../src/strategy/attribution.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,+EAA+E;AAC/E,yBAAyB;AACzB,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,UAAkB,EAClB,UAAkB;IAElB,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC9B,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QACtB,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QACtB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,oDAAoD;IACpD,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAExC,uEAAuE;IACvE,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACjB,CAAC;IACD,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACjB,CAAC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AM,CAAC,eAAe,IAAI,UAAU,CAAC;YACrC,MAAM,CAAC,iBAAiB,IAAI,YAAY,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy Common Infrastructure
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities used by strategy implementations for metadata branch
|
|
5
|
+
* operations, repository validation, and setup.
|
|
6
|
+
*
|
|
7
|
+
* Ported from Go: strategy/common.go
|
|
8
|
+
*/
|
|
9
|
+
import { type CheckpointID, type CommittedMetadata } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Validates that the repository is suitable for the manual-commit strategy.
|
|
12
|
+
* Throws if the repository is bare, has no commits, or is not a git repo.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateRepository(cwd?: string): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Check if the repository has any commits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isEmptyRepository(cwd?: string): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Check if commit `ancestor` is an ancestor of commit `descendant`.
|
|
21
|
+
* Uses a bounded traversal to prevent runaway history walks.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isAncestorOf(ancestor: string, descendant: string, _maxDepth?: number, cwd?: string): Promise<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Check if we're inside a git worktree (not the main repo).
|
|
26
|
+
*/
|
|
27
|
+
export declare function isInsideWorktree(cwd?: string): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Ensure the metadata branch (entire/checkpoints/v1) exists.
|
|
30
|
+
* Creates it with an initial empty-tree commit if it doesn't exist.
|
|
31
|
+
*/
|
|
32
|
+
export declare function ensureMetadataBranch(cwd?: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Read checkpoint metadata from the metadata branch.
|
|
35
|
+
*/
|
|
36
|
+
export declare function readCheckpointMetadata(checkpointID: CheckpointID, cwd?: string): Promise<CommittedMetadata | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Read a session prompt from the metadata branch tree.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readSessionPromptFromTree(checkpointID: CheckpointID, sessionIndex: number, cwd?: string): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Read the agent type from checkpoint metadata.
|
|
43
|
+
*/
|
|
44
|
+
export declare function readAgentTypeFromTree(checkpointID: CheckpointID, cwd?: string): Promise<string>;
|
|
45
|
+
/**
|
|
46
|
+
* Extract the first user prompt from a transcript or prompt file.
|
|
47
|
+
*/
|
|
48
|
+
export declare function extractFirstPrompt(prompts: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Full strategy setup: create metadata branch, ensure .gitignore, etc.
|
|
51
|
+
*/
|
|
52
|
+
export declare function ensureSetup(cwd?: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Get the root directory of the main repository (not a worktree).
|
|
55
|
+
*/
|
|
56
|
+
export declare function getMainRepoRoot(cwd?: string): Promise<string>;
|
|
57
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/strategy/common.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAEvB,MAAM,aAAa,CAAC;AAOrB;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBpE;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOtE;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,MAAa,EACxB,GAAG,CAAC,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