baton-cli 0.1.3 → 0.2.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/README.md +71 -68
- package/dist/cli.js +229 -164
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# Baton
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/baton-cli)
|
|
6
|
+
[](https://github.com/quabug/baton/actions/workflows/ci.yml)
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
**Git-backed session handoff for Claude Code.**
|
|
9
|
+
|
|
10
|
+
Continue the same coding session on another machine without losing context.
|
|
8
11
|
|
|
9
12
|
```bash
|
|
10
13
|
baton push # on machine A
|
|
@@ -13,83 +16,68 @@ baton pull # on machine B
|
|
|
13
16
|
|
|
14
17
|
---
|
|
15
18
|
|
|
16
|
-
## Why
|
|
17
|
-
|
|
18
|
-
Claude Code sessions are trapped on one machine:
|
|
19
|
-
|
|
20
|
-
- session context doesn't travel between devices
|
|
21
|
-
- macOS, Linux, and Windows use different paths, usernames, and home directories
|
|
22
|
-
- the same repo often lives at different absolute paths on different machines
|
|
23
|
-
- existing tools sync config, not coding sessions
|
|
19
|
+
## Why
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
CLI coding agent sessions are trapped on one machine:
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
- Session context doesn't travel between devices
|
|
24
|
+
- The same repo lives at different absolute paths on different machines
|
|
25
|
+
- macOS, Linux, and Windows use different paths and home directories
|
|
26
|
+
- Existing tools sync config, not coding sessions
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
Baton fixes this. Push your session, pull it elsewhere, keep working.
|
|
30
29
|
|
|
31
30
|
---
|
|
32
31
|
|
|
33
|
-
##
|
|
34
|
-
|
|
35
|
-
**Git-backed session handoff for Claude Code.**
|
|
36
|
-
|
|
37
|
-
---
|
|
32
|
+
## Install
|
|
38
33
|
|
|
39
|
-
|
|
34
|
+
```bash
|
|
35
|
+
npm install -g baton-cli
|
|
36
|
+
```
|
|
40
37
|
|
|
41
|
-
|
|
42
|
-
2. Baton auto-detects the project from the git remote
|
|
43
|
-
3. All Claude Code sessions for that project are captured
|
|
44
|
-
4. Absolute paths are replaced with portable placeholders
|
|
45
|
-
5. The checkpoint is pushed to a private GitHub repo
|
|
46
|
-
6. On another machine, `baton pull` restores the sessions
|
|
47
|
-
7. Placeholders are expanded to machine-local paths
|
|
48
|
-
8. Claude Code can continue where you left off
|
|
38
|
+
**Requirements:** Node.js 18+, Git, [GitHub CLI](https://cli.github.com/) (authenticated)
|
|
49
39
|
|
|
50
40
|
---
|
|
51
41
|
|
|
52
|
-
##
|
|
53
|
-
|
|
54
|
-
Same repo, different machines:
|
|
55
|
-
|
|
56
|
-
- macOS: `/Users/dr_who/work/foo`
|
|
57
|
-
- Linux: `/root/projects/foo`
|
|
58
|
-
- Windows: `C:\Users\dr_who\work\foo`
|
|
59
|
-
|
|
60
|
-
Baton identifies them as the same project from the git remote:
|
|
42
|
+
## Quick start
|
|
61
43
|
|
|
62
44
|
```bash
|
|
63
|
-
#
|
|
64
|
-
cd
|
|
45
|
+
# On machine A — push your sessions
|
|
46
|
+
cd ~/work/my-project
|
|
65
47
|
baton push
|
|
66
48
|
|
|
67
|
-
#
|
|
68
|
-
cd
|
|
49
|
+
# On machine B — pull and continue
|
|
50
|
+
cd ~/projects/my-project
|
|
69
51
|
baton pull
|
|
70
52
|
```
|
|
71
53
|
|
|
72
|
-
|
|
54
|
+
On first run, `baton push` creates a private GitHub repo (`baton-sessions` by default) to store your session data. On another machine, `baton pull` auto-detects this repo from your GitHub account.
|
|
73
55
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## How it works
|
|
59
|
+
|
|
60
|
+
1. **Auto-detect** the project from `git remote` in the current directory
|
|
61
|
+
2. **Collect** all Claude Code sessions, tool results, and project memory
|
|
62
|
+
3. **Virtualize** absolute paths into portable placeholders (`${PROJECT_ROOT}`, `${HOME}`, `${TMP}`)
|
|
63
|
+
4. **Push** the checkpoint to your private GitHub repo
|
|
64
|
+
5. On another machine, **pull** and expand placeholders to local paths
|
|
65
|
+
6. Claude Code picks up the restored sessions automatically
|
|
78
66
|
|
|
79
67
|
---
|
|
80
68
|
|
|
81
69
|
## What gets synced
|
|
82
70
|
|
|
83
|
-
| Component | Synced
|
|
84
|
-
|
|
85
|
-
| Session conversation logs
|
|
71
|
+
| Component | Synced | Why |
|
|
72
|
+
|-----------|--------|-----|
|
|
73
|
+
| Session conversation logs | Yes | All sessions for the project |
|
|
86
74
|
| Tool results | Yes | Small, needed for reference integrity |
|
|
87
75
|
| Project memory | Yes | Tiny, valuable for continuity |
|
|
88
76
|
| Subagent logs | No | Too large, results already in main conversation |
|
|
89
77
|
|
|
90
78
|
---
|
|
91
79
|
|
|
92
|
-
## CLI
|
|
80
|
+
## CLI reference
|
|
93
81
|
|
|
94
82
|
```bash
|
|
95
83
|
baton push # push all sessions for this project
|
|
@@ -100,38 +88,53 @@ baton status # show current project and sync state
|
|
|
100
88
|
|
|
101
89
|
---
|
|
102
90
|
|
|
103
|
-
##
|
|
91
|
+
## Cross-platform path handling
|
|
104
92
|
|
|
105
|
-
|
|
93
|
+
Same repo, different machines:
|
|
94
|
+
|
|
95
|
+
| Machine | Path |
|
|
96
|
+
|---------|------|
|
|
97
|
+
| macOS | `/Users/you/work/my-project` |
|
|
98
|
+
| Linux | `/home/you/projects/my-project` |
|
|
99
|
+
| Windows | `C:\Users\you\my-project` |
|
|
106
100
|
|
|
107
|
-
|
|
108
|
-
- a multi-user collaboration platform
|
|
109
|
-
- a vector database or semantic memory system
|
|
110
|
-
- a config sync tool
|
|
111
|
-
- a full native state restoration guarantee
|
|
101
|
+
Baton replaces absolute paths with portable placeholders on push and expands them to local paths on pull. Longest paths are replaced first to prevent partial matches.
|
|
112
102
|
|
|
113
103
|
---
|
|
114
104
|
|
|
115
|
-
##
|
|
105
|
+
## Conflict guard
|
|
116
106
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
`baton push` checks if the remote has changes you haven't pulled. If so, it refuses to push to prevent accidental overwrites.
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
baton push # refused — remote is ahead
|
|
111
|
+
baton pull # pull first
|
|
112
|
+
baton push # now it works
|
|
113
|
+
|
|
114
|
+
baton push --force # or override the check
|
|
115
|
+
```
|
|
122
116
|
|
|
123
117
|
---
|
|
124
118
|
|
|
125
|
-
##
|
|
119
|
+
## Design principles
|
|
126
120
|
|
|
127
|
-
|
|
121
|
+
- **Project-aware**: identity comes from git remote, not local paths
|
|
122
|
+
- **Checkpoint-first**: restore from snapshots, not fragile live mirroring
|
|
123
|
+
- **Portable before native**: prioritize continuity over perfect restoration
|
|
124
|
+
- **Git-backed**: GitHub for durable history and recovery
|
|
125
|
+
- **Simple**: two commands, no daemon, no config ceremony
|
|
128
126
|
|
|
129
|
-
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## What Baton is not
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
- A real-time sync engine
|
|
132
|
+
- A multi-user collaboration platform
|
|
133
|
+
- A semantic memory system
|
|
134
|
+
- A config sync tool
|
|
132
135
|
|
|
133
136
|
---
|
|
134
137
|
|
|
135
138
|
## License
|
|
136
139
|
|
|
137
|
-
MIT
|
|
140
|
+
MIT
|
package/dist/cli.js
CHANGED
|
@@ -4,11 +4,31 @@
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/pull.ts
|
|
7
|
-
import { join as
|
|
7
|
+
import { join as join6 } from "path";
|
|
8
|
+
import { createInterface as createInterface2 } from "readline/promises";
|
|
8
9
|
|
|
9
|
-
// src/adapters/claude-code/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
// src/adapters/claude-code/reader.ts
|
|
11
|
+
import { readdir, readFile, stat } from "fs/promises";
|
|
12
|
+
import { basename, join as join2 } from "path";
|
|
13
|
+
|
|
14
|
+
// src/errors.ts
|
|
15
|
+
var BatonError = class extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = this.constructor.name;
|
|
19
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var ProjectNotFoundError = class extends BatonError {
|
|
23
|
+
};
|
|
24
|
+
var NoSessionsError = class extends BatonError {
|
|
25
|
+
};
|
|
26
|
+
var ConflictError = class extends BatonError {
|
|
27
|
+
};
|
|
28
|
+
var GitNotFoundError = class extends BatonError {
|
|
29
|
+
};
|
|
30
|
+
var GhNotFoundError = class extends BatonError {
|
|
31
|
+
};
|
|
12
32
|
|
|
13
33
|
// src/adapters/claude-code/paths.ts
|
|
14
34
|
import { homedir } from "os";
|
|
@@ -24,34 +44,116 @@ function getProjectConfigPath() {
|
|
|
24
44
|
return join(homedir(), ".claude", "project-config.json");
|
|
25
45
|
}
|
|
26
46
|
|
|
47
|
+
// src/adapters/claude-code/reader.ts
|
|
48
|
+
async function listLocalSessionIds(projectPath) {
|
|
49
|
+
const projectDirName = encodeProjectDir(projectPath);
|
|
50
|
+
const projectDir = join2(getClaudeProjectsDir(), projectDirName);
|
|
51
|
+
let entries;
|
|
52
|
+
try {
|
|
53
|
+
entries = await readdir(projectDir);
|
|
54
|
+
} catch {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
return entries.filter((e) => e.endsWith(".jsonl")).map((e) => basename(e, ".jsonl"));
|
|
58
|
+
}
|
|
59
|
+
async function collectProjectData(projectPath) {
|
|
60
|
+
const projectDirName = encodeProjectDir(projectPath);
|
|
61
|
+
const projectDir = join2(getClaudeProjectsDir(), projectDirName);
|
|
62
|
+
const sessions = await collectSessions(projectDir);
|
|
63
|
+
if (sessions.length === 0) {
|
|
64
|
+
throw new NoSessionsError(
|
|
65
|
+
`No Claude Code sessions found for this project. Start a Claude Code session first.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const memory = await collectMemory(projectDir);
|
|
69
|
+
return { sessions, memory, projectDirName };
|
|
70
|
+
}
|
|
71
|
+
async function collectSessions(projectDir) {
|
|
72
|
+
let entries;
|
|
73
|
+
try {
|
|
74
|
+
entries = await readdir(projectDir);
|
|
75
|
+
} catch {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
const jsonlFiles = entries.filter((e) => e.endsWith(".jsonl"));
|
|
79
|
+
const sessions = [];
|
|
80
|
+
for (const jsonlFile of jsonlFiles) {
|
|
81
|
+
const sessionId = basename(jsonlFile, ".jsonl");
|
|
82
|
+
const jsonl = await readFile(join2(projectDir, jsonlFile), "utf-8");
|
|
83
|
+
const toolResults = await collectToolResults(projectDir, sessionId);
|
|
84
|
+
sessions.push({ sessionId, jsonl, toolResults });
|
|
85
|
+
}
|
|
86
|
+
return sessions;
|
|
87
|
+
}
|
|
88
|
+
async function collectToolResults(projectDir, sessionId) {
|
|
89
|
+
const results = /* @__PURE__ */ new Map();
|
|
90
|
+
const toolResultsDir = join2(projectDir, sessionId, "tool-results");
|
|
91
|
+
let entries;
|
|
92
|
+
try {
|
|
93
|
+
entries = await readdir(toolResultsDir);
|
|
94
|
+
} catch {
|
|
95
|
+
return results;
|
|
96
|
+
}
|
|
97
|
+
for (const entry of entries) {
|
|
98
|
+
const filePath = join2(toolResultsDir, entry);
|
|
99
|
+
const fileStat = await stat(filePath);
|
|
100
|
+
if (fileStat.isFile()) {
|
|
101
|
+
const content = await readFile(filePath, "utf-8");
|
|
102
|
+
results.set(entry, content);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return results;
|
|
106
|
+
}
|
|
107
|
+
async function collectMemory(projectDir) {
|
|
108
|
+
const memory = /* @__PURE__ */ new Map();
|
|
109
|
+
const memoryDir = join2(projectDir, "memory");
|
|
110
|
+
let entries;
|
|
111
|
+
try {
|
|
112
|
+
entries = await readdir(memoryDir);
|
|
113
|
+
} catch {
|
|
114
|
+
return memory;
|
|
115
|
+
}
|
|
116
|
+
for (const entry of entries) {
|
|
117
|
+
const filePath = join2(memoryDir, entry);
|
|
118
|
+
const fileStat = await stat(filePath);
|
|
119
|
+
if (fileStat.isFile()) {
|
|
120
|
+
const content = await readFile(filePath, "utf-8");
|
|
121
|
+
memory.set(entry, content);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return memory;
|
|
125
|
+
}
|
|
126
|
+
|
|
27
127
|
// src/adapters/claude-code/writer.ts
|
|
128
|
+
import { mkdir, readFile as readFile2, writeFile } from "fs/promises";
|
|
129
|
+
import { dirname, join as join3 } from "path";
|
|
28
130
|
async function restoreProjectData(projectPath, data) {
|
|
29
131
|
const projectDirName = encodeProjectDir(projectPath);
|
|
30
|
-
const projectDir =
|
|
132
|
+
const projectDir = join3(getClaudeProjectsDir(), projectDirName);
|
|
31
133
|
await mkdir(projectDir, { recursive: true });
|
|
32
134
|
for (const session of data.sessions) {
|
|
33
135
|
await writeFile(
|
|
34
|
-
|
|
136
|
+
join3(projectDir, `${session.sessionId}.jsonl`),
|
|
35
137
|
session.jsonl,
|
|
36
138
|
"utf-8"
|
|
37
139
|
);
|
|
38
140
|
if (session.toolResults.size > 0) {
|
|
39
|
-
const toolResultsDir =
|
|
141
|
+
const toolResultsDir = join3(
|
|
40
142
|
projectDir,
|
|
41
143
|
session.sessionId,
|
|
42
144
|
"tool-results"
|
|
43
145
|
);
|
|
44
146
|
await mkdir(toolResultsDir, { recursive: true });
|
|
45
147
|
for (const [filename, content] of session.toolResults) {
|
|
46
|
-
await writeFile(
|
|
148
|
+
await writeFile(join3(toolResultsDir, filename), content, "utf-8");
|
|
47
149
|
}
|
|
48
150
|
}
|
|
49
151
|
}
|
|
50
152
|
if (data.memory.size > 0) {
|
|
51
|
-
const memoryDir =
|
|
153
|
+
const memoryDir = join3(projectDir, "memory");
|
|
52
154
|
await mkdir(memoryDir, { recursive: true });
|
|
53
155
|
for (const [filename, content] of data.memory) {
|
|
54
|
-
await writeFile(
|
|
156
|
+
await writeFile(join3(memoryDir, filename), content, "utf-8");
|
|
55
157
|
}
|
|
56
158
|
}
|
|
57
159
|
await ensureProjectConfig(projectPath, projectDirName);
|
|
@@ -60,7 +162,7 @@ async function ensureProjectConfig(projectPath, projectDirName) {
|
|
|
60
162
|
const configPath = getProjectConfigPath();
|
|
61
163
|
let config = {};
|
|
62
164
|
try {
|
|
63
|
-
const raw = await
|
|
165
|
+
const raw = await readFile2(configPath, "utf-8");
|
|
64
166
|
config = JSON.parse(raw);
|
|
65
167
|
} catch {
|
|
66
168
|
}
|
|
@@ -74,21 +176,21 @@ async function ensureProjectConfig(projectPath, projectDirName) {
|
|
|
74
176
|
}
|
|
75
177
|
|
|
76
178
|
// src/core/config.ts
|
|
77
|
-
import { mkdir as mkdir2, readFile as
|
|
179
|
+
import { mkdir as mkdir2, readFile as readFile3, writeFile as writeFile2 } from "fs/promises";
|
|
78
180
|
import { homedir as homedir2 } from "os";
|
|
79
|
-
import { dirname as dirname2, join as
|
|
181
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
80
182
|
function getBatonDir() {
|
|
81
|
-
return
|
|
183
|
+
return join4(homedir2(), ".baton");
|
|
82
184
|
}
|
|
83
185
|
function getConfigPath() {
|
|
84
|
-
return
|
|
186
|
+
return join4(getBatonDir(), "config.json");
|
|
85
187
|
}
|
|
86
188
|
function getRepoDir() {
|
|
87
|
-
return
|
|
189
|
+
return join4(getBatonDir(), "repo");
|
|
88
190
|
}
|
|
89
191
|
async function loadConfig() {
|
|
90
192
|
try {
|
|
91
|
-
const raw = await
|
|
193
|
+
const raw = await readFile3(getConfigPath(), "utf-8");
|
|
92
194
|
const config = JSON.parse(raw);
|
|
93
195
|
if (!config.repo || typeof config.repo !== "string") {
|
|
94
196
|
return null;
|
|
@@ -108,27 +210,6 @@ async function saveConfig(config) {
|
|
|
108
210
|
import { execFile } from "child_process";
|
|
109
211
|
import { access } from "fs/promises";
|
|
110
212
|
import { promisify } from "util";
|
|
111
|
-
|
|
112
|
-
// src/errors.ts
|
|
113
|
-
var BatonError = class extends Error {
|
|
114
|
-
constructor(message) {
|
|
115
|
-
super(message);
|
|
116
|
-
this.name = this.constructor.name;
|
|
117
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
var ProjectNotFoundError = class extends BatonError {
|
|
121
|
-
};
|
|
122
|
-
var NoSessionsError = class extends BatonError {
|
|
123
|
-
};
|
|
124
|
-
var ConflictError = class extends BatonError {
|
|
125
|
-
};
|
|
126
|
-
var GitNotFoundError = class extends BatonError {
|
|
127
|
-
};
|
|
128
|
-
var GhNotFoundError = class extends BatonError {
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
// src/core/git.ts
|
|
132
213
|
var execFileAsync = promisify(execFile);
|
|
133
214
|
var GIT_TIMEOUT_MS = 3e4;
|
|
134
215
|
var GH_TIMEOUT_MS = 6e4;
|
|
@@ -349,10 +430,10 @@ async function detectProject(cwd) {
|
|
|
349
430
|
}
|
|
350
431
|
|
|
351
432
|
// src/commands/checkpoint.ts
|
|
352
|
-
import { mkdir as mkdir3, readdir, readFile as
|
|
353
|
-
import { join as
|
|
433
|
+
import { mkdir as mkdir3, readdir as readdir2, readFile as readFile4, rm, writeFile as writeFile3 } from "fs/promises";
|
|
434
|
+
import { join as join5 } from "path";
|
|
354
435
|
async function writeCheckpoint(projectDir, project, data) {
|
|
355
|
-
const sessionsDir =
|
|
436
|
+
const sessionsDir = join5(projectDir, "sessions");
|
|
356
437
|
await rm(sessionsDir, { recursive: true, force: true });
|
|
357
438
|
await mkdir3(sessionsDir, { recursive: true });
|
|
358
439
|
const meta = {
|
|
@@ -361,41 +442,41 @@ async function writeCheckpoint(projectDir, project, data) {
|
|
|
361
442
|
pushed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
362
443
|
};
|
|
363
444
|
await writeFile3(
|
|
364
|
-
|
|
445
|
+
join5(projectDir, "meta.json"),
|
|
365
446
|
JSON.stringify(meta, null, 2),
|
|
366
447
|
"utf-8"
|
|
367
448
|
);
|
|
368
449
|
for (const session of data.sessions) {
|
|
369
450
|
await writeFile3(
|
|
370
|
-
|
|
451
|
+
join5(sessionsDir, `${session.sessionId}.jsonl`),
|
|
371
452
|
session.jsonl,
|
|
372
453
|
"utf-8"
|
|
373
454
|
);
|
|
374
455
|
if (session.toolResults.size > 0) {
|
|
375
|
-
const toolResultsDir =
|
|
456
|
+
const toolResultsDir = join5(
|
|
376
457
|
sessionsDir,
|
|
377
458
|
session.sessionId,
|
|
378
459
|
"tool-results"
|
|
379
460
|
);
|
|
380
461
|
await mkdir3(toolResultsDir, { recursive: true });
|
|
381
462
|
for (const [filename, content] of session.toolResults) {
|
|
382
|
-
await writeFile3(
|
|
463
|
+
await writeFile3(join5(toolResultsDir, filename), content, "utf-8");
|
|
383
464
|
}
|
|
384
465
|
}
|
|
385
466
|
}
|
|
386
467
|
if (data.memory.size > 0) {
|
|
387
|
-
const memoryDir =
|
|
468
|
+
const memoryDir = join5(projectDir, "memory");
|
|
388
469
|
await mkdir3(memoryDir, { recursive: true });
|
|
389
470
|
for (const [filename, content] of data.memory) {
|
|
390
|
-
await writeFile3(
|
|
471
|
+
await writeFile3(join5(memoryDir, filename), content, "utf-8");
|
|
391
472
|
}
|
|
392
473
|
}
|
|
393
474
|
}
|
|
394
475
|
async function readCheckpoint(projectDir) {
|
|
395
|
-
const sessionsDir =
|
|
476
|
+
const sessionsDir = join5(projectDir, "sessions");
|
|
396
477
|
let sessionFiles;
|
|
397
478
|
try {
|
|
398
|
-
const entries = await
|
|
479
|
+
const entries = await readdir2(sessionsDir);
|
|
399
480
|
sessionFiles = entries.filter((e) => e.endsWith(".jsonl"));
|
|
400
481
|
} catch {
|
|
401
482
|
return null;
|
|
@@ -406,7 +487,7 @@ async function readCheckpoint(projectDir) {
|
|
|
406
487
|
const sessions = [];
|
|
407
488
|
for (const file of sessionFiles) {
|
|
408
489
|
const sessionId = file.replace(".jsonl", "");
|
|
409
|
-
const jsonl = await
|
|
490
|
+
const jsonl = await readFile4(join5(sessionsDir, file), "utf-8");
|
|
410
491
|
const toolResults = await readToolResults(sessionsDir, sessionId);
|
|
411
492
|
sessions.push({ sessionId, jsonl, toolResults });
|
|
412
493
|
}
|
|
@@ -419,30 +500,30 @@ async function readCheckpoint(projectDir) {
|
|
|
419
500
|
}
|
|
420
501
|
async function readToolResults(sessionsDir, sessionId) {
|
|
421
502
|
const results = /* @__PURE__ */ new Map();
|
|
422
|
-
const toolResultsDir =
|
|
503
|
+
const toolResultsDir = join5(sessionsDir, sessionId, "tool-results");
|
|
423
504
|
let entries;
|
|
424
505
|
try {
|
|
425
|
-
entries = await
|
|
506
|
+
entries = await readdir2(toolResultsDir);
|
|
426
507
|
} catch {
|
|
427
508
|
return results;
|
|
428
509
|
}
|
|
429
510
|
for (const entry of entries) {
|
|
430
|
-
const content = await
|
|
511
|
+
const content = await readFile4(join5(toolResultsDir, entry), "utf-8");
|
|
431
512
|
results.set(entry, content);
|
|
432
513
|
}
|
|
433
514
|
return results;
|
|
434
515
|
}
|
|
435
516
|
async function readMemory(projectDir) {
|
|
436
517
|
const memory = /* @__PURE__ */ new Map();
|
|
437
|
-
const memoryDir =
|
|
518
|
+
const memoryDir = join5(projectDir, "memory");
|
|
438
519
|
let entries;
|
|
439
520
|
try {
|
|
440
|
-
entries = await
|
|
521
|
+
entries = await readdir2(memoryDir);
|
|
441
522
|
} catch {
|
|
442
523
|
return memory;
|
|
443
524
|
}
|
|
444
525
|
for (const entry of entries) {
|
|
445
|
-
const content = await
|
|
526
|
+
const content = await readFile4(join5(memoryDir, entry), "utf-8");
|
|
446
527
|
memory.set(entry, content);
|
|
447
528
|
}
|
|
448
529
|
return memory;
|
|
@@ -450,56 +531,88 @@ async function readMemory(projectDir) {
|
|
|
450
531
|
|
|
451
532
|
// src/commands/setup.ts
|
|
452
533
|
import { createInterface } from "readline/promises";
|
|
534
|
+
var DEFAULT_REPO_NAME = "baton-sessions";
|
|
453
535
|
async function ensureBatonRepo(mode) {
|
|
454
536
|
const repoDir = getRepoDir();
|
|
455
537
|
let config = await loadConfig();
|
|
456
538
|
if (!config) {
|
|
539
|
+
if (mode === "push") {
|
|
540
|
+
config = await promptCreateRepo();
|
|
541
|
+
} else {
|
|
542
|
+
config = await autoDetectOrPrompt();
|
|
543
|
+
}
|
|
544
|
+
await saveConfig(config);
|
|
545
|
+
}
|
|
546
|
+
if (!await repoExists(repoDir)) {
|
|
547
|
+
console.log("Cloning baton repo...");
|
|
548
|
+
await cloneRepo(config.repo, repoDir);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
async function getGitHubUsername() {
|
|
552
|
+
return await gh(["api", "user", "--jq", ".login"]);
|
|
553
|
+
}
|
|
554
|
+
async function promptCreateRepo() {
|
|
555
|
+
const rl = createInterface({
|
|
556
|
+
input: process.stdin,
|
|
557
|
+
output: process.stdout
|
|
558
|
+
});
|
|
559
|
+
try {
|
|
560
|
+
const rawName = await rl.question(
|
|
561
|
+
`Enter repo name for baton sync (${DEFAULT_REPO_NAME}): `
|
|
562
|
+
);
|
|
563
|
+
const repoName = rawName.trim() || DEFAULT_REPO_NAME;
|
|
564
|
+
console.log(`Creating private repo '${repoName}'...`);
|
|
565
|
+
const repoUrl = await createGhRepo(repoName);
|
|
566
|
+
console.log(`Repo created: ${repoUrl}`);
|
|
567
|
+
return { repo: repoUrl };
|
|
568
|
+
} finally {
|
|
569
|
+
rl.close();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
async function autoDetectOrPrompt() {
|
|
573
|
+
const username = await getGitHubUsername();
|
|
574
|
+
const defaultUrl = `https://github.com/${username}/${DEFAULT_REPO_NAME}`;
|
|
575
|
+
try {
|
|
576
|
+
await gh([
|
|
577
|
+
"repo",
|
|
578
|
+
"view",
|
|
579
|
+
`${username}/${DEFAULT_REPO_NAME}`,
|
|
580
|
+
"--json",
|
|
581
|
+
"name"
|
|
582
|
+
]);
|
|
583
|
+
console.log(`Found baton repo: ${defaultUrl}`);
|
|
584
|
+
return { repo: defaultUrl };
|
|
585
|
+
} catch (error) {
|
|
586
|
+
if (!isRepoNotFoundError(error)) {
|
|
587
|
+
throw error;
|
|
588
|
+
}
|
|
457
589
|
const rl = createInterface({
|
|
458
590
|
input: process.stdin,
|
|
459
591
|
output: process.stdout
|
|
460
592
|
});
|
|
461
593
|
try {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
594
|
+
const rawUrl = await rl.question(
|
|
595
|
+
`No '${DEFAULT_REPO_NAME}' repo found for ${username}. Enter your baton repo URL: `
|
|
596
|
+
);
|
|
597
|
+
const repoUrl = rawUrl.trim();
|
|
598
|
+
if (!repoUrl) {
|
|
599
|
+
throw new Error("Repo URL cannot be empty.");
|
|
466
600
|
}
|
|
467
|
-
|
|
601
|
+
return { repo: repoUrl };
|
|
468
602
|
} finally {
|
|
469
603
|
rl.close();
|
|
470
604
|
}
|
|
471
605
|
}
|
|
472
|
-
if (!await repoExists(repoDir)) {
|
|
473
|
-
console.log("Cloning baton repo...");
|
|
474
|
-
await cloneRepo(config.repo, repoDir);
|
|
475
|
-
}
|
|
476
606
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (!repoName) {
|
|
483
|
-
throw new Error("Repo name cannot be empty.");
|
|
484
|
-
}
|
|
485
|
-
console.log(`Creating private repo '${repoName}'...`);
|
|
486
|
-
const repoUrl = await createGhRepo(repoName);
|
|
487
|
-
console.log(`Repo created: ${repoUrl}`);
|
|
488
|
-
return { repo: repoUrl };
|
|
489
|
-
}
|
|
490
|
-
async function promptExistingRepo(rl) {
|
|
491
|
-
const rawUrl = await rl.question(
|
|
492
|
-
"Enter your baton sync repo URL (e.g. https://github.com/user/baton-sync): "
|
|
493
|
-
);
|
|
494
|
-
const repoUrl = rawUrl.trim();
|
|
495
|
-
if (!repoUrl) {
|
|
496
|
-
throw new Error("Repo URL cannot be empty.");
|
|
497
|
-
}
|
|
498
|
-
return { repo: repoUrl };
|
|
607
|
+
function isRepoNotFoundError(error) {
|
|
608
|
+
if (!(error instanceof Error)) return false;
|
|
609
|
+
const stderr = error.stderr ?? "";
|
|
610
|
+
const message = error.message + stderr;
|
|
611
|
+
return message.includes("Could not resolve") || message.includes("HTTP 404") || message.includes("Not Found");
|
|
499
612
|
}
|
|
500
613
|
|
|
501
614
|
// src/commands/pull.ts
|
|
502
|
-
async function pull() {
|
|
615
|
+
async function pull(options) {
|
|
503
616
|
const cwd = process.cwd();
|
|
504
617
|
const project = await detectProject(cwd);
|
|
505
618
|
console.log(`Project: ${project.normalizedRemote} (${project.projectId})`);
|
|
@@ -509,7 +622,7 @@ async function pull() {
|
|
|
509
622
|
console.log("Pulling latest...");
|
|
510
623
|
await pullRepo(repoDir);
|
|
511
624
|
}
|
|
512
|
-
const projectDir =
|
|
625
|
+
const projectDir = join6(repoDir, "projects", project.projectId);
|
|
513
626
|
const data = await readCheckpoint(projectDir);
|
|
514
627
|
if (!data) {
|
|
515
628
|
throw new NoSessionsError(
|
|
@@ -519,6 +632,31 @@ async function pull() {
|
|
|
519
632
|
console.log(
|
|
520
633
|
`Found ${data.sessions.length} session(s), ${data.memory.size} memory file(s)`
|
|
521
634
|
);
|
|
635
|
+
if (!options.force) {
|
|
636
|
+
const localIds = await listLocalSessionIds(cwd);
|
|
637
|
+
const remoteIds = new Set(data.sessions.map((s) => s.sessionId));
|
|
638
|
+
const conflicts = localIds.filter((id) => remoteIds.has(id));
|
|
639
|
+
if (conflicts.length > 0) {
|
|
640
|
+
console.log(
|
|
641
|
+
`Warning: ${conflicts.length} local session(s) will be overwritten.`
|
|
642
|
+
);
|
|
643
|
+
const rl = createInterface2({
|
|
644
|
+
input: process.stdin,
|
|
645
|
+
output: process.stdout
|
|
646
|
+
});
|
|
647
|
+
try {
|
|
648
|
+
const answer = await rl.question("Continue? (y/N): ");
|
|
649
|
+
if (answer.trim().toLowerCase() !== "y") {
|
|
650
|
+
console.log(
|
|
651
|
+
"Pull cancelled. Use 'baton pull --force' to skip this check."
|
|
652
|
+
);
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
} finally {
|
|
656
|
+
rl.close();
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
522
660
|
const pathCtx = getLocalPathContext(cwd);
|
|
523
661
|
for (const session of data.sessions) {
|
|
524
662
|
session.jsonl = expandPaths(session.jsonl, pathCtx);
|
|
@@ -529,79 +667,6 @@ async function pull() {
|
|
|
529
667
|
|
|
530
668
|
// src/commands/push.ts
|
|
531
669
|
import { join as join7 } from "path";
|
|
532
|
-
|
|
533
|
-
// src/adapters/claude-code/reader.ts
|
|
534
|
-
import { readdir as readdir2, readFile as readFile4, stat } from "fs/promises";
|
|
535
|
-
import { basename, join as join6 } from "path";
|
|
536
|
-
async function collectProjectData(projectPath) {
|
|
537
|
-
const projectDirName = encodeProjectDir(projectPath);
|
|
538
|
-
const projectDir = join6(getClaudeProjectsDir(), projectDirName);
|
|
539
|
-
const sessions = await collectSessions(projectDir);
|
|
540
|
-
if (sessions.length === 0) {
|
|
541
|
-
throw new NoSessionsError(
|
|
542
|
-
`No Claude Code sessions found for this project. Start a Claude Code session first.`
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
const memory = await collectMemory(projectDir);
|
|
546
|
-
return { sessions, memory, projectDirName };
|
|
547
|
-
}
|
|
548
|
-
async function collectSessions(projectDir) {
|
|
549
|
-
let entries;
|
|
550
|
-
try {
|
|
551
|
-
entries = await readdir2(projectDir);
|
|
552
|
-
} catch {
|
|
553
|
-
return [];
|
|
554
|
-
}
|
|
555
|
-
const jsonlFiles = entries.filter((e) => e.endsWith(".jsonl"));
|
|
556
|
-
const sessions = [];
|
|
557
|
-
for (const jsonlFile of jsonlFiles) {
|
|
558
|
-
const sessionId = basename(jsonlFile, ".jsonl");
|
|
559
|
-
const jsonl = await readFile4(join6(projectDir, jsonlFile), "utf-8");
|
|
560
|
-
const toolResults = await collectToolResults(projectDir, sessionId);
|
|
561
|
-
sessions.push({ sessionId, jsonl, toolResults });
|
|
562
|
-
}
|
|
563
|
-
return sessions;
|
|
564
|
-
}
|
|
565
|
-
async function collectToolResults(projectDir, sessionId) {
|
|
566
|
-
const results = /* @__PURE__ */ new Map();
|
|
567
|
-
const toolResultsDir = join6(projectDir, sessionId, "tool-results");
|
|
568
|
-
let entries;
|
|
569
|
-
try {
|
|
570
|
-
entries = await readdir2(toolResultsDir);
|
|
571
|
-
} catch {
|
|
572
|
-
return results;
|
|
573
|
-
}
|
|
574
|
-
for (const entry of entries) {
|
|
575
|
-
const filePath = join6(toolResultsDir, entry);
|
|
576
|
-
const fileStat = await stat(filePath);
|
|
577
|
-
if (fileStat.isFile()) {
|
|
578
|
-
const content = await readFile4(filePath, "utf-8");
|
|
579
|
-
results.set(entry, content);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
return results;
|
|
583
|
-
}
|
|
584
|
-
async function collectMemory(projectDir) {
|
|
585
|
-
const memory = /* @__PURE__ */ new Map();
|
|
586
|
-
const memoryDir = join6(projectDir, "memory");
|
|
587
|
-
let entries;
|
|
588
|
-
try {
|
|
589
|
-
entries = await readdir2(memoryDir);
|
|
590
|
-
} catch {
|
|
591
|
-
return memory;
|
|
592
|
-
}
|
|
593
|
-
for (const entry of entries) {
|
|
594
|
-
const filePath = join6(memoryDir, entry);
|
|
595
|
-
const fileStat = await stat(filePath);
|
|
596
|
-
if (fileStat.isFile()) {
|
|
597
|
-
const content = await readFile4(filePath, "utf-8");
|
|
598
|
-
memory.set(entry, content);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return memory;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// src/commands/push.ts
|
|
605
670
|
async function push(options) {
|
|
606
671
|
const cwd = process.cwd();
|
|
607
672
|
const project = await detectProject(cwd);
|
|
@@ -682,8 +747,8 @@ program.name("baton").description("Git-backed session handoff for Claude Code").
|
|
|
682
747
|
program.command("push").description("Push all sessions for the current project to GitHub").option("-f, --force", "Overwrite remote even if ahead").action(async (options) => {
|
|
683
748
|
await push({ force: options.force });
|
|
684
749
|
});
|
|
685
|
-
program.command("pull").description("Restore sessions for the current project from GitHub").action(async () => {
|
|
686
|
-
await pull();
|
|
750
|
+
program.command("pull").description("Restore sessions for the current project from GitHub").option("-f, --force", "Overwrite local sessions without confirmation").action(async (options) => {
|
|
751
|
+
await pull({ force: options.force });
|
|
687
752
|
});
|
|
688
753
|
program.command("status").description("Show current project and sync state").action(async () => {
|
|
689
754
|
await status();
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli.ts","../src/commands/pull.ts","../src/adapters/claude-code/writer.ts","../src/adapters/claude-code/paths.ts","../src/core/config.ts","../src/core/git.ts","../src/errors.ts","../src/core/paths.ts","../src/core/project.ts","../src/commands/checkpoint.ts","../src/commands/setup.ts","../src/commands/push.ts","../src/adapters/claude-code/reader.ts","../src/commands/status.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { pull } from \"./commands/pull.js\";\nimport { push } from \"./commands/push.js\";\nimport { status } from \"./commands/status.js\";\nimport { BatonError } from \"./errors.js\";\n\nconst program = new Command();\n\nprogram\n\t.name(\"baton\")\n\t.description(\"Git-backed session handoff for Claude Code\")\n\t.version(\"0.1.0\");\n\nprogram\n\t.command(\"push\")\n\t.description(\"Push all sessions for the current project to GitHub\")\n\t.option(\"-f, --force\", \"Overwrite remote even if ahead\")\n\t.action(async (options) => {\n\t\tawait push({ force: options.force });\n\t});\n\nprogram\n\t.command(\"pull\")\n\t.description(\"Restore sessions for the current project from GitHub\")\n\t.action(async () => {\n\t\tawait pull();\n\t});\n\nprogram\n\t.command(\"status\")\n\t.description(\"Show current project and sync state\")\n\t.action(async () => {\n\t\tawait status();\n\t});\n\ntry {\n\tawait program.parseAsync(process.argv);\n} catch (error) {\n\tif (error instanceof BatonError) {\n\t\tconsole.error(`Error: ${error.message}`);\n\t} else {\n\t\tconsole.error(\n\t\t\t`Unexpected error: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tprocess.exit(1);\n}\n","import { join } from \"node:path\";\nimport { restoreProjectData } from \"../adapters/claude-code/writer.js\";\nimport { getRepoDir } from \"../core/config.js\";\nimport { pullRepo, repoExists } from \"../core/git.js\";\nimport { expandPaths, getLocalPathContext } from \"../core/paths.js\";\nimport { detectProject } from \"../core/project.js\";\nimport { NoSessionsError } from \"../errors.js\";\nimport { readCheckpoint } from \"./checkpoint.js\";\nimport { ensureBatonRepo } from \"./setup.js\";\n\nexport async function pull(): Promise<void> {\n\tconst cwd = process.cwd();\n\n\t// 1. Detect project\n\tconst project = await detectProject(cwd);\n\tconsole.log(`Project: ${project.normalizedRemote} (${project.projectId})`);\n\n\t// 2. Ensure baton repo is available\n\tawait ensureBatonRepo(\"pull\");\n\n\tconst repoDir = getRepoDir();\n\tif (await repoExists(repoDir)) {\n\t\tconsole.log(\"Pulling latest...\");\n\t\tawait pullRepo(repoDir);\n\t}\n\n\t// 3. Read checkpoint from baton repo\n\tconst projectDir = join(repoDir, \"projects\", project.projectId);\n\tconst data = await readCheckpoint(projectDir);\n\n\tif (!data) {\n\t\tthrow new NoSessionsError(\n\t\t\t\"No checkpoint found for this project. Run 'baton push' on another machine first.\",\n\t\t);\n\t}\n\n\tconsole.log(\n\t\t`Found ${data.sessions.length} session(s), ${data.memory.size} memory file(s)`,\n\t);\n\n\t// 4. Expand paths\n\tconst pathCtx = getLocalPathContext(cwd);\n\tfor (const session of data.sessions) {\n\t\tsession.jsonl = expandPaths(session.jsonl, pathCtx);\n\t}\n\n\t// 5. Restore to Claude Code's local storage\n\tawait restoreProjectData(cwd, data);\n\n\tconsole.log(\"Pulled successfully. Sessions restored to Claude Code.\");\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport {\n\tencodeProjectDir,\n\tgetClaudeProjectsDir,\n\tgetProjectConfigPath,\n} from \"./paths.js\";\nimport type { ProjectData } from \"./reader.js\";\n\n/**\n * Restore project data to Claude Code's local storage.\n */\nexport async function restoreProjectData(\n\tprojectPath: string,\n\tdata: ProjectData,\n): Promise<void> {\n\tconst projectDirName = encodeProjectDir(projectPath);\n\tconst projectDir = join(getClaudeProjectsDir(), projectDirName);\n\n\tawait mkdir(projectDir, { recursive: true });\n\n\tfor (const session of data.sessions) {\n\t\t// Write session JSONL\n\t\tawait writeFile(\n\t\t\tjoin(projectDir, `${session.sessionId}.jsonl`),\n\t\t\tsession.jsonl,\n\t\t\t\"utf-8\",\n\t\t);\n\n\t\t// Write tool results\n\t\tif (session.toolResults.size > 0) {\n\t\t\tconst toolResultsDir = join(\n\t\t\t\tprojectDir,\n\t\t\t\tsession.sessionId,\n\t\t\t\t\"tool-results\",\n\t\t\t);\n\t\t\tawait mkdir(toolResultsDir, { recursive: true });\n\t\t\tfor (const [filename, content] of session.toolResults) {\n\t\t\t\tawait writeFile(join(toolResultsDir, filename), content, \"utf-8\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Write memory files\n\tif (data.memory.size > 0) {\n\t\tconst memoryDir = join(projectDir, \"memory\");\n\t\tawait mkdir(memoryDir, { recursive: true });\n\t\tfor (const [filename, content] of data.memory) {\n\t\t\tawait writeFile(join(memoryDir, filename), content, \"utf-8\");\n\t\t}\n\t}\n\n\t// Ensure project-config.json has a mapping\n\tawait ensureProjectConfig(projectPath, projectDirName);\n}\n\nasync function ensureProjectConfig(\n\tprojectPath: string,\n\tprojectDirName: string,\n): Promise<void> {\n\tconst configPath = getProjectConfigPath();\n\n\tlet config: Record<\n\t\tstring,\n\t\t{ manuallyAdded?: boolean; originalPath: string }\n\t> = {};\n\ttry {\n\t\tconst raw = await readFile(configPath, \"utf-8\");\n\t\tconfig = JSON.parse(raw);\n\t} catch {\n\t\t// File doesn't exist or is invalid, start fresh\n\t}\n\n\tif (!config[projectDirName]) {\n\t\tconfig[projectDirName] = {\n\t\t\toriginalPath: projectPath,\n\t\t};\n\t\tawait mkdir(dirname(configPath), { recursive: true });\n\t\tawait writeFile(configPath, JSON.stringify(config, null, 2), \"utf-8\");\n\t}\n}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\n/**\n * Encode a local project path into a Claude Code project directory name.\n * Claude Code replaces `/`, `.`, and `:` with `-`.\n *\n * Examples:\n * /home/dr_who/baton → -home-dr_who-baton\n * /Users/dr_who/work/baton → -Users-dr_who-work-baton\n * C:\\Users\\dr_who\\baton → -C-Users-dr_who-baton\n */\nexport function encodeProjectDir(projectPath: string): string {\n\t// Normalize backslashes to forward slashes (Windows support)\n\tconst normalized = projectPath.replace(/\\\\/g, \"/\");\n\treturn normalized.replace(/[/.:]/g, \"-\");\n}\n\n/**\n * Get the Claude Code projects base directory.\n */\nexport function getClaudeProjectsDir(): string {\n\treturn join(homedir(), \".claude\", \"projects\");\n}\n\n/**\n * Get the full path to a Claude Code project directory.\n */\nexport function getClaudeProjectPath(projectPath: string): string {\n\treturn join(getClaudeProjectsDir(), encodeProjectDir(projectPath));\n}\n\n/**\n * Get the path to Claude Code's project-config.json.\n */\nexport function getProjectConfigPath(): string {\n\treturn join(homedir(), \".claude\", \"project-config.json\");\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport interface BatonConfig {\n\trepo: string;\n}\n\n/**\n * Get the path to the baton config directory.\n */\nexport function getBatonDir(): string {\n\treturn join(homedir(), \".baton\");\n}\n\n/**\n * Get the path to the baton config file.\n */\nexport function getConfigPath(): string {\n\treturn join(getBatonDir(), \"config.json\");\n}\n\n/**\n * Get the path to the local repo clone.\n */\nexport function getRepoDir(): string {\n\treturn join(getBatonDir(), \"repo\");\n}\n\n/**\n * Load baton config. Returns null if not configured.\n */\nexport async function loadConfig(): Promise<BatonConfig | null> {\n\ttry {\n\t\tconst raw = await readFile(getConfigPath(), \"utf-8\");\n\t\tconst config = JSON.parse(raw);\n\t\tif (!config.repo || typeof config.repo !== \"string\") {\n\t\t\treturn null;\n\t\t}\n\t\treturn config as BatonConfig;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Save baton config.\n */\nexport async function saveConfig(config: BatonConfig): Promise<void> {\n\tconst configPath = getConfigPath();\n\tawait mkdir(dirname(configPath), { recursive: true });\n\tawait writeFile(configPath, JSON.stringify(config, null, 2), \"utf-8\");\n}\n","import { execFile } from \"node:child_process\";\nimport { access } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\nimport { GhNotFoundError, GitNotFoundError } from \"../errors.js\";\n\nconst execFileAsync = promisify(execFile);\n\nconst GIT_TIMEOUT_MS = 30_000;\nconst GH_TIMEOUT_MS = 60_000;\n\n/**\n * Run a git command in the given directory.\n */\nexport async function git(args: string[], cwd: string): Promise<string> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\"git\", args, {\n\t\t\tcwd,\n\t\t\ttimeout: GIT_TIMEOUT_MS,\n\t\t});\n\t\treturn stdout.trim();\n\t} catch (error) {\n\t\tif (isNotFound(error)) {\n\t\t\tthrow new GitNotFoundError(\"git is not installed or not found in PATH.\");\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * Run a gh CLI command.\n */\nexport async function gh(args: string[]): Promise<string> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\"gh\", args, {\n\t\t\ttimeout: GH_TIMEOUT_MS,\n\t\t});\n\t\treturn stdout.trim();\n\t} catch (error) {\n\t\tif (isNotFound(error)) {\n\t\t\tthrow new GhNotFoundError(\n\t\t\t\t\"gh CLI is not installed. Install it from https://cli.github.com/\",\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * Check if the local repo clone exists.\n */\nexport async function repoExists(repoDir: string): Promise<boolean> {\n\ttry {\n\t\tawait access(repoDir);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Clone a repo to the local cache directory.\n */\nexport async function cloneRepo(\n\trepoUrl: string,\n\ttargetDir: string,\n): Promise<void> {\n\tawait execFileAsync(\"git\", [\"clone\", repoUrl, targetDir], {\n\t\ttimeout: GH_TIMEOUT_MS,\n\t});\n}\n\n/**\n * Fetch latest from remote without merging.\n */\nexport async function fetchRepo(repoDir: string): Promise<void> {\n\tawait git([\"fetch\", \"origin\"], repoDir);\n}\n\n/**\n * Pull latest from remote (fast-forward).\n */\nexport async function pullRepo(repoDir: string): Promise<void> {\n\tawait git([\"pull\", \"--ff-only\"], repoDir);\n}\n\n/**\n * Check if remote is ahead of local (has commits we haven't pulled).\n */\nexport async function isRemoteAhead(repoDir: string): Promise<boolean> {\n\tawait fetchRepo(repoDir);\n\tconst localHead = await git([\"rev-parse\", \"HEAD\"], repoDir);\n\tconst remoteHead = await git([\"rev-parse\", \"origin/main\"], repoDir);\n\treturn localHead !== remoteHead;\n}\n\n/**\n * Stage, commit, and push changes.\n */\nexport async function commitAndPush(\n\trepoDir: string,\n\tmessage: string,\n\tforce: boolean,\n): Promise<void> {\n\tawait git([\"add\", \"-A\"], repoDir);\n\n\t// Check if there are changes to commit\n\tconst status = await git([\"status\", \"--porcelain\"], repoDir);\n\tif (!status) {\n\t\treturn; // Nothing to commit\n\t}\n\n\tawait git([\"commit\", \"-m\", message], repoDir);\n\n\tconst pushArgs = force\n\t\t? [\"push\", \"--force\", \"origin\", \"main\"]\n\t\t: [\"push\", \"origin\", \"main\"];\n\tawait git(pushArgs, repoDir);\n}\n\n/**\n * Create a private GitHub repo via gh CLI.\n */\nexport async function createGhRepo(repoName: string): Promise<string> {\n\tconst output = await gh([\n\t\t\"repo\",\n\t\t\"create\",\n\t\trepoName,\n\t\t\"--private\",\n\t\t\"--confirm\",\n\t]);\n\t// gh repo create outputs the URL\n\tconst match = output.match(/https:\\/\\/github\\.com\\/[\\w.-]+\\/[\\w.-]+/);\n\tif (match) {\n\t\treturn match[0];\n\t}\n\t// Fallback: construct from gh whoami\n\tconst username = await gh([\"api\", \"user\", \"--jq\", \".login\"]);\n\treturn `https://github.com/${username}/${repoName}`;\n}\n\n/**\n * Initialize a new git repo with an initial commit.\n */\nexport async function initRepo(repoDir: string): Promise<void> {\n\tawait git([\"init\", \"-b\", \"main\"], repoDir);\n\tawait git([\"config\", \"user.name\", \"baton\"], repoDir);\n\tawait git([\"config\", \"user.email\", \"baton@localhost\"], repoDir);\n\tawait git([\"commit\", \"--allow-empty\", \"-m\", \"init baton repo\"], repoDir);\n}\n\nfunction isNotFound(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\treturn (error as NodeJS.ErrnoException).code === \"ENOENT\";\n}\n","export class BatonError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n}\n\nexport class ProjectNotFoundError extends BatonError {}\n\nexport class NoSessionsError extends BatonError {}\n\nexport class ConflictError extends BatonError {}\n\nexport class GitNotFoundError extends BatonError {}\n\nexport class GhNotFoundError extends BatonError {}\n\nexport class ConfigError extends BatonError {}\n","import { homedir, tmpdir } from \"node:os\";\nimport { sep } from \"node:path\";\n\nconst PLACEHOLDER_PROJECT_ROOT = \"$\" + \"{PROJECT_ROOT}\";\nconst PLACEHOLDER_HOME = \"$\" + \"{HOME}\";\nconst PLACEHOLDER_TMP = \"$\" + \"{TMP}\";\n\nconst PLACEHOLDERS = {\n\tPROJECT_ROOT: PLACEHOLDER_PROJECT_ROOT,\n\tHOME: PLACEHOLDER_HOME,\n\tTMP: PLACEHOLDER_TMP,\n} as const;\n\ninterface PathContext {\n\tprojectRoot: string;\n\thome: string;\n\ttmp: string;\n}\n\n/**\n * Get the current machine's path context.\n */\nexport function getLocalPathContext(projectRoot: string): PathContext {\n\treturn {\n\t\tprojectRoot,\n\t\thome: homedir(),\n\t\ttmp: tmpdir(),\n\t};\n}\n\n/**\n * Virtualize paths in content: replace machine-local absolute paths\n * with portable placeholders.\n *\n * Replaces longest paths first to prevent partial matches.\n * Normalizes path separators to `/` in stored content.\n */\nexport function virtualizePaths(content: string, ctx: PathContext): string {\n\t// Normalize backslashes to forward slashes for consistent matching\n\tconst normalizedContent =\n\t\tsep === \"\\\\\" ? content.replace(/\\\\/g, \"/\") : content;\n\n\t// Build replacement pairs, sorted by path length (longest first)\n\tconst replacements: [string, string][] = (\n\t\t[\n\t\t\t[normalizeSeparators(ctx.projectRoot), PLACEHOLDERS.PROJECT_ROOT],\n\t\t\t[normalizeSeparators(ctx.home), PLACEHOLDERS.HOME],\n\t\t\t[normalizeSeparators(ctx.tmp), PLACEHOLDERS.TMP],\n\t\t] as [string, string][]\n\t).sort((a, b) => b[0].length - a[0].length);\n\n\tlet result = normalizedContent;\n\tfor (const [path, placeholder] of replacements) {\n\t\tif (path) {\n\t\t\tresult = replacePathWithBoundary(result, path, placeholder);\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Expand placeholders in content: replace portable placeholders\n * with machine-local absolute paths.\n *\n * Expands to OS-native path separators.\n */\nexport function expandPaths(content: string, ctx: PathContext): string {\n\tlet result = content;\n\n\tresult = replaceAll(\n\t\tresult,\n\t\tPLACEHOLDERS.PROJECT_ROOT,\n\t\ttoNativePath(ctx.projectRoot),\n\t);\n\tresult = replaceAll(result, PLACEHOLDERS.HOME, toNativePath(ctx.home));\n\tresult = replaceAll(result, PLACEHOLDERS.TMP, toNativePath(ctx.tmp));\n\n\treturn result;\n}\n\n/**\n * Normalize path separators to forward slashes.\n */\nfunction normalizeSeparators(path: string): string {\n\treturn path.replace(/\\\\/g, \"/\");\n}\n\n/**\n * Convert a path to use the OS-native separator.\n */\nfunction toNativePath(path: string): string {\n\tif (sep === \"\\\\\") {\n\t\treturn path.replace(/\\//g, \"\\\\\");\n\t}\n\treturn path;\n}\n\n/**\n * Replace all occurrences of a path, but only when followed by a path\n * boundary character (/, \\, \", whitespace, end of string, etc.).\n * Prevents matching /home/dr_who inside /home/dr_who_backup.\n */\nfunction replacePathWithBoundary(\n\tstr: string,\n\tpath: string,\n\treplacement: string,\n): string {\n\tconst escaped = escapeRegex(path);\n\tconst regex = new RegExp(`${escaped}(?=[/\\\\\\\\\"\\\\s,}\\\\]]|$)`, \"g\");\n\treturn str.replace(regex, replacement);\n}\n\n/**\n * Replace all occurrences of a substring.\n */\nfunction replaceAll(str: string, search: string, replacement: string): string {\n\treturn str.split(search).join(replacement);\n}\n\n/**\n * Escape special regex characters in a string.\n */\nfunction escapeRegex(str: string): string {\n\treturn str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n","import { execFile } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { promisify } from \"node:util\";\nimport { GitNotFoundError, ProjectNotFoundError } from \"../errors.js\";\n\nconst execFileAsync = promisify(execFile);\n\nconst GIT_TIMEOUT_MS = 10_000;\n\n/**\n * Detect the git remote URL from the current working directory.\n * Uses the \"origin\" remote by default.\n */\nexport async function getGitRemote(cwd: string): Promise<string> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\n\t\t\t\"git\",\n\t\t\t[\"remote\", \"get-url\", \"origin\"],\n\t\t\t{ cwd, timeout: GIT_TIMEOUT_MS },\n\t\t);\n\t\tconst remote = stdout.trim();\n\t\tif (!remote) {\n\t\t\tthrow new ProjectNotFoundError(\n\t\t\t\t\"No git remote URL found. Run this command from a git repository with an 'origin' remote.\",\n\t\t\t);\n\t\t}\n\t\treturn remote;\n\t} catch (error) {\n\t\tif (error instanceof ProjectNotFoundError) throw error;\n\t\tif (isGitNotInstalled(error)) {\n\t\t\tthrow new GitNotFoundError(\n\t\t\t\t\"git is not installed or not found in PATH. Please install git first.\",\n\t\t\t);\n\t\t}\n\t\tthrow new ProjectNotFoundError(\n\t\t\t\"Not a git repository or no 'origin' remote configured. Run this command from a git repository.\",\n\t\t);\n\t}\n}\n\nfunction isGitNotInstalled(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tconst err = error as NodeJS.ErrnoException;\n\treturn err.code === \"ENOENT\";\n}\n\n/**\n * Normalize a git remote URL to a canonical form.\n *\n * Handles:\n * - git@github.com:user/repo.git → github.com/user/repo\n * - https://github.com/user/repo.git → github.com/user/repo\n * - https://github.com/user/repo → github.com/user/repo\n * - ssh://git@github.com/user/repo.git → github.com/user/repo\n * - git://github.com/user/repo.git → github.com/user/repo\n */\nexport function normalizeGitRemote(remote: string): string {\n\tconst normalized = remote.trim();\n\n\t// SSH shorthand: git@github.com:user/repo.git\n\tconst sshMatch = normalized.match(/^[\\w.-]+@([\\w.-]+):(.*?)(?:\\.git)?$/);\n\tif (sshMatch) {\n\t\treturn `${sshMatch[1]}/${sshMatch[2]}`;\n\t}\n\n\t// ssh:// or git:// protocol: ssh://git@github.com/user/repo.git\n\tconst protoMatch = normalized.match(\n\t\t/^(?:ssh|git):\\/\\/(?:[\\w.-]+@)?([\\w.-]+)\\/(.*?)(?:\\.git)?$/,\n\t);\n\tif (protoMatch) {\n\t\treturn `${protoMatch[1]}/${protoMatch[2]}`;\n\t}\n\n\t// HTTPS: https://github.com/user/repo.git\n\tconst httpsMatch = normalized.match(\n\t\t/^https?:\\/\\/([\\w.-]+)\\/(.*?)(?:\\.git)?$/,\n\t);\n\tif (httpsMatch) {\n\t\treturn `${httpsMatch[1]}/${httpsMatch[2]}`;\n\t}\n\n\t// Fallback: return as-is (stripped)\n\treturn normalized;\n}\n\n/**\n * Hash a normalized git remote URL to produce a stable project ID.\n */\nexport function hashProjectId(normalizedRemote: string): string {\n\treturn createHash(\"sha256\")\n\t\t.update(normalizedRemote)\n\t\t.digest(\"hex\")\n\t\t.slice(0, 16);\n}\n\n/**\n * Detect the project from the current working directory.\n * Returns the project hash and normalized git remote.\n */\nexport async function detectProject(\n\tcwd: string,\n): Promise<{ projectId: string; gitRemote: string; normalizedRemote: string }> {\n\tconst gitRemote = await getGitRemote(cwd);\n\tconst normalizedRemote = normalizeGitRemote(gitRemote);\n\tconst projectId = hashProjectId(normalizedRemote);\n\treturn { projectId, gitRemote, normalizedRemote };\n}\n","import { mkdir, readdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type {\n\tProjectData,\n\tSessionData,\n} from \"../adapters/claude-code/reader.js\";\n\ninterface ProjectMeta {\n\tproject_id: string;\n\tgit_remote: string;\n\tpushed_at: string;\n}\n\n/**\n * Write project data as a checkpoint to the baton repo.\n */\nexport async function writeCheckpoint(\n\tprojectDir: string,\n\tproject: { projectId: string; gitRemote: string },\n\tdata: ProjectData,\n): Promise<void> {\n\t// Clean existing sessions directory to remove stale sessions\n\tconst sessionsDir = join(projectDir, \"sessions\");\n\tawait rm(sessionsDir, { recursive: true, force: true });\n\tawait mkdir(sessionsDir, { recursive: true });\n\n\t// Write meta\n\tconst meta: ProjectMeta = {\n\t\tproject_id: project.projectId,\n\t\tgit_remote: project.gitRemote,\n\t\tpushed_at: new Date().toISOString(),\n\t};\n\tawait writeFile(\n\t\tjoin(projectDir, \"meta.json\"),\n\t\tJSON.stringify(meta, null, 2),\n\t\t\"utf-8\",\n\t);\n\n\t// Write sessions\n\tfor (const session of data.sessions) {\n\t\tawait writeFile(\n\t\t\tjoin(sessionsDir, `${session.sessionId}.jsonl`),\n\t\t\tsession.jsonl,\n\t\t\t\"utf-8\",\n\t\t);\n\n\t\t// Write tool results\n\t\tif (session.toolResults.size > 0) {\n\t\t\tconst toolResultsDir = join(\n\t\t\t\tsessionsDir,\n\t\t\t\tsession.sessionId,\n\t\t\t\t\"tool-results\",\n\t\t\t);\n\t\t\tawait mkdir(toolResultsDir, { recursive: true });\n\t\t\tfor (const [filename, content] of session.toolResults) {\n\t\t\t\tawait writeFile(join(toolResultsDir, filename), content, \"utf-8\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Write memory\n\tif (data.memory.size > 0) {\n\t\tconst memoryDir = join(projectDir, \"memory\");\n\t\tawait mkdir(memoryDir, { recursive: true });\n\t\tfor (const [filename, content] of data.memory) {\n\t\t\tawait writeFile(join(memoryDir, filename), content, \"utf-8\");\n\t\t}\n\t}\n}\n\n/**\n * Read a checkpoint from the baton repo. Returns null if not found.\n */\nexport async function readCheckpoint(\n\tprojectDir: string,\n): Promise<ProjectData | null> {\n\tconst sessionsDir = join(projectDir, \"sessions\");\n\n\tlet sessionFiles: string[];\n\ttry {\n\t\tconst entries = await readdir(sessionsDir);\n\t\tsessionFiles = entries.filter((e) => e.endsWith(\".jsonl\"));\n\t} catch {\n\t\treturn null;\n\t}\n\n\tif (sessionFiles.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst sessions: SessionData[] = [];\n\tfor (const file of sessionFiles) {\n\t\tconst sessionId = file.replace(\".jsonl\", \"\");\n\t\tconst jsonl = await readFile(join(sessionsDir, file), \"utf-8\");\n\t\tconst toolResults = await readToolResults(sessionsDir, sessionId);\n\t\tsessions.push({ sessionId, jsonl, toolResults });\n\t}\n\n\tconst memory = await readMemory(projectDir);\n\n\treturn {\n\t\tsessions,\n\t\tmemory,\n\t\tprojectDirName: \"\",\n\t};\n}\n\nasync function readToolResults(\n\tsessionsDir: string,\n\tsessionId: string,\n): Promise<Map<string, string>> {\n\tconst results = new Map<string, string>();\n\tconst toolResultsDir = join(sessionsDir, sessionId, \"tool-results\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(toolResultsDir);\n\t} catch {\n\t\treturn results;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst content = await readFile(join(toolResultsDir, entry), \"utf-8\");\n\t\tresults.set(entry, content);\n\t}\n\n\treturn results;\n}\n\nasync function readMemory(projectDir: string): Promise<Map<string, string>> {\n\tconst memory = new Map<string, string>();\n\tconst memoryDir = join(projectDir, \"memory\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(memoryDir);\n\t} catch {\n\t\treturn memory;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst content = await readFile(join(memoryDir, entry), \"utf-8\");\n\t\tmemory.set(entry, content);\n\t}\n\n\treturn memory;\n}\n","import { createInterface } from \"node:readline/promises\";\nimport { getRepoDir, loadConfig, saveConfig } from \"../core/config.js\";\nimport { cloneRepo, createGhRepo, repoExists } from \"../core/git.js\";\n\n/**\n * Ensure the baton repo is configured and cloned locally.\n * On first run, prompts the user to either create a new repo (push) or enter an existing repo URL (pull).\n */\nexport async function ensureBatonRepo(mode: \"push\" | \"pull\"): Promise<void> {\n\tconst repoDir = getRepoDir();\n\tlet config = await loadConfig();\n\n\tif (!config) {\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\ttry {\n\t\t\tif (mode === \"push\") {\n\t\t\t\tconfig = await promptCreateRepo(rl);\n\t\t\t} else {\n\t\t\t\tconfig = await promptExistingRepo(rl);\n\t\t\t}\n\t\t\tawait saveConfig(config);\n\t\t} finally {\n\t\t\trl.close();\n\t\t}\n\t}\n\n\tif (!(await repoExists(repoDir))) {\n\t\tconsole.log(\"Cloning baton repo...\");\n\t\tawait cloneRepo(config.repo, repoDir);\n\t}\n}\n\nasync function promptCreateRepo(\n\trl: ReturnType<typeof createInterface>,\n): Promise<{ repo: string }> {\n\tconst rawName = await rl.question(\n\t\t\"Enter a name for your baton sync repo (will be created as private on GitHub): \",\n\t);\n\tconst repoName = rawName.trim();\n\tif (!repoName) {\n\t\tthrow new Error(\"Repo name cannot be empty.\");\n\t}\n\n\tconsole.log(`Creating private repo '${repoName}'...`);\n\tconst repoUrl = await createGhRepo(repoName);\n\tconsole.log(`Repo created: ${repoUrl}`);\n\treturn { repo: repoUrl };\n}\n\nasync function promptExistingRepo(\n\trl: ReturnType<typeof createInterface>,\n): Promise<{ repo: string }> {\n\tconst rawUrl = await rl.question(\n\t\t\"Enter your baton sync repo URL (e.g. https://github.com/user/baton-sync): \",\n\t);\n\tconst repoUrl = rawUrl.trim();\n\tif (!repoUrl) {\n\t\tthrow new Error(\"Repo URL cannot be empty.\");\n\t}\n\n\treturn { repo: repoUrl };\n}\n","import { join } from \"node:path\";\nimport { collectProjectData } from \"../adapters/claude-code/reader.js\";\nimport { getRepoDir } from \"../core/config.js\";\nimport { commitAndPush, isRemoteAhead, repoExists } from \"../core/git.js\";\nimport { getLocalPathContext, virtualizePaths } from \"../core/paths.js\";\nimport { detectProject } from \"../core/project.js\";\nimport { ConflictError } from \"../errors.js\";\nimport { writeCheckpoint } from \"./checkpoint.js\";\nimport { ensureBatonRepo } from \"./setup.js\";\n\nexport async function push(options: { force?: boolean }): Promise<void> {\n\tconst cwd = process.cwd();\n\n\t// 1. Detect project\n\tconst project = await detectProject(cwd);\n\tconsole.log(`Project: ${project.normalizedRemote} (${project.projectId})`);\n\n\t// 2. Collect session data\n\tconst data = await collectProjectData(cwd);\n\tconsole.log(\n\t\t`Found ${data.sessions.length} session(s), ${data.memory.size} memory file(s)`,\n\t);\n\n\t// 3. Virtualize paths\n\tconst pathCtx = getLocalPathContext(cwd);\n\tfor (const session of data.sessions) {\n\t\tsession.jsonl = virtualizePaths(session.jsonl, pathCtx);\n\t}\n\n\t// 4. Ensure baton repo exists\n\tconst repoDir = getRepoDir();\n\tawait ensureBatonRepo(\"push\");\n\n\t// 5. Conflict check\n\tif (!options.force && (await repoExists(repoDir))) {\n\t\ttry {\n\t\t\tconst ahead = await isRemoteAhead(repoDir);\n\t\t\tif (ahead) {\n\t\t\t\tthrow new ConflictError(\n\t\t\t\t\t\"Remote has changes you haven't pulled. Run 'baton pull' first, or use 'baton push --force' to overwrite.\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof ConflictError) throw error;\n\t\t\t// Ignore fetch errors (e.g., empty repo with no commits on remote yet)\n\t\t}\n\t}\n\n\t// 6. Write checkpoint to baton repo\n\tconst projectDir = join(repoDir, \"projects\", project.projectId);\n\tawait writeCheckpoint(projectDir, project, data);\n\n\t// 7. Commit and push\n\tawait commitAndPush(\n\t\trepoDir,\n\t\t`push: ${project.normalizedRemote}`,\n\t\toptions.force ?? false,\n\t);\n\n\tconsole.log(\"Pushed successfully.\");\n}\n","import { readdir, readFile, stat } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport { NoSessionsError } from \"../../errors.js\";\nimport { encodeProjectDir, getClaudeProjectsDir } from \"./paths.js\";\n\nexport interface SessionData {\n\tsessionId: string;\n\tjsonl: string;\n\ttoolResults: Map<string, string>;\n}\n\nexport interface ProjectData {\n\tsessions: SessionData[];\n\tmemory: Map<string, string>;\n\tprojectDirName: string;\n}\n\n/**\n * Collect all session data for a project from Claude Code's local storage.\n */\nexport async function collectProjectData(\n\tprojectPath: string,\n): Promise<ProjectData> {\n\tconst projectDirName = encodeProjectDir(projectPath);\n\tconst projectDir = join(getClaudeProjectsDir(), projectDirName);\n\n\tconst sessions = await collectSessions(projectDir);\n\tif (sessions.length === 0) {\n\t\tthrow new NoSessionsError(\n\t\t\t`No Claude Code sessions found for this project. Start a Claude Code session first.`,\n\t\t);\n\t}\n\n\tconst memory = await collectMemory(projectDir);\n\n\treturn { sessions, memory, projectDirName };\n}\n\nasync function collectSessions(projectDir: string): Promise<SessionData[]> {\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(projectDir);\n\t} catch {\n\t\treturn [];\n\t}\n\n\tconst jsonlFiles = entries.filter((e) => e.endsWith(\".jsonl\"));\n\tconst sessions: SessionData[] = [];\n\n\tfor (const jsonlFile of jsonlFiles) {\n\t\tconst sessionId = basename(jsonlFile, \".jsonl\");\n\t\tconst jsonl = await readFile(join(projectDir, jsonlFile), \"utf-8\");\n\t\tconst toolResults = await collectToolResults(projectDir, sessionId);\n\t\tsessions.push({ sessionId, jsonl, toolResults });\n\t}\n\n\treturn sessions;\n}\n\nasync function collectToolResults(\n\tprojectDir: string,\n\tsessionId: string,\n): Promise<Map<string, string>> {\n\tconst results = new Map<string, string>();\n\tconst toolResultsDir = join(projectDir, sessionId, \"tool-results\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(toolResultsDir);\n\t} catch {\n\t\treturn results;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst filePath = join(toolResultsDir, entry);\n\t\tconst fileStat = await stat(filePath);\n\t\tif (fileStat.isFile()) {\n\t\t\tconst content = await readFile(filePath, \"utf-8\");\n\t\t\tresults.set(entry, content);\n\t\t}\n\t}\n\n\treturn results;\n}\n\nasync function collectMemory(projectDir: string): Promise<Map<string, string>> {\n\tconst memory = new Map<string, string>();\n\tconst memoryDir = join(projectDir, \"memory\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(memoryDir);\n\t} catch {\n\t\treturn memory;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst filePath = join(memoryDir, entry);\n\t\tconst fileStat = await stat(filePath);\n\t\tif (fileStat.isFile()) {\n\t\t\tconst content = await readFile(filePath, \"utf-8\");\n\t\t\tmemory.set(entry, content);\n\t\t}\n\t}\n\n\treturn memory;\n}\n","import { readdir, readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n\tencodeProjectDir,\n\tgetClaudeProjectsDir,\n} from \"../adapters/claude-code/paths.js\";\nimport { getRepoDir, loadConfig } from \"../core/config.js\";\nimport { repoExists } from \"../core/git.js\";\nimport { detectProject } from \"../core/project.js\";\n\nexport async function status(): Promise<void> {\n\tconst cwd = process.cwd();\n\n\t// Project info\n\tconst project = await detectProject(cwd);\n\tconsole.log(`Project: ${project.normalizedRemote}`);\n\tconsole.log(`Project ID: ${project.projectId}`);\n\n\t// Local sessions\n\tconst projectDirName = encodeProjectDir(cwd);\n\tconst localProjectDir = join(getClaudeProjectsDir(), projectDirName);\n\ttry {\n\t\tconst entries = await readdir(localProjectDir);\n\t\tconst sessionCount = entries.filter((e) => e.endsWith(\".jsonl\")).length;\n\t\tconsole.log(`Local sessions: ${sessionCount}`);\n\t} catch {\n\t\tconsole.log(\"Local sessions: 0\");\n\t}\n\n\t// Baton config\n\tconst config = await loadConfig();\n\tif (!config) {\n\t\tconsole.log(\"Baton repo: not configured (run 'baton push' to set up)\");\n\t\treturn;\n\t}\n\tconsole.log(`Baton repo: ${config.repo}`);\n\n\t// Remote checkpoint\n\tconst repoDir = getRepoDir();\n\tif (!(await repoExists(repoDir))) {\n\t\tconsole.log(\"Remote checkpoint: not cloned yet\");\n\t\treturn;\n\t}\n\n\tconst metaPath = join(repoDir, \"projects\", project.projectId, \"meta.json\");\n\ttry {\n\t\tconst raw = await readFile(metaPath, \"utf-8\");\n\t\tconst meta = JSON.parse(raw);\n\t\tconsole.log(`Last pushed: ${meta.pushed_at ?? \"unknown\"}`);\n\t} catch {\n\t\tconsole.log(\"Remote checkpoint: none for this project\");\n\t}\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;;;ACAxB,SAAS,QAAAA,aAAY;;;ACArB,SAAS,OAAO,UAAU,iBAAiB;AAC3C,SAAS,SAAS,QAAAC,aAAY;;;ACD9B,SAAS,eAAe;AACxB,SAAS,YAAY;AAWd,SAAS,iBAAiB,aAA6B;AAE7D,QAAM,aAAa,YAAY,QAAQ,OAAO,GAAG;AACjD,SAAO,WAAW,QAAQ,UAAU,GAAG;AACxC;AAKO,SAAS,uBAA+B;AAC9C,SAAO,KAAK,QAAQ,GAAG,WAAW,UAAU;AAC7C;AAYO,SAAS,uBAA+B;AAC9C,SAAO,KAAK,QAAQ,GAAG,WAAW,qBAAqB;AACxD;;;ADzBA,eAAsB,mBACrB,aACA,MACgB;AAChB,QAAM,iBAAiB,iBAAiB,WAAW;AACnD,QAAM,aAAaC,MAAK,qBAAqB,GAAG,cAAc;AAE9D,QAAM,MAAM,YAAY,EAAE,WAAW,KAAK,CAAC;AAE3C,aAAW,WAAW,KAAK,UAAU;AAEpC,UAAM;AAAA,MACLA,MAAK,YAAY,GAAG,QAAQ,SAAS,QAAQ;AAAA,MAC7C,QAAQ;AAAA,MACR;AAAA,IACD;AAGA,QAAI,QAAQ,Y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AAY,qCAAqC,EACjD,OAAO,YAAY;AACnB,QAAM,OAAO;AACd,CAAC;AAEF,IAAI;AACH,QAAM,QAAQ,WAAW,QAAQ,IAAI;AACtC,SAAS,OAAO;AACf,MAAI,iBAAiB,YAAY;AAChC,YAAQ,MAAM,UAAU,MAAM,OAAO,EAAE;AAAA,EACxC,OAAO;AACN,YAAQ;AAAA,MACP,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC5E;AAAA,EACD;AACA,UAAQ,KAAK,CAAC;AACf;","names":["join","join","join","mkdir","readFile","writeFile","homedir","dirname","join","status","homedir","execFile","promisify","execFileAsync","promisify","execFile","GIT_TIMEOUT_MS","mkdir","readFile","writeFile","join","join","join","readdir","readFile","join","join","readdir","readFile","join","readdir","readFile","join","join","readdir","readFile"]}
|
|
1
|
+
{"version":3,"sources":["../src/cli.ts","../src/commands/pull.ts","../src/adapters/claude-code/reader.ts","../src/errors.ts","../src/adapters/claude-code/paths.ts","../src/adapters/claude-code/writer.ts","../src/core/config.ts","../src/core/git.ts","../src/core/paths.ts","../src/core/project.ts","../src/commands/checkpoint.ts","../src/commands/setup.ts","../src/commands/push.ts","../src/commands/status.ts"],"sourcesContent":["import { Command } from \"commander\";\nimport { pull } from \"./commands/pull.js\";\nimport { push } from \"./commands/push.js\";\nimport { status } from \"./commands/status.js\";\nimport { BatonError } from \"./errors.js\";\n\nconst program = new Command();\n\nprogram\n\t.name(\"baton\")\n\t.description(\"Git-backed session handoff for Claude Code\")\n\t.version(\"0.1.0\");\n\nprogram\n\t.command(\"push\")\n\t.description(\"Push all sessions for the current project to GitHub\")\n\t.option(\"-f, --force\", \"Overwrite remote even if ahead\")\n\t.action(async (options) => {\n\t\tawait push({ force: options.force });\n\t});\n\nprogram\n\t.command(\"pull\")\n\t.description(\"Restore sessions for the current project from GitHub\")\n\t.option(\"-f, --force\", \"Overwrite local sessions without confirmation\")\n\t.action(async (options) => {\n\t\tawait pull({ force: options.force });\n\t});\n\nprogram\n\t.command(\"status\")\n\t.description(\"Show current project and sync state\")\n\t.action(async () => {\n\t\tawait status();\n\t});\n\ntry {\n\tawait program.parseAsync(process.argv);\n} catch (error) {\n\tif (error instanceof BatonError) {\n\t\tconsole.error(`Error: ${error.message}`);\n\t} else {\n\t\tconsole.error(\n\t\t\t`Unexpected error: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tprocess.exit(1);\n}\n","import { join } from \"node:path\";\nimport { createInterface } from \"node:readline/promises\";\nimport { listLocalSessionIds } from \"../adapters/claude-code/reader.js\";\nimport { restoreProjectData } from \"../adapters/claude-code/writer.js\";\nimport { getRepoDir } from \"../core/config.js\";\nimport { pullRepo, repoExists } from \"../core/git.js\";\nimport { expandPaths, getLocalPathContext } from \"../core/paths.js\";\nimport { detectProject } from \"../core/project.js\";\nimport { NoSessionsError } from \"../errors.js\";\nimport { readCheckpoint } from \"./checkpoint.js\";\nimport { ensureBatonRepo } from \"./setup.js\";\n\nexport async function pull(options: { force?: boolean }): Promise<void> {\n\tconst cwd = process.cwd();\n\n\t// 1. Detect project\n\tconst project = await detectProject(cwd);\n\tconsole.log(`Project: ${project.normalizedRemote} (${project.projectId})`);\n\n\t// 2. Ensure baton repo is available\n\tawait ensureBatonRepo(\"pull\");\n\n\tconst repoDir = getRepoDir();\n\tif (await repoExists(repoDir)) {\n\t\tconsole.log(\"Pulling latest...\");\n\t\tawait pullRepo(repoDir);\n\t}\n\n\t// 3. Read checkpoint from baton repo\n\tconst projectDir = join(repoDir, \"projects\", project.projectId);\n\tconst data = await readCheckpoint(projectDir);\n\n\tif (!data) {\n\t\tthrow new NoSessionsError(\n\t\t\t\"No checkpoint found for this project. Run 'baton push' on another machine first.\",\n\t\t);\n\t}\n\n\tconsole.log(\n\t\t`Found ${data.sessions.length} session(s), ${data.memory.size} memory file(s)`,\n\t);\n\n\t// 4. Check for local sessions that would be overwritten\n\tif (!options.force) {\n\t\tconst localIds = await listLocalSessionIds(cwd);\n\t\tconst remoteIds = new Set(data.sessions.map((s) => s.sessionId));\n\t\tconst conflicts = localIds.filter((id) => remoteIds.has(id));\n\n\t\tif (conflicts.length > 0) {\n\t\t\tconsole.log(\n\t\t\t\t`Warning: ${conflicts.length} local session(s) will be overwritten.`,\n\t\t\t);\n\t\t\tconst rl = createInterface({\n\t\t\t\tinput: process.stdin,\n\t\t\t\toutput: process.stdout,\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tconst answer = await rl.question(\"Continue? (y/N): \");\n\t\t\t\tif (answer.trim().toLowerCase() !== \"y\") {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\"Pull cancelled. Use 'baton pull --force' to skip this check.\",\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\trl.close();\n\t\t\t}\n\t\t}\n\t}\n\n\t// 5. Expand paths\n\tconst pathCtx = getLocalPathContext(cwd);\n\tfor (const session of data.sessions) {\n\t\tsession.jsonl = expandPaths(session.jsonl, pathCtx);\n\t}\n\n\t// 6. Restore to Claude Code's local storage\n\tawait restoreProjectData(cwd, data);\n\n\tconsole.log(\"Pulled successfully. Sessions restored to Claude Code.\");\n}\n","import { readdir, readFile, stat } from \"node:fs/promises\";\nimport { basename, join } from \"node:path\";\nimport { NoSessionsError } from \"../../errors.js\";\nimport { encodeProjectDir, getClaudeProjectsDir } from \"./paths.js\";\n\nexport interface SessionData {\n\tsessionId: string;\n\tjsonl: string;\n\ttoolResults: Map<string, string>;\n}\n\nexport interface ProjectData {\n\tsessions: SessionData[];\n\tmemory: Map<string, string>;\n\tprojectDirName: string;\n}\n\n/**\n * List local session IDs for a project (lightweight, no content read).\n */\nexport async function listLocalSessionIds(\n\tprojectPath: string,\n): Promise<string[]> {\n\tconst projectDirName = encodeProjectDir(projectPath);\n\tconst projectDir = join(getClaudeProjectsDir(), projectDirName);\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(projectDir);\n\t} catch {\n\t\treturn [];\n\t}\n\n\treturn entries\n\t\t.filter((e) => e.endsWith(\".jsonl\"))\n\t\t.map((e) => basename(e, \".jsonl\"));\n}\n\n/**\n * Collect all session data for a project from Claude Code's local storage.\n */\nexport async function collectProjectData(\n\tprojectPath: string,\n): Promise<ProjectData> {\n\tconst projectDirName = encodeProjectDir(projectPath);\n\tconst projectDir = join(getClaudeProjectsDir(), projectDirName);\n\n\tconst sessions = await collectSessions(projectDir);\n\tif (sessions.length === 0) {\n\t\tthrow new NoSessionsError(\n\t\t\t`No Claude Code sessions found for this project. Start a Claude Code session first.`,\n\t\t);\n\t}\n\n\tconst memory = await collectMemory(projectDir);\n\n\treturn { sessions, memory, projectDirName };\n}\n\nasync function collectSessions(projectDir: string): Promise<SessionData[]> {\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(projectDir);\n\t} catch {\n\t\treturn [];\n\t}\n\n\tconst jsonlFiles = entries.filter((e) => e.endsWith(\".jsonl\"));\n\tconst sessions: SessionData[] = [];\n\n\tfor (const jsonlFile of jsonlFiles) {\n\t\tconst sessionId = basename(jsonlFile, \".jsonl\");\n\t\tconst jsonl = await readFile(join(projectDir, jsonlFile), \"utf-8\");\n\t\tconst toolResults = await collectToolResults(projectDir, sessionId);\n\t\tsessions.push({ sessionId, jsonl, toolResults });\n\t}\n\n\treturn sessions;\n}\n\nasync function collectToolResults(\n\tprojectDir: string,\n\tsessionId: string,\n): Promise<Map<string, string>> {\n\tconst results = new Map<string, string>();\n\tconst toolResultsDir = join(projectDir, sessionId, \"tool-results\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(toolResultsDir);\n\t} catch {\n\t\treturn results;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst filePath = join(toolResultsDir, entry);\n\t\tconst fileStat = await stat(filePath);\n\t\tif (fileStat.isFile()) {\n\t\t\tconst content = await readFile(filePath, \"utf-8\");\n\t\t\tresults.set(entry, content);\n\t\t}\n\t}\n\n\treturn results;\n}\n\nasync function collectMemory(projectDir: string): Promise<Map<string, string>> {\n\tconst memory = new Map<string, string>();\n\tconst memoryDir = join(projectDir, \"memory\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(memoryDir);\n\t} catch {\n\t\treturn memory;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst filePath = join(memoryDir, entry);\n\t\tconst fileStat = await stat(filePath);\n\t\tif (fileStat.isFile()) {\n\t\t\tconst content = await readFile(filePath, \"utf-8\");\n\t\t\tmemory.set(entry, content);\n\t\t}\n\t}\n\n\treturn memory;\n}\n","export class BatonError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = this.constructor.name;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n}\n\nexport class ProjectNotFoundError extends BatonError {}\n\nexport class NoSessionsError extends BatonError {}\n\nexport class ConflictError extends BatonError {}\n\nexport class GitNotFoundError extends BatonError {}\n\nexport class GhNotFoundError extends BatonError {}\n\nexport class ConfigError extends BatonError {}\n","import { homedir } from \"node:os\";\nimport { join } from \"node:path\";\n\n/**\n * Encode a local project path into a Claude Code project directory name.\n * Claude Code replaces `/`, `.`, and `:` with `-`.\n *\n * Examples:\n * /home/dr_who/baton → -home-dr_who-baton\n * /Users/dr_who/work/baton → -Users-dr_who-work-baton\n * C:\\Users\\dr_who\\baton → -C-Users-dr_who-baton\n */\nexport function encodeProjectDir(projectPath: string): string {\n\t// Normalize backslashes to forward slashes (Windows support)\n\tconst normalized = projectPath.replace(/\\\\/g, \"/\");\n\treturn normalized.replace(/[/.:]/g, \"-\");\n}\n\n/**\n * Get the Claude Code projects base directory.\n */\nexport function getClaudeProjectsDir(): string {\n\treturn join(homedir(), \".claude\", \"projects\");\n}\n\n/**\n * Get the full path to a Claude Code project directory.\n */\nexport function getClaudeProjectPath(projectPath: string): string {\n\treturn join(getClaudeProjectsDir(), encodeProjectDir(projectPath));\n}\n\n/**\n * Get the path to Claude Code's project-config.json.\n */\nexport function getProjectConfigPath(): string {\n\treturn join(homedir(), \".claude\", \"project-config.json\");\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport {\n\tencodeProjectDir,\n\tgetClaudeProjectsDir,\n\tgetProjectConfigPath,\n} from \"./paths.js\";\nimport type { ProjectData } from \"./reader.js\";\n\n/**\n * Restore project data to Claude Code's local storage.\n */\nexport async function restoreProjectData(\n\tprojectPath: string,\n\tdata: ProjectData,\n): Promise<void> {\n\tconst projectDirName = encodeProjectDir(projectPath);\n\tconst projectDir = join(getClaudeProjectsDir(), projectDirName);\n\n\tawait mkdir(projectDir, { recursive: true });\n\n\tfor (const session of data.sessions) {\n\t\t// Write session JSONL\n\t\tawait writeFile(\n\t\t\tjoin(projectDir, `${session.sessionId}.jsonl`),\n\t\t\tsession.jsonl,\n\t\t\t\"utf-8\",\n\t\t);\n\n\t\t// Write tool results\n\t\tif (session.toolResults.size > 0) {\n\t\t\tconst toolResultsDir = join(\n\t\t\t\tprojectDir,\n\t\t\t\tsession.sessionId,\n\t\t\t\t\"tool-results\",\n\t\t\t);\n\t\t\tawait mkdir(toolResultsDir, { recursive: true });\n\t\t\tfor (const [filename, content] of session.toolResults) {\n\t\t\t\tawait writeFile(join(toolResultsDir, filename), content, \"utf-8\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Write memory files\n\tif (data.memory.size > 0) {\n\t\tconst memoryDir = join(projectDir, \"memory\");\n\t\tawait mkdir(memoryDir, { recursive: true });\n\t\tfor (const [filename, content] of data.memory) {\n\t\t\tawait writeFile(join(memoryDir, filename), content, \"utf-8\");\n\t\t}\n\t}\n\n\t// Ensure project-config.json has a mapping\n\tawait ensureProjectConfig(projectPath, projectDirName);\n}\n\nasync function ensureProjectConfig(\n\tprojectPath: string,\n\tprojectDirName: string,\n): Promise<void> {\n\tconst configPath = getProjectConfigPath();\n\n\tlet config: Record<\n\t\tstring,\n\t\t{ manuallyAdded?: boolean; originalPath: string }\n\t> = {};\n\ttry {\n\t\tconst raw = await readFile(configPath, \"utf-8\");\n\t\tconfig = JSON.parse(raw);\n\t} catch {\n\t\t// File doesn't exist or is invalid, start fresh\n\t}\n\n\tif (!config[projectDirName]) {\n\t\tconfig[projectDirName] = {\n\t\t\toriginalPath: projectPath,\n\t\t};\n\t\tawait mkdir(dirname(configPath), { recursive: true });\n\t\tawait writeFile(configPath, JSON.stringify(config, null, 2), \"utf-8\");\n\t}\n}\n","import { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport interface BatonConfig {\n\trepo: string;\n}\n\n/**\n * Get the path to the baton config directory.\n */\nexport function getBatonDir(): string {\n\treturn join(homedir(), \".baton\");\n}\n\n/**\n * Get the path to the baton config file.\n */\nexport function getConfigPath(): string {\n\treturn join(getBatonDir(), \"config.json\");\n}\n\n/**\n * Get the path to the local repo clone.\n */\nexport function getRepoDir(): string {\n\treturn join(getBatonDir(), \"repo\");\n}\n\n/**\n * Load baton config. Returns null if not configured.\n */\nexport async function loadConfig(): Promise<BatonConfig | null> {\n\ttry {\n\t\tconst raw = await readFile(getConfigPath(), \"utf-8\");\n\t\tconst config = JSON.parse(raw);\n\t\tif (!config.repo || typeof config.repo !== \"string\") {\n\t\t\treturn null;\n\t\t}\n\t\treturn config as BatonConfig;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Save baton config.\n */\nexport async function saveConfig(config: BatonConfig): Promise<void> {\n\tconst configPath = getConfigPath();\n\tawait mkdir(dirname(configPath), { recursive: true });\n\tawait writeFile(configPath, JSON.stringify(config, null, 2), \"utf-8\");\n}\n","import { execFile } from \"node:child_process\";\nimport { access } from \"node:fs/promises\";\nimport { promisify } from \"node:util\";\nimport { GhNotFoundError, GitNotFoundError } from \"../errors.js\";\n\nconst execFileAsync = promisify(execFile);\n\nconst GIT_TIMEOUT_MS = 30_000;\nconst GH_TIMEOUT_MS = 60_000;\n\n/**\n * Run a git command in the given directory.\n */\nexport async function git(args: string[], cwd: string): Promise<string> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\"git\", args, {\n\t\t\tcwd,\n\t\t\ttimeout: GIT_TIMEOUT_MS,\n\t\t});\n\t\treturn stdout.trim();\n\t} catch (error) {\n\t\tif (isNotFound(error)) {\n\t\t\tthrow new GitNotFoundError(\"git is not installed or not found in PATH.\");\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * Run a gh CLI command.\n */\nexport async function gh(args: string[]): Promise<string> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\"gh\", args, {\n\t\t\ttimeout: GH_TIMEOUT_MS,\n\t\t});\n\t\treturn stdout.trim();\n\t} catch (error) {\n\t\tif (isNotFound(error)) {\n\t\t\tthrow new GhNotFoundError(\n\t\t\t\t\"gh CLI is not installed. Install it from https://cli.github.com/\",\n\t\t\t);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * Check if the local repo clone exists.\n */\nexport async function repoExists(repoDir: string): Promise<boolean> {\n\ttry {\n\t\tawait access(repoDir);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Clone a repo to the local cache directory.\n */\nexport async function cloneRepo(\n\trepoUrl: string,\n\ttargetDir: string,\n): Promise<void> {\n\tawait execFileAsync(\"git\", [\"clone\", repoUrl, targetDir], {\n\t\ttimeout: GH_TIMEOUT_MS,\n\t});\n}\n\n/**\n * Fetch latest from remote without merging.\n */\nexport async function fetchRepo(repoDir: string): Promise<void> {\n\tawait git([\"fetch\", \"origin\"], repoDir);\n}\n\n/**\n * Pull latest from remote (fast-forward).\n */\nexport async function pullRepo(repoDir: string): Promise<void> {\n\tawait git([\"pull\", \"--ff-only\"], repoDir);\n}\n\n/**\n * Check if remote is ahead of local (has commits we haven't pulled).\n */\nexport async function isRemoteAhead(repoDir: string): Promise<boolean> {\n\tawait fetchRepo(repoDir);\n\tconst localHead = await git([\"rev-parse\", \"HEAD\"], repoDir);\n\tconst remoteHead = await git([\"rev-parse\", \"origin/main\"], repoDir);\n\treturn localHead !== remoteHead;\n}\n\n/**\n * Stage, commit, and push changes.\n */\nexport async function commitAndPush(\n\trepoDir: string,\n\tmessage: string,\n\tforce: boolean,\n): Promise<void> {\n\tawait git([\"add\", \"-A\"], repoDir);\n\n\t// Check if there are changes to commit\n\tconst status = await git([\"status\", \"--porcelain\"], repoDir);\n\tif (!status) {\n\t\treturn; // Nothing to commit\n\t}\n\n\tawait git([\"commit\", \"-m\", message], repoDir);\n\n\tconst pushArgs = force\n\t\t? [\"push\", \"--force\", \"origin\", \"main\"]\n\t\t: [\"push\", \"origin\", \"main\"];\n\tawait git(pushArgs, repoDir);\n}\n\n/**\n * Create a private GitHub repo via gh CLI.\n */\nexport async function createGhRepo(repoName: string): Promise<string> {\n\tconst output = await gh([\n\t\t\"repo\",\n\t\t\"create\",\n\t\trepoName,\n\t\t\"--private\",\n\t\t\"--confirm\",\n\t]);\n\t// gh repo create outputs the URL\n\tconst match = output.match(/https:\\/\\/github\\.com\\/[\\w.-]+\\/[\\w.-]+/);\n\tif (match) {\n\t\treturn match[0];\n\t}\n\t// Fallback: construct from gh whoami\n\tconst username = await gh([\"api\", \"user\", \"--jq\", \".login\"]);\n\treturn `https://github.com/${username}/${repoName}`;\n}\n\n/**\n * Initialize a new git repo with an initial commit.\n */\nexport async function initRepo(repoDir: string): Promise<void> {\n\tawait git([\"init\", \"-b\", \"main\"], repoDir);\n\tawait git([\"config\", \"user.name\", \"baton\"], repoDir);\n\tawait git([\"config\", \"user.email\", \"baton@localhost\"], repoDir);\n\tawait git([\"commit\", \"--allow-empty\", \"-m\", \"init baton repo\"], repoDir);\n}\n\nfunction isNotFound(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\treturn (error as NodeJS.ErrnoException).code === \"ENOENT\";\n}\n","import { homedir, tmpdir } from \"node:os\";\nimport { sep } from \"node:path\";\n\nconst PLACEHOLDER_PROJECT_ROOT = \"$\" + \"{PROJECT_ROOT}\";\nconst PLACEHOLDER_HOME = \"$\" + \"{HOME}\";\nconst PLACEHOLDER_TMP = \"$\" + \"{TMP}\";\n\nconst PLACEHOLDERS = {\n\tPROJECT_ROOT: PLACEHOLDER_PROJECT_ROOT,\n\tHOME: PLACEHOLDER_HOME,\n\tTMP: PLACEHOLDER_TMP,\n} as const;\n\ninterface PathContext {\n\tprojectRoot: string;\n\thome: string;\n\ttmp: string;\n}\n\n/**\n * Get the current machine's path context.\n */\nexport function getLocalPathContext(projectRoot: string): PathContext {\n\treturn {\n\t\tprojectRoot,\n\t\thome: homedir(),\n\t\ttmp: tmpdir(),\n\t};\n}\n\n/**\n * Virtualize paths in content: replace machine-local absolute paths\n * with portable placeholders.\n *\n * Replaces longest paths first to prevent partial matches.\n * Normalizes path separators to `/` in stored content.\n */\nexport function virtualizePaths(content: string, ctx: PathContext): string {\n\t// Normalize backslashes to forward slashes for consistent matching\n\tconst normalizedContent =\n\t\tsep === \"\\\\\" ? content.replace(/\\\\/g, \"/\") : content;\n\n\t// Build replacement pairs, sorted by path length (longest first)\n\tconst replacements: [string, string][] = (\n\t\t[\n\t\t\t[normalizeSeparators(ctx.projectRoot), PLACEHOLDERS.PROJECT_ROOT],\n\t\t\t[normalizeSeparators(ctx.home), PLACEHOLDERS.HOME],\n\t\t\t[normalizeSeparators(ctx.tmp), PLACEHOLDERS.TMP],\n\t\t] as [string, string][]\n\t).sort((a, b) => b[0].length - a[0].length);\n\n\tlet result = normalizedContent;\n\tfor (const [path, placeholder] of replacements) {\n\t\tif (path) {\n\t\t\tresult = replacePathWithBoundary(result, path, placeholder);\n\t\t}\n\t}\n\n\treturn result;\n}\n\n/**\n * Expand placeholders in content: replace portable placeholders\n * with machine-local absolute paths.\n *\n * Expands to OS-native path separators.\n */\nexport function expandPaths(content: string, ctx: PathContext): string {\n\tlet result = content;\n\n\tresult = replaceAll(\n\t\tresult,\n\t\tPLACEHOLDERS.PROJECT_ROOT,\n\t\ttoNativePath(ctx.projectRoot),\n\t);\n\tresult = replaceAll(result, PLACEHOLDERS.HOME, toNativePath(ctx.home));\n\tresult = replaceAll(result, PLACEHOLDERS.TMP, toNativePath(ctx.tmp));\n\n\treturn result;\n}\n\n/**\n * Normalize path separators to forward slashes.\n */\nfunction normalizeSeparators(path: string): string {\n\treturn path.replace(/\\\\/g, \"/\");\n}\n\n/**\n * Convert a path to use the OS-native separator.\n */\nfunction toNativePath(path: string): string {\n\tif (sep === \"\\\\\") {\n\t\treturn path.replace(/\\//g, \"\\\\\");\n\t}\n\treturn path;\n}\n\n/**\n * Replace all occurrences of a path, but only when followed by a path\n * boundary character (/, \\, \", whitespace, end of string, etc.).\n * Prevents matching /home/dr_who inside /home/dr_who_backup.\n */\nfunction replacePathWithBoundary(\n\tstr: string,\n\tpath: string,\n\treplacement: string,\n): string {\n\tconst escaped = escapeRegex(path);\n\tconst regex = new RegExp(`${escaped}(?=[/\\\\\\\\\"\\\\s,}\\\\]]|$)`, \"g\");\n\treturn str.replace(regex, replacement);\n}\n\n/**\n * Replace all occurrences of a substring.\n */\nfunction replaceAll(str: string, search: string, replacement: string): string {\n\treturn str.split(search).join(replacement);\n}\n\n/**\n * Escape special regex characters in a string.\n */\nfunction escapeRegex(str: string): string {\n\treturn str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n","import { execFile } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { promisify } from \"node:util\";\nimport { GitNotFoundError, ProjectNotFoundError } from \"../errors.js\";\n\nconst execFileAsync = promisify(execFile);\n\nconst GIT_TIMEOUT_MS = 10_000;\n\n/**\n * Detect the git remote URL from the current working directory.\n * Uses the \"origin\" remote by default.\n */\nexport async function getGitRemote(cwd: string): Promise<string> {\n\ttry {\n\t\tconst { stdout } = await execFileAsync(\n\t\t\t\"git\",\n\t\t\t[\"remote\", \"get-url\", \"origin\"],\n\t\t\t{ cwd, timeout: GIT_TIMEOUT_MS },\n\t\t);\n\t\tconst remote = stdout.trim();\n\t\tif (!remote) {\n\t\t\tthrow new ProjectNotFoundError(\n\t\t\t\t\"No git remote URL found. Run this command from a git repository with an 'origin' remote.\",\n\t\t\t);\n\t\t}\n\t\treturn remote;\n\t} catch (error) {\n\t\tif (error instanceof ProjectNotFoundError) throw error;\n\t\tif (isGitNotInstalled(error)) {\n\t\t\tthrow new GitNotFoundError(\n\t\t\t\t\"git is not installed or not found in PATH. Please install git first.\",\n\t\t\t);\n\t\t}\n\t\tthrow new ProjectNotFoundError(\n\t\t\t\"Not a git repository or no 'origin' remote configured. Run this command from a git repository.\",\n\t\t);\n\t}\n}\n\nfunction isGitNotInstalled(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tconst err = error as NodeJS.ErrnoException;\n\treturn err.code === \"ENOENT\";\n}\n\n/**\n * Normalize a git remote URL to a canonical form.\n *\n * Handles:\n * - git@github.com:user/repo.git → github.com/user/repo\n * - https://github.com/user/repo.git → github.com/user/repo\n * - https://github.com/user/repo → github.com/user/repo\n * - ssh://git@github.com/user/repo.git → github.com/user/repo\n * - git://github.com/user/repo.git → github.com/user/repo\n */\nexport function normalizeGitRemote(remote: string): string {\n\tconst normalized = remote.trim();\n\n\t// SSH shorthand: git@github.com:user/repo.git\n\tconst sshMatch = normalized.match(/^[\\w.-]+@([\\w.-]+):(.*?)(?:\\.git)?$/);\n\tif (sshMatch) {\n\t\treturn `${sshMatch[1]}/${sshMatch[2]}`;\n\t}\n\n\t// ssh:// or git:// protocol: ssh://git@github.com/user/repo.git\n\tconst protoMatch = normalized.match(\n\t\t/^(?:ssh|git):\\/\\/(?:[\\w.-]+@)?([\\w.-]+)\\/(.*?)(?:\\.git)?$/,\n\t);\n\tif (protoMatch) {\n\t\treturn `${protoMatch[1]}/${protoMatch[2]}`;\n\t}\n\n\t// HTTPS: https://github.com/user/repo.git\n\tconst httpsMatch = normalized.match(\n\t\t/^https?:\\/\\/([\\w.-]+)\\/(.*?)(?:\\.git)?$/,\n\t);\n\tif (httpsMatch) {\n\t\treturn `${httpsMatch[1]}/${httpsMatch[2]}`;\n\t}\n\n\t// Fallback: return as-is (stripped)\n\treturn normalized;\n}\n\n/**\n * Hash a normalized git remote URL to produce a stable project ID.\n */\nexport function hashProjectId(normalizedRemote: string): string {\n\treturn createHash(\"sha256\")\n\t\t.update(normalizedRemote)\n\t\t.digest(\"hex\")\n\t\t.slice(0, 16);\n}\n\n/**\n * Detect the project from the current working directory.\n * Returns the project hash and normalized git remote.\n */\nexport async function detectProject(\n\tcwd: string,\n): Promise<{ projectId: string; gitRemote: string; normalizedRemote: string }> {\n\tconst gitRemote = await getGitRemote(cwd);\n\tconst normalizedRemote = normalizeGitRemote(gitRemote);\n\tconst projectId = hashProjectId(normalizedRemote);\n\treturn { projectId, gitRemote, normalizedRemote };\n}\n","import { mkdir, readdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport type {\n\tProjectData,\n\tSessionData,\n} from \"../adapters/claude-code/reader.js\";\n\ninterface ProjectMeta {\n\tproject_id: string;\n\tgit_remote: string;\n\tpushed_at: string;\n}\n\n/**\n * Write project data as a checkpoint to the baton repo.\n */\nexport async function writeCheckpoint(\n\tprojectDir: string,\n\tproject: { projectId: string; gitRemote: string },\n\tdata: ProjectData,\n): Promise<void> {\n\t// Clean existing sessions directory to remove stale sessions\n\tconst sessionsDir = join(projectDir, \"sessions\");\n\tawait rm(sessionsDir, { recursive: true, force: true });\n\tawait mkdir(sessionsDir, { recursive: true });\n\n\t// Write meta\n\tconst meta: ProjectMeta = {\n\t\tproject_id: project.projectId,\n\t\tgit_remote: project.gitRemote,\n\t\tpushed_at: new Date().toISOString(),\n\t};\n\tawait writeFile(\n\t\tjoin(projectDir, \"meta.json\"),\n\t\tJSON.stringify(meta, null, 2),\n\t\t\"utf-8\",\n\t);\n\n\t// Write sessions\n\tfor (const session of data.sessions) {\n\t\tawait writeFile(\n\t\t\tjoin(sessionsDir, `${session.sessionId}.jsonl`),\n\t\t\tsession.jsonl,\n\t\t\t\"utf-8\",\n\t\t);\n\n\t\t// Write tool results\n\t\tif (session.toolResults.size > 0) {\n\t\t\tconst toolResultsDir = join(\n\t\t\t\tsessionsDir,\n\t\t\t\tsession.sessionId,\n\t\t\t\t\"tool-results\",\n\t\t\t);\n\t\t\tawait mkdir(toolResultsDir, { recursive: true });\n\t\t\tfor (const [filename, content] of session.toolResults) {\n\t\t\t\tawait writeFile(join(toolResultsDir, filename), content, \"utf-8\");\n\t\t\t}\n\t\t}\n\t}\n\n\t// Write memory\n\tif (data.memory.size > 0) {\n\t\tconst memoryDir = join(projectDir, \"memory\");\n\t\tawait mkdir(memoryDir, { recursive: true });\n\t\tfor (const [filename, content] of data.memory) {\n\t\t\tawait writeFile(join(memoryDir, filename), content, \"utf-8\");\n\t\t}\n\t}\n}\n\n/**\n * Read a checkpoint from the baton repo. Returns null if not found.\n */\nexport async function readCheckpoint(\n\tprojectDir: string,\n): Promise<ProjectData | null> {\n\tconst sessionsDir = join(projectDir, \"sessions\");\n\n\tlet sessionFiles: string[];\n\ttry {\n\t\tconst entries = await readdir(sessionsDir);\n\t\tsessionFiles = entries.filter((e) => e.endsWith(\".jsonl\"));\n\t} catch {\n\t\treturn null;\n\t}\n\n\tif (sessionFiles.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst sessions: SessionData[] = [];\n\tfor (const file of sessionFiles) {\n\t\tconst sessionId = file.replace(\".jsonl\", \"\");\n\t\tconst jsonl = await readFile(join(sessionsDir, file), \"utf-8\");\n\t\tconst toolResults = await readToolResults(sessionsDir, sessionId);\n\t\tsessions.push({ sessionId, jsonl, toolResults });\n\t}\n\n\tconst memory = await readMemory(projectDir);\n\n\treturn {\n\t\tsessions,\n\t\tmemory,\n\t\tprojectDirName: \"\",\n\t};\n}\n\nasync function readToolResults(\n\tsessionsDir: string,\n\tsessionId: string,\n): Promise<Map<string, string>> {\n\tconst results = new Map<string, string>();\n\tconst toolResultsDir = join(sessionsDir, sessionId, \"tool-results\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(toolResultsDir);\n\t} catch {\n\t\treturn results;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst content = await readFile(join(toolResultsDir, entry), \"utf-8\");\n\t\tresults.set(entry, content);\n\t}\n\n\treturn results;\n}\n\nasync function readMemory(projectDir: string): Promise<Map<string, string>> {\n\tconst memory = new Map<string, string>();\n\tconst memoryDir = join(projectDir, \"memory\");\n\n\tlet entries: string[];\n\ttry {\n\t\tentries = await readdir(memoryDir);\n\t} catch {\n\t\treturn memory;\n\t}\n\n\tfor (const entry of entries) {\n\t\tconst content = await readFile(join(memoryDir, entry), \"utf-8\");\n\t\tmemory.set(entry, content);\n\t}\n\n\treturn memory;\n}\n","import { createInterface } from \"node:readline/promises\";\nimport { getRepoDir, loadConfig, saveConfig } from \"../core/config.js\";\nimport { cloneRepo, createGhRepo, gh, repoExists } from \"../core/git.js\";\n\nconst DEFAULT_REPO_NAME = \"baton-sessions\";\n\n/**\n * Ensure the baton repo is configured and cloned locally.\n * On first run:\n * - push: auto-creates a private \"baton-sessions\" repo\n * - pull: tries the current user's \"baton-sessions\" repo, prompts if not found\n */\nexport async function ensureBatonRepo(mode: \"push\" | \"pull\"): Promise<void> {\n\tconst repoDir = getRepoDir();\n\tlet config = await loadConfig();\n\n\tif (!config) {\n\t\tif (mode === \"push\") {\n\t\t\tconfig = await promptCreateRepo();\n\t\t} else {\n\t\t\tconfig = await autoDetectOrPrompt();\n\t\t}\n\t\tawait saveConfig(config);\n\t}\n\n\tif (!(await repoExists(repoDir))) {\n\t\tconsole.log(\"Cloning baton repo...\");\n\t\tawait cloneRepo(config.repo, repoDir);\n\t}\n}\n\nasync function getGitHubUsername(): Promise<string> {\n\treturn await gh([\"api\", \"user\", \"--jq\", \".login\"]);\n}\n\nasync function promptCreateRepo(): Promise<{ repo: string }> {\n\tconst rl = createInterface({\n\t\tinput: process.stdin,\n\t\toutput: process.stdout,\n\t});\n\ttry {\n\t\tconst rawName = await rl.question(\n\t\t\t`Enter repo name for baton sync (${DEFAULT_REPO_NAME}): `,\n\t\t);\n\t\tconst repoName = rawName.trim() || DEFAULT_REPO_NAME;\n\t\tconsole.log(`Creating private repo '${repoName}'...`);\n\t\tconst repoUrl = await createGhRepo(repoName);\n\t\tconsole.log(`Repo created: ${repoUrl}`);\n\t\treturn { repo: repoUrl };\n\t} finally {\n\t\trl.close();\n\t}\n}\n\nasync function autoDetectOrPrompt(): Promise<{ repo: string }> {\n\t// Try the current user's default repo name first\n\tconst username = await getGitHubUsername();\n\tconst defaultUrl = `https://github.com/${username}/${DEFAULT_REPO_NAME}`;\n\n\ttry {\n\t\t// Check if the repo exists\n\t\tawait gh([\n\t\t\t\"repo\",\n\t\t\t\"view\",\n\t\t\t`${username}/${DEFAULT_REPO_NAME}`,\n\t\t\t\"--json\",\n\t\t\t\"name\",\n\t\t]);\n\t\tconsole.log(`Found baton repo: ${defaultUrl}`);\n\t\treturn { repo: defaultUrl };\n\t} catch (error) {\n\t\t// Re-throw if not a \"repo not found\" error (e.g., auth, network, gh not installed)\n\t\tif (!isRepoNotFoundError(error)) {\n\t\t\tthrow error;\n\t\t}\n\n\t\t// Repo doesn't exist, prompt for URL\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\ttry {\n\t\t\tconst rawUrl = await rl.question(\n\t\t\t\t`No '${DEFAULT_REPO_NAME}' repo found for ${username}. Enter your baton repo URL: `,\n\t\t\t);\n\t\t\tconst repoUrl = rawUrl.trim();\n\t\t\tif (!repoUrl) {\n\t\t\t\tthrow new Error(\"Repo URL cannot be empty.\");\n\t\t\t}\n\t\t\treturn { repo: repoUrl };\n\t\t} finally {\n\t\t\trl.close();\n\t\t}\n\t}\n}\n\nfunction isRepoNotFoundError(error: unknown): boolean {\n\tif (!(error instanceof Error)) return false;\n\tconst stderr = (error as { stderr?: string }).stderr ?? \"\";\n\tconst message = error.message + stderr;\n\treturn (\n\t\tmessage.includes(\"Could not resolve\") ||\n\t\tmessage.includes(\"HTTP 404\") ||\n\t\tmessage.includes(\"Not Found\")\n\t);\n}\n","import { join } from \"node:path\";\nimport { collectProjectData } from \"../adapters/claude-code/reader.js\";\nimport { getRepoDir } from \"../core/config.js\";\nimport { commitAndPush, isRemoteAhead, repoExists } from \"../core/git.js\";\nimport { getLocalPathContext, virtualizePaths } from \"../core/paths.js\";\nimport { detectProject } from \"../core/project.js\";\nimport { ConflictError } from \"../errors.js\";\nimport { writeCheckpoint } from \"./checkpoint.js\";\nimport { ensureBatonRepo } from \"./setup.js\";\n\nexport async function push(options: { force?: boolean }): Promise<void> {\n\tconst cwd = process.cwd();\n\n\t// 1. Detect project\n\tconst project = await detectProject(cwd);\n\tconsole.log(`Project: ${project.normalizedRemote} (${project.projectId})`);\n\n\t// 2. Collect session data\n\tconst data = await collectProjectData(cwd);\n\tconsole.log(\n\t\t`Found ${data.sessions.length} session(s), ${data.memory.size} memory file(s)`,\n\t);\n\n\t// 3. Virtualize paths\n\tconst pathCtx = getLocalPathContext(cwd);\n\tfor (const session of data.sessions) {\n\t\tsession.jsonl = virtualizePaths(session.jsonl, pathCtx);\n\t}\n\n\t// 4. Ensure baton repo exists\n\tconst repoDir = getRepoDir();\n\tawait ensureBatonRepo(\"push\");\n\n\t// 5. Conflict check\n\tif (!options.force && (await repoExists(repoDir))) {\n\t\ttry {\n\t\t\tconst ahead = await isRemoteAhead(repoDir);\n\t\t\tif (ahead) {\n\t\t\t\tthrow new ConflictError(\n\t\t\t\t\t\"Remote has changes you haven't pulled. Run 'baton pull' first, or use 'baton push --force' to overwrite.\",\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (error instanceof ConflictError) throw error;\n\t\t\t// Ignore fetch errors (e.g., empty repo with no commits on remote yet)\n\t\t}\n\t}\n\n\t// 6. Write checkpoint to baton repo\n\tconst projectDir = join(repoDir, \"projects\", project.projectId);\n\tawait writeCheckpoint(projectDir, project, data);\n\n\t// 7. Commit and push\n\tawait commitAndPush(\n\t\trepoDir,\n\t\t`push: ${project.normalizedRemote}`,\n\t\toptions.force ?? false,\n\t);\n\n\tconsole.log(\"Pushed successfully.\");\n}\n","import { readdir, readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n\tencodeProjectDir,\n\tgetClaudeProjectsDir,\n} from \"../adapters/claude-code/paths.js\";\nimport { getRepoDir, loadConfig } from \"../core/config.js\";\nimport { repoExists } from \"../core/git.js\";\nimport { detectProject } from \"../core/project.js\";\n\nexport async function status(): Promise<void> {\n\tconst cwd = process.cwd();\n\n\t// Project info\n\tconst project = await detectProject(cwd);\n\tconsole.log(`Project: ${project.normalizedRemote}`);\n\tconsole.log(`Project ID: ${project.projectId}`);\n\n\t// Local sessions\n\tconst projectDirName = encodeProjectDir(cwd);\n\tconst localProjectDir = join(getClaudeProjectsDir(), projectDirName);\n\ttry {\n\t\tconst entries = await readdir(localProjectDir);\n\t\tconst sessionCount = entries.filter((e) => e.endsWith(\".jsonl\")).length;\n\t\tconsole.log(`Local sessions: ${sessionCount}`);\n\t} catch {\n\t\tconsole.log(\"Local sessions: 0\");\n\t}\n\n\t// Baton config\n\tconst config = await loadConfig();\n\tif (!config) {\n\t\tconsole.log(\"Baton repo: not configured (run 'baton push' to set up)\");\n\t\treturn;\n\t}\n\tconsole.log(`Baton repo: ${config.repo}`);\n\n\t// Remote checkpoint\n\tconst repoDir = getRepoDir();\n\tif (!(await repoExists(repoDir))) {\n\t\tconsole.log(\"Remote checkpoint: not cloned yet\");\n\t\treturn;\n\t}\n\n\tconst metaPath = join(repoDir, \"projects\", project.projectId, \"meta.json\");\n\ttry {\n\t\tconst raw = await readFile(metaPath, \"utf-8\");\n\t\tconst meta = JSON.parse(raw);\n\t\tconsole.log(`Last pushed: ${meta.pushed_at ?? \"unknown\"}`);\n\t} catch {\n\t\tconsole.log(\"Remote checkpoint: none for this project\");\n\t}\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;;;ACAxB,SAAS,QAAAA,aAAY;AACrB,SAAS,mBAAAC,wBAA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OAAO,QAAQ,MAAM,CAAC;AACpC,CAAC;AAEF,QACE,QAAQ,QAAQ,EAChB,YAAY,qCAAqC,EACjD,OAAO,YAAY;AACnB,QAAM,OAAO;AACd,CAAC;AAEF,IAAI;AACH,QAAM,QAAQ,WAAW,QAAQ,IAAI;AACtC,SAAS,OAAO;AACf,MAAI,iBAAiB,YAAY;AAChC,YAAQ,MAAM,UAAU,MAAM,OAAO,EAAE;AAAA,EACxC,OAAO;AACN,YAAQ;AAAA,MACP,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC5E;AAAA,EACD;AACA,UAAQ,KAAK,CAAC;AACf;","names":["join","createInterface","join","join","readFile","join","join","readFile","mkdir","readFile","writeFile","homedir","dirname","join","status","homedir","execFile","promisify","execFileAsync","promisify","execFile","GIT_TIMEOUT_MS","mkdir","readdir","readFile","writeFile","join","join","createInterface","join","join","readdir","readFile","join","join","readdir","readFile"]}
|