@botcord/daemon 0.1.1
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/activity-tracker.d.ts +43 -0
- package/dist/activity-tracker.js +110 -0
- package/dist/adapters/runtimes.d.ts +14 -0
- package/dist/adapters/runtimes.js +18 -0
- package/dist/agent-discovery.d.ts +81 -0
- package/dist/agent-discovery.js +181 -0
- package/dist/agent-workspace.d.ts +31 -0
- package/dist/agent-workspace.js +221 -0
- package/dist/config.d.ts +116 -0
- package/dist/config.js +180 -0
- package/dist/control-channel.d.ts +99 -0
- package/dist/control-channel.js +388 -0
- package/dist/cross-room.d.ts +23 -0
- package/dist/cross-room.js +55 -0
- package/dist/daemon-config-map.d.ts +61 -0
- package/dist/daemon-config-map.js +153 -0
- package/dist/daemon.d.ts +123 -0
- package/dist/daemon.js +349 -0
- package/dist/doctor.d.ts +89 -0
- package/dist/doctor.js +191 -0
- package/dist/gateway/channel-manager.d.ts +54 -0
- package/dist/gateway/channel-manager.js +292 -0
- package/dist/gateway/channels/botcord.d.ts +93 -0
- package/dist/gateway/channels/botcord.js +510 -0
- package/dist/gateway/channels/index.d.ts +2 -0
- package/dist/gateway/channels/index.js +1 -0
- package/dist/gateway/channels/sanitize.d.ts +20 -0
- package/dist/gateway/channels/sanitize.js +56 -0
- package/dist/gateway/dispatcher.d.ts +73 -0
- package/dist/gateway/dispatcher.js +431 -0
- package/dist/gateway/gateway.d.ts +87 -0
- package/dist/gateway/gateway.js +158 -0
- package/dist/gateway/index.d.ts +15 -0
- package/dist/gateway/index.js +15 -0
- package/dist/gateway/log.d.ts +9 -0
- package/dist/gateway/log.js +20 -0
- package/dist/gateway/router.d.ts +10 -0
- package/dist/gateway/router.js +48 -0
- package/dist/gateway/runtimes/claude-code.d.ts +30 -0
- package/dist/gateway/runtimes/claude-code.js +162 -0
- package/dist/gateway/runtimes/codex.d.ts +83 -0
- package/dist/gateway/runtimes/codex.js +272 -0
- package/dist/gateway/runtimes/gemini.d.ts +15 -0
- package/dist/gateway/runtimes/gemini.js +29 -0
- package/dist/gateway/runtimes/ndjson-stream.d.ts +43 -0
- package/dist/gateway/runtimes/ndjson-stream.js +169 -0
- package/dist/gateway/runtimes/probe.d.ts +17 -0
- package/dist/gateway/runtimes/probe.js +54 -0
- package/dist/gateway/runtimes/registry.d.ts +59 -0
- package/dist/gateway/runtimes/registry.js +94 -0
- package/dist/gateway/session-store.d.ts +39 -0
- package/dist/gateway/session-store.js +133 -0
- package/dist/gateway/types.d.ts +265 -0
- package/dist/gateway/types.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +854 -0
- package/dist/log.d.ts +7 -0
- package/dist/log.js +44 -0
- package/dist/provision.d.ts +88 -0
- package/dist/provision.js +749 -0
- package/dist/room-context-fetcher.d.ts +18 -0
- package/dist/room-context-fetcher.js +101 -0
- package/dist/room-context.d.ts +53 -0
- package/dist/room-context.js +112 -0
- package/dist/sender-classify.d.ts +30 -0
- package/dist/sender-classify.js +32 -0
- package/dist/snapshot-writer.d.ts +37 -0
- package/dist/snapshot-writer.js +84 -0
- package/dist/status-render.d.ts +28 -0
- package/dist/status-render.js +97 -0
- package/dist/system-context.d.ts +57 -0
- package/dist/system-context.js +91 -0
- package/dist/turn-text.d.ts +36 -0
- package/dist/turn-text.js +57 -0
- package/dist/user-auth.d.ts +75 -0
- package/dist/user-auth.js +245 -0
- package/dist/working-memory.d.ts +46 -0
- package/dist/working-memory.js +274 -0
- package/package.json +39 -0
- package/src/__tests__/activity-tracker.test.ts +130 -0
- package/src/__tests__/agent-discovery.test.ts +191 -0
- package/src/__tests__/agent-workspace.test.ts +147 -0
- package/src/__tests__/control-channel.test.ts +327 -0
- package/src/__tests__/cross-room.test.ts +116 -0
- package/src/__tests__/daemon-config-map.test.ts +416 -0
- package/src/__tests__/daemon.test.ts +300 -0
- package/src/__tests__/device-code.test.ts +152 -0
- package/src/__tests__/doctor.test.ts +218 -0
- package/src/__tests__/protocol-core-reexport.test.ts +24 -0
- package/src/__tests__/provision.test.ts +922 -0
- package/src/__tests__/room-context.test.ts +233 -0
- package/src/__tests__/runtime-discovery.test.ts +173 -0
- package/src/__tests__/snapshot-writer.test.ts +141 -0
- package/src/__tests__/status-render.test.ts +137 -0
- package/src/__tests__/system-context.test.ts +315 -0
- package/src/__tests__/turn-text.test.ts +116 -0
- package/src/__tests__/user-auth.test.ts +125 -0
- package/src/__tests__/working-memory.test.ts +240 -0
- package/src/activity-tracker.ts +140 -0
- package/src/adapters/runtimes.ts +30 -0
- package/src/agent-discovery.ts +262 -0
- package/src/agent-workspace.ts +247 -0
- package/src/config.ts +290 -0
- package/src/control-channel.ts +455 -0
- package/src/cross-room.ts +89 -0
- package/src/daemon-config-map.ts +200 -0
- package/src/daemon.ts +478 -0
- package/src/doctor.ts +282 -0
- package/src/gateway/__tests__/.gitkeep +0 -0
- package/src/gateway/__tests__/botcord-channel.test.ts +480 -0
- package/src/gateway/__tests__/channel-manager.test.ts +475 -0
- package/src/gateway/__tests__/claude-code-adapter.test.ts +318 -0
- package/src/gateway/__tests__/codex-adapter.test.ts +350 -0
- package/src/gateway/__tests__/dispatcher.test.ts +1159 -0
- package/src/gateway/__tests__/gateway-add-channel.test.ts +180 -0
- package/src/gateway/__tests__/gateway-managed-routes.test.ts +181 -0
- package/src/gateway/__tests__/gateway.test.ts +222 -0
- package/src/gateway/__tests__/router.test.ts +247 -0
- package/src/gateway/__tests__/sanitize.test.ts +193 -0
- package/src/gateway/__tests__/session-store.test.ts +235 -0
- package/src/gateway/channel-manager.ts +349 -0
- package/src/gateway/channels/botcord.ts +605 -0
- package/src/gateway/channels/index.ts +6 -0
- package/src/gateway/channels/sanitize.ts +68 -0
- package/src/gateway/dispatcher.ts +554 -0
- package/src/gateway/gateway.ts +211 -0
- package/src/gateway/index.ts +29 -0
- package/src/gateway/log.ts +30 -0
- package/src/gateway/router.ts +60 -0
- package/src/gateway/runtimes/claude-code.ts +180 -0
- package/src/gateway/runtimes/codex.ts +312 -0
- package/src/gateway/runtimes/gemini.ts +43 -0
- package/src/gateway/runtimes/ndjson-stream.ts +225 -0
- package/src/gateway/runtimes/probe.ts +73 -0
- package/src/gateway/runtimes/registry.ts +143 -0
- package/src/gateway/session-store.ts +157 -0
- package/src/gateway/types.ts +325 -0
- package/src/index.ts +961 -0
- package/src/log.ts +47 -0
- package/src/provision.ts +879 -0
- package/src/room-context-fetcher.ts +124 -0
- package/src/room-context.ts +167 -0
- package/src/sender-classify.ts +46 -0
- package/src/snapshot-writer.ts +103 -0
- package/src/status-render.ts +132 -0
- package/src/system-context.ts +162 -0
- package/src/turn-text.ts +93 -0
- package/src/user-auth.ts +295 -0
- package/src/working-memory.ts +352 -0
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const log: {
|
|
2
|
+
info: (msg: string, fields?: Record<string, unknown>) => void;
|
|
3
|
+
warn: (msg: string, fields?: Record<string, unknown>) => void;
|
|
4
|
+
error: (msg: string, fields?: Record<string, unknown>) => void;
|
|
5
|
+
debug: (msg: string, fields?: Record<string, unknown>) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const LOG_FILE_PATH: string;
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const LOG_DIR = path.join(homedir(), ".botcord", "logs");
|
|
5
|
+
const LOG_FILE = path.join(LOG_DIR, "daemon.log");
|
|
6
|
+
let inited = false;
|
|
7
|
+
function ensureDir() {
|
|
8
|
+
if (inited)
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
mkdirSync(LOG_DIR, { recursive: true, mode: 0o700 });
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
// best-effort
|
|
15
|
+
}
|
|
16
|
+
inited = true;
|
|
17
|
+
}
|
|
18
|
+
function write(level, msg, fields) {
|
|
19
|
+
ensureDir();
|
|
20
|
+
const line = JSON.stringify({
|
|
21
|
+
ts: new Date().toISOString(),
|
|
22
|
+
level,
|
|
23
|
+
msg,
|
|
24
|
+
...(fields ?? {}),
|
|
25
|
+
});
|
|
26
|
+
try {
|
|
27
|
+
appendFileSync(LOG_FILE, line + "\n", { mode: 0o600 });
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// ignore log write errors
|
|
31
|
+
}
|
|
32
|
+
// Mirror to stderr so `--foreground` and `logs -f` both see it.
|
|
33
|
+
process.stderr.write(line + "\n");
|
|
34
|
+
}
|
|
35
|
+
export const log = {
|
|
36
|
+
info: (msg, fields) => write("info", msg, fields),
|
|
37
|
+
warn: (msg, fields) => write("warn", msg, fields),
|
|
38
|
+
error: (msg, fields) => write("error", msg, fields),
|
|
39
|
+
debug: (msg, fields) => {
|
|
40
|
+
if (process.env.BOTCORD_DAEMON_DEBUG)
|
|
41
|
+
write("debug", msg, fields);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export const LOG_FILE_PATH = LOG_FILE;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { BotCordClient, type ControlAck, type ControlFrame, type ListRuntimesResult } from "@botcord/protocol-core";
|
|
2
|
+
import type { Gateway } from "./gateway/index.js";
|
|
3
|
+
import { type DaemonConfig } from "./config.js";
|
|
4
|
+
/** Options accepted by {@link createProvisioner}. */
|
|
5
|
+
export interface ProvisionerOptions {
|
|
6
|
+
/** Live gateway handle used to hot-plug channels. */
|
|
7
|
+
gateway: Gateway;
|
|
8
|
+
/**
|
|
9
|
+
* Override for `BotCordClient.register` — tests inject a stub so they can
|
|
10
|
+
* run without a real Hub.
|
|
11
|
+
*/
|
|
12
|
+
register?: typeof BotCordClient.register;
|
|
13
|
+
}
|
|
14
|
+
/** The value a frame handler returns (minus the `id` which the channel fills in). */
|
|
15
|
+
type AckBody = Omit<ControlAck, "id">;
|
|
16
|
+
/**
|
|
17
|
+
* Build a dispatcher function that routes a `ControlFrame` to the right
|
|
18
|
+
* handler. Returned function signature matches
|
|
19
|
+
* `ControlChannelOptions.handle`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createProvisioner(opts: ProvisionerOptions): (frame: ControlFrame) => Promise<AckBody>;
|
|
22
|
+
/**
|
|
23
|
+
* Append `agentId` to the daemon config if not already present. Returns a
|
|
24
|
+
* new config object or `null` if nothing changed (so callers can skip the
|
|
25
|
+
* disk write).
|
|
26
|
+
*/
|
|
27
|
+
export declare function addAgentToConfig(cfg: DaemonConfig, agentId: string): DaemonConfig | null;
|
|
28
|
+
/** Inverse of {@link addAgentToConfig}. Returns `null` on no-op. */
|
|
29
|
+
export declare function removeAgentFromConfig(cfg: DaemonConfig, agentId: string): DaemonConfig | null;
|
|
30
|
+
/**
|
|
31
|
+
* Probe every registered adapter and shape the result as the wire-level
|
|
32
|
+
* {@link ListRuntimesResult} — used by both the `list_runtimes` ack path and
|
|
33
|
+
* the daemon-side first-connect `runtime_snapshot` push in `daemon.ts`.
|
|
34
|
+
*
|
|
35
|
+
* Kept pure: the only side effects are `detectRuntimes()` itself (which the
|
|
36
|
+
* gateway already isolates from throwing) and reading the wall clock.
|
|
37
|
+
*/
|
|
38
|
+
export declare function collectRuntimeSnapshot(): ListRuntimesResult;
|
|
39
|
+
interface ReloadResult {
|
|
40
|
+
reloaded: true;
|
|
41
|
+
added: string[];
|
|
42
|
+
removed: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Re-read `config.json` and reconcile the running gateway against it. New
|
|
46
|
+
* agents in config but not in gateway snapshot → `addChannel`; agents in
|
|
47
|
+
* gateway but no longer in config → `removeChannel`. The agent's
|
|
48
|
+
* credentials must already exist on disk; we don't re-register identities
|
|
49
|
+
* here (that's `provision_agent`'s job).
|
|
50
|
+
*/
|
|
51
|
+
export declare function reloadConfig(ctx: {
|
|
52
|
+
gateway: Gateway;
|
|
53
|
+
}): Promise<ReloadResult>;
|
|
54
|
+
/**
|
|
55
|
+
* Per-agent entry returned by `list_agents`. Shape follows
|
|
56
|
+
* `docs/daemon-control-plane-api-contract.md` §3.2 — `{id, name, online}`.
|
|
57
|
+
* `status` and `lastMessageAt` are extra daemon-only fields the dashboard
|
|
58
|
+
* may ignore; kept so future contract revisions can promote them without
|
|
59
|
+
* breaking the wire.
|
|
60
|
+
*/
|
|
61
|
+
export interface AgentListEntry {
|
|
62
|
+
id: string;
|
|
63
|
+
/** Display name from credentials, when known. Falls back to the agent id. */
|
|
64
|
+
name: string;
|
|
65
|
+
/** True when the gateway channel is currently running + connected. */
|
|
66
|
+
online: boolean;
|
|
67
|
+
status: "running" | "stopped" | "unknown";
|
|
68
|
+
lastMessageAt?: number;
|
|
69
|
+
}
|
|
70
|
+
interface SetRouteResult {
|
|
71
|
+
ok: true;
|
|
72
|
+
agentId: string;
|
|
73
|
+
routeIndex: number;
|
|
74
|
+
inserted: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Persist a route in `config.json` for the given agent. If a route already
|
|
78
|
+
* matches `agentId` exactly (single-key match), it is replaced; otherwise a
|
|
79
|
+
* new entry is appended. `match.accountId` is forced to `agentId` so the
|
|
80
|
+
* route is always agent-scoped. The change is applied at next
|
|
81
|
+
* `reload_config` — it does not mutate the live router immediately.
|
|
82
|
+
*
|
|
83
|
+
* Accepts the contract's `{pattern, agentId}` shape (treats `pattern` as a
|
|
84
|
+
* conversation-id prefix) AND the richer `{agentId, route: {...}}` shape
|
|
85
|
+
* for daemon-side callers that need to set adapter/cwd explicitly.
|
|
86
|
+
*/
|
|
87
|
+
export declare function setRoute(params: unknown): SetRouteResult;
|
|
88
|
+
export {};
|