@datagrok/grokky 1.0.4 → 1.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/.claude/skills/deploy-grokky/SKILL.md +193 -0
- package/.grokignore +2 -0
- package/.turbo/turbo-build.log +24 -0
- package/.vscode/settings.json +16 -0
- package/CHANGELOG.md +151 -8
- package/CLAUDE.md +284 -0
- package/CREDITS.md +173 -0
- package/LICENSE.md +16 -0
- package/README.md +24 -0
- package/bdd/bdd.config.json +1 -0
- package/bdd/bindings/elements.ts +9 -0
- package/bdd/bindings/steps.ts +787 -0
- package/bdd/features/ai-panel/platform-work.feature +63 -0
- package/bdd/features/ai-panel/session.feature +69 -0
- package/bdd/features/ai-panel/table-work.feature +99 -0
- package/bdd/generated/ai-panel/platform-work.test.ts +103 -0
- package/bdd/generated/ai-panel/session.test.ts +100 -0
- package/bdd/generated/ai-panel/table-work.test.ts +150 -0
- package/bdd/package.json +1 -0
- package/bdd/tsconfig.json +13 -0
- package/css/ai.css +637 -49
- package/dist/package-test.js +4 -1707
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +742 -92317
- package/dist/package.js.map +1 -1
- package/dockerfiles/claude-runtime/.dockerignore +1 -0
- package/{.eslintrc.json → dockerfiles/claude-runtime/.eslintrc.json} +7 -16
- package/dockerfiles/claude-runtime/Dockerfile +73 -13
- package/dockerfiles/claude-runtime/agent/grokky_agent/__init__.py +0 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/__main__.py +80 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/browser_tools.py +180 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/config.py +26 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/formats.py +155 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/guard.py +87 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.py +212 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes.yaml +45 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/__init__.py +8 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/hermes_plugin/plugin.yaml +3 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/protocol.py +174 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/__init__.py +21 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/anthropic.py +21 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/azure.py +46 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/base.py +127 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/bedrock.py +46 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/custom.py +40 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/databricks.py +54 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openai_platform.py +41 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/providers/openrouter.py +46 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/session.py +471 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/skills.py +44 -0
- package/dockerfiles/claude-runtime/agent/grokky_agent/structured.py +40 -0
- package/dockerfiles/claude-runtime/container.json +2 -2
- package/dockerfiles/claude-runtime/entrypoint.sh +20 -0
- package/dockerfiles/claude-runtime/package-lock.json +1721 -306
- package/dockerfiles/claude-runtime/package.json +20 -5
- package/dockerfiles/claude-runtime/plugin/.claude-plugin/plugin.json +5 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-calc-column/SKILL.md +92 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-data/SKILL.md +250 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-chem-toolkit/SKILL.md +395 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-df-and-columns/SKILL.md +454 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-entities/SKILL.md +38 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-exec/SKILL.md +209 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-filtering/SKILL.md +185 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-grid-customization/SKILL.md +270 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-projects/SKILL.md +100 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-selection/SKILL.md +344 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-undo/SKILL.md +78 -0
- package/dockerfiles/claude-runtime/plugin/skills/datagrok-viewers/SKILL.md +303 -0
- package/dockerfiles/claude-runtime/pyproject.toml +18 -0
- package/dockerfiles/claude-runtime/src/agent/pool.ts +411 -0
- package/dockerfiles/claude-runtime/src/agent/turn.ts +153 -0
- package/dockerfiles/claude-runtime/src/constants.ts +20 -0
- package/dockerfiles/claude-runtime/src/credentials.ts +45 -0
- package/dockerfiles/claude-runtime/src/grounding.ts +104 -0
- package/dockerfiles/claude-runtime/src/help-index.ts +118 -0
- package/dockerfiles/claude-runtime/src/privileges.ts +8 -0
- package/dockerfiles/claude-runtime/src/prompts.ts +211 -0
- package/dockerfiles/claude-runtime/src/server.ts +134 -234
- package/dockerfiles/claude-runtime/src/session.ts +328 -0
- package/dockerfiles/claude-runtime/src/shared-api-client.ts +112 -0
- package/dockerfiles/claude-runtime/src/stream-filter.ts +80 -0
- package/dockerfiles/claude-runtime/src/sync/home-files.ts +80 -0
- package/dockerfiles/claude-runtime/src/sync/orchestrator.ts +214 -0
- package/dockerfiles/claude-runtime/src/sync/packages.ts +145 -0
- package/dockerfiles/claude-runtime/src/sync/shared-connections.ts +87 -0
- package/dockerfiles/claude-runtime/src/sync/workspace.ts +68 -0
- package/dockerfiles/claude-runtime/src/tasks.ts +124 -0
- package/dockerfiles/claude-runtime/src/tool-summary.ts +66 -0
- package/dockerfiles/claude-runtime/src/types.ts +142 -23
- package/dockerfiles/claude-runtime/src/user/installed-packages.ts +17 -0
- package/dockerfiles/claude-runtime/src/user/staged-workspace.ts +80 -0
- package/dockerfiles/claude-runtime/src/user/user-dir.ts +108 -0
- package/dockerfiles/claude-runtime/src/verify.ts +136 -0
- package/dockerfiles/claude-runtime/src/watchdog.ts +115 -0
- package/dockerfiles/claude-runtime/test/credentials.test.js +43 -0
- package/dockerfiles/claude-runtime/test/grounding.test.js +191 -0
- package/dockerfiles/claude-runtime/test/help-index.test.js +115 -0
- package/dockerfiles/claude-runtime/test/plugin-skills.test.js +57 -0
- package/dockerfiles/claude-runtime/test/prompts.test.js +62 -0
- package/dockerfiles/claude-runtime/test/reaper.test.js +60 -0
- package/dockerfiles/claude-runtime/test/stream-filter.test.js +132 -0
- package/dockerfiles/claude-runtime/test/tasks.test.js +74 -0
- package/dockerfiles/claude-runtime/test/user-dir.test.js +71 -0
- package/dockerfiles/claude-runtime/test/verify.test.js +187 -0
- package/dockerfiles/claude-runtime/test/watchdog.test.js +43 -0
- package/dockerfiles/mcp-server/.eslintrc.json +39 -0
- package/dockerfiles/mcp-server/Dockerfile +10 -2
- package/dockerfiles/mcp-server/package-lock.json +1743 -98
- package/dockerfiles/mcp-server/package.json +27 -5
- package/dockerfiles/mcp-server/src/api-client.ts +123 -66
- package/dockerfiles/mcp-server/src/format.ts +51 -0
- package/dockerfiles/mcp-server/src/index.ts +44 -113
- package/dockerfiles/mcp-server/src/ops.ts +325 -0
- package/dockerfiles/mcp-server/src/shared-api-client.ts +81 -0
- package/dockerfiles/mcp-server/test/format.test.js +62 -0
- package/dockerfiles/mcp-server/test/ops.test.js +84 -0
- package/dockerfiles/mcp-server/test/shared-api-client.test.js +35 -0
- package/dockerfiles/queue/Dockerfile +2 -0
- package/dockerfiles/queue/container.json +7 -0
- package/docs/AUDIT-2026-08-03.md +1064 -0
- package/docs/BENCHMARK.md +292 -0
- package/docs/CLAUDE_CODE_FLOW.md +746 -0
- package/docs/EXAMPLES.md +82 -0
- package/docs/FEATURES.md +71 -0
- package/docs/IMPLEMENTATION.md +128 -0
- package/docs/LATENCY.md +170 -0
- package/docs/VISION.md +36 -0
- package/files/benchmark/suite.yaml +404 -0
- package/files/scripts/process-cro-results.md +14 -0
- package/files/suggestions.yaml +344 -0
- package/package.json +39 -97
- package/src/ai/ai-window.ts +157 -0
- package/src/ai/benchmark/benchmark.ts +737 -0
- package/src/ai/db-view-functions.ts +56 -0
- package/src/ai/engine.ts +98 -0
- package/src/ai/gemma-engine.ts +81 -0
- package/src/ai/panel.ts +1385 -0
- package/src/ai/prompt-suggestions.ts +209 -0
- package/src/ai/search/combined-search.ts +244 -0
- package/src/{llm-utils → ai/search}/query-matching.ts +46 -167
- package/src/{llm-utils → ai}/storage.ts +0 -1
- package/src/ai/table-tools.ts +145 -0
- package/src/ai/ui.ts +720 -0
- package/src/ai/usage-limiter.ts +105 -0
- package/src/ai/view-tools.ts +352 -0
- package/src/claude/ai-feature.ts +16 -0
- package/src/claude/exec-blocks.ts +176 -0
- package/src/claude/queue-task.ts +84 -0
- package/src/claude/runtime-client.ts +310 -0
- package/src/claude/turn-log.ts +114 -0
- package/src/claude/undoable.ts +105 -0
- package/src/{llm-utils → db}/db-index-tools.ts +24 -32
- package/src/db/sql-tools.ts +336 -0
- package/src/depr/LLM-client.ts +251 -0
- package/src/depr/ai-panel.ts +174 -0
- package/src/depr/chatgpt-assistant.ts +257 -0
- package/src/depr/creds.ts +30 -0
- package/src/depr/deepwikiclient.ts +118 -0
- package/src/depr/indexes/dg-repository-index.ts +266 -0
- package/src/depr/interfaces.ts +170 -0
- package/src/depr/is-help-request.ts +39 -0
- package/src/depr/prompt-engine.ts +52 -0
- package/src/depr/rendering-tools.ts +103 -0
- package/src/depr/script-tools.ts +785 -0
- package/src/depr/tableview-tools.ts +746 -0
- package/src/depr/viewers-ai.ts +67 -0
- package/src/package-api.ts +87 -28
- package/src/package-test.ts +1 -0
- package/src/package.g.ts +98 -48
- package/src/package.ts +211 -157
- package/src/polyfills.ts +12 -0
- package/src/utils.ts +128 -0
- package/tsconfig.json +8 -70
- package/webpack.config.js +3 -49
- package/.eslintignore +0 -2
- package/src/ai-panel.ts +0 -174
- package/src/claude-code/claude-panel.ts +0 -34
- package/src/claude-code/claude-runtime-client.ts +0 -148
- package/src/llm-utils/LLM-client.ts +0 -251
- package/src/llm-utils/combined-search.ts +0 -162
- package/src/llm-utils/creds.ts +0 -30
- package/src/llm-utils/deepwikiclient.ts +0 -118
- package/src/llm-utils/indexes/dg-repository-index.ts +0 -266
- package/src/llm-utils/panel.ts +0 -866
- package/src/llm-utils/script-tools.ts +0 -784
- package/src/llm-utils/sql-tools.ts +0 -840
- package/src/llm-utils/tableview-tools.ts +0 -704
- package/src/llm-utils/ui.ts +0 -315
- package/src/prompt-engine/chatgpt-assistant.ts +0 -257
- package/src/prompt-engine/interfaces.ts +0 -170
- package/src/prompt-engine/prompt-engine.ts +0 -52
- package/src/prompt-engine/rendering-tools.ts +0 -103
- package/src/prompts/is-help-request.ts +0 -26
- package/src/viewers-ai.ts +0 -67
- /package/src/{llm-utils → db}/indexes/biologics-index.ts +0 -0
- /package/src/{llm-utils → db}/indexes/chembl-index.ts +0 -0
- /package/src/{llm-utils → db}/query-meta-utils.ts +0 -0
- /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-chat-completions-provider.ts +0 -0
- /package/src/{llm-utils/depr → depr}/AI-API-providers/openai-responses-provider.ts +0 -0
- /package/src/{llm-utils/depr → depr}/AI-API-providers/types.ts +0 -0
- /package/src/{llm-utils/depr → depr}/depr.ts +0 -0
- /package/src/{llm-utils/depr → depr}/embeddings.ts +0 -0
- /package/src/{llm-utils/depr → depr}/sql-utils.ts +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Bounds how long a turn may produce nothing, and kills agent process trees. A wedged agent may
|
|
2
|
+
// never act on a polite cancel, so the bound ends in a real kill.
|
|
3
|
+
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
|
|
6
|
+
/** Returned by `raceIdle` when the wrapped promise produced nothing in time. */
|
|
7
|
+
export const IDLE = Symbol('idle');
|
|
8
|
+
|
|
9
|
+
/** Resolves with the promise's value, or IDLE if it does not settle within `ms`.
|
|
10
|
+
* Always clears its timer, so a long turn does not accumulate one per streamed event. */
|
|
11
|
+
export function raceIdle<T>(p: Promise<T>, ms: number): Promise<T | typeof IDLE> {
|
|
12
|
+
let timer: NodeJS.Timeout;
|
|
13
|
+
const idle = new Promise<typeof IDLE>((resolve) => {
|
|
14
|
+
timer = setTimeout(() => resolve(IDLE), ms);
|
|
15
|
+
});
|
|
16
|
+
return Promise.race([p, idle]).finally(() => clearTimeout(timer));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Every process with its parent and command name, from /proc (Linux); empty anywhere else. */
|
|
20
|
+
export function processTable(): {pid: number; ppid: number; command: string}[] {
|
|
21
|
+
const out: {pid: number; ppid: number; command: string}[] = [];
|
|
22
|
+
let entries: string[];
|
|
23
|
+
try {
|
|
24
|
+
entries = fs.readdirSync('/proc');
|
|
25
|
+
} catch {
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const pid = Number(entry);
|
|
30
|
+
if (!pid) continue;
|
|
31
|
+
try {
|
|
32
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, 'utf8');
|
|
33
|
+
// The parenthesised command may contain spaces and ')': after the last ')' come state, then ppid.
|
|
34
|
+
out.push({pid, ppid: Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]),
|
|
35
|
+
command: stat.slice(stat.indexOf('(') + 1, stat.lastIndexOf(')'))});
|
|
36
|
+
} catch { /* exited while we were reading it */ }
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function descendantPids(root: number, table: {pid: number; ppid: number}[]): number[] {
|
|
42
|
+
const children = new Map<number, number[]>();
|
|
43
|
+
for (const {pid, ppid} of table)
|
|
44
|
+
children.set(ppid, [...(children.get(ppid) ?? []), pid]);
|
|
45
|
+
const out = [...(children.get(root) ?? [])];
|
|
46
|
+
for (let i = 0; i < out.length; i++)
|
|
47
|
+
out.push(...(children.get(out[i]) ?? []));
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** SIGKILLs a process and its whole descendant tree. Hermes starts tool commands in sessions of
|
|
52
|
+
* their own, so a process-group kill misses them; the tree is read before the first signal, while
|
|
53
|
+
* the children still point at their parents. Returns the pids that could not be signalled. */
|
|
54
|
+
export function killTree(root: number): number[] {
|
|
55
|
+
const pids = [root, ...descendantPids(root, processTable())];
|
|
56
|
+
const failed: number[] = [];
|
|
57
|
+
for (const pid of pids) {
|
|
58
|
+
try {
|
|
59
|
+
process.kill(pid, 'SIGKILL');
|
|
60
|
+
} catch (e: any) {
|
|
61
|
+
if (e?.code !== 'ESRCH')
|
|
62
|
+
failed.push(pid);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
process.kill(-root, 'SIGKILL');
|
|
67
|
+
} catch { /* not a group leader, or the group is gone */ }
|
|
68
|
+
return failed;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** SIGKILLs everything under a process (not the process itself). */
|
|
72
|
+
export function killDescendants(root: number): void {
|
|
73
|
+
for (const pid of descendantPids(root, processTable())) {
|
|
74
|
+
try {
|
|
75
|
+
process.kill(pid, 'SIGKILL');
|
|
76
|
+
} catch { /* already gone */ }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function cmdline(pid: number): string {
|
|
81
|
+
try {
|
|
82
|
+
return fs.readFileSync(`/proc/${pid}/cmdline`, 'utf8').replace(/\0/g, ' ');
|
|
83
|
+
} catch {
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** True for an agent process. Keyed on the module in the command line, not on the interpreter, so a
|
|
89
|
+
* `python3` script a terminal tool call runs is never mistaken for an agent. */
|
|
90
|
+
export function isAgentProcess(commandLine: string): boolean {
|
|
91
|
+
return /\s-m grokky_agent(\s|$)/.test(commandLine);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Reaps agent processes the session pool no longer tracks (a dispose that raced a spawn, a
|
|
95
|
+
* kill the process survived): an untracked agent would hold memory with no turn left to time it out. */
|
|
96
|
+
export function startOrphanReaper(ownedPids: () => ReadonlySet<number>, intervalMs = 30000): NodeJS.Timeout {
|
|
97
|
+
const timer = setInterval(() => {
|
|
98
|
+
try {
|
|
99
|
+
const owned = ownedPids();
|
|
100
|
+
// Every process, not only this server's children: with tini as PID 1 an agent whose parent
|
|
101
|
+
// link was lost is reparented to tini.
|
|
102
|
+
for (const c of processTable()) {
|
|
103
|
+
if (owned.has(c.pid) || !isAgentProcess(cmdline(c.pid)))
|
|
104
|
+
continue;
|
|
105
|
+
const failed = killTree(c.pid);
|
|
106
|
+
console.warn(`reaper: SIGKILL orphaned ${c.command} (pid ${c.pid}) and its descendants — not owned by ` +
|
|
107
|
+
`the session pool${failed.length ? `; could not signal ${failed.join(', ')}` : ''}`);
|
|
108
|
+
}
|
|
109
|
+
} catch (e: any) {
|
|
110
|
+
console.warn('reaper: sweep failed:', e?.message ?? e);
|
|
111
|
+
}
|
|
112
|
+
}, intervalMs);
|
|
113
|
+
timer.unref?.();
|
|
114
|
+
return timer;
|
|
115
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert');
|
|
3
|
+
const http = require('node:http');
|
|
4
|
+
|
|
5
|
+
const TOKEN = 'eyJhbGciOiJSUzI1NiJ9.CONTAINER-TOKEN.sig';
|
|
6
|
+
const NOT_SET = /^No AI model credentials are set for you/;
|
|
7
|
+
let reply;
|
|
8
|
+
let seen;
|
|
9
|
+
const datlas = http.createServer((req, res) => {
|
|
10
|
+
seen = {url: req.url, authorization: req.headers.authorization};
|
|
11
|
+
res.writeHead(reply.status, {'content-type': 'application/json', ...reply.headers});
|
|
12
|
+
res.end(JSON.stringify(reply.body ?? {}));
|
|
13
|
+
});
|
|
14
|
+
let credentials;
|
|
15
|
+
|
|
16
|
+
test.before(async () => {
|
|
17
|
+
await new Promise((resolve) => datlas.listen(0, '127.0.0.1', resolve));
|
|
18
|
+
process.env.DATAGROK_API_URL = `http://127.0.0.1:${datlas.address().port}`;
|
|
19
|
+
credentials = require('../dist/credentials.js');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test.after(() => datlas.close());
|
|
23
|
+
|
|
24
|
+
test('the container token buys the caller\'s provider credentials, and only those', async () => {
|
|
25
|
+
reply = {status: 200, body: {provider: 'Azure', apiKey: 'group-key', model: 'claude-x', region: '', dbPassword: 'p'}};
|
|
26
|
+
const c = await credentials.userCredentials(TOKEN);
|
|
27
|
+
assert.deepEqual(seen, {url: '/docker/credentials', authorization: `Bearer ${TOKEN}`});
|
|
28
|
+
assert.deepEqual(c.values, {provider: 'Azure', apiKey: 'group-key', model: 'claude-x'});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('without the caller\'s credentials there is nothing to run on', async () => {
|
|
32
|
+
for (reply of [{status: 404}, {status: 200, headers: {'api-error': 'NotFound', 'api-error-code': '404'}},
|
|
33
|
+
{status: 200, body: {dbPassword: 'p'}}])
|
|
34
|
+
await assert.rejects(credentials.userCredentials(TOKEN), {message: NOT_SET});
|
|
35
|
+
await assert.rejects(credentials.userCredentials(undefined),
|
|
36
|
+
{message: 'The assistant could not read its credentials: the connection did not come through Datagrok'});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('a refused token fails with its status, never the token', async () => {
|
|
40
|
+
reply = {status: 200, headers: {'api-error': 'UserException', 'api-error-code': '401'}, body: {message: TOKEN}};
|
|
41
|
+
await assert.rejects(credentials.userCredentials(TOKEN),
|
|
42
|
+
{message: 'The assistant could not read its credentials: HTTP 401 from /docker/credentials'});
|
|
43
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// GroundingGate — blocks a Stop once if the turn answered platform questions from memory
|
|
2
|
+
// rather than from a source opened this turn.
|
|
3
|
+
|
|
4
|
+
const test = require('node:test');
|
|
5
|
+
const assert = require('node:assert');
|
|
6
|
+
const {GroundingGate, isSmallTalk, makesPlatformClaims} = require('../dist/grounding.js');
|
|
7
|
+
|
|
8
|
+
const blocked = (feedback) => feedback !== undefined;
|
|
9
|
+
|
|
10
|
+
test('reading a help page grounds the turn', () => {
|
|
11
|
+
const g = new GroundingGate();
|
|
12
|
+
g.afterTool('read_file', {path: 'workspace/help/visualize/viewers/scatter-plot.md'}, '');
|
|
13
|
+
assert.ok(!blocked(g.atStop()));
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('reading js-api source grounds the turn', () => {
|
|
17
|
+
const g = new GroundingGate();
|
|
18
|
+
g.afterTool('read_file', {path: 'workspace/js-api/src/dataframe.ts'}, '');
|
|
19
|
+
assert.ok(!blocked(g.atStop()));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('web lookups count as grounding', () => {
|
|
23
|
+
for (const tool of ['web_extract', 'web_search']) {
|
|
24
|
+
const g = new GroundingGate();
|
|
25
|
+
g.afterTool(tool, {url: 'https://datagrok.ai/help'}, '');
|
|
26
|
+
assert.ok(!blocked(g.atStop()), `${tool} should ground`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('taking an action grounds the turn — it is not a from-memory answer', () => {
|
|
31
|
+
const g = new GroundingGate();
|
|
32
|
+
g.afterTool('datagrok_exec', {code: 'return 1'}, '');
|
|
33
|
+
assert.ok(!blocked(g.atStop()));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('reading an unrelated file does NOT ground the turn', () => {
|
|
37
|
+
const g = new GroundingGate();
|
|
38
|
+
g.afterTool('read_file', {path: 'workspace/packages/Chem/package.json'}, '');
|
|
39
|
+
assert.ok(blocked(g.atStop()));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('an answer with no tool use at all is blocked once', () => {
|
|
43
|
+
const g = new GroundingGate();
|
|
44
|
+
const r = g.atStop();
|
|
45
|
+
assert.ok(blocked(r));
|
|
46
|
+
assert.match(r, /INDEX\.md/, 'the block must point at the index, not at grepping');
|
|
47
|
+
assert.match(r, /NO_REVISION/, 'and must offer the keep-original escape hatch');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('the gate blocks at most once per turn', () => {
|
|
51
|
+
const g = new GroundingGate();
|
|
52
|
+
assert.ok(blocked(g.atStop()));
|
|
53
|
+
assert.ok(!blocked(g.atStop()), 'a second Stop must pass or the turn cannot end');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('block reason is framed as internal feedback', () => {
|
|
57
|
+
const g = new GroundingGate();
|
|
58
|
+
const r = g.atStop();
|
|
59
|
+
assert.match(r, /never mention, quote, or allude to it/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('onBlock fires so the runtime can start a hidden revision', () => {
|
|
63
|
+
let calls = 0;
|
|
64
|
+
const g = new GroundingGate(() => calls++);
|
|
65
|
+
g.atStop();
|
|
66
|
+
g.atStop();
|
|
67
|
+
assert.equal(calls, 1, 'only the single real block should trigger a revision');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('summary reports both flags', () => {
|
|
71
|
+
const g = new GroundingGate();
|
|
72
|
+
assert.equal(g.summary(), 'grounded=false blocked=false');
|
|
73
|
+
g.afterTool('read_file', {path: 'workspace/help/index.md'}, '');
|
|
74
|
+
assert.equal(g.summary(), 'grounded=true blocked=false');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('search_files over help counts, over other paths does not', () => {
|
|
78
|
+
const yes = new GroundingGate();
|
|
79
|
+
yes.afterTool('search_files', {pattern: 'scatter', path: 'workspace/help/'}, '');
|
|
80
|
+
assert.ok(!blocked(yes.atStop()));
|
|
81
|
+
|
|
82
|
+
const no = new GroundingGate();
|
|
83
|
+
no.afterTool('search_files', {pattern: '*.ts', target: 'files', path: 'workspace/packages/'}, '');
|
|
84
|
+
assert.ok(blocked(no.atStop()));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// isSmallTalk decides whether the gate is armed AT ALL (session.ts), so both failure directions
|
|
88
|
+
// are real: a greeting that matches nothing costs a hidden revision call and a "Revising…" flash;
|
|
89
|
+
// a question that matches by accident answers ungrounded with no safety net.
|
|
90
|
+
test('isSmallTalk accepts pure greetings and acknowledgements', () => {
|
|
91
|
+
for (const m of ['hello', 'Hi!', 'hey', 'HELLO', 'thanks', 'Thank you!', 'ok', 'cool',
|
|
92
|
+
'good morning', 'got it', 'hello there', 'hi grokky', 'thanks again', 'bye', 'how are you?'])
|
|
93
|
+
assert.ok(isSmallTalk(m), `"${m}" should be small talk`);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('isSmallTalk rejects anything with actual content', () => {
|
|
97
|
+
for (const m of ['hello, how do I add a scatter plot?', 'hi — can you filter this table?',
|
|
98
|
+
'what is a project?', 'help', 'select all rows', 'thanks, now add a histogram',
|
|
99
|
+
'ok now delete the AGE column', 'hello world program in python', ''])
|
|
100
|
+
assert.ok(!isSmallTalk(m), `"${m}" must NOT be small talk`);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('isSmallTalk sees through the prepended workspace context', () => {
|
|
104
|
+
// The panel sends '<workspace context>\n---\n\nhello' when a view is open (panel.ts
|
|
105
|
+
// prependViewContext) — the dashboard-open case that made the regression visible. Stripping is
|
|
106
|
+
// anchored on the context block's fixed header, not on '---' alone.
|
|
107
|
+
const ctx = 'Workspace state (live, changes as the user navigates):\n' +
|
|
108
|
+
'Current view: "Dashboard" (TableView)\nTable: demog, 5850 rows';
|
|
109
|
+
assert.ok(isSmallTalk(ctx + '\n---\n\nhello'), 'context + greeting is still small talk');
|
|
110
|
+
assert.ok(!isSmallTalk(ctx + '\n---\n\nhow many rows are selected?'),
|
|
111
|
+
'context + real question keeps the gate');
|
|
112
|
+
// A user message that merely contains a --- separator is never split — fail-closed.
|
|
113
|
+
assert.ok(!isSmallTalk('explain this:\n---\n\nok'), 'user-typed --- must not discard the head');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('loading a skill counts as grounding', () => {
|
|
117
|
+
// The system prompt names skills as the source of truth for code/API answers; blocking a
|
|
118
|
+
// skill-grounded turn costs a revision call that always ends NO_REVISION.
|
|
119
|
+
const g = new GroundingGate();
|
|
120
|
+
g.afterTool('skill_view', {name: 'datagrok-viewers'}, '');
|
|
121
|
+
assert.ok(!blocked(g.atStop()));
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Content-aware gating (from the 36-turn A/B: every Stop-block ended NO_REVISION, so the block
|
|
125
|
+
// is only worth its revision call when the answer actually makes platform how-to claims).
|
|
126
|
+
|
|
127
|
+
test('makesPlatformClaims: UI-instruction answers are claims', () => {
|
|
128
|
+
for (const a of [
|
|
129
|
+
'Click Tools | Data Science | Cluster, then pick the columns.',
|
|
130
|
+
'Right-click the column header and choose Rename.',
|
|
131
|
+
'Open the Add viewer dialog from the toolbar.',
|
|
132
|
+
'Go to File > Open and select your CSV.',
|
|
133
|
+
'Use the context panel to edit properties.',
|
|
134
|
+
'Press Ctrl+F to open the search.',
|
|
135
|
+
])
|
|
136
|
+
assert.ok(makesPlatformClaims(a), `should be a claim: "${a}"`);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('makesPlatformClaims: data answers are not claims', () => {
|
|
140
|
+
for (const a of [
|
|
141
|
+
'The **demog** table has **5,850 rows** and **11 columns**: USUBJID, AGE, SEX, RACE.',
|
|
142
|
+
'The average WEIGHT across all patients is 78.4 kg.',
|
|
143
|
+
'There are 878 patients older than 65.',
|
|
144
|
+
'Correlation between HEIGHT and WEIGHT is 0.71 — moderately strong.',
|
|
145
|
+
])
|
|
146
|
+
assert.ok(!makesPlatformClaims(a), `should NOT be a claim: "${a}"`);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('an ungrounded answer WITHOUT platform claims is not blocked', () => {
|
|
150
|
+
const g = new GroundingGate(undefined, () => 'The table has 5,850 rows and 11 columns.');
|
|
151
|
+
assert.ok(!blocked(g.atStop()));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('an ungrounded answer WITH platform claims is blocked once', () => {
|
|
155
|
+
const g = new GroundingGate(undefined, () => 'Click Tools | X | Y to do that.');
|
|
156
|
+
assert.ok(blocked(g.atStop()));
|
|
157
|
+
assert.ok(!blocked(g.atStop()), 'still at most one block per turn');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('a grounded claimy answer is not blocked', () => {
|
|
161
|
+
const g = new GroundingGate(undefined, () => 'Click Add | Scatter plot (from the docs).');
|
|
162
|
+
g.afterTool('read_file', {path: 'workspace/help/visualize/viewers/scatter-plot.md'}, '');
|
|
163
|
+
assert.ok(!blocked(g.atStop()));
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('without an answerText getter the gate keeps the old always-block behavior', () => {
|
|
167
|
+
const g = new GroundingGate();
|
|
168
|
+
assert.ok(blocked(g.atStop()), 'fail-closed when no text is available');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('a terminal search of the docs or the js-api source grounds the turn, any other command does not', () => {
|
|
172
|
+
for (const [args, grounds] of [[{command: 'grep -rn "scatter" workspace/help/visualize'}, true],
|
|
173
|
+
[{command: 'rg addViewer workspace/js-api/src'}, true], [{command: 'ls workspace/packages'}, false]]) {
|
|
174
|
+
const g = new GroundingGate(undefined, () => 'Click Add | Scatter plot.');
|
|
175
|
+
g.afterTool('terminal', args, '');
|
|
176
|
+
assert.equal(!blocked(g.atStop()), grounds, args.command);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('state-changing browser, view and domain calls ground the turn; reads and questions do not', () => {
|
|
181
|
+
for (const [name, args, grounds] of [['datagrok_exec', {code: 'x'}, true],
|
|
182
|
+
['call_view_function', {name: 'setColumn'}, true],
|
|
183
|
+
['mcp__datagrok__datagrok_functions', {op: 'call', args: {name: 'X:y'}}, true],
|
|
184
|
+
['list_view_functions', {query: 'x'}, false], ['get_view_function_result', {name: 'getRange'}, false],
|
|
185
|
+
['mcp__datagrok__datagrok_functions', {op: 'list'}, false], ['datagrok_show_entities', {entities: []}, false],
|
|
186
|
+
['AskUserQuestion', {questions: []}, false]]) {
|
|
187
|
+
const g = new GroundingGate(undefined, () => 'Click the toolbar icon.');
|
|
188
|
+
g.afterTool(name, args, '{}');
|
|
189
|
+
assert.equal(!blocked(g.atStop()), grounds, name);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// buildHelpIndex — generates workspace/help/INDEX.md, the single Read that replaced an
|
|
2
|
+
// unbounded grep chain for help grounding (see docs/LATENCY.md tier 1a). What it indexes,
|
|
3
|
+
// and what it deliberately skips, directly determines help-turn round-trip count.
|
|
4
|
+
|
|
5
|
+
const test = require('node:test');
|
|
6
|
+
const assert = require('node:assert');
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const os = require('node:os');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
const {buildHelpIndex} = require('../dist/help-index.js');
|
|
11
|
+
|
|
12
|
+
// Builds a throwaway workspace/help tree from {relPath: contents} and returns the INDEX.md text.
|
|
13
|
+
function indexOf(files) {
|
|
14
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'helpidx-'));
|
|
15
|
+
for (const [rel, body] of Object.entries(files)) {
|
|
16
|
+
const full = path.join(root, 'help', rel);
|
|
17
|
+
fs.mkdirSync(path.dirname(full), {recursive: true});
|
|
18
|
+
fs.writeFileSync(full, body);
|
|
19
|
+
}
|
|
20
|
+
buildHelpIndex(root);
|
|
21
|
+
const out = fs.readFileSync(path.join(root, 'help', 'INDEX.md'), 'utf8');
|
|
22
|
+
fs.rmSync(root, {recursive: true, force: true});
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test('frontmatter title, description and keywords all reach the index line', () => {
|
|
27
|
+
const idx = indexOf({
|
|
28
|
+
'visualize/scatter-plot.md': `---
|
|
29
|
+
title: Scatter plot
|
|
30
|
+
description: Plots two numeric columns against each other
|
|
31
|
+
keywords:
|
|
32
|
+
- scatterplot
|
|
33
|
+
- xy chart
|
|
34
|
+
---
|
|
35
|
+
# Scatter plot
|
|
36
|
+
body`,
|
|
37
|
+
});
|
|
38
|
+
assert.match(idx, /visualize\/scatter-plot\.md — Scatter plot/);
|
|
39
|
+
assert.match(idx, /Plots two numeric columns against each other/);
|
|
40
|
+
assert.match(idx, /\[scatterplot, xy chart\]/);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('a page with no frontmatter falls back to its first H1', () => {
|
|
44
|
+
const idx = indexOf({'basics/intro.md': '# Getting started\n\nsome text'});
|
|
45
|
+
assert.match(idx, /basics\/intro\.md — Getting started/);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('a page with neither frontmatter nor H1 falls back to its filename', () => {
|
|
49
|
+
const idx = indexOf({'basics/orphan.md': 'no heading at all'});
|
|
50
|
+
assert.match(idx, /basics\/orphan\.md — orphan/);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('quoted frontmatter values are unquoted', () => {
|
|
54
|
+
const idx = indexOf({'a/b.md': '---\ntitle: "Quoted Title"\ndescription: \'single\'\n---\nx'});
|
|
55
|
+
assert.match(idx, /— Quoted Title — single/);
|
|
56
|
+
assert.ok(!idx.includes('"Quoted Title"'));
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('QA scenario pages (-test.md) are excluded so answers cite real docs', () => {
|
|
60
|
+
const idx = indexOf({
|
|
61
|
+
'viewers/scatter.md': '# Scatter',
|
|
62
|
+
'viewers/scatter-test.md': '# Scatter test checklist',
|
|
63
|
+
});
|
|
64
|
+
assert.match(idx, /viewers\/scatter\.md/);
|
|
65
|
+
assert.ok(!idx.includes('scatter-test.md'), '-test.md pages must not be indexed');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('underscore-prefixed files, INDEX.md and CLAUDE.md are excluded', () => {
|
|
69
|
+
const idx = indexOf({
|
|
70
|
+
'real.md': '# Real',
|
|
71
|
+
'_draft.md': '# Draft',
|
|
72
|
+
'CLAUDE.md': '# Agent instructions',
|
|
73
|
+
});
|
|
74
|
+
assert.match(idx, /real\.md/);
|
|
75
|
+
assert.ok(!idx.includes('_draft.md'));
|
|
76
|
+
assert.ok(!idx.includes('CLAUDE.md'));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('internal and asset directories are skipped', () => {
|
|
80
|
+
const idx = indexOf({
|
|
81
|
+
'keep/page.md': '# Keep',
|
|
82
|
+
'_internal/secret.md': '# Secret',
|
|
83
|
+
'uploads/blob.md': '# Blob',
|
|
84
|
+
'img/pic.md': '# Pic',
|
|
85
|
+
});
|
|
86
|
+
assert.match(idx, /keep\/page\.md/);
|
|
87
|
+
for (const skipped of ['secret.md', 'blob.md', 'pic.md'])
|
|
88
|
+
assert.ok(!idx.includes(skipped), `${skipped} should be skipped`);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('pages are grouped under a section header per top-level directory', () => {
|
|
92
|
+
const idx = indexOf({
|
|
93
|
+
'access/login.md': '# Login',
|
|
94
|
+
'visualize/chart.md': '# Chart',
|
|
95
|
+
});
|
|
96
|
+
assert.match(idx, /^## access$/m);
|
|
97
|
+
assert.match(idx, /^## visualize$/m);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('the header tells the model to stop searching when nothing matches', () => {
|
|
101
|
+
const idx = indexOf({'a.md': '# A'});
|
|
102
|
+
assert.match(idx, /If no page covers the topic, the docs do not cover it/);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('mdx pages are indexed alongside md', () => {
|
|
106
|
+
const idx = indexOf({'guide/tour.mdx': '# Tour'});
|
|
107
|
+
assert.match(idx, /guide\/tour\.mdx — Tour/);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('a missing help directory is a no-op rather than a crash', () => {
|
|
111
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'helpidx-empty-'));
|
|
112
|
+
assert.doesNotThrow(() => buildHelpIndex(root));
|
|
113
|
+
assert.ok(!fs.existsSync(path.join(root, 'help', 'INDEX.md')));
|
|
114
|
+
fs.rmSync(root, {recursive: true, force: true});
|
|
115
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Skills are prose, so nothing type-checks them — a skill can keep instructing the model to call
|
|
2
|
+
// a tool that no longer exists and the only symptom is a turn that fails in an odd way. The
|
|
3
|
+
// 34-tool -> 5-domain-tool consolidation left three such references behind; these tests are the
|
|
4
|
+
// guard against the next rename.
|
|
5
|
+
|
|
6
|
+
const test = require('node:test');
|
|
7
|
+
const assert = require('node:assert');
|
|
8
|
+
const fs = require('node:fs');
|
|
9
|
+
const path = require('node:path');
|
|
10
|
+
|
|
11
|
+
const SKILLS = path.join(__dirname, '..', 'plugin', 'skills');
|
|
12
|
+
|
|
13
|
+
// Retired when the datagrok MCP server moved to one tool per domain (mcp-server/src/ops.ts).
|
|
14
|
+
// Matched as whole words so prose like "create a project" is not flagged.
|
|
15
|
+
const RETIRED = [
|
|
16
|
+
'list_functions', 'get_function', 'call_function', 'list_scripts', 'list_queries',
|
|
17
|
+
'create_script', 'create_query', 'list_files', 'download_file', 'upload_file',
|
|
18
|
+
'list_projects', 'get_project', 'create_project', 'delete_project', 'search_project',
|
|
19
|
+
'list_recent_projects', 'attach_entity_to_project', 'share_project', 'list_project_shares',
|
|
20
|
+
'list_spaces', 'get_space', 'create_space', 'delete_space', 'create_subspace',
|
|
21
|
+
'list_space_children', 'add_entity_to_space', 'remove_entity_from_space',
|
|
22
|
+
'read_space_file', 'write_space_file', 'delete_space_file',
|
|
23
|
+
'whoami', 'list_connections', 'list_groups', 'list_users',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const skillFiles = () => fs.readdirSync(SKILLS)
|
|
27
|
+
.map((d) => path.join(SKILLS, d, 'SKILL.md'))
|
|
28
|
+
.filter((p) => fs.existsSync(p));
|
|
29
|
+
|
|
30
|
+
test('skills exist and are loadable', () => {
|
|
31
|
+
assert.ok(skillFiles().length >= 10, 'expected the full skill set');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('no skill references a retired MCP tool name', () => {
|
|
35
|
+
const offences = [];
|
|
36
|
+
for (const file of skillFiles()) {
|
|
37
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
38
|
+
for (const name of RETIRED) {
|
|
39
|
+
const re = new RegExp(`\\b${name}\\b`);
|
|
40
|
+
if (re.test(text))
|
|
41
|
+
offences.push(`${path.basename(path.dirname(file))}: ${name}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
assert.deepEqual(offences, [],
|
|
45
|
+
'skills name tools that no longer exist — use datagrok_<domain>(op:"…", args:{…})');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('every skill has name and description frontmatter', () => {
|
|
49
|
+
for (const file of skillFiles()) {
|
|
50
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
51
|
+
const fm = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
52
|
+
assert.ok(fm, `${file} has no frontmatter`);
|
|
53
|
+
assert.match(fm[1], /^name:\s*\S+/m, `${file} has no name`);
|
|
54
|
+
// The description is what the model routes on; an empty one makes the skill unreachable.
|
|
55
|
+
assert.match(fm[1], /^description:\s*\S.{40,}/m, `${file} needs a routing description`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// System prompt assembly. The prefix these produce is re-read on every API call of every turn, so anything that
|
|
2
|
+
// silently bloats it is a per-turn tax.
|
|
3
|
+
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const test = require('node:test');
|
|
6
|
+
const assert = require('node:assert');
|
|
7
|
+
|
|
8
|
+
process.env.GROKKY_PLUGIN_DIR = path.join(__dirname, '..', 'plugin');
|
|
9
|
+
const {buildSystemPrompt} = require('../dist/prompts.js');
|
|
10
|
+
|
|
11
|
+
test('bash and none modes stay minimal', () => {
|
|
12
|
+
assert.match(buildSystemPrompt('bash'), /^Execute the given shell command/);
|
|
13
|
+
assert.equal(buildSystemPrompt('none'), '');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('the full prompt is the default for any other mode', () => {
|
|
17
|
+
const full = buildSystemPrompt();
|
|
18
|
+
assert.ok(full.length > 1000);
|
|
19
|
+
assert.equal(buildSystemPrompt('datagrok'), full);
|
|
20
|
+
assert.equal(buildSystemPrompt(undefined), full);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('the search prompt adds the no-browser-tools note to the full prompt', () => {
|
|
24
|
+
const full = buildSystemPrompt();
|
|
25
|
+
assert.match(buildSystemPrompt('search').replace(full, ''), /No browser tools this turn/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('the full prompt documents the domain MCP tools', () => {
|
|
29
|
+
const full = buildSystemPrompt();
|
|
30
|
+
for (const tool of ['datagrok_functions', 'datagrok_files', 'datagrok_projects',
|
|
31
|
+
'datagrok_spaces', 'datagrok_platform'])
|
|
32
|
+
assert.ok(full.includes(tool), `system prompt never mentions ${tool}`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('the full prompt prefers widget quick functions for viewer-targeted requests', () => {
|
|
36
|
+
const full = buildSystemPrompt();
|
|
37
|
+
assert.ok(full.includes('list_view_widgets'), 'widget tool never mentioned');
|
|
38
|
+
assert.match(full, /prefer\s+its own quick functions/i, 'no widget-function preference rule');
|
|
39
|
+
for (const fn of ['zoomIn', 'resetView', 'colorBy', 'splitBy'])
|
|
40
|
+
assert.ok(full.includes(fn), `viewer quick command ${fn} not named in the prompt`);
|
|
41
|
+
// Function names are camelCase across the board; snake_case in the widget list is a regression.
|
|
42
|
+
for (const stale of ['get_dialog_info', 'list_panes', 'set_column', 'list_items'])
|
|
43
|
+
assert.ok(!full.includes(stale), `stale snake_case name ${stale} in the prompt`);
|
|
44
|
+
assert.match(full, /preference, not a hard rule/i, 'the rule must stay soft');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('inlined skills carry no YAML frontmatter', () => {
|
|
48
|
+
const full = buildSystemPrompt();
|
|
49
|
+
assert.ok(full.includes('## Inlined Skills'), 'the inlined skills are missing');
|
|
50
|
+
const inlined = full.slice(full.indexOf('## Inlined Skills'));
|
|
51
|
+
assert.ok(!/^name:\s/m.test(inlined), 'frontmatter leaked into the system prompt');
|
|
52
|
+
assert.ok(!/^description:\s/m.test(inlined), 'frontmatter leaked into the system prompt');
|
|
53
|
+
assert.ok(!/^---\s*$/m.test(inlined.replace(/^---$/gm, (m, i) =>
|
|
54
|
+
// the section separator between skills is a legitimate '---'
|
|
55
|
+
inlined.slice(0, i).includes('### ') ? '' : m)), 'stray frontmatter delimiters');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('the full prompt warns that search_files lists hidden directories and matches names only', () => {
|
|
59
|
+
const full = buildSystemPrompt('datagrok');
|
|
60
|
+
assert.match(full, /`search_files` with `target: "files"` matches file names only/);
|
|
61
|
+
assert.match(full, /hidden directories such as `\.git`/);
|
|
62
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert');
|
|
3
|
+
const {startOrphanReaper, isAgentProcess, descendantPids} = require('../dist/watchdog');
|
|
4
|
+
|
|
5
|
+
const tick = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
6
|
+
// Every process counts as owned, so a sweep on Linux never kills anything of this machine's.
|
|
7
|
+
const everyPid = {has: () => true};
|
|
8
|
+
|
|
9
|
+
test('polls the pool\'s owned pids on a schedule', async () => {
|
|
10
|
+
let polls = 0;
|
|
11
|
+
const timer = startOrphanReaper(() => {
|
|
12
|
+
polls++;
|
|
13
|
+
return everyPid;
|
|
14
|
+
}, 10);
|
|
15
|
+
await tick(60);
|
|
16
|
+
clearInterval(timer);
|
|
17
|
+
assert.ok(polls > 1, `polled ${polls} times`);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('returns an unref-ed timer so it cannot hold the process open', () => {
|
|
21
|
+
const timer = startOrphanReaper(() => everyPid, 10);
|
|
22
|
+
// A reaper that kept the event loop alive would stop the container ever shutting down.
|
|
23
|
+
assert.equal(typeof timer.hasRef === 'function' ? timer.hasRef() : false, false);
|
|
24
|
+
clearInterval(timer);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('survives an ownedPids that throws instead of crashing the runtime', async () => {
|
|
28
|
+
// This runs on a bare timer callback: an escaping throw is an uncaught exception that takes
|
|
29
|
+
// down the whole runtime. The janitor must never kill the process it is cleaning up after.
|
|
30
|
+
const timer = startOrphanReaper(() => {
|
|
31
|
+
throw new Error('registry unavailable');
|
|
32
|
+
}, 10);
|
|
33
|
+
await tick(40);
|
|
34
|
+
clearInterval(timer);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('isAgentProcess matches the agent module on the command line, whatever the interpreter', () => {
|
|
38
|
+
assert.ok(isAgentProcess('/opt/hermes/.venv/bin/python -m grokky_agent '));
|
|
39
|
+
assert.ok(isAgentProcess('/opt/hermes/.venv/bin/python3.14 -m grokky_agent'));
|
|
40
|
+
assert.ok(isAgentProcess('python3 -u -m grokky_agent '));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('isAgentProcess never matches a script a terminal tool call runs', () => {
|
|
44
|
+
assert.ok(!isAgentProcess('python3 analyze.py '));
|
|
45
|
+
assert.ok(!isAgentProcess('python3 -c print("-m grokky_agent is fine") '));
|
|
46
|
+
assert.ok(!isAgentProcess('python3 -m grokky_agent_tools '));
|
|
47
|
+
assert.ok(!isAgentProcess('python3 -m pytest grokky_agent '));
|
|
48
|
+
assert.ok(!isAgentProcess('bash -c ls /opt/grokky_agent-notes '));
|
|
49
|
+
assert.ok(!isAgentProcess('node /app/dist/server.js '));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('descendantPids collects the whole tree under a pid, at any depth, and nothing else', () => {
|
|
53
|
+
const table = [
|
|
54
|
+
{pid: 1, ppid: 0}, {pid: 10, ppid: 1}, {pid: 11, ppid: 10}, {pid: 12, ppid: 11}, {pid: 13, ppid: 11},
|
|
55
|
+
{pid: 14, ppid: 10}, {pid: 20, ppid: 1}, {pid: 21, ppid: 20},
|
|
56
|
+
];
|
|
57
|
+
assert.deepEqual(descendantPids(10, table).sort((a, b) => a - b), [11, 12, 13, 14]);
|
|
58
|
+
assert.deepEqual(descendantPids(20, table), [21]);
|
|
59
|
+
assert.deepEqual(descendantPids(12, table), []);
|
|
60
|
+
});
|