agentsofmine 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +297 -2
- package/dist/adapters/adapter.d.ts +14 -0
- package/dist/adapters/adapter.js +2 -0
- package/dist/adapters/claude-code/accumulator.d.ts +34 -0
- package/dist/adapters/claude-code/accumulator.js +129 -0
- package/dist/adapters/claude-code/content-blocks.d.ts +40 -0
- package/dist/adapters/claude-code/content-blocks.js +93 -0
- package/dist/adapters/claude-code/index.d.ts +20 -0
- package/dist/adapters/claude-code/index.js +92 -0
- package/dist/adapters/claude-code/jsonl-reader.d.ts +14 -0
- package/dist/adapters/claude-code/jsonl-reader.js +31 -0
- package/dist/adapters/claude-code/mapper.d.ts +6 -0
- package/dist/adapters/claude-code/mapper.js +23 -0
- package/dist/adapters/codex/index.d.ts +8 -0
- package/dist/adapters/codex/index.js +42 -0
- package/dist/adapters/codex/log-reader.d.ts +14 -0
- package/dist/adapters/codex/log-reader.js +182 -0
- package/dist/adapters/codex/shell-parser.d.ts +6 -0
- package/dist/adapters/codex/shell-parser.js +72 -0
- package/dist/adapters/opencode/file-changes.d.ts +8 -0
- package/dist/adapters/opencode/file-changes.js +38 -0
- package/dist/adapters/opencode/index.d.ts +13 -0
- package/dist/adapters/opencode/index.js +58 -0
- package/dist/adapters/opencode/mapper.d.ts +4 -0
- package/dist/adapters/opencode/mapper.js +56 -0
- package/dist/adapters/opencode/sqlite-reader.d.ts +19 -0
- package/dist/adapters/opencode/sqlite-reader.js +109 -0
- package/dist/adapters/pi/index.d.ts +8 -0
- package/dist/adapters/pi/index.js +76 -0
- package/dist/adapters/pi/jsonl-reader.d.ts +2 -0
- package/dist/adapters/pi/jsonl-reader.js +2 -0
- package/dist/adapters/pi/mapper.d.ts +22 -0
- package/dist/adapters/pi/mapper.js +230 -0
- package/dist/api/pairing-client.d.ts +41 -0
- package/dist/api/pairing-client.js +77 -0
- package/dist/bin/aom.d.ts +13 -0
- package/dist/bin/aom.js +73 -0
- package/dist/cli/pair.d.ts +28 -0
- package/dist/cli/pair.js +114 -0
- package/dist/cli/start.d.ts +22 -0
- package/dist/cli/start.js +78 -0
- package/dist/cli/status.d.ts +19 -0
- package/dist/cli/status.js +108 -0
- package/dist/cli/sync.d.ts +16 -0
- package/dist/cli/sync.js +50 -0
- package/dist/cli/unpair.d.ts +18 -0
- package/dist/cli/unpair.js +49 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +33 -0
- package/dist/core/canonical.d.ts +957 -0
- package/dist/core/canonical.js +80 -0
- package/dist/core/cursor-store.d.ts +18 -0
- package/dist/core/cursor-store.js +50 -0
- package/dist/core/debug-log.d.ts +12 -0
- package/dist/core/debug-log.js +17 -0
- package/dist/core/git-identity.d.ts +23 -0
- package/dist/core/git-identity.js +127 -0
- package/dist/core/http-client.d.ts +7 -0
- package/dist/core/http-client.js +63 -0
- package/dist/core/last-sync-store.d.ts +9 -0
- package/dist/core/last-sync-store.js +31 -0
- package/dist/core/message-truncation.d.ts +10 -0
- package/dist/core/message-truncation.js +13 -0
- package/dist/core/perform-sync.d.ts +23 -0
- package/dist/core/perform-sync.js +57 -0
- package/dist/core/project-identity.d.ts +40 -0
- package/dist/core/project-identity.js +67 -0
- package/dist/core/providers.d.ts +26 -0
- package/dist/core/providers.js +25 -0
- package/dist/core/providers.json +4 -0
- package/dist/core/redact.d.ts +44 -0
- package/dist/core/redact.js +177 -0
- package/dist/core/safe-json.d.ts +7 -0
- package/dist/core/safe-json.js +14 -0
- package/dist/core/sync-engine.d.ts +17 -0
- package/dist/core/sync-engine.js +64 -0
- package/dist/daemon/state.d.ts +22 -0
- package/dist/daemon/state.js +32 -0
- package/dist/daemon/sync-runner.d.ts +52 -0
- package/dist/daemon/sync-runner.js +104 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +68 -0
- package/dist/infrastructure/config-repository.d.ts +34 -0
- package/dist/infrastructure/config-repository.js +102 -0
- package/dist/keychain/index.d.ts +31 -0
- package/dist/keychain/index.js +62 -0
- package/dist/mcp/json-rpc.d.ts +39 -0
- package/dist/mcp/json-rpc.js +46 -0
- package/dist/mcp/server.d.ts +33 -0
- package/dist/mcp/server.js +110 -0
- package/dist/mcp-tools/status.d.ts +17 -0
- package/dist/mcp-tools/status.js +24 -0
- package/dist/mcp-tools/sync-now.d.ts +9 -0
- package/dist/mcp-tools/sync-now.js +8 -0
- package/dist/services/pairing-service.d.ts +58 -0
- package/dist/services/pairing-service.js +102 -0
- package/dist/watchers/directory-watcher.d.ts +26 -0
- package/dist/watchers/directory-watcher.js +47 -0
- package/dist/watchers/opencode.d.ts +27 -0
- package/dist/watchers/opencode.js +58 -0
- package/package.json +64 -4
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { readJsonlFrom } from "./jsonl-reader.js";
|
|
5
|
+
import { createAccumulator, processEvent, finalizeSession } from "./mapper.js";
|
|
6
|
+
import { truncateMessages } from "../../core/message-truncation.js";
|
|
7
|
+
import { debugLog } from "../../core/debug-log.js";
|
|
8
|
+
const defaultFsReader = {
|
|
9
|
+
existsSync,
|
|
10
|
+
readdirSync: (path) => readdirSync(path, { withFileTypes: true }),
|
|
11
|
+
};
|
|
12
|
+
function parseCursor(raw) {
|
|
13
|
+
if (!raw)
|
|
14
|
+
return {};
|
|
15
|
+
try {
|
|
16
|
+
const parsed = JSON.parse(raw);
|
|
17
|
+
if (typeof parsed === "object" && parsed !== null)
|
|
18
|
+
return parsed;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// ignore
|
|
22
|
+
}
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
function findJsonlFiles(projectsDir, fs) {
|
|
26
|
+
const files = [];
|
|
27
|
+
if (!fs.existsSync(projectsDir))
|
|
28
|
+
return files;
|
|
29
|
+
let projectDirs;
|
|
30
|
+
try {
|
|
31
|
+
projectDirs = fs
|
|
32
|
+
.readdirSync(projectsDir)
|
|
33
|
+
.filter((d) => d.isDirectory())
|
|
34
|
+
.map((d) => join(projectsDir, d.name));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return files;
|
|
38
|
+
}
|
|
39
|
+
for (const dir of projectDirs) {
|
|
40
|
+
try {
|
|
41
|
+
const entries = fs.readdirSync(dir);
|
|
42
|
+
for (const entry of entries) {
|
|
43
|
+
if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
44
|
+
files.push(join(dir, entry.name));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Unreadable directory (permissions, race) — skip; best-effort discovery.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return files;
|
|
53
|
+
}
|
|
54
|
+
export class ClaudeCodeAdapter {
|
|
55
|
+
name = "claude-code";
|
|
56
|
+
projectsDir;
|
|
57
|
+
fs;
|
|
58
|
+
constructor(projectsGlob = join(homedir(), ".claude", "projects", "*", "*.jsonl"), fs = defaultFsReader) {
|
|
59
|
+
this.projectsDir = projectsGlob
|
|
60
|
+
.replace(/[/\\]\*[/\\]\*\.jsonl$/, "")
|
|
61
|
+
.replace(/[/\\]\*\.jsonl$/, "");
|
|
62
|
+
this.fs = fs;
|
|
63
|
+
}
|
|
64
|
+
async *listNewSessions(cursor) {
|
|
65
|
+
const offsets = parseCursor(cursor.value);
|
|
66
|
+
const files = findJsonlFiles(this.projectsDir, this.fs);
|
|
67
|
+
for (const filePath of files) {
|
|
68
|
+
if (!this.fs.existsSync(filePath))
|
|
69
|
+
continue;
|
|
70
|
+
const fromOffset = offsets[filePath] ?? 0;
|
|
71
|
+
const acc = createAccumulator(filePath);
|
|
72
|
+
let lastOffset = fromOffset;
|
|
73
|
+
try {
|
|
74
|
+
for await (const { line, byteOffset } of readJsonlFrom(filePath, fromOffset)) {
|
|
75
|
+
processEvent(acc, line);
|
|
76
|
+
lastOffset = byteOffset;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
debugLog(`claude-code: failed reading ${filePath}`, err);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (acc.messageCount > 0 || acc.linesAdded > 0) {
|
|
84
|
+
offsets[filePath] = lastOffset;
|
|
85
|
+
const session = finalizeSession(acc);
|
|
86
|
+
const messages = truncateMessages(acc.messages);
|
|
87
|
+
yield { session: { ...session, messages }, cursor: JSON.stringify(offsets) };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface JsonlLine {
|
|
2
|
+
filePath: string;
|
|
3
|
+
byteOffset: number;
|
|
4
|
+
parsed: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface JsonlCursor {
|
|
7
|
+
filePath: string;
|
|
8
|
+
byteOffset: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function readJsonlFrom(filePath: string, fromOffset: number): AsyncIterable<{
|
|
11
|
+
line: unknown;
|
|
12
|
+
byteOffset: number;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=jsonl-reader.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createReadStream, statSync } from "node:fs";
|
|
2
|
+
import { createInterface } from "node:readline";
|
|
3
|
+
export async function* readJsonlFrom(filePath, fromOffset) {
|
|
4
|
+
const stat = statSync(filePath);
|
|
5
|
+
if (stat.size < fromOffset) {
|
|
6
|
+
// File shrank — restart from 0
|
|
7
|
+
fromOffset = 0;
|
|
8
|
+
}
|
|
9
|
+
const stream = createReadStream(filePath, {
|
|
10
|
+
start: fromOffset,
|
|
11
|
+
encoding: "utf8",
|
|
12
|
+
});
|
|
13
|
+
const rl = createInterface({ input: stream, crlfDelay: Infinity });
|
|
14
|
+
let offset = fromOffset;
|
|
15
|
+
for await (const rawLine of rl) {
|
|
16
|
+
const lineBytes = Buffer.byteLength(rawLine, "utf8") + 1; // +1 for newline
|
|
17
|
+
if (rawLine.trim() === "") {
|
|
18
|
+
offset += lineBytes;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(rawLine);
|
|
23
|
+
yield { line: parsed, byteOffset: offset };
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Skip unparseable lines — never crash on bad JSONL
|
|
27
|
+
}
|
|
28
|
+
offset += lineBytes;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=jsonl-reader.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CanonicalSession } from "../../core/canonical.js";
|
|
2
|
+
import type { SessionAccumulator } from "./accumulator.js";
|
|
3
|
+
export type { SessionAccumulator } from "./accumulator.js";
|
|
4
|
+
export { createAccumulator, processEvent } from "./accumulator.js";
|
|
5
|
+
export declare function finalizeSession(acc: SessionAccumulator): CanonicalSession;
|
|
6
|
+
//# sourceMappingURL=mapper.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { projectFields } from "../../core/project-identity.js";
|
|
2
|
+
export { createAccumulator, processEvent } from "./accumulator.js";
|
|
3
|
+
export function finalizeSession(acc) {
|
|
4
|
+
const filesChanged = acc.filesChanged.size > 0 ? Array.from(acc.filesChanged) : null;
|
|
5
|
+
return {
|
|
6
|
+
sessionId: acc.sessionId,
|
|
7
|
+
provider: "claude-code",
|
|
8
|
+
...projectFields(acc.projectPath),
|
|
9
|
+
agentName: "Claude Code",
|
|
10
|
+
title: acc.title,
|
|
11
|
+
modelLine: acc.modelLine,
|
|
12
|
+
startedAt: acc.startedAt ?? new Date(0).toISOString(),
|
|
13
|
+
endedAt: acc.endedAt,
|
|
14
|
+
messageCount: acc.messageCount > 0 ? acc.messageCount : null,
|
|
15
|
+
fileCount: acc.filesChanged.size > 0 ? acc.filesChanged.size : null,
|
|
16
|
+
linesAdded: acc.linesAdded > 0 ? acc.linesAdded : null,
|
|
17
|
+
linesRemoved: acc.linesRemoved > 0 ? acc.linesRemoved : null,
|
|
18
|
+
filesChanged,
|
|
19
|
+
filesChangedApproximate: false,
|
|
20
|
+
extensions: {},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=mapper.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Adapter, Cursor, SyncItem } from "../adapter.js";
|
|
2
|
+
export declare class CodexAdapter implements Adapter {
|
|
3
|
+
private readonly sessionsDir;
|
|
4
|
+
readonly name = "codex";
|
|
5
|
+
constructor(sessionsDir?: string);
|
|
6
|
+
listNewSessions(cursor: Cursor): AsyncIterable<SyncItem>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { projectFields } from "../../core/project-identity.js";
|
|
2
|
+
import { readCodexSessions } from "./log-reader.js";
|
|
3
|
+
import { extractFiles } from "./shell-parser.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
export class CodexAdapter {
|
|
7
|
+
sessionsDir;
|
|
8
|
+
name = "codex";
|
|
9
|
+
constructor(sessionsDir = join(homedir(), ".codex", "sessions")) {
|
|
10
|
+
this.sessionsDir = sessionsDir;
|
|
11
|
+
}
|
|
12
|
+
async *listNewSessions(cursor) {
|
|
13
|
+
const since = cursor.value;
|
|
14
|
+
const sessions = readCodexSessions(this.sessionsDir).sort((a, b) => a.startedAt < b.startedAt ? -1 : a.startedAt > b.startedAt ? 1 : 0);
|
|
15
|
+
for (const s of sessions) {
|
|
16
|
+
if (since !== null && s.startedAt <= since)
|
|
17
|
+
continue;
|
|
18
|
+
const { paths } = extractFiles(s.commands);
|
|
19
|
+
const filesChanged = paths.length > 0 ? paths : null;
|
|
20
|
+
const session = {
|
|
21
|
+
sessionId: s.sessionId,
|
|
22
|
+
provider: "codex",
|
|
23
|
+
...projectFields(s.projectPath),
|
|
24
|
+
agentName: "Codex",
|
|
25
|
+
title: s.title,
|
|
26
|
+
modelLine: null,
|
|
27
|
+
startedAt: s.startedAt,
|
|
28
|
+
endedAt: s.endedAt,
|
|
29
|
+
messageCount: s.messageCount > 0 ? s.messageCount : null,
|
|
30
|
+
fileCount: filesChanged ? filesChanged.length : null,
|
|
31
|
+
linesAdded: null,
|
|
32
|
+
linesRemoved: null,
|
|
33
|
+
filesChanged,
|
|
34
|
+
filesChangedApproximate: true,
|
|
35
|
+
extensions: {},
|
|
36
|
+
messages: s.messages,
|
|
37
|
+
};
|
|
38
|
+
yield { session, cursor: s.startedAt };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CanonicalMessage } from "../../core/canonical.js";
|
|
2
|
+
export interface CodexSession {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
projectPath: string;
|
|
5
|
+
startedAt: string;
|
|
6
|
+
endedAt: string | null;
|
|
7
|
+
title: string | null;
|
|
8
|
+
commands: string[];
|
|
9
|
+
messageCount: number;
|
|
10
|
+
messages: CanonicalMessage[];
|
|
11
|
+
rawData: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare function readCodexSessions(sessionsDir: string): CodexSession[];
|
|
14
|
+
//# sourceMappingURL=log-reader.d.ts.map
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { safeJsonParse } from "../../core/safe-json.js";
|
|
4
|
+
function findRolloutFiles(root) {
|
|
5
|
+
const out = [];
|
|
6
|
+
const walk = (dir) => {
|
|
7
|
+
let entries;
|
|
8
|
+
try {
|
|
9
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
for (const entry of entries) {
|
|
15
|
+
const full = join(dir, entry.name);
|
|
16
|
+
if (entry.isDirectory()) {
|
|
17
|
+
walk(full);
|
|
18
|
+
}
|
|
19
|
+
else if (entry.name.startsWith("rollout-") && entry.name.endsWith(".jsonl")) {
|
|
20
|
+
out.push(full);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
walk(root);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function commandFromExec(payload) {
|
|
28
|
+
const args = payload["arguments"];
|
|
29
|
+
if (typeof args !== "string")
|
|
30
|
+
return null;
|
|
31
|
+
const parsed = safeJsonParse(args);
|
|
32
|
+
if (parsed && typeof parsed === "object") {
|
|
33
|
+
const cmd = parsed["cmd"];
|
|
34
|
+
if (typeof cmd === "string")
|
|
35
|
+
return cmd;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
function messageText(payload) {
|
|
40
|
+
const content = payload["content"];
|
|
41
|
+
if (typeof content === "string")
|
|
42
|
+
return content;
|
|
43
|
+
if (!Array.isArray(content))
|
|
44
|
+
return "";
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const part of content) {
|
|
47
|
+
if (part && typeof part === "object") {
|
|
48
|
+
const text = part["text"];
|
|
49
|
+
if (typeof text === "string")
|
|
50
|
+
out.push(text);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return out.join("\n");
|
|
54
|
+
}
|
|
55
|
+
function messageFromPayload(payload, sessionId, index, createdAt) {
|
|
56
|
+
const role = payload["role"];
|
|
57
|
+
if (role !== "user" && role !== "assistant")
|
|
58
|
+
return null;
|
|
59
|
+
const text = messageText(payload);
|
|
60
|
+
if (!text.trim())
|
|
61
|
+
return null;
|
|
62
|
+
const part = { type: "text", text };
|
|
63
|
+
return {
|
|
64
|
+
messageId: `${sessionId}:${index}`,
|
|
65
|
+
sessionId,
|
|
66
|
+
role,
|
|
67
|
+
senderName: role === "user" ? "You" : "Codex",
|
|
68
|
+
createdAt,
|
|
69
|
+
parts: [part],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function isInjectedContext(text) {
|
|
73
|
+
const head = text.trimStart();
|
|
74
|
+
return head.startsWith("#") || head.startsWith("<");
|
|
75
|
+
}
|
|
76
|
+
function deriveTitle(messages) {
|
|
77
|
+
for (const message of messages) {
|
|
78
|
+
if (message.role !== "user")
|
|
79
|
+
continue;
|
|
80
|
+
const text = message.parts
|
|
81
|
+
.map((p) => p.text ?? "")
|
|
82
|
+
.join(" ")
|
|
83
|
+
.trim();
|
|
84
|
+
if (!text || isInjectedContext(text))
|
|
85
|
+
continue;
|
|
86
|
+
const title = text.split(/\s+/).slice(0, 10).join(" ");
|
|
87
|
+
return title.length > 80 ? title.slice(0, 80) : title;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
function parseRollout(filePath) {
|
|
92
|
+
let content;
|
|
93
|
+
try {
|
|
94
|
+
content = readFileSync(filePath, "utf8");
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
let sessionId = "";
|
|
100
|
+
let projectPath = "/";
|
|
101
|
+
let startedAt = "";
|
|
102
|
+
let lastTimestamp = null;
|
|
103
|
+
const commands = [];
|
|
104
|
+
const rawMessages = [];
|
|
105
|
+
for (const rawLine of content.split("\n")) {
|
|
106
|
+
const line = rawLine.trim();
|
|
107
|
+
if (!line)
|
|
108
|
+
continue;
|
|
109
|
+
const parsed = safeJsonParse(line);
|
|
110
|
+
if (!parsed || typeof parsed !== "object")
|
|
111
|
+
continue;
|
|
112
|
+
if (typeof parsed.timestamp === "string") {
|
|
113
|
+
lastTimestamp = parsed.timestamp;
|
|
114
|
+
}
|
|
115
|
+
const payload = parsed.payload ?? {};
|
|
116
|
+
switch (parsed.type) {
|
|
117
|
+
case "session_meta": {
|
|
118
|
+
if (typeof payload["id"] === "string")
|
|
119
|
+
sessionId = payload["id"];
|
|
120
|
+
if (typeof payload["timestamp"] === "string")
|
|
121
|
+
startedAt = payload["timestamp"];
|
|
122
|
+
else if (typeof parsed.timestamp === "string")
|
|
123
|
+
startedAt = parsed.timestamp;
|
|
124
|
+
if (typeof payload["cwd"] === "string")
|
|
125
|
+
projectPath = payload["cwd"];
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "turn_context": {
|
|
129
|
+
if (projectPath === "/" && typeof payload["cwd"] === "string") {
|
|
130
|
+
projectPath = payload["cwd"];
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case "response_item": {
|
|
135
|
+
if (payload["type"] === "function_call" && payload["name"] === "exec_command") {
|
|
136
|
+
const cmd = commandFromExec(payload);
|
|
137
|
+
if (cmd)
|
|
138
|
+
commands.push(cmd);
|
|
139
|
+
}
|
|
140
|
+
else if (payload["type"] === "message") {
|
|
141
|
+
rawMessages.push({ payload, timestamp: parsed.timestamp ?? lastTimestamp ?? "" });
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
default:
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!sessionId)
|
|
150
|
+
return null;
|
|
151
|
+
if (!startedAt)
|
|
152
|
+
startedAt = lastTimestamp ?? new Date(0).toISOString();
|
|
153
|
+
const messages = [];
|
|
154
|
+
rawMessages.forEach((m, i) => {
|
|
155
|
+
const msg = messageFromPayload(m.payload, sessionId, i, m.timestamp || startedAt);
|
|
156
|
+
if (msg)
|
|
157
|
+
messages.push(msg);
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
sessionId,
|
|
161
|
+
projectPath,
|
|
162
|
+
startedAt,
|
|
163
|
+
endedAt: lastTimestamp,
|
|
164
|
+
title: deriveTitle(messages),
|
|
165
|
+
commands,
|
|
166
|
+
messageCount: messages.length,
|
|
167
|
+
messages,
|
|
168
|
+
rawData: null,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export function readCodexSessions(sessionsDir) {
|
|
172
|
+
if (!existsSync(sessionsDir))
|
|
173
|
+
return [];
|
|
174
|
+
const sessions = [];
|
|
175
|
+
for (const file of findRolloutFiles(sessionsDir)) {
|
|
176
|
+
const session = parseRollout(file);
|
|
177
|
+
if (session)
|
|
178
|
+
sessions.push(session);
|
|
179
|
+
}
|
|
180
|
+
return sessions;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=log-reader.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Redirects always indicate a file write, regardless of the leading command
|
|
2
|
+
const REDIRECT_PATTERN = />{1,2}\s*(\S+)/g;
|
|
3
|
+
// File ops that take one or more file args; capture all space-separated non-flag args
|
|
4
|
+
const FILE_OP_SINGLE_PATTERN = /(?:vim|nano|touch|rm)\s+(\S+)/g;
|
|
5
|
+
const FILE_OP_MULTI_PATTERN = /(?:mv|cp)\s+((?:\S+\s+)*\S+)$/g;
|
|
6
|
+
// git ops — skip flags like `--` before the path
|
|
7
|
+
const GIT_PATTERN = /git\s+(?:add|checkout|restore)\s+(?:--\s+)?(\S+)/g;
|
|
8
|
+
const SED_AWK_PATTERN = /(?:sed|awk)\s+(?:-i\S*\s+)?(?:'[^']*'\s+)?(\S+)/g;
|
|
9
|
+
// Commands that are read/navigate only and produce no file writes on their own
|
|
10
|
+
const DENYLIST_COMMANDS = new Set(["ls", "pwd", "echo", "which", "cd", "cat"]);
|
|
11
|
+
function isDenylisted(command) {
|
|
12
|
+
const first = command.trim().split(/\s+/)[0] ?? "";
|
|
13
|
+
return DENYLIST_COMMANDS.has(first);
|
|
14
|
+
}
|
|
15
|
+
function extractFromPattern(command, pattern) {
|
|
16
|
+
const results = [];
|
|
17
|
+
const re = new RegExp(pattern.source, pattern.flags);
|
|
18
|
+
let match;
|
|
19
|
+
while ((match = re.exec(command)) !== null) {
|
|
20
|
+
const path = match[1];
|
|
21
|
+
if (path && !path.startsWith("-")) {
|
|
22
|
+
results.push(path);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return results;
|
|
26
|
+
}
|
|
27
|
+
function extractMultiArgs(command, pattern) {
|
|
28
|
+
const results = [];
|
|
29
|
+
const re = new RegExp(pattern.source, pattern.flags);
|
|
30
|
+
let match;
|
|
31
|
+
while ((match = re.exec(command)) !== null) {
|
|
32
|
+
const argsStr = match[1];
|
|
33
|
+
if (argsStr) {
|
|
34
|
+
for (const arg of argsStr.trim().split(/\s+/)) {
|
|
35
|
+
if (arg && !arg.startsWith("-")) {
|
|
36
|
+
results.push(arg);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
42
|
+
}
|
|
43
|
+
export function extractFiles(commands) {
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
const paths = [];
|
|
46
|
+
function addPaths(found) {
|
|
47
|
+
for (const p of found) {
|
|
48
|
+
if (!seen.has(p)) {
|
|
49
|
+
seen.add(p);
|
|
50
|
+
paths.push(p);
|
|
51
|
+
}
|
|
52
|
+
if (paths.length >= 50)
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const cmd of commands) {
|
|
57
|
+
// Redirects are extracted even from denylisted commands (echo > file IS a write)
|
|
58
|
+
addPaths(extractFromPattern(cmd, REDIRECT_PATTERN));
|
|
59
|
+
if (paths.length >= 50)
|
|
60
|
+
break;
|
|
61
|
+
if (isDenylisted(cmd))
|
|
62
|
+
continue;
|
|
63
|
+
addPaths(extractFromPattern(cmd, FILE_OP_SINGLE_PATTERN));
|
|
64
|
+
addPaths(extractMultiArgs(cmd, FILE_OP_MULTI_PATTERN));
|
|
65
|
+
addPaths(extractFromPattern(cmd, GIT_PATTERN));
|
|
66
|
+
addPaths(extractFromPattern(cmd, SED_AWK_PATTERN));
|
|
67
|
+
if (paths.length >= 50)
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
return { paths: paths.slice(0, 50), approximate: true };
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=shell-parser.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CanonicalMessage } from "../../core/canonical.js";
|
|
2
|
+
export interface FileChangeSummary {
|
|
3
|
+
filesChanged: string[];
|
|
4
|
+
linesAdded: number;
|
|
5
|
+
linesRemoved: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function deriveFileChanges(messages: CanonicalMessage[]): FileChangeSummary;
|
|
8
|
+
//# sourceMappingURL=file-changes.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function lineCount(s) {
|
|
2
|
+
if (s === "")
|
|
3
|
+
return 0;
|
|
4
|
+
return s.split("\n").length;
|
|
5
|
+
}
|
|
6
|
+
export function deriveFileChanges(messages) {
|
|
7
|
+
const files = new Set();
|
|
8
|
+
let linesAdded = 0;
|
|
9
|
+
let linesRemoved = 0;
|
|
10
|
+
for (const message of messages) {
|
|
11
|
+
for (const part of message.parts) {
|
|
12
|
+
if (part.type !== "tool")
|
|
13
|
+
continue;
|
|
14
|
+
if (part.tool !== "edit" && part.tool !== "write")
|
|
15
|
+
continue;
|
|
16
|
+
const input = part.input;
|
|
17
|
+
const filePath = input?.filePath;
|
|
18
|
+
if (typeof filePath !== "string" || filePath === "")
|
|
19
|
+
continue;
|
|
20
|
+
files.add(filePath);
|
|
21
|
+
if (part.tool === "write" && typeof input?.content === "string") {
|
|
22
|
+
linesAdded += lineCount(input.content);
|
|
23
|
+
}
|
|
24
|
+
else if (part.tool === "edit") {
|
|
25
|
+
if (typeof input?.newString === "string")
|
|
26
|
+
linesAdded += lineCount(input.newString);
|
|
27
|
+
if (typeof input?.oldString === "string")
|
|
28
|
+
linesRemoved += lineCount(input.oldString);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
filesChanged: Array.from(files),
|
|
34
|
+
linesAdded,
|
|
35
|
+
linesRemoved,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=file-changes.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Adapter, Cursor, SyncItem } from "../adapter.js";
|
|
2
|
+
import { openReadOnlyDb } from "./sqlite-reader.js";
|
|
3
|
+
type DbOpener = typeof openReadOnlyDb;
|
|
4
|
+
export declare class OpenCodeAdapter implements Adapter {
|
|
5
|
+
private readonly dbPath;
|
|
6
|
+
private readonly projectPath;
|
|
7
|
+
private readonly openDb;
|
|
8
|
+
readonly name = "opencode";
|
|
9
|
+
constructor(dbPath?: string, projectPath?: string, openDb?: DbOpener);
|
|
10
|
+
listNewSessions(cursor: Cursor): AsyncIterable<SyncItem>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { openReadOnlyDb, querySessions, queryMessages } from "./sqlite-reader.js";
|
|
3
|
+
import { mapRow } from "./mapper.js";
|
|
4
|
+
import { deriveFileChanges } from "./file-changes.js";
|
|
5
|
+
import { truncateMessages } from "../../core/message-truncation.js";
|
|
6
|
+
import { debugLog } from "../../core/debug-log.js";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
export class OpenCodeAdapter {
|
|
10
|
+
dbPath;
|
|
11
|
+
projectPath;
|
|
12
|
+
openDb;
|
|
13
|
+
name = "opencode";
|
|
14
|
+
constructor(dbPath = join(homedir(), ".local", "share", "opencode", "opencode.db"), projectPath = homedir(), openDb = openReadOnlyDb) {
|
|
15
|
+
this.dbPath = dbPath;
|
|
16
|
+
this.projectPath = projectPath;
|
|
17
|
+
this.openDb = openDb;
|
|
18
|
+
}
|
|
19
|
+
async *listNewSessions(cursor) {
|
|
20
|
+
if (!existsSync(this.dbPath))
|
|
21
|
+
return;
|
|
22
|
+
let db;
|
|
23
|
+
try {
|
|
24
|
+
db = this.openDb(this.dbPath);
|
|
25
|
+
const rows = querySessions(db, cursor.value);
|
|
26
|
+
for (const row of rows) {
|
|
27
|
+
const session = mapRow(row, this.projectPath);
|
|
28
|
+
const allMessages = queryMessages(db, row.id);
|
|
29
|
+
// summary_* DB columns are unpopulated in current OpenCode; derive from tool parts.
|
|
30
|
+
if (session.filesChanged === null || session.filesChanged.length === 0) {
|
|
31
|
+
const derived = deriveFileChanges(allMessages);
|
|
32
|
+
if (derived.filesChanged.length > 0) {
|
|
33
|
+
session.filesChanged = derived.filesChanged;
|
|
34
|
+
session.fileCount = derived.filesChanged.length;
|
|
35
|
+
session.linesAdded = derived.linesAdded;
|
|
36
|
+
session.linesRemoved = derived.linesRemoved;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const messages = truncateMessages(allMessages);
|
|
40
|
+
yield { session: { ...session, messages }, cursor: session.startedAt };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
45
|
+
if (!msg.includes("SQLITE_BUSY")) {
|
|
46
|
+
debugLog("opencode: db read failed", err);
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
// SQLITE_BUSY: DB is locked by an active OpenCode write — skip this sync
|
|
50
|
+
// cycle and retry next tick. Never fail the sync; just make it observable.
|
|
51
|
+
debugLog("opencode: db busy, skipping this cycle", err);
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
db?.close();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=index.js.map
|