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.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -2
  3. package/dist/adapters/adapter.d.ts +14 -0
  4. package/dist/adapters/adapter.js +2 -0
  5. package/dist/adapters/claude-code/accumulator.d.ts +34 -0
  6. package/dist/adapters/claude-code/accumulator.js +129 -0
  7. package/dist/adapters/claude-code/content-blocks.d.ts +40 -0
  8. package/dist/adapters/claude-code/content-blocks.js +93 -0
  9. package/dist/adapters/claude-code/index.d.ts +20 -0
  10. package/dist/adapters/claude-code/index.js +92 -0
  11. package/dist/adapters/claude-code/jsonl-reader.d.ts +14 -0
  12. package/dist/adapters/claude-code/jsonl-reader.js +31 -0
  13. package/dist/adapters/claude-code/mapper.d.ts +6 -0
  14. package/dist/adapters/claude-code/mapper.js +23 -0
  15. package/dist/adapters/codex/index.d.ts +8 -0
  16. package/dist/adapters/codex/index.js +42 -0
  17. package/dist/adapters/codex/log-reader.d.ts +14 -0
  18. package/dist/adapters/codex/log-reader.js +182 -0
  19. package/dist/adapters/codex/shell-parser.d.ts +6 -0
  20. package/dist/adapters/codex/shell-parser.js +72 -0
  21. package/dist/adapters/opencode/file-changes.d.ts +8 -0
  22. package/dist/adapters/opencode/file-changes.js +38 -0
  23. package/dist/adapters/opencode/index.d.ts +13 -0
  24. package/dist/adapters/opencode/index.js +58 -0
  25. package/dist/adapters/opencode/mapper.d.ts +4 -0
  26. package/dist/adapters/opencode/mapper.js +56 -0
  27. package/dist/adapters/opencode/sqlite-reader.d.ts +19 -0
  28. package/dist/adapters/opencode/sqlite-reader.js +109 -0
  29. package/dist/adapters/pi/index.d.ts +8 -0
  30. package/dist/adapters/pi/index.js +76 -0
  31. package/dist/adapters/pi/jsonl-reader.d.ts +2 -0
  32. package/dist/adapters/pi/jsonl-reader.js +2 -0
  33. package/dist/adapters/pi/mapper.d.ts +22 -0
  34. package/dist/adapters/pi/mapper.js +230 -0
  35. package/dist/api/pairing-client.d.ts +41 -0
  36. package/dist/api/pairing-client.js +77 -0
  37. package/dist/bin/aom.d.ts +13 -0
  38. package/dist/bin/aom.js +73 -0
  39. package/dist/cli/pair.d.ts +28 -0
  40. package/dist/cli/pair.js +114 -0
  41. package/dist/cli/start.d.ts +22 -0
  42. package/dist/cli/start.js +78 -0
  43. package/dist/cli/status.d.ts +19 -0
  44. package/dist/cli/status.js +108 -0
  45. package/dist/cli/sync.d.ts +16 -0
  46. package/dist/cli/sync.js +50 -0
  47. package/dist/cli/unpair.d.ts +18 -0
  48. package/dist/cli/unpair.js +49 -0
  49. package/dist/config.d.ts +15 -0
  50. package/dist/config.js +33 -0
  51. package/dist/core/canonical.d.ts +957 -0
  52. package/dist/core/canonical.js +80 -0
  53. package/dist/core/cursor-store.d.ts +18 -0
  54. package/dist/core/cursor-store.js +50 -0
  55. package/dist/core/debug-log.d.ts +12 -0
  56. package/dist/core/debug-log.js +17 -0
  57. package/dist/core/git-identity.d.ts +23 -0
  58. package/dist/core/git-identity.js +127 -0
  59. package/dist/core/http-client.d.ts +7 -0
  60. package/dist/core/http-client.js +63 -0
  61. package/dist/core/last-sync-store.d.ts +9 -0
  62. package/dist/core/last-sync-store.js +31 -0
  63. package/dist/core/message-truncation.d.ts +10 -0
  64. package/dist/core/message-truncation.js +13 -0
  65. package/dist/core/perform-sync.d.ts +23 -0
  66. package/dist/core/perform-sync.js +57 -0
  67. package/dist/core/project-identity.d.ts +40 -0
  68. package/dist/core/project-identity.js +67 -0
  69. package/dist/core/providers.d.ts +26 -0
  70. package/dist/core/providers.js +25 -0
  71. package/dist/core/providers.json +4 -0
  72. package/dist/core/redact.d.ts +44 -0
  73. package/dist/core/redact.js +177 -0
  74. package/dist/core/safe-json.d.ts +7 -0
  75. package/dist/core/safe-json.js +14 -0
  76. package/dist/core/sync-engine.d.ts +17 -0
  77. package/dist/core/sync-engine.js +64 -0
  78. package/dist/daemon/state.d.ts +22 -0
  79. package/dist/daemon/state.js +32 -0
  80. package/dist/daemon/sync-runner.d.ts +52 -0
  81. package/dist/daemon/sync-runner.js +104 -0
  82. package/dist/index.d.ts +2 -0
  83. package/dist/index.js +68 -0
  84. package/dist/infrastructure/config-repository.d.ts +34 -0
  85. package/dist/infrastructure/config-repository.js +102 -0
  86. package/dist/keychain/index.d.ts +31 -0
  87. package/dist/keychain/index.js +62 -0
  88. package/dist/mcp/json-rpc.d.ts +39 -0
  89. package/dist/mcp/json-rpc.js +46 -0
  90. package/dist/mcp/server.d.ts +33 -0
  91. package/dist/mcp/server.js +110 -0
  92. package/dist/mcp-tools/status.d.ts +17 -0
  93. package/dist/mcp-tools/status.js +24 -0
  94. package/dist/mcp-tools/sync-now.d.ts +9 -0
  95. package/dist/mcp-tools/sync-now.js +8 -0
  96. package/dist/services/pairing-service.d.ts +58 -0
  97. package/dist/services/pairing-service.js +102 -0
  98. package/dist/watchers/directory-watcher.d.ts +26 -0
  99. package/dist/watchers/directory-watcher.js +47 -0
  100. package/dist/watchers/opencode.d.ts +27 -0
  101. package/dist/watchers/opencode.js +58 -0
  102. package/package.json +64 -4
