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,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider registry — the single source of truth for which provider ids the
|
|
3
|
+
* collector may emit and the backend will accept.
|
|
4
|
+
*
|
|
5
|
+
* The list lives in `providers.json` (a plain data file) so adding a new
|
|
6
|
+
* provider is a one-line edit, not a code change to the schema. To add a
|
|
7
|
+
* provider end to end:
|
|
8
|
+
* 1. Append its id to `providers.json`.
|
|
9
|
+
* 2. Add an adapter under `src/adapters/<id>/` implementing `Adapter`.
|
|
10
|
+
* 3. Wire it in `src/core/perform-sync.ts` (and a watcher in `cli/start.ts`).
|
|
11
|
+
*
|
|
12
|
+
* The backend (`lambdas/sync/handler.py`) only requires `provider` to be
|
|
13
|
+
* non-empty and stores it verbatim in the session sort key, so no backend
|
|
14
|
+
* change is needed to accept a new id — this registry is the gate.
|
|
15
|
+
*/
|
|
16
|
+
/** Frozen list of known provider ids, loaded from `providers.json`. */
|
|
17
|
+
export declare const KNOWN_PROVIDERS: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* A provider id is just a string at the type level — the concrete set is
|
|
20
|
+
* data-driven via `providers.json`, so the compiler cannot enumerate it.
|
|
21
|
+
* Use {@link isKnownProvider} for runtime validation.
|
|
22
|
+
*/
|
|
23
|
+
export type Provider = string;
|
|
24
|
+
/** True when `value` is a non-empty string registered in `providers.json`. */
|
|
25
|
+
export declare function isKnownProvider(value: unknown): value is Provider;
|
|
26
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider registry — the single source of truth for which provider ids the
|
|
3
|
+
* collector may emit and the backend will accept.
|
|
4
|
+
*
|
|
5
|
+
* The list lives in `providers.json` (a plain data file) so adding a new
|
|
6
|
+
* provider is a one-line edit, not a code change to the schema. To add a
|
|
7
|
+
* provider end to end:
|
|
8
|
+
* 1. Append its id to `providers.json`.
|
|
9
|
+
* 2. Add an adapter under `src/adapters/<id>/` implementing `Adapter`.
|
|
10
|
+
* 3. Wire it in `src/core/perform-sync.ts` (and a watcher in `cli/start.ts`).
|
|
11
|
+
*
|
|
12
|
+
* The backend (`lambdas/sync/handler.py`) only requires `provider` to be
|
|
13
|
+
* non-empty and stores it verbatim in the session sort key, so no backend
|
|
14
|
+
* change is needed to accept a new id — this registry is the gate.
|
|
15
|
+
*/
|
|
16
|
+
import registry from "./providers.json" with { type: "json" };
|
|
17
|
+
/** Frozen list of known provider ids, loaded from `providers.json`. */
|
|
18
|
+
export const KNOWN_PROVIDERS = Object.freeze([
|
|
19
|
+
...new Set(registry.providers),
|
|
20
|
+
]);
|
|
21
|
+
/** True when `value` is a non-empty string registered in `providers.json`. */
|
|
22
|
+
export function isKnownProvider(value) {
|
|
23
|
+
return typeof value === "string" && KNOWN_PROVIDERS.includes(value);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Registry of provider ids the collector is allowed to emit and the backend will accept. To add a provider (e.g. \"pi\"), append its id here, then add the matching adapter under src/adapters/<id>/ and wire it in src/core/perform-sync.ts. The backend stores this value verbatim in the session sort key and only requires it to be non-empty, so no backend change is needed to accept a new id.",
|
|
3
|
+
"providers": ["claude-code", "opencode", "codex", "pi"]
|
|
4
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort secret redaction, applied to every session before it leaves the
|
|
3
|
+
* machine (see `runSync`). This is defense in depth, NOT a guarantee: regex
|
|
4
|
+
* cannot find every secret, and it will occasionally redact something harmless.
|
|
5
|
+
* The goal is to keep the common, recognisable credential formats out of the
|
|
6
|
+
* cloud copy. What it does and does not cover is documented in the README.
|
|
7
|
+
*
|
|
8
|
+
* Design rules:
|
|
9
|
+
* - Pure and idempotent: `redactText(redactText(x)) === redactText(x)`.
|
|
10
|
+
* - Never throws, never mutates its input.
|
|
11
|
+
* - Linear time on hostile input. No rule uses an unbounded lazy match across
|
|
12
|
+
* arbitrary text; private-key blocks are found with `indexOf`, not a regex.
|
|
13
|
+
* - Replacements are markers like `<REDACTED:github-token>` so a transcript
|
|
14
|
+
* stays readable and the kind of secret is visible.
|
|
15
|
+
*/
|
|
16
|
+
import type { SessionWithMessages } from "./canonical.js";
|
|
17
|
+
export interface RedactionRule {
|
|
18
|
+
/** Stable id, used in the `<REDACTED:name>` marker. */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** Global regex. Callers must not rely on `lastIndex`. */
|
|
21
|
+
readonly pattern: RegExp;
|
|
22
|
+
/**
|
|
23
|
+
* Build the replacement. Receives the regex match groups. Defaults to
|
|
24
|
+
* replacing the whole match with the marker.
|
|
25
|
+
*/
|
|
26
|
+
readonly replace?: (...groups: string[]) => string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Regex rules, applied in order. Order matters: specific token formats run
|
|
30
|
+
* before the generic ones so the marker names stay precise (a JWT inside an
|
|
31
|
+
* `Authorization: Bearer` header is reported as a JWT, not a bearer token).
|
|
32
|
+
*/
|
|
33
|
+
export declare const REDACTION_RULES: readonly RedactionRule[];
|
|
34
|
+
/** Redact secrets in a string. Returns the input unchanged when nothing matches. */
|
|
35
|
+
export declare function redactText(text: string): string;
|
|
36
|
+
/** Redact secrets inside arbitrary JSON (tool-call input). Returns a copy. */
|
|
37
|
+
export declare function redactValue(value: unknown, seen?: WeakMap<object, unknown>): unknown;
|
|
38
|
+
/**
|
|
39
|
+
* Redact every free-text field a session carries: title, changed-file paths,
|
|
40
|
+
* and each message part's text, tool input and tool output. Ids, timestamps,
|
|
41
|
+
* roles, counts and image data are left as they are. Returns a new object.
|
|
42
|
+
*/
|
|
43
|
+
export declare function redactSession(session: SessionWithMessages): SessionWithMessages;
|
|
44
|
+
//# sourceMappingURL=redact.d.ts.map
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort secret redaction, applied to every session before it leaves the
|
|
3
|
+
* machine (see `runSync`). This is defense in depth, NOT a guarantee: regex
|
|
4
|
+
* cannot find every secret, and it will occasionally redact something harmless.
|
|
5
|
+
* The goal is to keep the common, recognisable credential formats out of the
|
|
6
|
+
* cloud copy. What it does and does not cover is documented in the README.
|
|
7
|
+
*
|
|
8
|
+
* Design rules:
|
|
9
|
+
* - Pure and idempotent: `redactText(redactText(x)) === redactText(x)`.
|
|
10
|
+
* - Never throws, never mutates its input.
|
|
11
|
+
* - Linear time on hostile input. No rule uses an unbounded lazy match across
|
|
12
|
+
* arbitrary text; private-key blocks are found with `indexOf`, not a regex.
|
|
13
|
+
* - Replacements are markers like `<REDACTED:github-token>` so a transcript
|
|
14
|
+
* stays readable and the kind of secret is visible.
|
|
15
|
+
*/
|
|
16
|
+
const marker = (name) => `<REDACTED:${name}>`;
|
|
17
|
+
/**
|
|
18
|
+
* Regex rules, applied in order. Order matters: specific token formats run
|
|
19
|
+
* before the generic ones so the marker names stay precise (a JWT inside an
|
|
20
|
+
* `Authorization: Bearer` header is reported as a JWT, not a bearer token).
|
|
21
|
+
*/
|
|
22
|
+
export const REDACTION_RULES = [
|
|
23
|
+
{
|
|
24
|
+
// AKIA/ASIA/... followed by 16 upper-case alphanumerics.
|
|
25
|
+
name: "aws-access-key",
|
|
26
|
+
pattern: /(?<![A-Z0-9])(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA|ANVA|AIPA)[A-Z0-9]{16}(?![A-Z0-9])/g,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
// A 40-char base64-ish string is only treated as an AWS secret key when it
|
|
30
|
+
// sits right after its own name; on its own it is indistinguishable from a
|
|
31
|
+
// git SHA or any other blob.
|
|
32
|
+
name: "aws-secret-key",
|
|
33
|
+
pattern: /((?:aws_?secret_?(?:access_?)?key|secret_?access_?key|SecretAccessKey)["']?\s*[:=]\s*["']?)[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])/gi,
|
|
34
|
+
replace: (_m, prefix) => `${prefix}${marker("aws-secret-key")}`,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "github-token",
|
|
38
|
+
pattern: /gh[pousr]_[A-Za-z0-9]{36,255}|github_pat_[A-Za-z0-9_]{22,255}/g,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
// OpenAI / Anthropic style: sk-..., sk-proj-..., sk-ant-...
|
|
42
|
+
name: "api-key",
|
|
43
|
+
pattern: /(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}/g,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "slack-token",
|
|
47
|
+
pattern: /(?<![A-Za-z0-9])xox[abeprs]-[A-Za-z0-9-]{10,}/g,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "jwt",
|
|
51
|
+
pattern: /eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
// `Bearer <token>`. Requires 16+ token characters including a digit, so the
|
|
55
|
+
// prose "Bearer authentication" is left alone.
|
|
56
|
+
name: "bearer-token",
|
|
57
|
+
pattern: /\b(bearer\s+)(?=[A-Za-z0-9._~+/=-]*[0-9])[A-Za-z0-9._~+/=-]{16,}/gi,
|
|
58
|
+
replace: (_m, prefix) => `${prefix}${marker("bearer-token")}`,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
// scheme://user:PASSWORD@host — redact only the password.
|
|
62
|
+
name: "password",
|
|
63
|
+
pattern: /\b([a-z][a-z0-9+.-]{1,20}:\/\/[^\s:@/'"]*:)(?!<REDACTED)[^\s@/'"]+(@)/gi,
|
|
64
|
+
replace: (_m, prefix, at) => `${prefix}${marker("password")}${at}`,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
// ENV_STYLE_NAME=value. Upper-case names only (so `const password = f()`
|
|
68
|
+
// in source code is left alone); the value must be 8+ characters with at
|
|
69
|
+
// least one letter and no code punctuation, which skips `$VAR`,
|
|
70
|
+
// `process.env.X`, `getToken()` and already-redacted markers.
|
|
71
|
+
name: "secret-assignment",
|
|
72
|
+
pattern: /\b([A-Z][A-Z0-9_]*(?:PASSWORD|PASSWD|SECRET|TOKEN|API_?KEY|PRIVATE_?KEY|ACCESS_?KEY)[A-Z0-9_]*["']?\s*[=:]\s*["']?)(?=[^\s"'`(){}<>$,;[\]]*[A-Za-z])[^\s"'`(){}<>$,;[\]]{8,}/g,
|
|
73
|
+
replace: (_m, prefix) => `${prefix}${marker("secret")}`,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
const PRIVATE_KEY_HEADER = /-----BEGIN ((?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?)-----/g;
|
|
77
|
+
/**
|
|
78
|
+
* Replace PEM / PGP private-key blocks. Done with `indexOf` so it is linear
|
|
79
|
+
* however many `BEGIN` markers an input contains. When the matching `END` line
|
|
80
|
+
* is missing (tool output is cut to 500 characters, so this is common) the
|
|
81
|
+
* redaction runs to the end of the text rather than leaving the key body behind.
|
|
82
|
+
*/
|
|
83
|
+
function redactPrivateKeys(text) {
|
|
84
|
+
if (!text.includes("PRIVATE KEY"))
|
|
85
|
+
return text;
|
|
86
|
+
const header = new RegExp(PRIVATE_KEY_HEADER.source, "g");
|
|
87
|
+
let out = "";
|
|
88
|
+
let pos = 0;
|
|
89
|
+
let m;
|
|
90
|
+
while ((m = header.exec(text)) !== null) {
|
|
91
|
+
const label = m[1] ?? "PRIVATE KEY";
|
|
92
|
+
const endMarker = `-----END ${label}-----`;
|
|
93
|
+
const bodyStart = m.index + m[0].length;
|
|
94
|
+
const endIdx = text.indexOf(endMarker, bodyStart);
|
|
95
|
+
const stop = endIdx === -1 ? text.length : endIdx + endMarker.length;
|
|
96
|
+
out += text.slice(pos, m.index) + marker("private-key");
|
|
97
|
+
pos = stop;
|
|
98
|
+
header.lastIndex = stop;
|
|
99
|
+
}
|
|
100
|
+
return pos === 0 ? text : out + text.slice(pos);
|
|
101
|
+
}
|
|
102
|
+
/** Redact secrets in a string. Returns the input unchanged when nothing matches. */
|
|
103
|
+
export function redactText(text) {
|
|
104
|
+
if (text.length === 0)
|
|
105
|
+
return text;
|
|
106
|
+
let out = redactPrivateKeys(text);
|
|
107
|
+
for (const rule of REDACTION_RULES) {
|
|
108
|
+
// A fresh RegExp per call: shared /g regexes keep `lastIndex` between uses.
|
|
109
|
+
const re = new RegExp(rule.pattern.source, rule.pattern.flags);
|
|
110
|
+
const build = rule.replace;
|
|
111
|
+
out = build
|
|
112
|
+
? out.replace(re, (...args) => build(...args))
|
|
113
|
+
: out.replace(re, marker(rule.name));
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Object keys whose string values are secrets however the value looks, e.g.
|
|
119
|
+
* `{ "AWS_SECRET_ACCESS_KEY": "wJalr…" }` in a tool call's JSON input, where
|
|
120
|
+
* the name and the value are separate strings and the text rules cannot pair
|
|
121
|
+
* them.
|
|
122
|
+
*/
|
|
123
|
+
const SENSITIVE_KEY = /^(?:.*[_-])?(?:password|passwd|secret|secret[_-]?key|access[_-]?key|api[_-]?key|apikey|private[_-]?key|client[_-]?secret|auth[_-]?token|access[_-]?token|refresh[_-]?token|token|authorization|credentials?)$/i;
|
|
124
|
+
/** Redact secrets inside arbitrary JSON (tool-call input). Returns a copy. */
|
|
125
|
+
export function redactValue(value, seen = new WeakMap()) {
|
|
126
|
+
if (typeof value === "string")
|
|
127
|
+
return redactText(value);
|
|
128
|
+
if (value === null || typeof value !== "object")
|
|
129
|
+
return value;
|
|
130
|
+
const cached = seen.get(value);
|
|
131
|
+
if (cached !== undefined)
|
|
132
|
+
return cached;
|
|
133
|
+
if (Array.isArray(value)) {
|
|
134
|
+
const copy = [];
|
|
135
|
+
seen.set(value, copy);
|
|
136
|
+
for (const item of value)
|
|
137
|
+
copy.push(redactValue(item, seen));
|
|
138
|
+
return copy;
|
|
139
|
+
}
|
|
140
|
+
const copy = {};
|
|
141
|
+
seen.set(value, copy);
|
|
142
|
+
for (const [key, v] of Object.entries(value)) {
|
|
143
|
+
copy[key] =
|
|
144
|
+
typeof v === "string" && v.length > 0 && SENSITIVE_KEY.test(key)
|
|
145
|
+
? marker("secret")
|
|
146
|
+
: redactValue(v, seen);
|
|
147
|
+
}
|
|
148
|
+
return copy;
|
|
149
|
+
}
|
|
150
|
+
function redactPart(part) {
|
|
151
|
+
const out = { ...part };
|
|
152
|
+
if (part.text !== undefined)
|
|
153
|
+
out.text = redactText(part.text);
|
|
154
|
+
if (part.output !== undefined)
|
|
155
|
+
out.output = redactText(part.output);
|
|
156
|
+
if (part.input !== undefined)
|
|
157
|
+
out.input = redactValue(part.input);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Redact every free-text field a session carries: title, changed-file paths,
|
|
162
|
+
* and each message part's text, tool input and tool output. Ids, timestamps,
|
|
163
|
+
* roles, counts and image data are left as they are. Returns a new object.
|
|
164
|
+
*/
|
|
165
|
+
export function redactSession(session) {
|
|
166
|
+
const out = { ...session };
|
|
167
|
+
if (session.title !== null)
|
|
168
|
+
out.title = redactText(session.title);
|
|
169
|
+
if (session.filesChanged !== null)
|
|
170
|
+
out.filesChanged = session.filesChanged.map(redactText);
|
|
171
|
+
out.extensions = redactValue(session.extensions);
|
|
172
|
+
if (session.messages !== undefined) {
|
|
173
|
+
out.messages = session.messages.map((m) => ({ ...m, parts: m.parts.map(redactPart) }));
|
|
174
|
+
}
|
|
175
|
+
return out;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=redact.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse JSON, returning `null` instead of throwing on invalid input.
|
|
3
|
+
* For call sites that additionally validate the parsed shape, keep that
|
|
4
|
+
* validation at the call site — this only replaces the bare parse-or-null.
|
|
5
|
+
*/
|
|
6
|
+
export declare function safeJsonParse(raw: string): unknown;
|
|
7
|
+
//# sourceMappingURL=safe-json.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse JSON, returning `null` instead of throwing on invalid input.
|
|
3
|
+
* For call sites that additionally validate the parsed shape, keep that
|
|
4
|
+
* validation at the call site — this only replaces the bare parse-or-null.
|
|
5
|
+
*/
|
|
6
|
+
export function safeJsonParse(raw) {
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(raw);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=safe-json.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Adapter } from "../adapters/adapter.js";
|
|
2
|
+
import type { CursorStore } from "./cursor-store.js";
|
|
3
|
+
import { post } from "./http-client.js";
|
|
4
|
+
export interface SyncConfig {
|
|
5
|
+
syncUrl: string;
|
|
6
|
+
deviceId: string;
|
|
7
|
+
collectorVersion: string;
|
|
8
|
+
deviceToken: string;
|
|
9
|
+
batchSize?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SyncSummary {
|
|
12
|
+
synced: number;
|
|
13
|
+
failed: number;
|
|
14
|
+
errors: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare function runSync(adapters: Adapter[], config: SyncConfig, cursorStore: CursorStore, httpPost?: typeof post): Promise<SyncSummary>;
|
|
17
|
+
//# sourceMappingURL=sync-engine.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { post } from "./http-client.js";
|
|
2
|
+
import { redactSession } from "./redact.js";
|
|
3
|
+
export async function runSync(adapters, config, cursorStore, httpPost = post) {
|
|
4
|
+
const batchSize = config.batchSize ?? 5;
|
|
5
|
+
// Every session is redacted here, the single choke point all uploads share
|
|
6
|
+
// (CLI sync, daemon, MCP `sync_now`). AOM_NO_REDACT=1 is a debugging escape
|
|
7
|
+
// hatch; it is loud on purpose.
|
|
8
|
+
const redact = process.env["AOM_NO_REDACT"] !== "1";
|
|
9
|
+
if (!redact) {
|
|
10
|
+
console.error("[aom] WARNING: AOM_NO_REDACT=1 — secrets are NOT being removed before upload.");
|
|
11
|
+
}
|
|
12
|
+
let synced = 0;
|
|
13
|
+
let failed = 0;
|
|
14
|
+
const errors = [];
|
|
15
|
+
for (const adapter of adapters) {
|
|
16
|
+
const cursorValue = cursorStore.get(adapter.name);
|
|
17
|
+
const cursor = { value: cursorValue };
|
|
18
|
+
const batch = [];
|
|
19
|
+
let pendingCursor = null;
|
|
20
|
+
const flush = async () => {
|
|
21
|
+
if (batch.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
try {
|
|
24
|
+
const body = {
|
|
25
|
+
deviceId: config.deviceId,
|
|
26
|
+
collectorVersion: config.collectorVersion,
|
|
27
|
+
sentAt: new Date().toISOString(),
|
|
28
|
+
sessions: redact ? batch.map(redactSession) : [...batch],
|
|
29
|
+
};
|
|
30
|
+
const response = await httpPost(config.syncUrl, body, config.deviceToken);
|
|
31
|
+
synced += response.accepted.length;
|
|
32
|
+
failed += response.rejected.length;
|
|
33
|
+
for (const r of response.rejected) {
|
|
34
|
+
errors.push(`${adapter.name}/${r.sessionId}: ${r.reason}`);
|
|
35
|
+
}
|
|
36
|
+
if (pendingCursor !== null) {
|
|
37
|
+
cursorStore.set(adapter.name, pendingCursor);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
42
|
+
errors.push(`${adapter.name} batch error: ${msg}`);
|
|
43
|
+
failed += batch.length;
|
|
44
|
+
}
|
|
45
|
+
batch.length = 0;
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
for await (const { session, cursor: itemCursor } of adapter.listNewSessions(cursor)) {
|
|
49
|
+
batch.push(session);
|
|
50
|
+
pendingCursor = itemCursor;
|
|
51
|
+
if (batch.length >= batchSize) {
|
|
52
|
+
await flush();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
await flush();
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
59
|
+
errors.push(`${adapter.name} iteration error: ${msg}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { synced, failed, errors };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=sync-engine.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon shared state — passed to all watchers and the MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Holds the device token, verbose flag, sync-timestamp bookkeeping, and an
|
|
5
|
+
* optional reference to the shared SyncRunner so the MCP server can trigger
|
|
6
|
+
* real syncs on session_event pushes.
|
|
7
|
+
*/
|
|
8
|
+
import type { SyncRunner } from "./sync-runner.js";
|
|
9
|
+
export interface DaemonStateOptions {
|
|
10
|
+
deviceToken: string;
|
|
11
|
+
verbose: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class DaemonState {
|
|
14
|
+
readonly deviceToken: string;
|
|
15
|
+
readonly verbose: boolean;
|
|
16
|
+
/** Set by `aom start` once the SyncRunner is constructed. */
|
|
17
|
+
syncRunner: SyncRunner | null;
|
|
18
|
+
constructor(opts: DaemonStateOptions);
|
|
19
|
+
markSynced(watcher: string): void;
|
|
20
|
+
log(msg: string): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon shared state — passed to all watchers and the MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Holds the device token, verbose flag, sync-timestamp bookkeeping, and an
|
|
5
|
+
* optional reference to the shared SyncRunner so the MCP server can trigger
|
|
6
|
+
* real syncs on session_event pushes.
|
|
7
|
+
*/
|
|
8
|
+
import { mkdirSync } from "node:fs";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { recordLastSync } from "../core/last-sync-store.js";
|
|
12
|
+
const STATE_DIR = join(homedir(), ".agentsofmine");
|
|
13
|
+
export class DaemonState {
|
|
14
|
+
deviceToken;
|
|
15
|
+
verbose;
|
|
16
|
+
/** Set by `aom start` once the SyncRunner is constructed. */
|
|
17
|
+
syncRunner = null;
|
|
18
|
+
constructor(opts) {
|
|
19
|
+
this.deviceToken = opts.deviceToken;
|
|
20
|
+
this.verbose = opts.verbose;
|
|
21
|
+
mkdirSync(STATE_DIR, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
markSynced(watcher) {
|
|
24
|
+
recordLastSync(watcher);
|
|
25
|
+
}
|
|
26
|
+
log(msg) {
|
|
27
|
+
if (this.verbose) {
|
|
28
|
+
console.log(`[aom] ${msg}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SyncRunner — debounced, single-flight wrapper around `performSync()`.
|
|
3
|
+
*
|
|
4
|
+
* File watchers and the MCP server fire many events in quick bursts (a single
|
|
5
|
+
* agent session writes many rows/lines). Running a full sync per event would
|
|
6
|
+
* hammer the backend. SyncRunner solves that:
|
|
7
|
+
*
|
|
8
|
+
* - **Debounce:** `trigger()` schedules a sync after a quiet window
|
|
9
|
+
* (`debounceMs`). Each new trigger inside the window resets the timer, so a
|
|
10
|
+
* burst of N events collapses into one sync.
|
|
11
|
+
* - **Single-flight:** never runs two syncs at once. If `trigger()` arrives
|
|
12
|
+
* while a sync is in flight, exactly one follow-up sync is queued to run
|
|
13
|
+
* after the current one finishes (further triggers coalesce into that same
|
|
14
|
+
* follow-up).
|
|
15
|
+
*
|
|
16
|
+
* The runner is provider-agnostic — it just calls `performSync()`, which
|
|
17
|
+
* itself drives all adapters since the last cursor. Any watcher can share one
|
|
18
|
+
* SyncRunner instance.
|
|
19
|
+
*/
|
|
20
|
+
import type { SyncSummary } from "../core/sync-engine.js";
|
|
21
|
+
export interface SyncRunnerOptions {
|
|
22
|
+
/** Quiet window before a triggered sync runs. Default 5000ms. */
|
|
23
|
+
debounceMs?: number;
|
|
24
|
+
/** Log callback (wired to DaemonState.log). */
|
|
25
|
+
log?: (msg: string) => void;
|
|
26
|
+
/** Injectable sync function — defaults to the real `performSync`. For tests. */
|
|
27
|
+
syncFn?: () => Promise<SyncSummary>;
|
|
28
|
+
/** Called after each completed sync with its summary. */
|
|
29
|
+
onSynced?: (summary: SyncSummary) => void;
|
|
30
|
+
}
|
|
31
|
+
export declare class SyncRunner {
|
|
32
|
+
private readonly debounceMs;
|
|
33
|
+
private readonly log;
|
|
34
|
+
private readonly syncFn;
|
|
35
|
+
private readonly onSynced;
|
|
36
|
+
private timer;
|
|
37
|
+
private running;
|
|
38
|
+
/** A trigger arrived while a sync was in flight — run once more after. */
|
|
39
|
+
private rerunQueued;
|
|
40
|
+
constructor(opts?: SyncRunnerOptions);
|
|
41
|
+
/**
|
|
42
|
+
* Request a sync. Coalesces with any pending debounce window and with an
|
|
43
|
+
* in-flight sync (single-flight). Returns immediately; the sync runs async.
|
|
44
|
+
*/
|
|
45
|
+
trigger(reason: string): void;
|
|
46
|
+
/** Run a sync immediately (bypasses debounce). Still single-flight. */
|
|
47
|
+
runNow(): Promise<void>;
|
|
48
|
+
/** Cancel any pending debounced sync. In-flight syncs are not interrupted. */
|
|
49
|
+
stop(): void;
|
|
50
|
+
private run;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=sync-runner.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SyncRunner — debounced, single-flight wrapper around `performSync()`.
|
|
3
|
+
*
|
|
4
|
+
* File watchers and the MCP server fire many events in quick bursts (a single
|
|
5
|
+
* agent session writes many rows/lines). Running a full sync per event would
|
|
6
|
+
* hammer the backend. SyncRunner solves that:
|
|
7
|
+
*
|
|
8
|
+
* - **Debounce:** `trigger()` schedules a sync after a quiet window
|
|
9
|
+
* (`debounceMs`). Each new trigger inside the window resets the timer, so a
|
|
10
|
+
* burst of N events collapses into one sync.
|
|
11
|
+
* - **Single-flight:** never runs two syncs at once. If `trigger()` arrives
|
|
12
|
+
* while a sync is in flight, exactly one follow-up sync is queued to run
|
|
13
|
+
* after the current one finishes (further triggers coalesce into that same
|
|
14
|
+
* follow-up).
|
|
15
|
+
*
|
|
16
|
+
* The runner is provider-agnostic — it just calls `performSync()`, which
|
|
17
|
+
* itself drives all adapters since the last cursor. Any watcher can share one
|
|
18
|
+
* SyncRunner instance.
|
|
19
|
+
*/
|
|
20
|
+
import { performSync, NotPairedError } from "../core/perform-sync.js";
|
|
21
|
+
export class SyncRunner {
|
|
22
|
+
debounceMs;
|
|
23
|
+
log;
|
|
24
|
+
syncFn;
|
|
25
|
+
onSynced;
|
|
26
|
+
timer = null;
|
|
27
|
+
running = false;
|
|
28
|
+
/** A trigger arrived while a sync was in flight — run once more after. */
|
|
29
|
+
rerunQueued = false;
|
|
30
|
+
constructor(opts = {}) {
|
|
31
|
+
this.debounceMs = opts.debounceMs ?? 5000;
|
|
32
|
+
this.log = opts.log ?? (() => { });
|
|
33
|
+
this.syncFn = opts.syncFn ?? performSync;
|
|
34
|
+
this.onSynced = opts.onSynced;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Request a sync. Coalesces with any pending debounce window and with an
|
|
38
|
+
* in-flight sync (single-flight). Returns immediately; the sync runs async.
|
|
39
|
+
*/
|
|
40
|
+
trigger(reason) {
|
|
41
|
+
this.log(`sync trigger: ${reason}`);
|
|
42
|
+
if (this.running) {
|
|
43
|
+
// A sync is in flight — guarantee one more pass after it completes so
|
|
44
|
+
// changes that landed mid-sync are not missed.
|
|
45
|
+
this.rerunQueued = true;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.timer) {
|
|
49
|
+
clearTimeout(this.timer);
|
|
50
|
+
}
|
|
51
|
+
this.timer = setTimeout(() => {
|
|
52
|
+
this.timer = null;
|
|
53
|
+
void this.run();
|
|
54
|
+
}, this.debounceMs);
|
|
55
|
+
}
|
|
56
|
+
/** Run a sync immediately (bypasses debounce). Still single-flight. */
|
|
57
|
+
async runNow() {
|
|
58
|
+
if (this.timer) {
|
|
59
|
+
clearTimeout(this.timer);
|
|
60
|
+
this.timer = null;
|
|
61
|
+
}
|
|
62
|
+
await this.run();
|
|
63
|
+
}
|
|
64
|
+
/** Cancel any pending debounced sync. In-flight syncs are not interrupted. */
|
|
65
|
+
stop() {
|
|
66
|
+
if (this.timer) {
|
|
67
|
+
clearTimeout(this.timer);
|
|
68
|
+
this.timer = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async run() {
|
|
72
|
+
if (this.running) {
|
|
73
|
+
this.rerunQueued = true;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.running = true;
|
|
77
|
+
try {
|
|
78
|
+
const summary = await this.syncFn();
|
|
79
|
+
this.log(`sync done: synced=${summary.synced} failed=${summary.failed}`);
|
|
80
|
+
if (summary.errors.length > 0) {
|
|
81
|
+
this.log(`sync errors: ${summary.errors.slice(0, 3).join("; ")}`);
|
|
82
|
+
}
|
|
83
|
+
this.onSynced?.(summary);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (err instanceof NotPairedError) {
|
|
87
|
+
this.log("sync skipped: not paired");
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
91
|
+
this.log(`sync error: ${msg}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
this.running = false;
|
|
96
|
+
}
|
|
97
|
+
// A trigger arrived while we were syncing — run exactly one more pass.
|
|
98
|
+
if (this.rerunQueued) {
|
|
99
|
+
this.rerunQueued = false;
|
|
100
|
+
await this.run();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=sync-runner.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { loadConfig } from "./config.js";
|
|
5
|
+
import { cursorStore } from "./core/cursor-store.js";
|
|
6
|
+
import { OpenCodeAdapter } from "./adapters/opencode/index.js";
|
|
7
|
+
import { ClaudeCodeAdapter } from "./adapters/claude-code/index.js";
|
|
8
|
+
import { CodexAdapter } from "./adapters/codex/index.js";
|
|
9
|
+
import { PiAdapter } from "./adapters/pi/index.js";
|
|
10
|
+
import { syncNow } from "./mcp-tools/sync-now.js";
|
|
11
|
+
import { getStatusPayload } from "./mcp-tools/status.js";
|
|
12
|
+
const config = await loadConfig();
|
|
13
|
+
const adapters = [
|
|
14
|
+
new OpenCodeAdapter(config.opencodeDbPath),
|
|
15
|
+
new ClaudeCodeAdapter(config.claudeProjectsGlob),
|
|
16
|
+
new CodexAdapter(config.codexSessionsDir),
|
|
17
|
+
new PiAdapter(config.piSessionsDir),
|
|
18
|
+
];
|
|
19
|
+
const syncConfig = {
|
|
20
|
+
syncUrl: config.syncUrl,
|
|
21
|
+
deviceId: config.deviceId,
|
|
22
|
+
deviceToken: config.deviceToken,
|
|
23
|
+
collectorVersion: config.collectorVersion,
|
|
24
|
+
};
|
|
25
|
+
const server = new Server({ name: "agentsofmine-collector", version: config.collectorVersion }, { capabilities: { tools: {} } });
|
|
26
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
27
|
+
tools: [
|
|
28
|
+
{
|
|
29
|
+
name: "sync_now",
|
|
30
|
+
description: "Trigger an immediate sync of all agent sessions to AgentsOfMine backend.",
|
|
31
|
+
inputSchema: { type: "object", properties: {}, required: [] },
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "status",
|
|
35
|
+
description: "Return the result of the last sync operation.",
|
|
36
|
+
inputSchema: { type: "object", properties: {}, required: [] },
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}));
|
|
40
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
41
|
+
const { name } = request.params;
|
|
42
|
+
if (name === "sync_now") {
|
|
43
|
+
const result = await syncNow(adapters, syncConfig, cursorStore);
|
|
44
|
+
return {
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
type: "text",
|
|
48
|
+
text: JSON.stringify(result, null, 2),
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (name === "status") {
|
|
54
|
+
const status = getStatusPayload();
|
|
55
|
+
return {
|
|
56
|
+
content: [
|
|
57
|
+
{
|
|
58
|
+
type: "text",
|
|
59
|
+
text: JSON.stringify(status, null, 2),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
65
|
+
});
|
|
66
|
+
const transport = new StdioServerTransport();
|
|
67
|
+
await server.connect(transport);
|
|
68
|
+
//# sourceMappingURL=index.js.map
|