@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,104 @@
|
|
|
1
|
+
import type {TurnGate} from './types';
|
|
2
|
+
import {bareToolName, isActionTool} from './verify';
|
|
3
|
+
|
|
4
|
+
// Enforces the "ground platform answers in sources" rule (see prompts.ts) with a revision
|
|
5
|
+
// protocol that keeps the UX clean: the model's first answer streams and STAYS visible; if the
|
|
6
|
+
// turn ends ungrounded, the Stop is blocked once and the model either writes a complete
|
|
7
|
+
// replacement (grounded in help/INDEX.md → page) or replies NO_REVISION to keep the original.
|
|
8
|
+
// The revision streams hidden — session.ts suppresses chunks after the block and the `final`
|
|
9
|
+
// event carries kept/replaced — so the user never sees drafts vanish or duplicate.
|
|
10
|
+
|
|
11
|
+
// Pure small talk never needs grounding, and the gate is not free: a Stop-block costs a full
|
|
12
|
+
// hidden revision call (~28k-token prefix re-read) that ends in NO_REVISION, and past 1.2s the
|
|
13
|
+
// panel shows "Revising…" over a greeting. So the gate is not armed at all for messages that are
|
|
14
|
+
// only a greeting/thanks/acknowledgement. The check runs on the USER'S OWN text: the panel
|
|
15
|
+
// prepends a workspace-context block terminated by '\n---\n\n' (see panel.ts
|
|
16
|
+
// prependViewContext), so with a dashboard open the message is '<context>\n---\n\nhello' —
|
|
17
|
+
// strip the context first or nothing ever matches. Conservative on purpose: anything beyond
|
|
18
|
+
// small talk ("hi, how do I add a scatter plot?") must keep the gate.
|
|
19
|
+
const SMALL_TALK_RE = new RegExp(
|
|
20
|
+
'^(?:hi|hii+|hello|hey|yo|good\\s+(?:morning|afternoon|evening)|how\\s+are\\s+you|' +
|
|
21
|
+
'thanks?|thank\\s+you|thx|ty|ok(?:ay)?|cool|nice|great|awesome|perfect|got\\s+it|' +
|
|
22
|
+
'bye|goodbye|see\\s+you|good\\s+night)' +
|
|
23
|
+
'(?:\\s+(?:there|again|grokky|claude))?[\\s.!?,]*$', 'i');
|
|
24
|
+
|
|
25
|
+
// The context block always opens with this exact header (exec-blocks.ts buildWorkspaceContext),
|
|
26
|
+
// so stripping is anchored on it — a user message that merely contains '---' is never split,
|
|
27
|
+
// which keeps misclassification fail-closed (gate stays armed).
|
|
28
|
+
const CONTEXT_HEADER = 'Workspace state (live, changes as the user navigates):';
|
|
29
|
+
|
|
30
|
+
export function isSmallTalk(message: string): boolean {
|
|
31
|
+
let text = message;
|
|
32
|
+
if (text.startsWith(CONTEXT_HEADER)) {
|
|
33
|
+
const sep = text.indexOf('\n---\n\n');
|
|
34
|
+
if (sep < 0)
|
|
35
|
+
return false;
|
|
36
|
+
text = text.slice(sep + 6);
|
|
37
|
+
}
|
|
38
|
+
text = text.trim();
|
|
39
|
+
return text.length <= 60 && SMALL_TALK_RE.test(text);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function openedDocs(toolName: string, input: unknown): boolean {
|
|
43
|
+
const bare = bareToolName(toolName);
|
|
44
|
+
// Web lookups and skills are sources the system prompt points at; re-blocking them only costs a revision.
|
|
45
|
+
if (bare === 'web_search' || bare === 'web_extract' || bare === 'skill_view')
|
|
46
|
+
return true;
|
|
47
|
+
if (bare !== 'read_file' && bare !== 'search_files' && bare !== 'terminal')
|
|
48
|
+
return false;
|
|
49
|
+
const source = JSON.stringify(input ?? '');
|
|
50
|
+
return source.includes('help/') || source.includes('js-api/');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// A Stop-block is only worth its hidden revision call when the answer actually makes platform
|
|
54
|
+
// how-to claims. Measured (36-turn A/B, docs/BENCHMARK.md "Grounding gate A/B"): every single
|
|
55
|
+
// block ended in NO_REVISION — the model grounds itself because the system prompt tells it to —
|
|
56
|
+
// while trivial contextual answers ("5,850 rows and 11 columns") paid 2× latency for the block.
|
|
57
|
+
// So the gate now fires only when the visible answer contains UI-instruction markers: those are
|
|
58
|
+
// the answers where an ungrounded claim ("click Tools | X") is both likely wrong and looks
|
|
59
|
+
// authoritative. False positive = one wasted call (the old behavior everywhere); false negative
|
|
60
|
+
// = a non-instructional answer, where a hallucinated claim has far less surface to hide in.
|
|
61
|
+
const PLATFORM_CLAIM_RE = new RegExp(
|
|
62
|
+
'\\b(?:click|right-click|double-click|menu|submenu|dialog|button|ribbon|toolbar|sidebar|' +
|
|
63
|
+
'dropdown|drop-down|checkbox|wizard|icon|drag|shortcut|hotkey|context panel|property panel|' +
|
|
64
|
+
'top menu|go to|navigate to|select .{1,40} from|open the)\\b|Ctrl\\s*\\+|\\|\\s*\\w+\\s*\\|', 'i');
|
|
65
|
+
|
|
66
|
+
export function makesPlatformClaims(answer: string): boolean {
|
|
67
|
+
return PLATFORM_CLAIM_RE.test(answer);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export class GroundingGate implements TurnGate {
|
|
71
|
+
private grounded = false;
|
|
72
|
+
private blocked = false;
|
|
73
|
+
|
|
74
|
+
/** @param answerText returns the turn's visible streamed text so far (session.ts accumulates it). */
|
|
75
|
+
constructor(private onBlock?: () => void, private answerText?: () => string) {}
|
|
76
|
+
|
|
77
|
+
summary(): string {
|
|
78
|
+
return `grounded=${this.grounded} blocked=${this.blocked}`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
afterTool(toolName: string, args: Record<string, unknown>): void {
|
|
82
|
+
if (openedDocs(toolName, args) || isActionTool(toolName, args))
|
|
83
|
+
this.grounded = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
atStop(): string | undefined {
|
|
87
|
+
if (this.grounded || this.blocked)
|
|
88
|
+
return undefined;
|
|
89
|
+
// No UI-instruction content in the answer → nothing the gate protects against; let it end.
|
|
90
|
+
if (this.answerText && !makesPlatformClaims(this.answerText()))
|
|
91
|
+
return undefined;
|
|
92
|
+
this.blocked = true;
|
|
93
|
+
this.onBlock?.();
|
|
94
|
+
return '[Internal pipeline feedback — never mention, quote, or allude to it in your reply.] ' +
|
|
95
|
+
'Review the answer you just gave: if it makes claims about how the Datagrok platform works ' +
|
|
96
|
+
'(features, menus, behavior) that you did not verify in a source this turn, ground it now — ' +
|
|
97
|
+
'read `workspace/help/INDEX.md` with read_file, pick the matching page, read it, and write a corrected ' +
|
|
98
|
+
'answer from what the docs say. The user still sees your previous answer and your new text ' +
|
|
99
|
+
'will replace it, so make it complete and standalone; if the index has no matching page, ' +
|
|
100
|
+
'state that the docs do not cover it. If your answer needed no such verification (greeting, ' +
|
|
101
|
+
'small talk, general knowledge, or it was already accurate without docs claims), reply with ' +
|
|
102
|
+
'exactly NO_REVISION.';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
|
|
4
|
+
// Generates workspace/help/INDEX.md — one line per published doc page, built from frontmatter
|
|
5
|
+
// (title / description / keywords, with first-H1 fallback). Grounding a help answer then costs
|
|
6
|
+
// one read of the index + one read of the right page instead of an unbounded grep chain
|
|
7
|
+
// (measured at 8-33 model round-trips per help turn before this existed — see docs/LATENCY.md).
|
|
8
|
+
// Regenerated at startup and after each workspace git sync; INDEX.md is untracked, so
|
|
9
|
+
// `git reset --hard` leaves it alone.
|
|
10
|
+
|
|
11
|
+
const SKIP_DIRS = new Set(['_internal', '_access', '_stashed', '_deprecated', '_stash', 'uploads', 'img']);
|
|
12
|
+
|
|
13
|
+
interface PageEntry {
|
|
14
|
+
rel: string;
|
|
15
|
+
title: string;
|
|
16
|
+
description: string;
|
|
17
|
+
keywords: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function parseFrontmatter(text: string): {title?: string; description?: string; keywords: string[]} {
|
|
21
|
+
const out: {title?: string; description?: string; keywords: string[]} = {keywords: []};
|
|
22
|
+
const lines = text.split(/\r?\n/);
|
|
23
|
+
if (!/^---\s*$/.test(lines[0] ?? ''))
|
|
24
|
+
return out;
|
|
25
|
+
let inKeywords = false;
|
|
26
|
+
for (let i = 1; i < lines.length; i++) {
|
|
27
|
+
const line = lines[i];
|
|
28
|
+
if (/^---\s*$/.test(line))
|
|
29
|
+
break;
|
|
30
|
+
const kw = line.match(/^\s+-\s+(.+)$/);
|
|
31
|
+
if (inKeywords && kw) {
|
|
32
|
+
out.keywords.push(kw[1].trim().replace(/^["']|["']$/g, ''));
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
inKeywords = false;
|
|
36
|
+
const field = line.match(/^(\w[\w-]*):\s*(.*)$/);
|
|
37
|
+
if (!field)
|
|
38
|
+
continue;
|
|
39
|
+
const [, key, value] = field;
|
|
40
|
+
if (key === 'keywords')
|
|
41
|
+
inKeywords = value.trim() === '' || value.trim() === '|';
|
|
42
|
+
else if (key === 'title')
|
|
43
|
+
out.title = value.trim().replace(/^["']|["']$/g, '');
|
|
44
|
+
else if (key === 'description')
|
|
45
|
+
out.description = value.trim().replace(/^["']|["']$/g, '');
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function firstH1(text: string): string | undefined {
|
|
51
|
+
return text.match(/^#\s+(.+)$/m)?.[1]?.trim();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function collectPages(helpDir: string): PageEntry[] {
|
|
55
|
+
const entries: PageEntry[] = [];
|
|
56
|
+
const walk = (dir: string): void => {
|
|
57
|
+
for (const name of fs.readdirSync(dir, {withFileTypes: true})) {
|
|
58
|
+
const full = path.join(dir, name.name);
|
|
59
|
+
if (name.isDirectory()) {
|
|
60
|
+
if (!SKIP_DIRS.has(name.name))
|
|
61
|
+
walk(full);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
// -test.md files are internal QA scenarios — indexing them would draw help answers
|
|
65
|
+
// to test checklists instead of the real page (they stay greppable on disk).
|
|
66
|
+
if (!/\.(md|mdx)$/.test(name.name) || name.name.startsWith('_') ||
|
|
67
|
+
/-test\.md$/.test(name.name) || name.name === 'INDEX.md' || name.name === 'CLAUDE.md')
|
|
68
|
+
continue;
|
|
69
|
+
let text: string;
|
|
70
|
+
try {
|
|
71
|
+
text = fs.readFileSync(full, 'utf8');
|
|
72
|
+
} catch {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const fm = parseFrontmatter(text);
|
|
76
|
+
const title = fm.title ?? firstH1(text) ?? name.name.replace(/\.(md|mdx)$/, '');
|
|
77
|
+
entries.push({
|
|
78
|
+
rel: path.relative(helpDir, full).split(path.sep).join('/'),
|
|
79
|
+
title,
|
|
80
|
+
description: fm.description ?? '',
|
|
81
|
+
keywords: fm.keywords,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
walk(helpDir);
|
|
86
|
+
return entries.sort((a, b) => a.rel.localeCompare(b.rel));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function buildHelpIndex(workspaceDir: string): void {
|
|
90
|
+
const helpDir = path.join(workspaceDir, 'help');
|
|
91
|
+
if (!fs.existsSync(helpDir))
|
|
92
|
+
return;
|
|
93
|
+
const pages = collectPages(helpDir);
|
|
94
|
+
const lines: string[] = [
|
|
95
|
+
'# Help documentation index',
|
|
96
|
+
'',
|
|
97
|
+
'One line per page: `path — Title — description [keywords]`. To answer a platform question:',
|
|
98
|
+
'find the relevant page below (titles + keywords), then read `workspace/help/<path>` with read_file.',
|
|
99
|
+
'Link the page you answer from: `<path>` is published at `https://datagrok.ai/help/<path>` without its',
|
|
100
|
+
'`.md` or `.mdx` (`transform/add-new-column.md` is `https://datagrok.ai/help/transform/add-new-column`).',
|
|
101
|
+
'If no page covers the topic, the docs do not cover it — say so instead of searching further.',
|
|
102
|
+
'',
|
|
103
|
+
];
|
|
104
|
+
let section = '';
|
|
105
|
+
for (const p of pages) {
|
|
106
|
+
const top = p.rel.split('/')[0];
|
|
107
|
+
if (top !== section) {
|
|
108
|
+
section = top;
|
|
109
|
+
lines.push(`## ${top}`, '');
|
|
110
|
+
}
|
|
111
|
+
const desc = p.description ? ` — ${p.description}` : '';
|
|
112
|
+
const kw = p.keywords.length ? ` [${p.keywords.join(', ')}]` : '';
|
|
113
|
+
lines.push(`- ${p.rel} — ${p.title}${desc}${kw}`);
|
|
114
|
+
}
|
|
115
|
+
lines.push('');
|
|
116
|
+
fs.writeFileSync(path.join(helpDir, 'INDEX.md'), lines.join('\n'));
|
|
117
|
+
console.log(`help-index: ${pages.length} pages indexed`);
|
|
118
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The image starts the server as root and the server drops to uid 1001 here, before anything else runs: a process
|
|
2
|
+
// whose uid changed after exec is not dumpable, so the agents' tools (also uid 1001) cannot read its memory, environ
|
|
3
|
+
// or fds, which hold the provider key and every connected user's key.
|
|
4
|
+
if (process.getuid?.() === 0) {
|
|
5
|
+
process.setgroups!([]);
|
|
6
|
+
process.setgid!(2001);
|
|
7
|
+
process.setuid!(1001);
|
|
8
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import * as YAML from 'yaml';
|
|
5
|
+
import {PLUGIN_DIR} from './constants';
|
|
6
|
+
import type {PromptMode} from './types';
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// System prompts — one per systemPromptMode: 'bash', 'none' (empty), full (default)
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
const BASH_EXEC_PROMPT = `\
|
|
13
|
+
Execute the given shell command with the terminal tool. \
|
|
14
|
+
Output ONLY the exact stdout of the command — no preamble, no explanation, nothing else.`;
|
|
15
|
+
|
|
16
|
+
const DATAGROK_PROMPT = `\
|
|
17
|
+
You are Datagrok Code Assistant — an AI coding agent embedded in the Datagrok data analytics platform.
|
|
18
|
+
Work through Datagrok's own tooling: the \`datagrok-*\` skills (\`skill_view\`), the MCP tools for
|
|
19
|
+
server-side entities, and the current view's functions (\`list_view_functions\`). They already carry
|
|
20
|
+
the calls and conventions you need. The Datagrok public repository at \`workspace/\` (relative to your
|
|
21
|
+
current working directory) holds the documentation, and the JS API source as a last resort for what no
|
|
22
|
+
tool covers. It contains only packages installed on this instance.
|
|
23
|
+
|
|
24
|
+
ALWAYS use paths under \`workspace/\` (e.g. \`workspace/packages/Chem/...\`, \`workspace/js-api/src/...\`).
|
|
25
|
+
NEVER use \`/workspace/...\` as an absolute path — the runtime blocks such access.
|
|
26
|
+
\`search_files\` with \`target: "files"\` matches file names only (a directory in \`pattern\` is dropped, so set \`path\` instead) and also lists hidden directories such as \`.git\` or \`.vscode\` that do not match: leave those out of counts and answers.
|
|
27
|
+
|
|
28
|
+
## Skills
|
|
29
|
+
|
|
30
|
+
A set of \`datagrok-*\` skills is available through the **\`skill_view\` tool** — they cover viewers,
|
|
31
|
+
filtering, selection, columns, calculated columns, grid customization, the cheminformatics and
|
|
32
|
+
bioactivity toolkits, projects, and executing/showing results. Their descriptions handle routing:
|
|
33
|
+
when a request matches one, load it with \`skill_view\` BEFORE any other tool and follow it — including
|
|
34
|
+
for changes to the current view, where the skill says when the view's own functions apply.
|
|
35
|
+
|
|
36
|
+
## View functions
|
|
37
|
+
|
|
38
|
+
Every view — and every widget inside it (grid, viewers, editors, panels) — exposes the functions
|
|
39
|
+
applicable to it: its commands and view/widget-specific operations. The workspace context may
|
|
40
|
+
carry an "About this view" line (the view's own briefing on what it is and which functions to
|
|
41
|
+
reach for — follow it) and a "Widgets in this view" line with sub-widget briefings. Reach the
|
|
42
|
+
functions through these tools:
|
|
43
|
+
- \`list_view_functions(query, widget?)\` — search the current view's functions. A view can have
|
|
44
|
+
hundreds (a table view's commands, the query editor's SQL tools, Flow's graph tools); pass one
|
|
45
|
+
or two broad words (matching is OR-ranked), or no query to see the first ~10. Entity gallery
|
|
46
|
+
views (users, groups, roles, projects, connections, dockers, ...) all support
|
|
47
|
+
\`listItems\` / \`searchItems\` / \`selectItem\` / \`listItemCommands\` / \`runItemCommand\`.
|
|
48
|
+
- \`list_view_widgets()\` — the view's widget tree plus any OPEN DIALOGS (refs \`dlg0\`, ...):
|
|
49
|
+
each widget's ref, type, AI briefing, and function count. Pass a ref as \`widget\` to the other
|
|
50
|
+
three tools to target that widget. Standard widgets ship functions: dialogs expose
|
|
51
|
+
\`getDialogInfo\` / \`setInput\` / \`clickButton\` (fill and confirm a dialog a command opened),
|
|
52
|
+
tab controls \`listTabs\` / \`selectTab\`, accordions \`listPanes\` / \`expandPane\`, column
|
|
53
|
+
selectors on viewers \`setColumn\`, range sliders \`getRange\` / \`setRange\`, viewer legends
|
|
54
|
+
\`listCategories\` / \`selectCategory\`, property grids \`getProperties\` / \`setProperty\`,
|
|
55
|
+
per-column filters \`resetFilter\`, the Browse tree \`listNodes\` / \`expandNode\` /
|
|
56
|
+
\`selectNode\`, the chemical sketcher \`getMolecule\` / \`setMolecule\`.
|
|
57
|
+
- \`get_view_function_result(name, parameters, widget?)\` — invoke a read-only function (inspect state).
|
|
58
|
+
- \`call_view_function(name, parameters, widget?)\` — invoke a state-changing function.
|
|
59
|
+
Custom plugin views (type \`js-view-base\`) commonly ship rich function sets: e.g. **Flow**,
|
|
60
|
+
Datagrok's visual pipeline editor for composing functions into executable workflows, ships graph
|
|
61
|
+
functions (list/find/add/connect/run nodes, interactive guides); the database query editor ships
|
|
62
|
+
SQL schema exploration and query-editing functions. Rules:
|
|
63
|
+
- When the request changes or operates the current view (filter, color, add or set up a viewer, run
|
|
64
|
+
one of its commands), call \`list_view_functions\` (after loading the matching skill) and PREFER its functions over generic
|
|
65
|
+
\`datagrok_exec\` code; when the user asks what you can do "here" / "for this view", enumerate
|
|
66
|
+
these functions first. A question answered from the data (an average, a count, which group is
|
|
67
|
+
largest) changes nothing: compute it with one read-only \`datagrok_exec\` and answer, without view
|
|
68
|
+
functions or \`datagrok_verify\`.
|
|
69
|
+
- When the request targets a specific viewer or widget ("zoom in to the scatter plot",
|
|
70
|
+
"color the box plot by AGE", "reset the chart"), find it via \`list_view_widgets\` and prefer
|
|
71
|
+
its own quick functions — viewers ship commands like \`zoomIn\` / \`zoomOut\` / \`resetView\` /
|
|
72
|
+
\`xBy\` / \`colorBy\` / \`splitBy\`(columnName) — over setting properties or writing code. This is
|
|
73
|
+
a preference, not a hard rule: if no matching function exists, act through properties or
|
|
74
|
+
\`datagrok_exec\` as usual.
|
|
75
|
+
- When \`list_view_functions\` returns nothing relevant, say so — do not DOM-inspect the view
|
|
76
|
+
with \`datagrok_exec\` to guess its capabilities.
|
|
77
|
+
|
|
78
|
+
## Don't invent names
|
|
79
|
+
|
|
80
|
+
NEVER guess function names, parameter names, signatures, or JS API methods. RDKit, pandas, scikit, numpy, AWS SDK, and other library conventions DO NOT translate to Datagrok. Inventing names is the #1 cause of silent failures. Look a name up in this order and stop at the first source that has it: the inlined skills below, a skill loaded with \`skill_view\` (the index below says which one covers what), the current view's functions (\`list_view_functions\`), an MCP discovery result. A name a skill gives is settled: call it as the skill shows, with the arguments the skill shows, and do not open the source to check it again. Read \`workspace/js-api/src/\` only for a call that no skill or tool covers, and then the one file you need, without searching the repository for it.
|
|
81
|
+
|
|
82
|
+
## Server-side entities (MCP)
|
|
83
|
+
|
|
84
|
+
Datagrok's server-side objects are reached through one MCP tool per domain, each taking an
|
|
85
|
+
\`op\` and its \`args\`: \`datagrok_functions\`, \`datagrok_files\`, \`datagrok_projects\`,
|
|
86
|
+
\`datagrok_spaces\`, \`datagrok_platform\`. The tool description lists each operation with its
|
|
87
|
+
parameters and what they mean, so call the operation directly.
|
|
88
|
+
Reach for these when the request concerns stored server-side objects
|
|
89
|
+
— not for anything in the current view, which the view functions cover.
|
|
90
|
+
|
|
91
|
+
For a Datagrok function in a package not covered by an inlined skill, call
|
|
92
|
+
\`datagrok_functions(op:"list", args:{filter})\` to discover it; use \`op:"get"\` only when you
|
|
93
|
+
need full parameter details.
|
|
94
|
+
|
|
95
|
+
## Ground answers in sources, not memory
|
|
96
|
+
|
|
97
|
+
Treat your own knowledge of Datagrok as unreliable. Its UI, menus, behavior, and
|
|
98
|
+
capabilities are platform-specific and do not follow the conventions of other tools. Answer only
|
|
99
|
+
from a source you open this turn — never from memory. Which source is authoritative depends on what
|
|
100
|
+
you are doing:
|
|
101
|
+
|
|
102
|
+
- **Explaining how the product works** (menus, dialogs, features, "how do I…", "what is…"): the
|
|
103
|
+
documentation under \`workspace/help/\` is the source of truth. Do NOT grep around for it —
|
|
104
|
+
read \`workspace/help/INDEX.md\` with \`read_file\` (one line per page: path, title, description,
|
|
105
|
+
keywords), pick the matching page, read it, and take the facts from it. If the index has no page for the topic,
|
|
106
|
+
the docs do not cover it — say so instead of searching further. Skills are convenience
|
|
107
|
+
summaries — incomplete, and a relevant-looking one may describe the wrong feature — so a skill is
|
|
108
|
+
not a substitute for the docs here; when they disagree, the docs win.
|
|
109
|
+
- **Writing code or taking an action**: the matching per-area skill is the source of truth for the
|
|
110
|
+
API and the conventions to follow (which call to prefer, which footgun to avoid). Open it and
|
|
111
|
+
follow it. The help docs are user-facing, so they do not override the skill.
|
|
112
|
+
|
|
113
|
+
Either way, answer only what a source supports, quoting it where the exact wording matters. Give one
|
|
114
|
+
verified answer, not a list of unverified possibilities. If no source covers it, say so rather than
|
|
115
|
+
guess.
|
|
116
|
+
|
|
117
|
+
## Internal feedback
|
|
118
|
+
|
|
119
|
+
Automated pipeline feedback may arrive mid-turn (verification demands, grounding reminders, hook
|
|
120
|
+
messages). It is internal machinery: act on it, but never mention, quote, or allude to it in your
|
|
121
|
+
visible reply.
|
|
122
|
+
|
|
123
|
+
## Clarifying ambiguous requests
|
|
124
|
+
|
|
125
|
+
You have the \`AskUserQuestion\` tool available. Use it only when the **intent** itself is unclear — e.g. a request names no action, or two fundamentally different actions are equally plausible. End your turn right after asking.`;
|
|
126
|
+
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Inlined skills — skill bodies appended to the full system prompt at startup
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
// Inlined into the system prompt. datagrok-exec is universal — it defines the contract for the
|
|
132
|
+
// datagrok_exec tool, which nearly every action-taking response uses. Everything else is loaded
|
|
133
|
+
// on demand via skill_view — skills' description triggers handle routing.
|
|
134
|
+
const INLINED_SKILL_NAMES = [
|
|
135
|
+
'datagrok-exec',
|
|
136
|
+
'datagrok-entities',
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
// CRLF-tolerant: the repo checks the skills in with Windows line endings, so an LF-only pattern
|
|
140
|
+
// silently matches nothing and inlines each skill's YAML frontmatter into the system prompt.
|
|
141
|
+
const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/;
|
|
142
|
+
|
|
143
|
+
function loadInlinedSkills(): string {
|
|
144
|
+
const sections: string[] = [];
|
|
145
|
+
for (const name of INLINED_SKILL_NAMES) {
|
|
146
|
+
const skillPath = path.join(PLUGIN_DIR, 'skills', name, 'SKILL.md');
|
|
147
|
+
try {
|
|
148
|
+
const body = fs.readFileSync(skillPath, 'utf8').replace(FRONTMATTER, '').trim();
|
|
149
|
+
sections.push(`### ${name}\n\n${body}`);
|
|
150
|
+
} catch (e: any) {
|
|
151
|
+
console.error(`inlined skill '${name}' failed to load from ${skillPath} — system prompt ships without it:`, e.message);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return sections.join('\n\n---\n\n');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const INLINED_SKILLS = loadInlinedSkills();
|
|
158
|
+
|
|
159
|
+
function frontmatter(md: string): Record<string, string> {
|
|
160
|
+
const m = md.match(FRONTMATTER);
|
|
161
|
+
if (!m)
|
|
162
|
+
return {};
|
|
163
|
+
try {
|
|
164
|
+
return YAML.parse(m[1]) ?? {};
|
|
165
|
+
} catch {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function loadSkillsIndex(): string {
|
|
171
|
+
const dir = path.join(PLUGIN_DIR, 'skills');
|
|
172
|
+
let names: string[];
|
|
173
|
+
try {
|
|
174
|
+
names = fs.readdirSync(dir).sort();
|
|
175
|
+
} catch (e: any) {
|
|
176
|
+
console.error(`skills index: cannot read ${dir}:`, e.message);
|
|
177
|
+
return '';
|
|
178
|
+
}
|
|
179
|
+
const lines: string[] = [];
|
|
180
|
+
for (const name of names) {
|
|
181
|
+
try {
|
|
182
|
+
const fm = frontmatter(fs.readFileSync(path.join(dir, name, 'SKILL.md'), 'utf8'));
|
|
183
|
+
lines.push(`- ${fm.name ?? name}: ${fm.description ?? ''}`);
|
|
184
|
+
} catch { /* not a skill directory */ }
|
|
185
|
+
}
|
|
186
|
+
return lines.length ?
|
|
187
|
+
`## Available skills\n\nLoad one with \`skill_view\` (\`name\`: its name) when the request matches its ` +
|
|
188
|
+
`description:\n\n${lines.join('\n')}` : '';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const SKILLS_INDEX = loadSkillsIndex();
|
|
192
|
+
|
|
193
|
+
// Build once at module load so the system prompt prefix is byte-stable across every turn and
|
|
194
|
+
// every user — required for Anthropic prompt-cache hits on the ~20-30 KB prefix.
|
|
195
|
+
const DATAGROK_SYSTEM_PROMPT = INLINED_SKILLS ?
|
|
196
|
+
`${DATAGROK_PROMPT}\n\n## Inlined Skills\n\nThese skills are available in this context — invoke them directly without loading them with skill_view. Each section gives the canonical signatures, conventions, and examples for one capability.\n\n${INLINED_SKILLS}` :
|
|
197
|
+
DATAGROK_PROMPT;
|
|
198
|
+
const DATAGROK_FULL_PROMPT = SKILLS_INDEX ? `${DATAGROK_SYSTEM_PROMPT}\n\n${SKILLS_INDEX}` : DATAGROK_SYSTEM_PROMPT;
|
|
199
|
+
|
|
200
|
+
const SEARCH_PROMPT = `${DATAGROK_FULL_PROMPT}
|
|
201
|
+
|
|
202
|
+
## Search bar request
|
|
203
|
+
|
|
204
|
+
No browser tools this turn: \`datagrok_exec\`, \`datagrok_verify\`, \`datagrok_show_entities\`, \`AskUserQuestion\` and the view functions are unavailable. Skills and MCP tools work. If the reply format has a \`code\` field, the search bar runs that code after your reply: do not run or verify it yourself.`;
|
|
205
|
+
|
|
206
|
+
export function buildSystemPrompt(mode?: PromptMode): string {
|
|
207
|
+
if (mode === 'bash') return BASH_EXEC_PROMPT;
|
|
208
|
+
if (mode === 'none') return '';
|
|
209
|
+
if (mode === 'search') return SEARCH_PROMPT;
|
|
210
|
+
return DATAGROK_FULL_PROMPT;
|
|
211
|
+
}
|