@@ -0,0 +1,56 @@
1
+ import { projectFields } from "../../core/project-identity.js";
2
+ function parsePatch(raw) {
3
+ if (raw === null || raw === "")
4
+ return null;
5
+ try {
6
+ const parsed = JSON.parse(raw);
7
+ if (typeof parsed !== "object" || parsed === null)
8
+ return null;
9
+ const patch = parsed;
10
+ const files = patch.files;
11
+ if (!Array.isArray(files))
12
+ return null;
13
+ return files
14
+ .filter((f) => typeof f === "object" && f !== null)
15
+ .map((f) => (typeof f.path === "string" ? f.path : ""))
16
+ .filter((p) => p.length > 0)
17
+ .slice(0, 200);
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ }
23
+ function parseModelLine(raw) {
24
+ if (!raw)
25
+ return null;
26
+ try {
27
+ const m = JSON.parse(raw);
28
+ const parts = [m.id, m.variant].filter(Boolean);
29
+ return parts.length > 0 ? parts.join(" · ") : raw;
30
+ }
31
+ catch {
32
+ return raw;
33
+ }
34
+ }
35
+ export function mapRow(row, projectPath) {
36
+ const filesChanged = parsePatch(row.summary_diffs);
37
+ const resolvedProjectPath = row.project_worktree ?? projectPath;
38
+ return {
39
+ sessionId: row.id,
40
+ provider: "opencode",
41
+ ...projectFields(resolvedProjectPath),
42
+ agentName: "OpenCode",
43
+ title: row.title ?? null,
44
+ modelLine: parseModelLine(row.model),
45
+ startedAt: new Date(row.time_created).toISOString(),
46
+ endedAt: new Date(row.time_updated).toISOString(),
47
+ messageCount: null,
48
+ fileCount: row.summary_files ?? null,
49
+ linesAdded: row.summary_additions ?? null,
50
+ linesRemoved: row.summary_deletions ?? null,
51
+ filesChanged,
52
+ filesChangedApproximate: false,
53
+ extensions: {},
54
+ };
55
+ }
56
+ //# sourceMappingURL=mapper.js.map
@@ -0,0 +1,19 @@
1
+ import Database from "better-sqlite3";
2
+ import type { CanonicalMessage } from "../../core/canonical.js";
3
+ export interface OpenCodeRow {
4
+ id: string;
5
+ project_id: string | null;
6
+ project_worktree: string | null;
7
+ title: string | null;
8
+ model: string | null;
9
+ time_created: number;
10
+ time_updated: number;
11
+ summary_additions: number | null;
12
+ summary_deletions: number | null;
13
+ summary_files: number | null;
14
+ summary_diffs: string | null;
15
+ }
16
+ export declare function openReadOnlyDb(dbPath: string): Database.Database;
17
+ export declare function querySessions(db: Database.Database, cursor: string | null): OpenCodeRow[];
18
+ export declare function queryMessages(db: Database.Database, sessionId: string): CanonicalMessage[];
19
+ //# sourceMappingURL=sqlite-reader.d.ts.map
@@ -0,0 +1,109 @@
1
+ import Database from "better-sqlite3";
2
+ export function openReadOnlyDb(dbPath) {
3
+ return new Database(dbPath, { readonly: true, fileMustExist: true });
4
+ }
5
+ export function querySessions(db, cursor) {
6
+ const sinceMs = cursor ? new Date(cursor).getTime() : 0;
7
+ const stmt = db.prepare(`
8
+ SELECT
9
+ s.id,
10
+ s.project_id,
11
+ p.worktree AS project_worktree,
12
+ s.title,
13
+ s.model,
14
+ s.time_created,
15
+ s.time_updated,
16
+ s.summary_additions,
17
+ s.summary_deletions,
18
+ s.summary_files,
19
+ s.summary_diffs
20
+ FROM session s
21
+ LEFT JOIN project p ON p.id = s.project_id
22
+ WHERE s.time_created > ?
23
+ AND s.parent_id IS NULL
24
+ ORDER BY s.time_created ASC
25
+ LIMIT 200
26
+ `);
27
+ return stmt.all(sinceMs);
28
+ }
29
+ export function queryMessages(db, sessionId) {
30
+ const stmt = db.prepare(`
31
+ SELECT
32
+ m.id AS message_id,
33
+ m.session_id,
34
+ json_extract(m.data, '$.role') AS role,
35
+ m.time_created,
36
+ p.data AS part_data
37
+ FROM message m
38
+ JOIN part p ON p.message_id = m.id
39
+ WHERE m.session_id = ?
40
+ ORDER BY m.time_created ASC, p.id ASC
41
+ `);
42
+ const rows = stmt.all(sessionId);
43
+ const byMessage = new Map();
44
+ for (const row of rows) {
45
+ if (!byMessage.has(row.message_id)) {
46
+ const rawRole = row.role ?? "";
47
+ const role = rawRole === "user" || rawRole === "assistant" ? rawRole : "assistant";
48
+ byMessage.set(row.message_id, {
49
+ role,
50
+ createdAt: new Date(row.time_created).toISOString(),
51
+ parts: [],
52
+ });
53
+ }
54
+ const part = parsePart(row.part_data);
55
+ if (part)
56
+ byMessage.get(row.message_id).parts.push(part);
57
+ }
58
+ return Array.from(byMessage.entries())
59
+ .map(([messageId, msg]) => ({
60
+ messageId,
61
+ sessionId,
62
+ role: msg.role,
63
+ senderName: msg.role === "user" ? "You" : "OpenCode",
64
+ createdAt: msg.createdAt,
65
+ parts: msg.parts,
66
+ }))
67
+ .filter((msg) => msg.parts.length > 0);
68
+ }
69
+ function parsePart(raw) {
70
+ try {
71
+ const d = JSON.parse(raw);
72
+ const type = d["type"];
73
+ if (!type)
74
+ return null;
75
+ switch (type) {
76
+ case "text":
77
+ case "reasoning":
78
+ return { type, text: d["text"] ?? "" };
79
+ case "tool":
80
+ return {
81
+ type: "tool",
82
+ tool: d["tool"] ?? "",
83
+ callId: d["callID"] ?? undefined,
84
+ input: d["state"]?.["input"],
85
+ output: extractToolOutput(d),
86
+ };
87
+ case "step-start":
88
+ case "step-finish":
89
+ return { type };
90
+ default:
91
+ return { type };
92
+ }
93
+ }
94
+ catch {
95
+ return null;
96
+ }
97
+ }
98
+ function extractToolOutput(d) {
99
+ const state = d["state"];
100
+ if (!state)
101
+ return undefined;
102
+ const output = state["output"];
103
+ if (typeof output === "string")
104
+ return output.slice(0, 500);
105
+ if (output != null)
106
+ return JSON.stringify(output).slice(0, 500);
107
+ return undefined;
108
+ }
109
+ //# sourceMappingURL=sqlite-reader.js.map
@@ -0,0 +1,8 @@
1
+ import type { Adapter, Cursor, SyncItem } from "../adapter.js";
2
+ export declare class PiAdapter implements Adapter {
3
+ readonly name = "pi";
4
+ private readonly sessionsDir;
5
+ constructor(sessionsDir?: string);
6
+ listNewSessions(cursor: Cursor): AsyncIterable<SyncItem>;
7
+ }
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,76 @@
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, processEntry, finalizeSession } from "./mapper.js";
6
+ import { truncateMessages } from "../../core/message-truncation.js";
7
+ function parseCursor(raw) {
8
+ if (!raw)
9
+ return {};
10
+ try {
11
+ const parsed = JSON.parse(raw);
12
+ if (typeof parsed === "object" && parsed !== null)
13
+ return parsed;
14
+ }
15
+ catch {
16
+ // ignore — malformed cursor, start fresh
17
+ }
18
+ return {};
19
+ }
20
+ function findJsonlFiles(rootDir) {
21
+ const files = [];
22
+ if (!existsSync(rootDir))
23
+ return files;
24
+ const walk = (dir) => {
25
+ let entries;
26
+ try {
27
+ entries = readdirSync(dir, { withFileTypes: true });
28
+ }
29
+ catch {
30
+ return;
31
+ }
32
+ for (const entry of entries) {
33
+ const full = join(dir, entry.name);
34
+ if (entry.isDirectory())
35
+ walk(full);
36
+ else if (entry.isFile() && entry.name.endsWith(".jsonl"))
37
+ files.push(full);
38
+ }
39
+ };
40
+ walk(rootDir);
41
+ return files;
42
+ }
43
+ export class PiAdapter {
44
+ name = "pi";
45
+ sessionsDir;
46
+ constructor(sessionsDir = join(homedir(), ".pi", "agent", "sessions")) {
47
+ this.sessionsDir = sessionsDir;
48
+ }
49
+ async *listNewSessions(cursor) {
50
+ const offsets = parseCursor(cursor.value);
51
+ const files = findJsonlFiles(this.sessionsDir);
52
+ for (const filePath of files) {
53
+ if (!existsSync(filePath))
54
+ continue;
55
+ const fromOffset = offsets[filePath] ?? 0;
56
+ const acc = createAccumulator(filePath);
57
+ let lastOffset = fromOffset;
58
+ try {
59
+ for await (const { line, byteOffset } of readJsonlFrom(filePath, fromOffset)) {
60
+ processEntry(acc, line);
61
+ lastOffset = byteOffset;
62
+ }
63
+ }
64
+ catch {
65
+ continue;
66
+ }
67
+ if (acc.messageCount > 0) {
68
+ offsets[filePath] = lastOffset;
69
+ const session = finalizeSession(acc);
70
+ const messages = truncateMessages(acc.messages);
71
+ yield { session: { ...session, messages }, cursor: JSON.stringify(offsets) };
72
+ }
73
+ }
74
+ }
75
+ }
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export { readJsonlFrom } from "../claude-code/jsonl-reader.js";
2
+ //# sourceMappingURL=jsonl-reader.d.ts.map
@@ -0,0 +1,2 @@
1
+ export { readJsonlFrom } from "../claude-code/jsonl-reader.js";
2
+ //# sourceMappingURL=jsonl-reader.js.map
@@ -0,0 +1,22 @@
1
+ import type { CanonicalSession, CanonicalMessage } from "../../core/canonical.js";
2
+ export interface SessionAccumulator {
3
+ sessionId: string;
4
+ projectPath: string;
5
+ title: string | null;
6
+ modelLine: string | null;
7
+ startedAt: string | null;
8
+ endedAt: string | null;
9
+ messageCount: number;
10
+ linesAdded: number;
11
+ linesRemoved: number;
12
+ filesChanged: Set<string>;
13
+ pendingEdit: Map<string, string>;
14
+ messages: CanonicalMessage[];
15
+ toolNameById: Map<string, string>;
16
+ }
17
+ export declare function sessionIdFromFilePath(filePath: string): string | null;
18
+ export declare function cwdFromSessionDir(filePath: string): string | null;
19
+ export declare function createAccumulator(filePath: string): SessionAccumulator;
20
+ export declare function processEntry(acc: SessionAccumulator, raw: unknown): void;
21
+ export declare function finalizeSession(acc: SessionAccumulator): CanonicalSession;
22
+ //# sourceMappingURL=mapper.d.ts.map
@@ -0,0 +1,230 @@
1
+ import { basename, dirname } from "node:path";
2
+ import { projectFields } from "../../core/project-identity.js";
3
+ function countPatchLines(patch) {
4
+ let added = 0;
5
+ let removed = 0;
6
+ for (const line of patch.split("\n")) {
7
+ if (line.startsWith("+") && !line.startsWith("+++"))
8
+ added++;
9
+ else if (line.startsWith("-") && !line.startsWith("---"))
10
+ removed++;
11
+ }
12
+ return { added, removed };
13
+ }
14
+ function normalizeContent(content) {
15
+ if (typeof content === "string")
16
+ return [{ type: "text", text: content }];
17
+ if (Array.isArray(content))
18
+ return content;
19
+ return [];
20
+ }
21
+ function firstText(content) {
22
+ if (typeof content === "string")
23
+ return content;
24
+ if (!Array.isArray(content))
25
+ return null;
26
+ for (const block of content) {
27
+ if (block.type === "text" && typeof block.text === "string") {
28
+ return block.text ?? null;
29
+ }
30
+ }
31
+ return null;
32
+ }
33
+ function contentToParts(content, toolNameById) {
34
+ const parts = [];
35
+ for (const block of content) {
36
+ switch (block.type) {
37
+ case "text": {
38
+ const b = block;
39
+ if (typeof b.text === "string" && b.text.length > 0) {
40
+ parts.push({ type: "text", text: b.text });
41
+ }
42
+ break;
43
+ }
44
+ case "thinking": {
45
+ const b = block;
46
+ if (typeof b.thinking === "string" && b.thinking.length > 0) {
47
+ parts.push({ type: "reasoning", text: b.thinking });
48
+ }
49
+ break;
50
+ }
51
+ case "toolCall": {
52
+ const b = block;
53
+ if (b.id && b.name) {
54
+ toolNameById.set(b.id, b.name);
55
+ parts.push({ type: "tool", tool: b.name, callId: b.id, input: b.arguments });
56
+ }
57
+ break;
58
+ }
59
+ case "image": {
60
+ const b = block;
61
+ if (b.data) {
62
+ parts.push({
63
+ type: "image_url",
64
+ mediaType: b.mimeType,
65
+ imageUrl: `data:${b.mimeType ?? "image/png"};base64,${b.data.slice(0, 64)}…`,
66
+ });
67
+ }
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ return parts;
73
+ }
74
+ /**
75
+ * Pi puts the session UUID in the filename (`<ts>_<uuid>.jsonl`, unambiguous)
76
+ * and the cwd in the parent dir (`--<cwd>--` with `/`→`-`, LOSSY to reverse).
77
+ * Deriving identity from the path keeps it stable when an incremental sync
78
+ * resumes mid-file and never re-reads the in-band `session` header; the header
79
+ * `id`/`cwd` override these structurally-derived values when observed.
80
+ */
81
+ const PI_UUID_RE = /_([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/;
82
+ export function sessionIdFromFilePath(filePath) {
83
+ const stem = basename(filePath, ".jsonl");
84
+ const match = PI_UUID_RE.exec(stem);
85
+ return match?.[1] ?? null;
86
+ }
87
+ export function cwdFromSessionDir(filePath) {
88
+ const dir = basename(dirname(filePath));
89
+ if (!dir.startsWith("--") || !dir.endsWith("--") || dir.length <= 4)
90
+ return null;
91
+ const inner = dir.slice(2, -2);
92
+ return "/" + inner.replace(/-/g, "/");
93
+ }
94
+ export function createAccumulator(filePath) {
95
+ return {
96
+ sessionId: sessionIdFromFilePath(filePath) ?? filePath,
97
+ projectPath: cwdFromSessionDir(filePath) ?? filePath,
98
+ title: null,
99
+ modelLine: null,
100
+ startedAt: null,
101
+ endedAt: null,
102
+ messageCount: 0,
103
+ linesAdded: 0,
104
+ linesRemoved: 0,
105
+ filesChanged: new Set(),
106
+ pendingEdit: new Map(),
107
+ messages: [],
108
+ toolNameById: new Map(),
109
+ };
110
+ }
111
+ function recordEdit(acc, call) {
112
+ if (!call.id || !call.arguments)
113
+ return;
114
+ const path = typeof call.arguments["path"] === "string" ? call.arguments["path"] : null;
115
+ if (!path)
116
+ return;
117
+ if (call.name === "write") {
118
+ const fileContent = typeof call.arguments["content"] === "string" ? call.arguments["content"] : "";
119
+ acc.linesAdded += fileContent.length > 0 ? fileContent.split("\n").length : 0;
120
+ acc.filesChanged.add(path);
121
+ }
122
+ else if (call.name === "edit") {
123
+ acc.pendingEdit.set(call.id, path);
124
+ }
125
+ }
126
+ function applyEditResult(acc, msg) {
127
+ const callId = msg.toolCallId;
128
+ if (!callId)
129
+ return;
130
+ const path = acc.pendingEdit.get(callId);
131
+ if (!path)
132
+ return;
133
+ acc.pendingEdit.delete(callId);
134
+ if (msg.isError === true)
135
+ return;
136
+ const patch = typeof msg.details?.patch === "string" ? msg.details.patch : null;
137
+ if (patch) {
138
+ const { added, removed } = countPatchLines(patch);
139
+ acc.linesAdded += added;
140
+ acc.linesRemoved += removed;
141
+ }
142
+ acc.filesChanged.add(path);
143
+ }
144
+ export function processEntry(acc, raw) {
145
+ if (typeof raw !== "object" || raw === null)
146
+ return;
147
+ const entry = raw;
148
+ if (entry.type === "session") {
149
+ if (typeof entry.id === "string")
150
+ acc.sessionId = entry.id;
151
+ if (typeof entry.cwd === "string")
152
+ acc.projectPath = entry.cwd;
153
+ if (typeof entry.timestamp === "string" && acc.startedAt === null) {
154
+ acc.startedAt = entry.timestamp;
155
+ }
156
+ return;
157
+ }
158
+ if (entry.type !== "message" || !entry.message)
159
+ return;
160
+ const ts = entry.timestamp;
161
+ if (typeof ts === "string") {
162
+ if (acc.startedAt === null)
163
+ acc.startedAt = ts;
164
+ acc.endedAt = ts;
165
+ }
166
+ const msg = entry.message;
167
+ if (typeof msg.model === "string" && acc.modelLine === null) {
168
+ acc.modelLine = msg.provider ? `${msg.provider}/${msg.model}` : msg.model;
169
+ }
170
+ if (msg.role === "toolResult") {
171
+ applyEditResult(acc, msg);
172
+ const output = firstText(msg.content);
173
+ // A toolResult is the outcome of an earlier toolCall, not a new tool
174
+ // invocation. Render its message as text (e.g. "Successfully replaced 2
175
+ // block(s) in …") rather than a second, input-less tool card that would
176
+ // show as a bare "edit"/"read" row with no file path.
177
+ if (output && output.trim().length > 0) {
178
+ pushMessage(acc, entry, "assistant", "Pi", [
179
+ { type: "text", text: output.slice(0, 500) },
180
+ ]);
181
+ }
182
+ return;
183
+ }
184
+ if (msg.role !== "user" && msg.role !== "assistant")
185
+ return;
186
+ const content = normalizeContent(msg.content);
187
+ for (const block of content) {
188
+ if (block.type === "toolCall")
189
+ recordEdit(acc, block);
190
+ }
191
+ const parts = contentToParts(content, acc.toolNameById);
192
+ if (parts.length === 0)
193
+ return;
194
+ if (msg.role === "user" && acc.title === null) {
195
+ const text = firstText(msg.content);
196
+ if (text)
197
+ acc.title = text.trim().slice(0, 80);
198
+ }
199
+ pushMessage(acc, entry, msg.role, msg.role === "user" ? "You" : "Pi", parts);
200
+ }
201
+ function pushMessage(acc, entry, role, senderName, parts) {
202
+ if (parts.length === 0)
203
+ return;
204
+ acc.messageCount++;
205
+ const sessionId = acc.sessionId;
206
+ const messageId = typeof entry.id === "string" ? entry.id : `${sessionId}-${acc.messageCount}`;
207
+ const createdAt = typeof entry.timestamp === "string" ? entry.timestamp : new Date(0).toISOString();
208
+ acc.messages.push({ messageId, sessionId, role, senderName, createdAt, parts });
209
+ }
210
+ export function finalizeSession(acc) {
211
+ const filesChanged = acc.filesChanged.size > 0 ? Array.from(acc.filesChanged) : null;
212
+ return {
213
+ sessionId: acc.sessionId,
214
+ provider: "pi",
215
+ ...projectFields(acc.projectPath),
216
+ agentName: "Pi",
217
+ title: acc.title,
218
+ modelLine: acc.modelLine,
219
+ startedAt: acc.startedAt ?? new Date(0).toISOString(),
220
+ endedAt: acc.endedAt,
221
+ messageCount: acc.messageCount > 0 ? acc.messageCount : null,
222
+ fileCount: acc.filesChanged.size > 0 ? acc.filesChanged.size : null,
223
+ linesAdded: acc.linesAdded > 0 ? acc.linesAdded : null,
224
+ linesRemoved: acc.linesRemoved > 0 ? acc.linesRemoved : null,
225
+ filesChanged,
226
+ filesChangedApproximate: false,
227
+ extensions: {},
228
+ };
229
+ }
230
+ //# sourceMappingURL=mapper.js.map
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Typed HTTP client for the AgentsOfMine Pairing API.
3
+ *
4
+ * Covers the two endpoints used by `aom pair`:
5
+ * POST /pair/init — register a deviceId, receive a pairingCode + qrUrl
6
+ * GET /pair/status — poll until the user approves on their phone
7
+ *
8
+ * Base URL defaults to https://agentsofmine.io but can be overridden via
9
+ * the AOM_API_BASE_URL env var for development / staging.
10
+ */
11
+ export interface PairInitRequest {
12
+ deviceId: string;
13
+ /** Human-readable OS hint. E.g. "agentsofmine-collector 0.1.0 / darwin-arm64 / hostname" */
14
+ userAgent: string;
15
+ }
16
+ export interface PairInitResponse {
17
+ pairingCode: string;
18
+ expiresAt: number;
19
+ pollInterval: number;
20
+ qrUrl: string;
21
+ }
22
+ export type PairingStatus = "pending" | "approved" | "denied" | "expired";
23
+ export interface PairStatusResponse {
24
+ status: PairingStatus;
25
+ /** Present only when status === "approved" */
26
+ deviceToken?: string;
27
+ }
28
+ export declare class PairingApiError extends Error {
29
+ readonly statusCode: number;
30
+ readonly body: string;
31
+ constructor(message: string, statusCode: number, body: string);
32
+ }
33
+ export declare class PairingClient {
34
+ private readonly baseUrl;
35
+ constructor(baseUrl?: string);
36
+ /** POST /pair/init — register deviceId and receive pairing code + QR URL */
37
+ initPairing(deviceId: string): Promise<PairInitResponse>;
38
+ /** GET /pair/status?device=<deviceId> — check whether the user has approved */
39
+ pollStatus(deviceId: string): Promise<PairStatusResponse>;
40
+ }
41
+ //# sourceMappingURL=pairing-client.d.ts.map
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Typed HTTP client for the AgentsOfMine Pairing API.
3
+ *
4
+ * Covers the two endpoints used by `aom pair`:
5
+ * POST /pair/init — register a deviceId, receive a pairingCode + qrUrl
6
+ * GET /pair/status — poll until the user approves on their phone
7
+ *
8
+ * Base URL defaults to https://agentsofmine.io but can be overridden via
9
+ * the AOM_API_BASE_URL env var for development / staging.
10
+ */
11
+ import { platform, hostname } from "node:os";
12
+ import { createRequire } from "node:module";
13
+ export class PairingApiError extends Error {
14
+ statusCode;
15
+ body;
16
+ constructor(message, statusCode, body) {
17
+ super(message);
18
+ this.statusCode = statusCode;
19
+ this.body = body;
20
+ this.name = "PairingApiError";
21
+ }
22
+ }
23
+ const DEFAULT_BASE_URL = "https://agentsofmine.io";
24
+ export class PairingClient {
25
+ baseUrl;
26
+ constructor(baseUrl) {
27
+ this.baseUrl =
28
+ baseUrl ??
29
+ process.env["AOM_API_BASE_URL"] ??
30
+ DEFAULT_BASE_URL;
31
+ }
32
+ /** POST /pair/init — register deviceId and receive pairing code + QR URL */
33
+ async initPairing(deviceId) {
34
+ const body = {
35
+ deviceId,
36
+ userAgent: buildUserAgent(),
37
+ };
38
+ const res = await fetch(`${this.baseUrl}/pair/init`, {
39
+ method: "POST",
40
+ headers: { "Content-Type": "application/json" },
41
+ body: JSON.stringify(body),
42
+ });
43
+ const text = await res.text();
44
+ if (!res.ok) {
45
+ throw new PairingApiError(`POST /pair/init failed: ${res.status}`, res.status, text);
46
+ }
47
+ return JSON.parse(text);
48
+ }
49
+ /** GET /pair/status?device=<deviceId> — check whether the user has approved */
50
+ async pollStatus(deviceId) {
51
+ const url = `${this.baseUrl}/pair/status?device=${encodeURIComponent(deviceId)}`;
52
+ const res = await fetch(url, { method: "GET" });
53
+ const text = await res.text();
54
+ if (!res.ok) {
55
+ throw new PairingApiError(`GET /pair/status failed: ${res.status}`, res.status, text);
56
+ }
57
+ return JSON.parse(text);
58
+ }
59
+ }
60
+ function buildUserAgent() {
61
+ const pkg = getPackageVersion();
62
+ const os = `${platform()}-${process.arch}`;
63
+ const host = hostname();
64
+ return `agentsofmine-collector ${pkg} / ${os} / ${host}`;
65
+ }
66
+ function getPackageVersion() {
67
+ try {
68
+ // Resolve package.json relative to this file at runtime
69
+ const require = createRequire(import.meta.url);
70
+ const pkg = require("../../package.json");
71
+ return pkg.version;
72
+ }
73
+ catch {
74
+ return "0.0.0";
75
+ }
76
+ }
77
+ //# sourceMappingURL=pairing-client.js.map
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `aom` — AgentsOfMine Collector CLI
4
+ *
5
+ * Commands:
6
+ * aom pair — one-time device pairing (prints QR, polls, stores token)
7
+ * aom start — start the collector daemon (watchers + MCP server)
8
+ * aom sync — sync new sessions to the cloud now (one-shot)
9
+ * aom status — show sync state and pairing status
10
+ * aom unpair — remove device token and clear local state
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=aom.d.ts.map