@gtc6244/immediacy-daemon 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/dist/src/actions.d.ts +22 -0
- package/dist/src/actions.js +44 -0
- package/dist/src/actions.js.map +1 -0
- package/dist/src/agent/agent.d.ts +89 -0
- package/dist/src/agent/agent.js +22 -0
- package/dist/src/agent/agent.js.map +1 -0
- package/dist/src/agent/claude.d.ts +70 -0
- package/dist/src/agent/claude.js +404 -0
- package/dist/src/agent/claude.js.map +1 -0
- package/dist/src/agent/codex.d.ts +44 -0
- package/dist/src/agent/codex.js +303 -0
- package/dist/src/agent/codex.js.map +1 -0
- package/dist/src/agent/mock.d.ts +31 -0
- package/dist/src/agent/mock.js +155 -0
- package/dist/src/agent/mock.js.map +1 -0
- package/dist/src/agent/model-error.d.ts +8 -0
- package/dist/src/agent/model-error.js +25 -0
- package/dist/src/agent/model-error.js.map +1 -0
- package/dist/src/agent/openrouter.d.ts +38 -0
- package/dist/src/agent/openrouter.js +60 -0
- package/dist/src/agent/openrouter.js.map +1 -0
- package/dist/src/agent/workspace-scope.d.ts +25 -0
- package/dist/src/agent/workspace-scope.js +71 -0
- package/dist/src/agent/workspace-scope.js.map +1 -0
- package/dist/src/allowlist.d.ts +56 -0
- package/dist/src/allowlist.js +141 -0
- package/dist/src/allowlist.js.map +1 -0
- package/dist/src/chatlog.d.ts +50 -0
- package/dist/src/chatlog.js +179 -0
- package/dist/src/chatlog.js.map +1 -0
- package/dist/src/cli/paths.d.ts +40 -0
- package/dist/src/cli/paths.js +76 -0
- package/dist/src/cli/paths.js.map +1 -0
- package/dist/src/cli/service.d.ts +20 -0
- package/dist/src/cli/service.js +245 -0
- package/dist/src/cli/service.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +227 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/config.d.ts +33 -0
- package/dist/src/config.js +122 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/credentials.d.ts +38 -0
- package/dist/src/credentials.js +120 -0
- package/dist/src/credentials.js.map +1 -0
- package/dist/src/crypto.d.ts +49 -0
- package/dist/src/crypto.js +202 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/daemon-identity.d.ts +31 -0
- package/dist/src/daemon-identity.js +97 -0
- package/dist/src/daemon-identity.js.map +1 -0
- package/dist/src/envelope.d.ts +14 -0
- package/dist/src/envelope.js +28 -0
- package/dist/src/envelope.js.map +1 -0
- package/dist/src/events.d.ts +40 -0
- package/dist/src/events.js +24 -0
- package/dist/src/events.js.map +1 -0
- package/dist/src/forward.d.ts +51 -0
- package/dist/src/forward.js +170 -0
- package/dist/src/forward.js.map +1 -0
- package/dist/src/fs-scope.d.ts +17 -0
- package/dist/src/fs-scope.js +47 -0
- package/dist/src/fs-scope.js.map +1 -0
- package/dist/src/github.d.ts +70 -0
- package/dist/src/github.js +178 -0
- package/dist/src/github.js.map +1 -0
- package/dist/src/gitops.d.ts +113 -0
- package/dist/src/gitops.js +557 -0
- package/dist/src/gitops.js.map +1 -0
- package/dist/src/hub.d.ts +50 -0
- package/dist/src/hub.js +92 -0
- package/dist/src/hub.js.map +1 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.js +56 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/jobs/scheduler.d.ts +94 -0
- package/dist/src/jobs/scheduler.js +373 -0
- package/dist/src/jobs/scheduler.js.map +1 -0
- package/dist/src/jobs/store.d.ts +33 -0
- package/dist/src/jobs/store.js +111 -0
- package/dist/src/jobs/store.js.map +1 -0
- package/dist/src/log.d.ts +61 -0
- package/dist/src/log.js +166 -0
- package/dist/src/log.js.map +1 -0
- package/dist/src/migrate-state-dir.d.ts +1 -0
- package/dist/src/migrate-state-dir.js +47 -0
- package/dist/src/migrate-state-dir.js.map +1 -0
- package/dist/src/models.d.ts +36 -0
- package/dist/src/models.js +71 -0
- package/dist/src/models.js.map +1 -0
- package/dist/src/permission-gate.d.ts +48 -0
- package/dist/src/permission-gate.js +93 -0
- package/dist/src/permission-gate.js.map +1 -0
- package/dist/src/permission-scope.d.ts +77 -0
- package/dist/src/permission-scope.js +244 -0
- package/dist/src/permission-scope.js.map +1 -0
- package/dist/src/ports.d.ts +71 -0
- package/dist/src/ports.js +216 -0
- package/dist/src/ports.js.map +1 -0
- package/dist/src/projects.d.ts +83 -0
- package/dist/src/projects.js +205 -0
- package/dist/src/projects.js.map +1 -0
- package/dist/src/protocol.d.ts +1226 -0
- package/dist/src/protocol.js +16 -0
- package/dist/src/protocol.js.map +1 -0
- package/dist/src/repo-sync.d.ts +49 -0
- package/dist/src/repo-sync.js +83 -0
- package/dist/src/repo-sync.js.map +1 -0
- package/dist/src/server.d.ts +33 -0
- package/dist/src/server.js +973 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/terminal.d.ts +32 -0
- package/dist/src/terminal.js +92 -0
- package/dist/src/terminal.js.map +1 -0
- package/dist/src/titler.d.ts +15 -0
- package/dist/src/titler.js +72 -0
- package/dist/src/titler.js.map +1 -0
- package/dist/src/types.d.ts +99 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/usage-limit.d.ts +49 -0
- package/dist/src/usage-limit.js +83 -0
- package/dist/src/usage-limit.js.map +1 -0
- package/dist/src/usage.d.ts +23 -0
- package/dist/src/usage.js +63 -0
- package/dist/src/usage.js.map +1 -0
- package/dist/src/workspace.d.ts +303 -0
- package/dist/src/workspace.js +1086 -0
- package/dist/src/workspace.js.map +1 -0
- package/dist/src/worktree.d.ts +133 -0
- package/dist/src/worktree.js +561 -0
- package/dist/src/worktree.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../../src/jobs/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACz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C5B,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC/D,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,SAAS,YAAY,CAAC,CAAkB;IACtC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACnE,CAAC,CAAC,IAAI,EAAE,CAAC;IACX,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,SAAS,OAAO,CAAC,GAAY;IAC3B,OAAO,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JobStore — durable persistence for cron/scheduled jobs and their run history.
|
|
3
|
+
*
|
|
4
|
+
* Two files under `~/.immediacy/`, each following an existing daemon pattern:
|
|
5
|
+
* - `jobs.json` — snapshot of every JobRecord (like `state.json`).
|
|
6
|
+
* - `job-runs.jsonl` — append-only run log (like a ChatLog), one JobRun/line.
|
|
7
|
+
*
|
|
8
|
+
* Definitions are few and mutated rarely, so the whole set is rewritten on every
|
|
9
|
+
* change. Runs are frequent and append-only, so they chain onto a single write
|
|
10
|
+
* promise (mirroring ChatLog) and the in-memory view is capped — the file is the
|
|
11
|
+
* full history, memory holds the most recent tail for fast `job.runs` replies.
|
|
12
|
+
*/
|
|
13
|
+
import type { JobRecord, JobRun } from "../protocol.js";
|
|
14
|
+
export declare class JobStore {
|
|
15
|
+
private jobsFile;
|
|
16
|
+
private runsFile;
|
|
17
|
+
private jobs;
|
|
18
|
+
private runs;
|
|
19
|
+
/** Serializes appends to the single runs file so lines never interleave. */
|
|
20
|
+
private runsChain;
|
|
21
|
+
constructor(jobsFile?: string, runsFile?: string);
|
|
22
|
+
load(): Promise<void>;
|
|
23
|
+
list(): JobRecord[];
|
|
24
|
+
get(id: string): JobRecord | undefined;
|
|
25
|
+
/** Insert or replace a job definition, then persist the snapshot. */
|
|
26
|
+
upsert(job: JobRecord): Promise<void>;
|
|
27
|
+
delete(id: string): Promise<boolean>;
|
|
28
|
+
/** Append a run to memory + the JSONL log (fire-and-forget, order-preserving). */
|
|
29
|
+
appendRun(run: JobRun): Promise<void>;
|
|
30
|
+
/** Recent runs, newest first; optionally scoped to one job. */
|
|
31
|
+
runsFor(jobId?: string, limit?: number): JobRun[];
|
|
32
|
+
private persistJobs;
|
|
33
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JobStore — durable persistence for cron/scheduled jobs and their run history.
|
|
3
|
+
*
|
|
4
|
+
* Two files under `~/.immediacy/`, each following an existing daemon pattern:
|
|
5
|
+
* - `jobs.json` — snapshot of every JobRecord (like `state.json`).
|
|
6
|
+
* - `job-runs.jsonl` — append-only run log (like a ChatLog), one JobRun/line.
|
|
7
|
+
*
|
|
8
|
+
* Definitions are few and mutated rarely, so the whole set is rewritten on every
|
|
9
|
+
* change. Runs are frequent and append-only, so they chain onto a single write
|
|
10
|
+
* promise (mirroring ChatLog) and the in-memory view is capped — the file is the
|
|
11
|
+
* full history, memory holds the most recent tail for fast `job.runs` replies.
|
|
12
|
+
*/
|
|
13
|
+
import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { logger } from "../log.js";
|
|
16
|
+
import { dirname, join } from "node:path";
|
|
17
|
+
const JOBS_FILE = process.env.JOBS_FILE ?? join(homedir(), ".immediacy", "jobs.json");
|
|
18
|
+
const JOB_RUNS_FILE = process.env.JOB_RUNS_FILE ?? join(homedir(), ".immediacy", "job-runs.jsonl");
|
|
19
|
+
/** How many recent runs to keep in memory (the file keeps them all). */
|
|
20
|
+
const RUNS_MEMORY_CAP = 500;
|
|
21
|
+
export class JobStore {
|
|
22
|
+
jobsFile;
|
|
23
|
+
runsFile;
|
|
24
|
+
jobs = new Map();
|
|
25
|
+
runs = []; // most-recent-last, capped to RUNS_MEMORY_CAP
|
|
26
|
+
/** Serializes appends to the single runs file so lines never interleave. */
|
|
27
|
+
runsChain = Promise.resolve();
|
|
28
|
+
constructor(jobsFile = JOBS_FILE, runsFile = JOB_RUNS_FILE) {
|
|
29
|
+
this.jobsFile = jobsFile;
|
|
30
|
+
this.runsFile = runsFile;
|
|
31
|
+
}
|
|
32
|
+
async load() {
|
|
33
|
+
try {
|
|
34
|
+
const raw = await readFile(this.jobsFile, "utf8");
|
|
35
|
+
const records = JSON.parse(raw);
|
|
36
|
+
for (const r of records)
|
|
37
|
+
this.jobs.set(r.id, r);
|
|
38
|
+
console.log(`[jobs] restored ${this.jobs.size} job(s)`);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
/* no prior jobs */
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const raw = await readFile(this.runsFile, "utf8");
|
|
45
|
+
for (const line of raw.split("\n")) {
|
|
46
|
+
if (line.trim().length === 0)
|
|
47
|
+
continue;
|
|
48
|
+
try {
|
|
49
|
+
this.runs.push(JSON.parse(line));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Skip a half-written final line (hard kill), keep the rest.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (this.runs.length > RUNS_MEMORY_CAP) {
|
|
56
|
+
this.runs = this.runs.slice(-RUNS_MEMORY_CAP);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
/* no prior runs */
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
list() {
|
|
64
|
+
return [...this.jobs.values()];
|
|
65
|
+
}
|
|
66
|
+
get(id) {
|
|
67
|
+
return this.jobs.get(id);
|
|
68
|
+
}
|
|
69
|
+
/** Insert or replace a job definition, then persist the snapshot. */
|
|
70
|
+
async upsert(job) {
|
|
71
|
+
this.jobs.set(job.id, job);
|
|
72
|
+
await this.persistJobs();
|
|
73
|
+
}
|
|
74
|
+
async delete(id) {
|
|
75
|
+
const existed = this.jobs.delete(id);
|
|
76
|
+
if (existed)
|
|
77
|
+
await this.persistJobs();
|
|
78
|
+
return existed;
|
|
79
|
+
}
|
|
80
|
+
/** Append a run to memory + the JSONL log (fire-and-forget, order-preserving). */
|
|
81
|
+
appendRun(run) {
|
|
82
|
+
this.runs.push(run);
|
|
83
|
+
if (this.runs.length > RUNS_MEMORY_CAP)
|
|
84
|
+
this.runs.shift();
|
|
85
|
+
this.runsChain = this.runsChain
|
|
86
|
+
.catch(() => { }) // a failed prior append must not poison the chain
|
|
87
|
+
.then(async () => {
|
|
88
|
+
try {
|
|
89
|
+
await mkdir(dirname(this.runsFile), { recursive: true });
|
|
90
|
+
await appendFile(this.runsFile, JSON.stringify(run) + "\n", "utf8");
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
logger.error("error", "job run append failed", {
|
|
94
|
+
data: { message: err instanceof Error ? err.message : String(err) },
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return this.runsChain;
|
|
99
|
+
}
|
|
100
|
+
/** Recent runs, newest first; optionally scoped to one job. */
|
|
101
|
+
runsFor(jobId, limit = 100) {
|
|
102
|
+
const cap = Math.min(Math.max(limit, 1), RUNS_MEMORY_CAP);
|
|
103
|
+
const filtered = jobId ? this.runs.filter((r) => r.jobId === jobId) : this.runs;
|
|
104
|
+
return filtered.slice(-cap).reverse();
|
|
105
|
+
}
|
|
106
|
+
async persistJobs() {
|
|
107
|
+
await mkdir(dirname(this.jobsFile), { recursive: true });
|
|
108
|
+
await writeFile(this.jobsFile, JSON.stringify(this.list(), null, 2), "utf8");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../src/jobs/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAG1C,MAAM,SAAS,GACb,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AACtE,MAAM,aAAa,GACjB,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAC;AAE/E,wEAAwE;AACxE,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,OAAO,QAAQ;IAOT;IACA;IAPF,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC;IACpC,IAAI,GAAa,EAAE,CAAC,CAAC,8CAA8C;IAC3E,4EAA4E;IACpE,SAAS,GAAkB,OAAO,CAAC,OA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ories, feeding three sinks:
|
|
5
|
+
* 1. an in-memory ring buffer (last N entries) for an instant tail when a
|
|
6
|
+
* client opens the Logs pane — no disk read on the hot path;
|
|
7
|
+
* 2. a size-capped JSONL file at ~/.immediacy/logs/daemon.jsonl (one .1
|
|
8
|
+
* generation kept) so a launchd-run daemon leaves a durable, bounded trail
|
|
9
|
+
* after its stderr is gone;
|
|
10
|
+
* 3. an optional live sink (wired to `hub.broadcast("log.event", …)` in
|
|
11
|
+
* server.ts) so subscribed clients see entries as they happen.
|
|
12
|
+
*
|
|
13
|
+
* `seq` is a monotonic counter (resets to 0 on restart) and is the ordering +
|
|
14
|
+
* dedup key across the ring/file/live sinks — clients render ascending `seq`.
|
|
15
|
+
*
|
|
16
|
+
* Secrets never reach here: `data` is allowlisted at each call site (no NaCl
|
|
17
|
+
* keys, Access tokens, or device `pub` values). `log-test.ts` scans emitted
|
|
18
|
+
* entries to keep that honest.
|
|
19
|
+
*
|
|
20
|
+
* stderr still gets one human line per captured entry, preserving the old
|
|
21
|
+
* `[tag] …` feel of `npm run dev`.
|
|
22
|
+
*/
|
|
23
|
+
import type { LogCategory, LogEntry, LogLevel } from "./protocol.js";
|
|
24
|
+
export interface LogOpts {
|
|
25
|
+
ws?: string;
|
|
26
|
+
data?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** A live consumer of entries (server wires this to the hub broadcast). */
|
|
29
|
+
export type LogSink = (entry: LogEntry) => void;
|
|
30
|
+
export declare class Logger {
|
|
31
|
+
private seq;
|
|
32
|
+
private ring;
|
|
33
|
+
private sink;
|
|
34
|
+
/** Serialize disk writes so an append can't interleave with a rotation. */
|
|
35
|
+
private writeChain;
|
|
36
|
+
/** Bytes currently in daemon.jsonl (tracked so we don't stat on every line). */
|
|
37
|
+
private bytes;
|
|
38
|
+
private started;
|
|
39
|
+
/**
|
|
40
|
+
* Best-effort startup: if a prior run left an oversized file, rotate it once
|
|
41
|
+
* so this run starts within the cap. The ring intentionally starts empty —
|
|
42
|
+
* the file is the durable record; the ring is just the fast-tail cache.
|
|
43
|
+
*/
|
|
44
|
+
start(): Promise<void>;
|
|
45
|
+
/** Point live entries at a sink (idempotent; last one wins). */
|
|
46
|
+
setSink(sink: LogSink | null): void;
|
|
47
|
+
/** The most recent entries, ascending by `seq`, for a fresh client tail. */
|
|
48
|
+
tail(limit?: number, sinceSeq?: number): LogEntry[];
|
|
49
|
+
log(level: LogLevel, cat: LogCategory, msg: string, opts?: LogOpts): void;
|
|
50
|
+
debug(cat: LogCategory, msg: string, opts?: LogOpts): void;
|
|
51
|
+
info(cat: LogCategory, msg: string, opts?: LogOpts): void;
|
|
52
|
+
warn(cat: LogCategory, msg: string, opts?: LogOpts): void;
|
|
53
|
+
error(cat: LogCategory, msg: string, opts?: LogOpts): void;
|
|
54
|
+
/** Flush any queued disk writes — used by tests to await persistence. */
|
|
55
|
+
flush(): Promise<void>;
|
|
56
|
+
private persist;
|
|
57
|
+
/** daemon.jsonl → daemon.jsonl.1 (overwriting any prior .1); start fresh. */
|
|
58
|
+
private rotate;
|
|
59
|
+
}
|
|
60
|
+
/** Process-wide singleton. Construct order doesn't matter; `start()` is idempotent. */
|
|
61
|
+
export declare const logger: Logger;
|
package/dist/src/log.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daemon structured logger — the observability spine.
|
|
3
|
+
*
|
|
4
|
+
* One process-wide log with levels + categories, feeding three sinks:
|
|
5
|
+
* 1. an in-memory ring buffer (last N entries) for an instant tail when a
|
|
6
|
+
* client opens the Logs pane — no disk read on the hot path;
|
|
7
|
+
* 2. a size-capped JSONL file at ~/.immediacy/logs/daemon.jsonl (one .1
|
|
8
|
+
* generation kept) so a launchd-run daemon leaves a durable, bounded trail
|
|
9
|
+
* after its stderr is gone;
|
|
10
|
+
* 3. an optional live sink (wired to `hub.broadcast("log.event", …)` in
|
|
11
|
+
* server.ts) so subscribed clients see entries as they happen.
|
|
12
|
+
*
|
|
13
|
+
* `seq` is a monotonic counter (resets to 0 on restart) and is the ordering +
|
|
14
|
+
* dedup key across the ring/file/live sinks — clients render ascending `seq`.
|
|
15
|
+
*
|
|
16
|
+
* Secrets never reach here: `data` is allowlisted at each call site (no NaCl
|
|
17
|
+
* keys, Access tokens, or device `pub` values). `log-test.ts` scans emitted
|
|
18
|
+
* entries to keep that honest.
|
|
19
|
+
*
|
|
20
|
+
* stderr still gets one human line per captured entry, preserving the old
|
|
21
|
+
* `[tag] …` feel of `npm run dev`.
|
|
22
|
+
*/
|
|
23
|
+
import { appendFile, mkdir, rename, stat, writeFile } from "node:fs/promises";
|
|
24
|
+
import { homedir } from "node:os";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
const LOG_DIR = process.env.LOG_DIR ?? join(homedir(), ".immediacy", "logs");
|
|
27
|
+
const LOG_FILE = join(LOG_DIR, "daemon.jsonl");
|
|
28
|
+
const LOG_FILE_PREV = join(LOG_DIR, "daemon.jsonl.1");
|
|
29
|
+
const RING_SIZE = 500;
|
|
30
|
+
/** Rotate the JSONL once it would exceed this; one .1 generation → ~2× ceiling. */
|
|
31
|
+
const MAX_BYTES = Number(process.env.LOG_MAX_BYTES) || 2 * 1024 * 1024;
|
|
32
|
+
/** `debug` is dropped unless this is set — same env-flag feel as DEBUG_WIRE. */
|
|
33
|
+
const DEBUG_ON = process.env.LOG_DEBUG === "1";
|
|
34
|
+
const LEVEL_RANK = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
35
|
+
export class Logger {
|
|
36
|
+
seq = 0;
|
|
37
|
+
ring = [];
|
|
38
|
+
sink = null;
|
|
39
|
+
/** Serialize disk writes so an append can't interleave with a rotation. */
|
|
40
|
+
writeChain = Promise.resolve();
|
|
41
|
+
/** Bytes currently in daemon.jsonl (tracked so we don't stat on every line). */
|
|
42
|
+
bytes = 0;
|
|
43
|
+
started = false;
|
|
44
|
+
/**
|
|
45
|
+
* Best-effort startup: if a prior run left an oversized file, rotate it once
|
|
46
|
+
* so this run starts within the cap. The ring intentionally starts empty —
|
|
47
|
+
* the file is the durable record; the ring is just the fast-tail cache.
|
|
48
|
+
*/
|
|
49
|
+
async start() {
|
|
50
|
+
if (this.started)
|
|
51
|
+
return;
|
|
52
|
+
this.started = true;
|
|
53
|
+
try {
|
|
54
|
+
const s = await stat(LOG_FILE);
|
|
55
|
+
this.bytes = s.size;
|
|
56
|
+
if (this.bytes > MAX_BYTES)
|
|
57
|
+
await this.rotate();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
this.bytes = 0; // no file yet
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Point live entries at a sink (idempotent; last one wins). */
|
|
64
|
+
setSink(sink) {
|
|
65
|
+
this.sink = sink;
|
|
66
|
+
}
|
|
67
|
+
/** The most recent entries, ascending by `seq`, for a fresh client tail. */
|
|
68
|
+
tail(limit = 200, sinceSeq) {
|
|
69
|
+
let out = this.ring;
|
|
70
|
+
if (sinceSeq !== undefined)
|
|
71
|
+
out = out.filter((e) => e.seq > sinceSeq);
|
|
72
|
+
const n = Math.max(0, Math.min(limit, RING_SIZE));
|
|
73
|
+
return out.slice(-n);
|
|
74
|
+
}
|
|
75
|
+
log(level, cat, msg, opts) {
|
|
76
|
+
if (level === "debug" && !DEBUG_ON)
|
|
77
|
+
return;
|
|
78
|
+
const entry = {
|
|
79
|
+
seq: this.seq++,
|
|
80
|
+
ts: Date.now(),
|
|
81
|
+
level,
|
|
82
|
+
cat,
|
|
83
|
+
msg,
|
|
84
|
+
...(opts?.ws ? { ws: opts.ws } : {}),
|
|
85
|
+
...(opts?.data ? { data: opts.data } : {}),
|
|
86
|
+
};
|
|
87
|
+
// 1. ring
|
|
88
|
+
this.ring.push(entry);
|
|
89
|
+
if (this.ring.length > RING_SIZE)
|
|
90
|
+
this.ring.shift();
|
|
91
|
+
// 2. stderr — one human line, matching the old [tag] feel
|
|
92
|
+
const line = `${new Date(entry.ts).toISOString()} ${level
|
|
93
|
+
.toUpperCase()
|
|
94
|
+
.padEnd(5)} [${cat}] ${msg}`;
|
|
95
|
+
if (LEVEL_RANK[level] >= LEVEL_RANK.warn)
|
|
96
|
+
console.error(line);
|
|
97
|
+
else
|
|
98
|
+
console.log(line);
|
|
99
|
+
// 3. live sink (subscribed clients)
|
|
100
|
+
try {
|
|
101
|
+
this.sink?.(entry);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
/* a broken sink must never break logging */
|
|
105
|
+
}
|
|
106
|
+
// 4. durable JSONL (serialized, best-effort)
|
|
107
|
+
this.persist(entry);
|
|
108
|
+
}
|
|
109
|
+
debug(cat, msg, opts) {
|
|
110
|
+
this.log("debug", cat, msg, opts);
|
|
111
|
+
}
|
|
112
|
+
info(cat, msg, opts) {
|
|
113
|
+
this.log("info", cat, msg, opts);
|
|
114
|
+
}
|
|
115
|
+
warn(cat, msg, opts) {
|
|
116
|
+
this.log("warn", cat, msg, opts);
|
|
117
|
+
}
|
|
118
|
+
error(cat, msg, opts) {
|
|
119
|
+
this.log("error", cat, msg, opts);
|
|
120
|
+
}
|
|
121
|
+
/** Flush any queued disk writes — used by tests to await persistence. */
|
|
122
|
+
async flush() {
|
|
123
|
+
await this.writeChain;
|
|
124
|
+
}
|
|
125
|
+
persist(entry) {
|
|
126
|
+
const record = JSON.stringify(entry) + "\n";
|
|
127
|
+
const size = Buffer.byteLength(record, "utf8");
|
|
128
|
+
this.writeChain = this.writeChain
|
|
129
|
+
.catch(() => { }) // a failed prior write must not poison the chain
|
|
130
|
+
.then(async () => {
|
|
131
|
+
try {
|
|
132
|
+
await mkdir(LOG_DIR, { recursive: true });
|
|
133
|
+
// Rotate BEFORE the write when this line would breach the cap, so the
|
|
134
|
+
// file only ever crosses the threshold by a single (possibly large)
|
|
135
|
+
// entry that then lands alone in the fresh file.
|
|
136
|
+
if (this.bytes > 0 && this.bytes + size > MAX_BYTES)
|
|
137
|
+
await this.rotate();
|
|
138
|
+
await appendFile(LOG_FILE, record, "utf8");
|
|
139
|
+
this.bytes += size;
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
// Never throw into the caller; surface once to stderr.
|
|
143
|
+
console.error("[log] persist failed:", err);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** daemon.jsonl → daemon.jsonl.1 (overwriting any prior .1); start fresh. */
|
|
148
|
+
async rotate() {
|
|
149
|
+
try {
|
|
150
|
+
await rename(LOG_FILE, LOG_FILE_PREV);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
// No current file (or rename raced) — ensure a clean slate either way.
|
|
154
|
+
try {
|
|
155
|
+
await writeFile(LOG_FILE, "");
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
/* best-effort */
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
this.bytes = 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/** Process-wide singleton. Construct order doesn't matter; `start()` is idempotent. */
|
|
165
|
+
export const logger = new Logger();
|
|
166
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AAC7E,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AAC/C,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,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+
export declare function migrateStateDir(home?: string): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-time on-disk state-dir migration.
|
|
3
|
+
*
|
|
4
|
+
* The daemon's persistent state (NaCl keys, provider credentials, project
|
|
5
|
+
* registry, chatlogs, jobs, allowlist, config, repo cache…) historically lived
|
|
6
|
+
* under `~/.agent-tether/`. The project was renamed to Immediacy, so the new
|
|
7
|
+
* home is `~/.immediacy/`. To avoid breaking existing installs (which would
|
|
8
|
+
* otherwise silently start from scratch — re-pair, re-enter API keys), this
|
|
9
|
+
* shim moves the old directory into place on first startup.
|
|
10
|
+
*
|
|
11
|
+
* Behavior:
|
|
12
|
+
* - Runs only for the DEFAULT layout (`~/.immediacy`). If the operator points
|
|
13
|
+
* individual files elsewhere via env overrides (STATE_FILE, KEYS_FILE, …),
|
|
14
|
+
* those are respected as-is and this no-ops.
|
|
15
|
+
* - Migrates only when the old dir exists AND the new dir does not, so it is
|
|
16
|
+
* idempotent and never clobbers an existing `~/.immediacy`.
|
|
17
|
+
* - Best-effort: on any error it logs and continues (a fresh dir is created
|
|
18
|
+
* lazily by the normal code paths).
|
|
19
|
+
*/
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { existsSync, renameSync, cpSync, rmSync } from "node:fs";
|
|
23
|
+
const LEGACY_DIR_NAME = ".agent-tether";
|
|
24
|
+
const NEW_DIR_NAME = ".immediacy";
|
|
25
|
+
export function migrateStateDir(home = homedir()) {
|
|
26
|
+
const legacy = join(home, LEGACY_DIR_NAME);
|
|
27
|
+
const next = join(home, NEW_DIR_NAME);
|
|
28
|
+
if (!existsSync(legacy) || existsSync(next))
|
|
29
|
+
return;
|
|
30
|
+
try {
|
|
31
|
+
// Fast path: same filesystem — atomic rename.
|
|
32
|
+
renameSync(legacy, next);
|
|
33
|
+
console.log(`[daemon] migrated state dir ${legacy} → ${next}`);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// Cross-device or partial: copy then remove the original.
|
|
37
|
+
try {
|
|
38
|
+
cpSync(legacy, next, { recursive: true });
|
|
39
|
+
rmSync(legacy, { recursive: true, force: true });
|
|
40
|
+
console.log(`[daemon] migrated state dir (copy) ${legacy} → ${next}`);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
console.warn(`[daemon] could not migrate ${legacy} → ${next}; starting fresh. (${err.message})`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=migrate-state-dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-state-dir.js","sourceRoot":"","sources":["../../src/migrate-state-dir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjE,MAAM,eAAe,GAAG,eAAe,CAAC;AACxC,MAAM,YAAY,GAAG,YAAY,CAAC;AAElC,MAAM,UAAU,eAAe,CAAC,IAAI,GAAG,OAAO,EAAE;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAEtC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO;IAEpD,IAAI,CAAC;QACH,8CAA8C;QAC9C,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,+BAA+B,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC;IAAC,MAAM,CAAC;QACP,0DAA0D;QAC1D,IAAI,CAAC;YACH,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1C,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACjD,OAAO,CAAC,GAAG,CAAC,sCAAsC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CACV,8BAA8B,MAAM,MAAM,IAAI,sBAC3C,GAAa,CAAC,OACjB,GAAG,CACJ,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model catalog — the daemon's source of truth for which agent models the app
|
|
3
|
+
* may pick from.
|
|
4
|
+
*
|
|
5
|
+
* A model's `provider` decides which agent backend runs it:
|
|
6
|
+
* - "claude" → ClaudeAgent (Agent SDK, `model` option)
|
|
7
|
+
* - "codex" → CodexAgent (OpenAI Codex CLI, `-m` flag)
|
|
8
|
+
* - "openrouter" → OpenRouterAgent (Agent SDK against OpenRouter's
|
|
9
|
+
* Anthropic-compatible endpoint; the `id` is an OpenRouter
|
|
10
|
+
* `vendor/model` slug — see OpenRouterAgent / OPENROUTER_API_KEY)
|
|
11
|
+
*
|
|
12
|
+
* The list is deliberately scoped to models released in roughly the last year
|
|
13
|
+
* (as of 2026-08). `id` is the exact string handed to the backend; keep them in
|
|
14
|
+
* sync with each provider's model IDs. The Dart mirror is app/lib/models.dart.
|
|
15
|
+
*/
|
|
16
|
+
import type { ModelInfo, ModelProvider } from "./protocol.js";
|
|
17
|
+
/**
|
|
18
|
+
* Available models, in display order. Exactly one is marked `default: true`;
|
|
19
|
+
* that model backs new workspaces when the client doesn't pick one, and any
|
|
20
|
+
* workspace restored from before model selection existed.
|
|
21
|
+
*/
|
|
22
|
+
export declare const MODELS: ModelInfo[];
|
|
23
|
+
export declare const DEFAULT_MODEL: ModelInfo;
|
|
24
|
+
/**
|
|
25
|
+
* Sentinel Codex model id meaning "don't pass -m; use the account's default".
|
|
26
|
+
* Passing an explicit model id requires API-key billing; a ChatGPT-login Codex
|
|
27
|
+
* only accepts its plan default, so this is the safe cross-setup choice.
|
|
28
|
+
*/
|
|
29
|
+
export declare const CODEX_DEFAULT_MODEL = "codex";
|
|
30
|
+
/** Look up a model by id (undefined id → the default). */
|
|
31
|
+
export declare function modelById(id?: string): ModelInfo | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Which backend runs a given model id. Unknown or missing ids fall back to
|
|
34
|
+
* "claude" so restored/legacy workspaces keep working.
|
|
35
|
+
*/
|
|
36
|
+
export declare function providerFor(id?: string): ModelProvider;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model catalog — the daemon's source of truth for which agent models the app
|
|
3
|
+
* may pick from.
|
|
4
|
+
*
|
|
5
|
+
* A model's `provider` decides which agent backend runs it:
|
|
6
|
+
* - "claude" → ClaudeAgent (Agent SDK, `model` option)
|
|
7
|
+
* - "codex" → CodexAgent (OpenAI Codex CLI, `-m` flag)
|
|
8
|
+
* - "openrouter" → OpenRouterAgent (Agent SDK against OpenRouter's
|
|
9
|
+
* Anthropic-compatible endpoint; the `id` is an OpenRouter
|
|
10
|
+
* `vendor/model` slug — see OpenRouterAgent / OPENROUTER_API_KEY)
|
|
11
|
+
*
|
|
12
|
+
* The list is deliberately scoped to models released in roughly the last year
|
|
13
|
+
* (as of 2026-08). `id` is the exact string handed to the backend; keep them in
|
|
14
|
+
* sync with each provider's model IDs. The Dart mirror is app/lib/models.dart.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Available models, in display order. Exactly one is marked `default: true`;
|
|
18
|
+
* that model backs new workspaces when the client doesn't pick one, and any
|
|
19
|
+
* workspace restored from before model selection existed.
|
|
20
|
+
*/
|
|
21
|
+
export const MODELS = [
|
|
22
|
+
// Anthropic — Claude (Agent SDK).
|
|
23
|
+
{ id: "claude-opus-4-8", label: "Claude Opus 4.8", provider: "claude", default: true },
|
|
24
|
+
{ id: "claude-fable-5", label: "Claude Fable 5", provider: "claude" },
|
|
25
|
+
{ id: "claude-opus-4-7", label: "Claude Opus 4.7", provider: "claude" },
|
|
26
|
+
{ id: "claude-opus-4-6", label: "Claude Opus 4.6", provider: "claude" },
|
|
27
|
+
{ id: "claude-opus-4-5", label: "Claude Opus 4.5", provider: "claude" },
|
|
28
|
+
{ id: "claude-sonnet-5", label: "Claude Sonnet 5", provider: "claude" },
|
|
29
|
+
{ id: "claude-sonnet-4-6", label: "Claude Sonnet 4.6", provider: "claude" },
|
|
30
|
+
{ id: "claude-sonnet-4-5", label: "Claude Sonnet 4.5", provider: "claude" },
|
|
31
|
+
{ id: "claude-haiku-4-5", label: "Claude Haiku 4.5", provider: "claude" },
|
|
32
|
+
// OpenAI — Codex CLI. "codex" is a sentinel meaning "let Codex pick the
|
|
33
|
+
// account's default model" — the only option that works on a ChatGPT login
|
|
34
|
+
// (explicit ids require API-key billing). See CODEX_DEFAULT_MODEL.
|
|
35
|
+
{ id: "codex", label: "Codex (account default)", provider: "codex" },
|
|
36
|
+
{ id: "gpt-5-codex", label: "GPT-5 Codex", provider: "codex" },
|
|
37
|
+
{ id: "gpt-5", label: "GPT-5", provider: "codex" },
|
|
38
|
+
{ id: "gpt-5-mini", label: "GPT-5 mini", provider: "codex" },
|
|
39
|
+
{ id: "o4-mini", label: "OpenAI o4-mini", provider: "codex" },
|
|
40
|
+
{ id: "o3", label: "OpenAI o3", provider: "codex" },
|
|
41
|
+
// OpenRouter — routed through the Agent SDK against OpenRouter's
|
|
42
|
+
// Anthropic-compatible endpoint (needs OPENROUTER_API_KEY). `id` is the exact
|
|
43
|
+
// OpenRouter `vendor/model` slug; this is a curated starter set of capable
|
|
44
|
+
// agentic models the native Claude/Codex backends don't already cover — add
|
|
45
|
+
// any slug from https://openrouter.ai/models here.
|
|
46
|
+
{ id: "google/gemini-3.7-flash", label: "Gemini 3.7 Flash", provider: "openrouter" },
|
|
47
|
+
{ id: "deepseek/deepseek-v4-pro-0813", label: "DeepSeek V4 Pro", provider: "openrouter" },
|
|
48
|
+
{ id: "x-ai/grok-4.6", label: "Grok 4.6", provider: "openrouter" },
|
|
49
|
+
{ id: "qwen/qwen3.8-max", label: "Qwen3.8 Max", provider: "openrouter" },
|
|
50
|
+
];
|
|
51
|
+
export const DEFAULT_MODEL = MODELS.find((m) => m.default) ?? MODELS[0];
|
|
52
|
+
/**
|
|
53
|
+
* Sentinel Codex model id meaning "don't pass -m; use the account's default".
|
|
54
|
+
* Passing an explicit model id requires API-key billing; a ChatGPT-login Codex
|
|
55
|
+
* only accepts its plan default, so this is the safe cross-setup choice.
|
|
56
|
+
*/
|
|
57
|
+
export const CODEX_DEFAULT_MODEL = "codex";
|
|
58
|
+
/** Look up a model by id (undefined id → the default). */
|
|
59
|
+
export function modelById(id) {
|
|
60
|
+
if (!id)
|
|
61
|
+
return DEFAULT_MODEL;
|
|
62
|
+
return MODELS.find((m) => m.id === id);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Which backend runs a given model id. Unknown or missing ids fall back to
|
|
66
|
+
* "claude" so restored/legacy workspaces keep working.
|
|
67
|
+
*/
|
|
68
|
+
export function providerFor(id) {
|
|
69
|
+
return modelById(id)?.provider ?? "claude";
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAgB;IACjC,kCAAkC;IAClC,EAAE,EAAE,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EA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AAE,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE;IAEnD,iEAAiE;IACjE,8EAA8E;IAC9E,2EAA2E;IAC3E,4EAA4E;IAC5E,mDAAmD;IACnD,EAAE,EAAE,EAAE,yBAAyB,EAAE,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,YAAY,EAAE;IACpF,EAAE,EAAE,EAAE,+BAA+B,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,YAAY,EAAE;IACzF,EAAE,EAAE,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE;IAClE,EAAE,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE;CACzE,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GACxB,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAC,CAAE,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC;AAE3C,0DAA0D;AAC1D,MAAM,UAAU,SAAS,CAAC,EAAW;IACnC,IAAI,CAAC,EAAE;QAAE,OAAO,aAAa,CAAC;IAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAAW;IACrC,OAAO,SAAS,CAAC,EAAE,CAAC,EAAE,QAAQ,IAAI,QAAQ,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permission gate: holds deferred tool-call decisions until the phone answers.
|
|
3
|
+
*
|
|
4
|
+
* Shared by every agent backend. Default-deny on timeout (§5) so a backgrounded
|
|
5
|
+
* or disconnected phone can never leave a tool call hanging — or worse, let one
|
|
6
|
+
* through.
|
|
7
|
+
*/
|
|
8
|
+
import type { QuestionAnswers } from "./protocol.js";
|
|
9
|
+
export type PermissionDecision = "allow" | "deny";
|
|
10
|
+
export declare class PermissionGate {
|
|
11
|
+
private timeoutMs;
|
|
12
|
+
private pending;
|
|
13
|
+
constructor(timeoutMs?: number);
|
|
14
|
+
/** Register a deferred request; resolves when the phone responds or times out. */
|
|
15
|
+
wait(requestId: string): Promise<PermissionDecision>;
|
|
16
|
+
/** Resolve a pending request from a `permission.respond`. No-op if unknown. */
|
|
17
|
+
resolve(requestId: string, decision: PermissionDecision): boolean;
|
|
18
|
+
/** Deny everything outstanding (e.g. on agent stop). */
|
|
19
|
+
denyAll(): void;
|
|
20
|
+
}
|
|
21
|
+
/** The user's reply to an AskUserQuestion — structured answers and/or free text. */
|
|
22
|
+
export interface QuestionResolution {
|
|
23
|
+
answers: QuestionAnswers;
|
|
24
|
+
response?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Question gate: the AskUserQuestion analogue of {@link PermissionGate}. Holds a
|
|
28
|
+
* deferred `AskUserQuestion` call until the user picks answers on some client.
|
|
29
|
+
*
|
|
30
|
+
* Two differences from the permission gate:
|
|
31
|
+
* - it resolves with the picked {@link QuestionResolution}, not allow/deny —
|
|
32
|
+
* those answers become the tool's result fed back to the model;
|
|
33
|
+
* - the timeout is long (a clarifying question is a deliberate ask the user may
|
|
34
|
+
* take minutes to answer). On timeout it resolves `null`, which the agent
|
|
35
|
+
* turns into a "no answer" denial so a disconnected client can't hang the
|
|
36
|
+
* SDK subprocess forever.
|
|
37
|
+
*/
|
|
38
|
+
export declare class QuestionGate {
|
|
39
|
+
private timeoutMs;
|
|
40
|
+
private pending;
|
|
41
|
+
constructor(timeoutMs?: number);
|
|
42
|
+
/** Register a deferred question; resolves when the user answers or times out. */
|
|
43
|
+
wait(requestId: string): Promise<QuestionResolution | null>;
|
|
44
|
+
/** Resolve a pending question from a `question.respond`. No-op if unknown. */
|
|
45
|
+
resolve(requestId: string, resolution: QuestionResolution): boolean;
|
|
46
|
+
/** Abandon everything outstanding (e.g. on agent stop) → treated as no answer. */
|
|
47
|
+
denyAll(): void;
|
|
48
|
+
}
|