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
package/dist/bin/aom.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
import { Command } from "commander";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { runPair } from "../cli/pair.js";
|
|
15
|
+
import { runStart } from "../cli/start.js";
|
|
16
|
+
import { runSyncCommand } from "../cli/sync.js";
|
|
17
|
+
import { runStatus } from "../cli/status.js";
|
|
18
|
+
import { runUnpair } from "../cli/unpair.js";
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
const pkg = require("../../package.json");
|
|
21
|
+
const program = new Command();
|
|
22
|
+
program
|
|
23
|
+
.name("aom")
|
|
24
|
+
.description(pkg.description)
|
|
25
|
+
.version(pkg.version, "-V, --version");
|
|
26
|
+
program
|
|
27
|
+
.command("pair")
|
|
28
|
+
.description("Pair this machine with your AgentsOfMine account (one-time setup)")
|
|
29
|
+
.option("--no-browser", "Skip auto-opening the approval URL in the browser")
|
|
30
|
+
.option("--force", "Re-pair even if this machine is already paired")
|
|
31
|
+
.option("--reset", "Alias for --force: discard the existing pairing and start fresh")
|
|
32
|
+
.option("--api-base-url <url>", "Override API base URL (for development)")
|
|
33
|
+
.action(async (opts) => {
|
|
34
|
+
await runPair({
|
|
35
|
+
noBrowser: !opts.browser,
|
|
36
|
+
force: opts.force || opts.reset,
|
|
37
|
+
...(opts.apiBaseUrl !== undefined ? { apiBaseUrl: opts.apiBaseUrl } : {}),
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
program
|
|
41
|
+
.command("start")
|
|
42
|
+
.description("Start the collector daemon (file watchers + MCP server)")
|
|
43
|
+
.option("-v, --verbose", "Enable verbose logging")
|
|
44
|
+
.option("--mcp-port <port>", "MCP server port (default: stdio)", parseInt)
|
|
45
|
+
.action(async (opts) => {
|
|
46
|
+
await runStart({
|
|
47
|
+
verbose: opts.verbose,
|
|
48
|
+
...(opts.mcpPort !== undefined ? { mcpPort: opts.mcpPort } : {}),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
program
|
|
52
|
+
.command("sync")
|
|
53
|
+
.description("Sync new sessions to the cloud now (one-shot)")
|
|
54
|
+
.option("-v, --verbose", "Print per-error detail")
|
|
55
|
+
.action(async (opts) => {
|
|
56
|
+
await runSyncCommand({ verbose: opts.verbose });
|
|
57
|
+
});
|
|
58
|
+
program
|
|
59
|
+
.command("status")
|
|
60
|
+
.description("Show pairing status and last-synced timestamps")
|
|
61
|
+
.option("--json", "Print machine-readable status as a single JSON object")
|
|
62
|
+
.action(async (opts) => {
|
|
63
|
+
await runStatus({ json: opts.json });
|
|
64
|
+
});
|
|
65
|
+
program
|
|
66
|
+
.command("unpair")
|
|
67
|
+
.description("Remove device token and clear local collector state")
|
|
68
|
+
.option("-y, --yes", "Skip confirmation prompt")
|
|
69
|
+
.action(async (opts) => {
|
|
70
|
+
await runUnpair({ yes: opts.yes });
|
|
71
|
+
});
|
|
72
|
+
await program.parseAsync(process.argv);
|
|
73
|
+
//# sourceMappingURL=aom.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom pair` — one-time device pairing.
|
|
3
|
+
*
|
|
4
|
+
* Presentation layer only: QR rendering, spinner, terminal output, error
|
|
5
|
+
* messages, process.exit() calls.
|
|
6
|
+
*
|
|
7
|
+
* All orchestration (init → poll → token storage → config write) lives in
|
|
8
|
+
* PairingService. All file I/O lives in ConfigRepository.
|
|
9
|
+
*
|
|
10
|
+
* Flow (mirrors ADR 0006 / D015):
|
|
11
|
+
* 1. Generate a stable deviceId (UUIDv4), persisted locally via ConfigRepository.
|
|
12
|
+
* 2. POST /pair/init → receive pairingCode + qrUrl.
|
|
13
|
+
* 3. Print URL + ASCII QR to terminal.
|
|
14
|
+
* 4. Optionally open browser automatically (--no-browser to skip).
|
|
15
|
+
* 5. Poll GET /pair/status every pollInterval seconds (via PairingService).
|
|
16
|
+
* 6. On "approved" → PairingService stores deviceToken in OS keychain.
|
|
17
|
+
* 7. On "denied" / "expired" → exit non-zero with a clear message.
|
|
18
|
+
*/
|
|
19
|
+
export interface PairOptions {
|
|
20
|
+
/** Skip auto-opening the browser. Defaults to false. */
|
|
21
|
+
noBrowser?: boolean;
|
|
22
|
+
/** Base URL override for staging / development. */
|
|
23
|
+
apiBaseUrl?: string;
|
|
24
|
+
/** Re-pair even if already paired. */
|
|
25
|
+
force?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function runPair(opts?: PairOptions): Promise<void>;
|
|
28
|
+
//# sourceMappingURL=pair.d.ts.map
|
package/dist/cli/pair.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom pair` — one-time device pairing.
|
|
3
|
+
*
|
|
4
|
+
* Presentation layer only: QR rendering, spinner, terminal output, error
|
|
5
|
+
* messages, process.exit() calls.
|
|
6
|
+
*
|
|
7
|
+
* All orchestration (init → poll → token storage → config write) lives in
|
|
8
|
+
* PairingService. All file I/O lives in ConfigRepository.
|
|
9
|
+
*
|
|
10
|
+
* Flow (mirrors ADR 0006 / D015):
|
|
11
|
+
* 1. Generate a stable deviceId (UUIDv4), persisted locally via ConfigRepository.
|
|
12
|
+
* 2. POST /pair/init → receive pairingCode + qrUrl.
|
|
13
|
+
* 3. Print URL + ASCII QR to terminal.
|
|
14
|
+
* 4. Optionally open browser automatically (--no-browser to skip).
|
|
15
|
+
* 5. Poll GET /pair/status every pollInterval seconds (via PairingService).
|
|
16
|
+
* 6. On "approved" → PairingService stores deviceToken in OS keychain.
|
|
17
|
+
* 7. On "denied" / "expired" → exit non-zero with a clear message.
|
|
18
|
+
*/
|
|
19
|
+
import qrcode from "qrcode-terminal";
|
|
20
|
+
import openBrowser from "open";
|
|
21
|
+
import { PairingClient, PairingApiError } from "../api/pairing-client.js";
|
|
22
|
+
import { ConfigRepository } from "../infrastructure/config-repository.js";
|
|
23
|
+
import { PairingService } from "../services/pairing-service.js";
|
|
24
|
+
import { isPaired } from "../keychain/index.js";
|
|
25
|
+
export async function runPair(opts = {}) {
|
|
26
|
+
// Guard: already paired
|
|
27
|
+
if (!opts.force && (await isPaired())) {
|
|
28
|
+
console.log("✓ This machine is already paired.");
|
|
29
|
+
console.log(" Run \x1b[36maom status\x1b[0m to see sync state.");
|
|
30
|
+
console.log(" Use \x1b[36maom pair --force\x1b[0m to re-pair.");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const client = new PairingClient(opts.apiBaseUrl);
|
|
34
|
+
const configRepo = new ConfigRepository();
|
|
35
|
+
const service = new PairingService(client, configRepo);
|
|
36
|
+
process.stdout.write("Requesting pairing code… ");
|
|
37
|
+
let result;
|
|
38
|
+
try {
|
|
39
|
+
result = await service.runPairFlow({
|
|
40
|
+
reset: opts.force ?? false,
|
|
41
|
+
onInitSuccess: ({ pairingCode, qrUrl, expiresInMinutes, pollIntervalMs: _unused }) => {
|
|
42
|
+
void _unused;
|
|
43
|
+
console.log("done\n");
|
|
44
|
+
printPairingUI(qrUrl, pairingCode, expiresInMinutes);
|
|
45
|
+
if (!opts.noBrowser) {
|
|
46
|
+
openBrowser(qrUrl).catch(() => {
|
|
47
|
+
// Non-fatal: browser open is best-effort
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
console.log("Waiting for approval on your phone…\n");
|
|
51
|
+
},
|
|
52
|
+
onPollTick: (tick) => {
|
|
53
|
+
const spinnerFrames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
54
|
+
const frame = spinnerFrames[tick % spinnerFrames.length] ?? "·";
|
|
55
|
+
process.stdout.write(`\r${frame} Waiting…`);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
process.stdout.write("\n");
|
|
61
|
+
handleApiError(err);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
process.stdout.write("\n\n");
|
|
65
|
+
switch (result.status) {
|
|
66
|
+
case "approved":
|
|
67
|
+
console.log("✓ \x1b[32mPaired!\x1b[0m Device token stored in keychain.");
|
|
68
|
+
console.log(" Run \x1b[36maom start\x1b[0m to begin syncing sessions.");
|
|
69
|
+
return;
|
|
70
|
+
case "denied":
|
|
71
|
+
console.error("✗ Pairing was denied on your phone.");
|
|
72
|
+
console.error(" Run \x1b[36maom pair\x1b[0m again to start a new pairing.");
|
|
73
|
+
process.exit(1);
|
|
74
|
+
break;
|
|
75
|
+
case "expired":
|
|
76
|
+
console.error("✗ Pairing code expired (5 minutes).");
|
|
77
|
+
console.error(" Run \x1b[36maom pair\x1b[0m again to get a fresh code.");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function printPairingUI(qrUrl, pairingCode, expiresInMinutes) {
|
|
83
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
84
|
+
console.log(" AgentsOfMine — Pair this machine");
|
|
85
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
|
|
86
|
+
qrcode.generate(qrUrl, { small: true });
|
|
87
|
+
console.log(`\n \x1b[1mPairing code:\x1b[0m \x1b[36m${pairingCode}\x1b[0m`);
|
|
88
|
+
console.log(` \x1b[2mExpires in ~${expiresInMinutes} minutes\x1b[0m\n`);
|
|
89
|
+
console.log(" Or open this URL on your phone:");
|
|
90
|
+
console.log(` \x1b[4m${qrUrl}\x1b[0m\n`);
|
|
91
|
+
console.log(" \x1b[33mOnly approve if you just ran this command.\x1b[0m");
|
|
92
|
+
console.log(" \x1b[33mVerify the pairing code matches what your phone shows.\x1b[0m\n");
|
|
93
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
|
|
94
|
+
}
|
|
95
|
+
function handleApiError(err) {
|
|
96
|
+
if (err instanceof PairingApiError) {
|
|
97
|
+
console.error(`\n✗ Pairing API returned HTTP ${err.statusCode}`);
|
|
98
|
+
if (err.statusCode === 429) {
|
|
99
|
+
console.error(" Too many requests — wait a moment and try again.");
|
|
100
|
+
}
|
|
101
|
+
else if (err.statusCode >= 500) {
|
|
102
|
+
console.error(" Server error — please try again in a few seconds.");
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
console.error(` ${err.body}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.error(`\n✗ Network error during pairing:`, err.message);
|
|
110
|
+
console.error(" Check your internet connection and try again.");
|
|
111
|
+
}
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=pair.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom start` — start the collector daemon.
|
|
3
|
+
*
|
|
4
|
+
* Starts:
|
|
5
|
+
* 1. A shared SyncRunner (debounced, single-flight) that uploads new sessions.
|
|
6
|
+
* 2. File watchers for each supported agent (OpenCode DB, Claude Code and
|
|
7
|
+
* Codex session directories). Each watcher triggers the SyncRunner.
|
|
8
|
+
* 3. The MCP server (stdio transport) so agents can push events directly;
|
|
9
|
+
* those pushes also trigger the SyncRunner.
|
|
10
|
+
*
|
|
11
|
+
* An initial sync runs at startup so a freshly started daemon catches up on
|
|
12
|
+
* anything written while it was down. Exits with a clear message if the
|
|
13
|
+
* machine is not yet paired.
|
|
14
|
+
*/
|
|
15
|
+
export interface StartOptions {
|
|
16
|
+
/** Override MCP server port (default: stdio). */
|
|
17
|
+
mcpPort?: number;
|
|
18
|
+
/** Verbose logging. */
|
|
19
|
+
verbose?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function runStart(opts?: StartOptions): Promise<void>;
|
|
22
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom start` — start the collector daemon.
|
|
3
|
+
*
|
|
4
|
+
* Starts:
|
|
5
|
+
* 1. A shared SyncRunner (debounced, single-flight) that uploads new sessions.
|
|
6
|
+
* 2. File watchers for each supported agent (OpenCode DB, Claude Code and
|
|
7
|
+
* Codex session directories). Each watcher triggers the SyncRunner.
|
|
8
|
+
* 3. The MCP server (stdio transport) so agents can push events directly;
|
|
9
|
+
* those pushes also trigger the SyncRunner.
|
|
10
|
+
*
|
|
11
|
+
* An initial sync runs at startup so a freshly started daemon catches up on
|
|
12
|
+
* anything written while it was down. Exits with a clear message if the
|
|
13
|
+
* machine is not yet paired.
|
|
14
|
+
*/
|
|
15
|
+
import { isPaired, getDeviceToken } from "../keychain/index.js";
|
|
16
|
+
import { loadConfig } from "../config.js";
|
|
17
|
+
import { startMcpServer } from "../mcp/server.js";
|
|
18
|
+
import { OpenCodeWatcher } from "../watchers/opencode.js";
|
|
19
|
+
import { DirectoryWatcher } from "../watchers/directory-watcher.js";
|
|
20
|
+
import { DaemonState } from "../daemon/state.js";
|
|
21
|
+
import { SyncRunner } from "../daemon/sync-runner.js";
|
|
22
|
+
export async function runStart(opts = {}) {
|
|
23
|
+
if (!(await isPaired())) {
|
|
24
|
+
console.error("✗ This machine is not paired yet.");
|
|
25
|
+
console.error(" Run \x1b[36maom pair\x1b[0m first.");
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
const deviceToken = await getDeviceToken();
|
|
29
|
+
if (!deviceToken) {
|
|
30
|
+
console.error("✗ Device token missing — run \x1b[36maom pair\x1b[0m again.");
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const config = await loadConfig();
|
|
34
|
+
const state = new DaemonState({ deviceToken, verbose: opts.verbose ?? false });
|
|
35
|
+
const syncRunner = new SyncRunner({
|
|
36
|
+
log: (msg) => state.log(msg),
|
|
37
|
+
onSynced: (summary) => {
|
|
38
|
+
if (summary.synced > 0 || summary.failed > 0) {
|
|
39
|
+
state.markSynced("daemon");
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
state.syncRunner = syncRunner;
|
|
44
|
+
console.log("agentsofmine-collector starting…\n");
|
|
45
|
+
const codexDir = config.codexSessionsDir;
|
|
46
|
+
const claudeProjectsDir = config.claudeProjectsGlob
|
|
47
|
+
.replace(/[/\\]\*[/\\]\*\.jsonl$/, "")
|
|
48
|
+
.replace(/[/\\]\*\.jsonl$/, "");
|
|
49
|
+
const watchers = [
|
|
50
|
+
new OpenCodeWatcher(state, syncRunner, config.opencodeDbPath),
|
|
51
|
+
new DirectoryWatcher("claude-code", claudeProjectsDir, state, syncRunner, (f) => f.endsWith(".jsonl")),
|
|
52
|
+
new DirectoryWatcher("codex", codexDir, state, syncRunner),
|
|
53
|
+
new DirectoryWatcher("pi", config.piSessionsDir, state, syncRunner, (f) => f.endsWith(".jsonl")),
|
|
54
|
+
];
|
|
55
|
+
for (const w of watchers) {
|
|
56
|
+
await w.start();
|
|
57
|
+
console.log(` ✓ ${w.name} watcher active`);
|
|
58
|
+
}
|
|
59
|
+
await startMcpServer(state);
|
|
60
|
+
console.log(" ✓ MCP server listening (stdio)");
|
|
61
|
+
console.log("\nRunning initial sync…");
|
|
62
|
+
await syncRunner.runNow();
|
|
63
|
+
console.log("\nCollector is running. Watching for changes. Press Ctrl+C to stop.\n");
|
|
64
|
+
setupSignalHandlers(watchers, syncRunner);
|
|
65
|
+
}
|
|
66
|
+
function setupSignalHandlers(watchers, syncRunner) {
|
|
67
|
+
const shutdown = async () => {
|
|
68
|
+
console.log("\nShutting down…");
|
|
69
|
+
syncRunner.stop();
|
|
70
|
+
for (const w of watchers) {
|
|
71
|
+
await w.stop();
|
|
72
|
+
}
|
|
73
|
+
process.exit(0);
|
|
74
|
+
};
|
|
75
|
+
process.on("SIGINT", () => void shutdown());
|
|
76
|
+
process.on("SIGTERM", () => void shutdown());
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom status` — show sync state and last-synced timestamps.
|
|
3
|
+
*/
|
|
4
|
+
export interface StatusJson {
|
|
5
|
+
paired: boolean;
|
|
6
|
+
deviceId: string | null;
|
|
7
|
+
lastSyncAt: string | null;
|
|
8
|
+
queueDepth: number;
|
|
9
|
+
lastError: {
|
|
10
|
+
kind: string;
|
|
11
|
+
message: string;
|
|
12
|
+
} | null;
|
|
13
|
+
}
|
|
14
|
+
export interface StatusOptions {
|
|
15
|
+
json?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildStatus(): Promise<StatusJson>;
|
|
18
|
+
export declare function runStatus(options?: StatusOptions): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom status` — show sync state and last-synced timestamps.
|
|
3
|
+
*/
|
|
4
|
+
import { isPaired, getDeviceToken } from "../keychain/index.js";
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
function stateDir() {
|
|
9
|
+
return process.env.HOME || process.env.USERPROFILE || homedir();
|
|
10
|
+
}
|
|
11
|
+
function deviceIdFile() {
|
|
12
|
+
return join(stateDir(), ".agentsofmine", "device-id");
|
|
13
|
+
}
|
|
14
|
+
function lastSyncFile() {
|
|
15
|
+
return join(stateDir(), ".agentsofmine", "last-sync.json");
|
|
16
|
+
}
|
|
17
|
+
function readDeviceId() {
|
|
18
|
+
if (!existsSync(deviceIdFile())) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return readFileSync(deviceIdFile(), "utf8").trim() || null;
|
|
22
|
+
}
|
|
23
|
+
function readLastSyncMap() {
|
|
24
|
+
if (!existsSync(lastSyncFile())) {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(readFileSync(lastSyncFile(), "utf8"));
|
|
29
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
30
|
+
return parsed;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
function newestSyncTimestamp(map) {
|
|
39
|
+
const times = Object.values(map).filter((v) => typeof v === "string");
|
|
40
|
+
if (times.length === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return times.reduce((newest, ts) => new Date(ts).getTime() > new Date(newest).getTime() ? ts : newest);
|
|
44
|
+
}
|
|
45
|
+
export async function buildStatus() {
|
|
46
|
+
const paired = await isPaired();
|
|
47
|
+
const syncMap = readLastSyncMap();
|
|
48
|
+
return {
|
|
49
|
+
paired,
|
|
50
|
+
deviceId: readDeviceId(),
|
|
51
|
+
lastSyncAt: newestSyncTimestamp(syncMap),
|
|
52
|
+
// queueDepth and lastError are not yet tracked by the collector;
|
|
53
|
+
// emitted as honest placeholders so the JSON contract is stable.
|
|
54
|
+
queueDepth: 0,
|
|
55
|
+
lastError: null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function runStatus(options = {}) {
|
|
59
|
+
if (options.json) {
|
|
60
|
+
const status = await buildStatus();
|
|
61
|
+
console.log(JSON.stringify(status));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const paired = await isPaired();
|
|
65
|
+
console.log("\nagentsofmine-collector status\n");
|
|
66
|
+
console.log(` Paired: ${paired ? "\x1b[32m✓ yes\x1b[0m" : "\x1b[31m✗ no\x1b[0m"}`);
|
|
67
|
+
if (!paired) {
|
|
68
|
+
console.log("\n Run \x1b[36maom pair\x1b[0m to pair this machine.\n");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Device ID
|
|
72
|
+
if (existsSync(deviceIdFile())) {
|
|
73
|
+
const deviceId = readFileSync(deviceIdFile(), "utf8").trim();
|
|
74
|
+
console.log(` Device ID: \x1b[2m${deviceId}\x1b[0m`);
|
|
75
|
+
}
|
|
76
|
+
// Token presence (never print the token itself)
|
|
77
|
+
const token = await getDeviceToken();
|
|
78
|
+
console.log(` Device token: ${token ? "\x1b[32m✓ present in keychain\x1b[0m" : "\x1b[31m✗ missing\x1b[0m"}`);
|
|
79
|
+
// Last sync timestamps per watcher
|
|
80
|
+
if (existsSync(lastSyncFile())) {
|
|
81
|
+
const raw = readFileSync(lastSyncFile(), "utf8");
|
|
82
|
+
const syncState = JSON.parse(raw);
|
|
83
|
+
console.log("\n Last synced:");
|
|
84
|
+
for (const [watcher, ts] of Object.entries(syncState)) {
|
|
85
|
+
const ago = formatAgo(new Date(ts));
|
|
86
|
+
console.log(` ${watcher.padEnd(16)} ${ago}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
console.log("\n No sessions synced yet.");
|
|
91
|
+
console.log(" Run \x1b[36maom start\x1b[0m to begin syncing.");
|
|
92
|
+
}
|
|
93
|
+
console.log();
|
|
94
|
+
}
|
|
95
|
+
function formatAgo(date) {
|
|
96
|
+
const diffMs = Date.now() - date.getTime();
|
|
97
|
+
const diffSec = Math.floor(diffMs / 1000);
|
|
98
|
+
if (diffSec < 60)
|
|
99
|
+
return `${diffSec}s ago`;
|
|
100
|
+
const diffMin = Math.floor(diffSec / 60);
|
|
101
|
+
if (diffMin < 60)
|
|
102
|
+
return `${diffMin}m ago`;
|
|
103
|
+
const diffHr = Math.floor(diffMin / 60);
|
|
104
|
+
if (diffHr < 24)
|
|
105
|
+
return `${diffHr}h ago`;
|
|
106
|
+
return `${Math.floor(diffHr / 24)}d ago`;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom sync` — one-shot sync of new sessions to the cloud.
|
|
3
|
+
*
|
|
4
|
+
* Presentation only. All orchestration lives in `performSync()`; all
|
|
5
|
+
* ingestion logic lives in the core `runSync()` engine.
|
|
6
|
+
*
|
|
7
|
+
* This is the manual counterpart to the daemon (`aom start`), which runs the
|
|
8
|
+
* same `performSync()` automatically on file changes. Exits non-zero if any
|
|
9
|
+
* session failed to sync, so it is CI-friendly.
|
|
10
|
+
*/
|
|
11
|
+
export interface SyncOptions {
|
|
12
|
+
/** Verbose logging — print per-error detail. */
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function runSyncCommand(opts?: SyncOptions): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=sync.d.ts.map
|
package/dist/cli/sync.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom sync` — one-shot sync of new sessions to the cloud.
|
|
3
|
+
*
|
|
4
|
+
* Presentation only. All orchestration lives in `performSync()`; all
|
|
5
|
+
* ingestion logic lives in the core `runSync()` engine.
|
|
6
|
+
*
|
|
7
|
+
* This is the manual counterpart to the daemon (`aom start`), which runs the
|
|
8
|
+
* same `performSync()` automatically on file changes. Exits non-zero if any
|
|
9
|
+
* session failed to sync, so it is CI-friendly.
|
|
10
|
+
*/
|
|
11
|
+
import { isPaired } from "../keychain/index.js";
|
|
12
|
+
import { performSync, NotPairedError } from "../core/perform-sync.js";
|
|
13
|
+
export async function runSyncCommand(opts = {}) {
|
|
14
|
+
// Guard: must be paired
|
|
15
|
+
if (!(await isPaired())) {
|
|
16
|
+
console.error("✗ This machine is not paired yet.");
|
|
17
|
+
console.error(" Run \x1b[36maom pair\x1b[0m first.");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
console.log("agentsofmine-collector — syncing…\n");
|
|
21
|
+
let summary;
|
|
22
|
+
try {
|
|
23
|
+
summary = await performSync();
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
if (err instanceof NotPairedError) {
|
|
27
|
+
console.error("✗ Device token missing — run \x1b[36maom pair\x1b[0m again.");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
console.log(` ✓ synced ${summary.synced}`);
|
|
33
|
+
if (summary.failed > 0) {
|
|
34
|
+
console.log(` ✗ failed ${summary.failed}`);
|
|
35
|
+
}
|
|
36
|
+
if (opts.verbose && summary.errors.length > 0) {
|
|
37
|
+
console.log("\n Errors:");
|
|
38
|
+
for (const err of summary.errors) {
|
|
39
|
+
console.log(` \x1b[31m${err}\x1b[0m`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (summary.errors.length > 0) {
|
|
43
|
+
console.log(`\n ${summary.errors.length} error(s). Re-run with -v for detail.`);
|
|
44
|
+
}
|
|
45
|
+
console.log();
|
|
46
|
+
if (summary.failed > 0) {
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom unpair` — revoke this device's token and clear the keychain entry.
|
|
3
|
+
*
|
|
4
|
+
* Does NOT call DELETE /devices/{deviceId} automatically (that would require
|
|
5
|
+
* the user to also be signed in to Cognito). Instead it:
|
|
6
|
+
* 1. Clears the device token from the OS keychain.
|
|
7
|
+
* 2. Prints a reminder to revoke the device from the mobile app if desired.
|
|
8
|
+
*
|
|
9
|
+
* The device token becomes useless the moment the backend revokes it
|
|
10
|
+
* (via DELETE /devices/{deviceId} from the mobile app), but clearing it
|
|
11
|
+
* locally is the immediate trust boundary.
|
|
12
|
+
*/
|
|
13
|
+
export interface UnpairOptions {
|
|
14
|
+
/** Skip confirmation prompt. */
|
|
15
|
+
yes?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function runUnpair(opts?: UnpairOptions): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=unpair.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aom unpair` — revoke this device's token and clear the keychain entry.
|
|
3
|
+
*
|
|
4
|
+
* Does NOT call DELETE /devices/{deviceId} automatically (that would require
|
|
5
|
+
* the user to also be signed in to Cognito). Instead it:
|
|
6
|
+
* 1. Clears the device token from the OS keychain.
|
|
7
|
+
* 2. Prints a reminder to revoke the device from the mobile app if desired.
|
|
8
|
+
*
|
|
9
|
+
* The device token becomes useless the moment the backend revokes it
|
|
10
|
+
* (via DELETE /devices/{deviceId} from the mobile app), but clearing it
|
|
11
|
+
* locally is the immediate trust boundary.
|
|
12
|
+
*/
|
|
13
|
+
import { deleteDeviceToken, isPaired } from "../keychain/index.js";
|
|
14
|
+
import { ConfigRepository } from "../infrastructure/config-repository.js";
|
|
15
|
+
export async function runUnpair(opts = {}) {
|
|
16
|
+
if (!(await isPaired())) {
|
|
17
|
+
console.log("This machine is not currently paired — nothing to do.");
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (!opts.yes) {
|
|
21
|
+
const confirmed = await confirm("Remove device token from keychain and stop syncing on this machine? [y/N] ");
|
|
22
|
+
if (!confirmed) {
|
|
23
|
+
console.log("Aborted.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const deleted = await deleteDeviceToken();
|
|
28
|
+
if (deleted) {
|
|
29
|
+
console.log("✓ Device token removed from keychain.");
|
|
30
|
+
}
|
|
31
|
+
new ConfigRepository().clearLocalState();
|
|
32
|
+
console.log("✓ Local collector state cleared.");
|
|
33
|
+
console.log();
|
|
34
|
+
console.log(" To also revoke this device from your account,");
|
|
35
|
+
console.log(" go to \x1b[4mhttps://agentsofmine.io\x1b[0m → Devices → Revoke.");
|
|
36
|
+
console.log();
|
|
37
|
+
console.log(" Run \x1b[36maom pair\x1b[0m to re-pair this machine.");
|
|
38
|
+
}
|
|
39
|
+
function confirm(prompt) {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
process.stdout.write(prompt);
|
|
42
|
+
process.stdin.setEncoding("utf8");
|
|
43
|
+
process.stdin.once("data", (chunk) => {
|
|
44
|
+
const answer = chunk.trim().toLowerCase();
|
|
45
|
+
resolve(answer === "y" || answer === "yes");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=unpair.js.map
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigRepository } from "./infrastructure/config-repository.js";
|
|
2
|
+
export interface Config {
|
|
3
|
+
syncUrl: string;
|
|
4
|
+
deviceId: string;
|
|
5
|
+
deviceToken: string;
|
|
6
|
+
collectorVersion: string;
|
|
7
|
+
opencodeDbPath: string;
|
|
8
|
+
claudeProjectsGlob: string;
|
|
9
|
+
codexSessionsDir: string;
|
|
10
|
+
piSessionsDir: string;
|
|
11
|
+
}
|
|
12
|
+
type KeychainTokenReader = () => Promise<string | null>;
|
|
13
|
+
export declare function loadConfig(readKeychainToken?: KeychainTokenReader, repo?: ConfigRepository): Promise<Config>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { getDeviceToken } from "./keychain/index.js";
|
|
4
|
+
import { ConfigRepository } from "./infrastructure/config-repository.js";
|
|
5
|
+
const version = "0.1.0";
|
|
6
|
+
// Shared singleton for internal use — callers that need richer access
|
|
7
|
+
// should import ConfigRepository directly.
|
|
8
|
+
const configRepo = new ConfigRepository();
|
|
9
|
+
export async function loadConfig(readKeychainToken = getDeviceToken, repo = configRepo) {
|
|
10
|
+
const syncUrl = process.env["AOM_SYNC_URL"] ?? "https://agentsofmine.io/sync";
|
|
11
|
+
// Device ID: env override → config.json → device-id file → fallback
|
|
12
|
+
const deviceId = process.env["AOM_DEVICE_ID"] ??
|
|
13
|
+
repo.readPairingConfig()?.deviceId ??
|
|
14
|
+
repo.readDeviceId() ??
|
|
15
|
+
"dev_local";
|
|
16
|
+
// Device token: env override → config.json field → OS keychain → empty string
|
|
17
|
+
const tokenFromFile = repo.readDeviceToken();
|
|
18
|
+
const deviceToken = process.env["AOM_DEVICE_TOKEN"] ??
|
|
19
|
+
tokenFromFile ??
|
|
20
|
+
(await readKeychainToken()) ??
|
|
21
|
+
"";
|
|
22
|
+
return {
|
|
23
|
+
syncUrl,
|
|
24
|
+
deviceId,
|
|
25
|
+
deviceToken,
|
|
26
|
+
collectorVersion: version,
|
|
27
|
+
opencodeDbPath: join(homedir(), ".local", "share", "opencode", "opencode.db"),
|
|
28
|
+
claudeProjectsGlob: join(homedir(), ".claude", "projects", "*", "*.jsonl"),
|
|
29
|
+
codexSessionsDir: join(homedir(), ".codex", "sessions"),
|
|
30
|
+
piSessionsDir: join(homedir(), ".pi", "agent", "sessions"),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=config.js.map
|