@addai/node 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +96 -0
  2. package/dist/agent-auth.d.ts +9 -0
  3. package/dist/agent-auth.js +96 -0
  4. package/dist/attachments.d.ts +20 -0
  5. package/dist/attachments.js +164 -0
  6. package/dist/capabilities.d.ts +64 -0
  7. package/dist/capabilities.js +406 -0
  8. package/dist/claude-binary.d.ts +16 -0
  9. package/dist/claude-binary.js +145 -0
  10. package/dist/claude-config.d.ts +11 -0
  11. package/dist/claude-config.js +144 -0
  12. package/dist/claude-print.d.ts +35 -0
  13. package/dist/claude-print.js +312 -0
  14. package/dist/claude-spawn.d.ts +40 -0
  15. package/dist/claude-spawn.js +220 -0
  16. package/dist/cli.d.ts +2 -0
  17. package/dist/cli.js +137 -0
  18. package/dist/codex-binary.d.ts +4 -0
  19. package/dist/codex-binary.js +70 -0
  20. package/dist/codex-spawn.d.ts +47 -0
  21. package/dist/codex-spawn.js +320 -0
  22. package/dist/command-runner.d.ts +9 -0
  23. package/dist/command-runner.js +592 -0
  24. package/dist/config.d.ts +7 -0
  25. package/dist/config.js +38 -0
  26. package/dist/control-server.d.ts +5 -0
  27. package/dist/control-server.js +292 -0
  28. package/dist/diskguard.d.ts +96 -0
  29. package/dist/diskguard.js +435 -0
  30. package/dist/error-classify.d.ts +20 -0
  31. package/dist/error-classify.js +159 -0
  32. package/dist/events.d.ts +26 -0
  33. package/dist/events.js +97 -0
  34. package/dist/gemini-binary.d.ts +4 -0
  35. package/dist/gemini-binary.js +64 -0
  36. package/dist/gemini-spawn.d.ts +52 -0
  37. package/dist/gemini-spawn.js +369 -0
  38. package/dist/git-identity.d.ts +18 -0
  39. package/dist/git-identity.js +104 -0
  40. package/dist/grok-binary.d.ts +4 -0
  41. package/dist/grok-binary.js +70 -0
  42. package/dist/grok-spawn.d.ts +41 -0
  43. package/dist/grok-spawn.js +495 -0
  44. package/dist/guardrails.d.ts +32 -0
  45. package/dist/guardrails.js +125 -0
  46. package/dist/hang-watchdog.d.ts +17 -0
  47. package/dist/hang-watchdog.js +48 -0
  48. package/dist/harness-registry.d.ts +55 -0
  49. package/dist/harness-registry.js +180 -0
  50. package/dist/heartbeat.d.ts +13 -0
  51. package/dist/heartbeat.js +95 -0
  52. package/dist/index.d.ts +12 -0
  53. package/dist/index.js +440 -0
  54. package/dist/install.d.ts +63 -0
  55. package/dist/install.js +467 -0
  56. package/dist/jsonl-tail.d.ts +20 -0
  57. package/dist/jsonl-tail.js +192 -0
  58. package/dist/kimi-binary.d.ts +4 -0
  59. package/dist/kimi-binary.js +68 -0
  60. package/dist/kimi-spawn.d.ts +47 -0
  61. package/dist/kimi-spawn.js +319 -0
  62. package/dist/lockfile.d.ts +30 -0
  63. package/dist/lockfile.js +169 -0
  64. package/dist/mcp-config.d.ts +23 -0
  65. package/dist/mcp-config.js +133 -0
  66. package/dist/memory-capture.d.ts +20 -0
  67. package/dist/memory-capture.js +45 -0
  68. package/dist/memory-pack.d.ts +34 -0
  69. package/dist/memory-pack.js +171 -0
  70. package/dist/model-filter.d.ts +4 -0
  71. package/dist/model-filter.js +34 -0
  72. package/dist/node-health.d.ts +18 -0
  73. package/dist/node-health.js +74 -0
  74. package/dist/pairing.d.ts +20 -0
  75. package/dist/pairing.js +129 -0
  76. package/dist/paths.d.ts +9 -0
  77. package/dist/paths.js +48 -0
  78. package/dist/precompact-hook.d.ts +27 -0
  79. package/dist/precompact-hook.js +136 -0
  80. package/dist/projects.d.ts +25 -0
  81. package/dist/projects.js +255 -0
  82. package/dist/prompt-keystrokes.d.ts +3 -0
  83. package/dist/prompt-keystrokes.js +56 -0
  84. package/dist/pty-helper.d.ts +26 -0
  85. package/dist/pty-helper.js +156 -0
  86. package/dist/request-pump.d.ts +12 -0
  87. package/dist/request-pump.js +249 -0
  88. package/dist/run-retry.d.ts +28 -0
  89. package/dist/run-retry.js +81 -0
  90. package/dist/self-update.d.ts +75 -0
  91. package/dist/self-update.js +192 -0
  92. package/dist/session-runner.d.ts +130 -0
  93. package/dist/session-runner.js +2271 -0
  94. package/dist/sleep-detector.d.ts +11 -0
  95. package/dist/sleep-detector.js +32 -0
  96. package/dist/state-migrate.d.ts +8 -0
  97. package/dist/state-migrate.js +91 -0
  98. package/dist/store.d.ts +5 -0
  99. package/dist/store.js +82 -0
  100. package/dist/supabase-client.d.ts +15 -0
  101. package/dist/supabase-client.js +119 -0
  102. package/dist/time-context.d.ts +10 -0
  103. package/dist/time-context.js +71 -0
  104. package/dist/tokens.d.ts +4 -0
  105. package/dist/tokens.js +33 -0
  106. package/dist/tui/app.d.ts +35 -0
  107. package/dist/tui/app.js +82 -0
  108. package/dist/tui/console-capture.d.ts +13 -0
  109. package/dist/tui/console-capture.js +62 -0
  110. package/dist/tui/dashboard.d.ts +42 -0
  111. package/dist/tui/dashboard.js +205 -0
  112. package/dist/tui/data.d.ts +57 -0
  113. package/dist/tui/data.js +62 -0
  114. package/dist/tui/harnesses.d.ts +16 -0
  115. package/dist/tui/harnesses.js +354 -0
  116. package/dist/tui/render.d.ts +21 -0
  117. package/dist/tui/render.js +116 -0
  118. package/dist/tui/requests.d.ts +18 -0
  119. package/dist/tui/requests.js +127 -0
  120. package/dist/tui/run.d.ts +13 -0
  121. package/dist/tui/run.js +178 -0
  122. package/dist/tui/transcript.d.ts +39 -0
  123. package/dist/tui/transcript.js +234 -0
  124. package/dist/tui.d.ts +1 -0
  125. package/dist/tui.js +314 -0
  126. package/dist/types.d.ts +65 -0
  127. package/dist/types.js +3 -0
  128. package/dist/win.d.ts +67 -0
  129. package/dist/win.js +317 -0
  130. package/package.json +60 -0
  131. package/scripts/fix-pty-helper.js +28 -0
  132. package/scripts/precompact-capture.js +292 -0
  133. package/scripts/smoke-test.sh +74 -0
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.applyGitIdentity = applyGitIdentity;
37
+ const child_process_1 = require("child_process");
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const supabase_client_1 = require("./supabase-client");
41
+ /**
42
+ * Give a freshly cloned repo the ENTITY's git identity, and optionally credit
43
+ * the person who asked for the work.
44
+ *
45
+ * Without this, commits land under whatever global git config the host machine
46
+ * happens to have — usually the machine's owner, which is wrong and confusing
47
+ * when several entities share a node.
48
+ *
49
+ * Identity comes from runtime_get_git_identity rather than the request row: six
50
+ * different RPCs create those rows and threading two more columns through all of
51
+ * them is needless fragility.
52
+ *
53
+ * On avatars: GitHub derives a commit's avatar from the email, so an entity's
54
+ * own photo cannot appear there without a real GitHub account per entity. The
55
+ * co-author trailer is what puts a real avatar and a real GitHub identity on the
56
+ * commit, which is why it defaults on.
57
+ */
58
+ async function applyGitIdentity(dir, requestId, token) {
59
+ let ident = null;
60
+ try {
61
+ ident = await (0, supabase_client_1.rpc)('runtime_get_git_identity', { p_token: token, p_request_id: requestId });
62
+ }
63
+ catch {
64
+ return; // never fail a clone over commit cosmetics
65
+ }
66
+ if (!ident?.configured || !ident.author_name || !ident.author_email)
67
+ return;
68
+ const git = (args) => new Promise((resolve) => {
69
+ (0, child_process_1.execFile)('git', ['-C', dir, ...args], { timeout: 10_000 }, () => resolve());
70
+ });
71
+ // Repo-local only — never touch the machine's global config, which other
72
+ // entities and the human owner share.
73
+ await git(['config', 'user.name', ident.author_name]);
74
+ await git(['config', 'user.email', ident.author_email]);
75
+ if (!ident.coauthor)
76
+ return;
77
+ // A prepare-commit-msg hook, not commit.template: templates are ignored by
78
+ // `git commit -m`, which is how an agent always commits. The hook appends the
79
+ // trailer only when it is not already present, so amends stay idempotent.
80
+ try {
81
+ const hooksDir = path.join(dir, '.git', 'hooks');
82
+ fs.mkdirSync(hooksDir, { recursive: true });
83
+ const hook = path.join(hooksDir, 'prepare-commit-msg');
84
+ const trailer = `Co-authored-by: ${ident.coauthor}`;
85
+ const script = [
86
+ '#!/bin/sh',
87
+ '# Written by +Ai entity-runtime: credit the person who asked for the work.',
88
+ 'MSG_FILE="$1"',
89
+ `TRAILER=${JSON.stringify(trailer)}`,
90
+ 'grep -qF "$TRAILER" "$MSG_FILE" 2>/dev/null && exit 0',
91
+ 'printf "\\n%s\\n" "$TRAILER" >> "$MSG_FILE"',
92
+ '',
93
+ ].join('\n');
94
+ fs.writeFileSync(hook, script, { mode: 0o755 });
95
+ // Windows checkouts ignore the mode bit; chmod is a harmless no-op there.
96
+ try {
97
+ fs.chmodSync(hook, 0o755);
98
+ }
99
+ catch { /* non-POSIX */ }
100
+ }
101
+ catch {
102
+ /* identity still applied; the trailer is a nice-to-have */
103
+ }
104
+ }
@@ -0,0 +1,4 @@
1
+ /** Forget the cached lookup — call after an install so a fresh probe
2
+ * can see a binary that was missing at daemon start. */
3
+ export declare function resetCache(): void;
4
+ export declare function findGrokBinary(): string | null;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ // Locate the `grok` binary on the host. The xAI installer drops it at
3
+ // ~/.local/bin/grok by default, but it can also live on PATH or under
4
+ // /usr/local/bin, /opt/homebrew/bin, or ~/.grok/bin depending on how the
5
+ // user installed it. On Windows: grok.exe in the same user-local spots,
6
+ // or an npm .cmd shim.
7
+ //
8
+ // Returns null if not present so callers can surface an install hint.
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || (function () {
26
+ var ownKeys = function(o) {
27
+ ownKeys = Object.getOwnPropertyNames || function (o) {
28
+ var ar = [];
29
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
30
+ return ar;
31
+ };
32
+ return ownKeys(o);
33
+ };
34
+ return function (mod) {
35
+ if (mod && mod.__esModule) return mod;
36
+ var result = {};
37
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
38
+ __setModuleDefault(result, mod);
39
+ return result;
40
+ };
41
+ })();
42
+ Object.defineProperty(exports, "__esModule", { value: true });
43
+ exports.resetCache = resetCache;
44
+ exports.findGrokBinary = findGrokBinary;
45
+ const path = __importStar(require("path"));
46
+ const os = __importStar(require("os"));
47
+ const win_1 = require("./win");
48
+ const POSIX_CANDIDATES = [
49
+ path.join(os.homedir(), '.local', 'bin', 'grok'), // xAI installer default
50
+ path.join(os.homedir(), '.grok', 'bin', 'grok'),
51
+ '/usr/local/bin/grok',
52
+ '/opt/homebrew/bin/grok',
53
+ ];
54
+ const WIN32_CANDIDATES = [
55
+ path.join(os.homedir(), '.local', 'bin', 'grok.exe'),
56
+ path.join(os.homedir(), '.grok', 'bin', 'grok.exe'),
57
+ ];
58
+ /** Forget the cached lookup — call after an install so a fresh probe
59
+ * can see a binary that was missing at daemon start. */
60
+ function resetCache() { cached = undefined; }
61
+ let cached;
62
+ function findGrokBinary() {
63
+ if (cached !== undefined)
64
+ return cached;
65
+ cached = (0, win_1.findCliBinary)('grok', {
66
+ posixCandidates: POSIX_CANDIDATES,
67
+ win32Candidates: WIN32_CANDIDATES,
68
+ });
69
+ return cached;
70
+ }
@@ -0,0 +1,41 @@
1
+ import type { RuntimeEvent, RuntimeEffortLevel } from './types';
2
+ export interface GrokMcpServer {
3
+ slug: string;
4
+ command: string;
5
+ args?: string[] | null;
6
+ env?: Record<string, string> | null;
7
+ }
8
+ export interface GrokInput {
9
+ workingDirectory: string;
10
+ prompt: string;
11
+ model?: string;
12
+ /** Resume an existing session (mapped to `--resume <id>`). */
13
+ resumeSessionId?: string;
14
+ /** Autonomous runs can't answer approval prompts; headless always
15
+ * auto-approves. This flag is accepted for parity but print mode is
16
+ * always non-interactive. */
17
+ bypassPermissions?: boolean;
18
+ /** The entity's servers. Written to a per-session project config.toml so
19
+ * grok exposes ONLY these (host Claude MCPs are masked via sandbox HOME). */
20
+ mcpServers?: GrokMcpServer[];
21
+ /** Studio-entity system prompt (identity + memory directive). Appended to
22
+ * grok's own system prompt via `--rules`. */
23
+ appendSystemPrompt?: string;
24
+ /** Per-run reasoning effort → grok `--reasoning-effort`. Only low/medium/
25
+ * high are forwarded (xhigh/max collapse to high) so we never emit an
26
+ * unsupported value that would fail the spawn. */
27
+ effortLevel?: RuntimeEffortLevel;
28
+ }
29
+ export interface GrokHandle {
30
+ pid: number | undefined;
31
+ sessionId: string | null;
32
+ kill(): void;
33
+ onEvent(cb: (e: RuntimeEvent) => void): void;
34
+ /** Fires on every raw stdout/stderr chunk — byte-level liveness. Grok
35
+ * emits NO events during tool execution (no per-tool stream), so parsed
36
+ * events alone under-report life; any bytes at all prove the child is
37
+ * still working and should hold off the hang watchdog. */
38
+ onActivity(cb: () => void): void;
39
+ done: Promise<number>;
40
+ }
41
+ export declare function spawnGrok(input: GrokInput): GrokHandle;