@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,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: datagrok-projects
|
|
3
|
+
description: Save, publish, create, attach to, or share a Datagrok project, including turning data sync on. The save and share flows drive the platform dialogs through their AI functions.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# datagrok-projects
|
|
7
|
+
|
|
8
|
+
## Save / publish — drive the platform's Save dialog
|
|
9
|
+
|
|
10
|
+
The Save Project dialog is the platform's save/publish entry and the only reliable way to get
|
|
11
|
+
per-table data sync, creation-script dependency linking, and the correct upload order. Do not
|
|
12
|
+
hand-write project/table saves with `grok.dapi` — open the dialog and drive it through its
|
|
13
|
+
functions.
|
|
14
|
+
|
|
15
|
+
1. **Open the dialog** (`datagrok_exec`) with the platform's Save Project command — it saves the
|
|
16
|
+
current project and moves the workspace onto it:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
grok.functions.call('CmdSaveProject');
|
|
20
|
+
return {dialogOpened: true};
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
A new project's name is pre-filled from the tables; a saved project is updated in place.
|
|
24
|
+
|
|
25
|
+
2. **Find it**: `list_view_widgets` — the dialog is an extra root ref `dlg0` ("Save project");
|
|
26
|
+
note also the child ref of its entity-list widget (type `ProjectEntityMoveWidget`).
|
|
27
|
+
|
|
28
|
+
3. **Read its state**: `get_view_function_result(name: 'getProjectSaveInfo', widget: 'dlg0')` —
|
|
29
|
+
name (with validity), description, presentation mode, and every entity to be saved, with
|
|
30
|
+
`dataSync` / `dataSyncPossible` per table.
|
|
31
|
+
|
|
32
|
+
4. **Adjust only what the user asked for**, via `call_view_function`:
|
|
33
|
+
- on `dlg0`: `setProjectName`, `setProjectDescription`, `setPresentationMode`, `setSaveMode`
|
|
34
|
+
(when the dialog offers it)
|
|
35
|
+
- on the entity-list widget ref: `listEntities`, `setDataSync(table, enabled)`,
|
|
36
|
+
`setEntityAction(name, action)`
|
|
37
|
+
|
|
38
|
+
Every function returns `{success: false, error: ...}` with the reason when something can't be
|
|
39
|
+
done (e.g. data sync without a creation script) — report that reason; never work around it
|
|
40
|
+
with raw tag/meta writes.
|
|
41
|
+
|
|
42
|
+
5. **Confirm**: `call_view_function(name: 'clickButton', parameters: {name: 'OK'}, widget: 'dlg0')`
|
|
43
|
+
— applies the save and closes the dialog. If the user wanted to review first, stop before this
|
|
44
|
+
step and say the dialog is ready.
|
|
45
|
+
A first save then opens a **Share dialog** (a new `dlg<N>`): `clickButton CANCEL` unless the
|
|
46
|
+
user asked to share.
|
|
47
|
+
|
|
48
|
+
6. **Verify server-side** (`datagrok_verify`) — the upload is asynchronous, so if the first
|
|
49
|
+
re-read misses, confirm the dialog has closed and retry once:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const p = await grok.dapi.projects.filter('friendlyName = "<name>"').first();
|
|
53
|
+
return p != null && grok.shell.project.id === p.id;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
When data sync was requested, also verify the table:
|
|
57
|
+
`(await grok.dapi.tables.find('<tableInfoId>')).tags['.data-sync'] === 'sync'`.
|
|
58
|
+
|
|
59
|
+
## Data sync — the one precondition
|
|
60
|
+
|
|
61
|
+
A synced table re-runs its **creation script** when the project opens. The platform records that
|
|
62
|
+
script only when the query/script runs through its own pipeline — `grok.functions.call` /
|
|
63
|
+
`grok.data.query` run as processed calls and record nothing. So for "query the database and save
|
|
64
|
+
it with data sync":
|
|
65
|
+
|
|
66
|
+
1. Make sure the query is **saved on the server**: create it with
|
|
67
|
+
`connection.query('<name>', '<sql>')`, `q = await grok.dapi.queries.save(q)`, then re-read by
|
|
68
|
+
**id** (`grok.dapi.queries.find(q.id)`) — never by name, duplicates shadow name lookups.
|
|
69
|
+
2. Run the server copy so the result opens in the workspace **with** a creation script:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
const call = q.prepare({});
|
|
73
|
+
await call.call(false, undefined, {processed: false});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
3. Open the Save dialog (above) and `setDataSync(table, true)`. If it answers
|
|
77
|
+
"no creation script", step 2 didn't happen — fix that instead of forcing tags.
|
|
78
|
+
|
|
79
|
+
## Create / attach / share
|
|
80
|
+
|
|
81
|
+
- **Create** an empty project: `datagrok_projects(op: "create", args: {name})` once.
|
|
82
|
+
- **Attach** the current table/view to a project: use the Save dialog flow above.
|
|
83
|
+
- **Share**: `datagrok_projects(op: "share", args: {projectId, groups, access})` —
|
|
84
|
+
`access` `"View"`|`"Edit"`, default `"View"`; ask when no group is named. Confirm it with
|
|
85
|
+
`datagrok_projects(op: "list_shares", args: {projectId})`, not with `grok.dapi.permissions`
|
|
86
|
+
(its lists come back empty from a script).
|
|
87
|
+
When the platform's **Share dialog** is open instead (a `dlg<N>` ref), drive it the same way:
|
|
88
|
+
`getShareInfo`, `addShareGrantee(name)`, `setShareAccess(access)`, `setShareMessage(message)`,
|
|
89
|
+
then `clickButton OK`.
|
|
90
|
+
|
|
91
|
+
## Don't
|
|
92
|
+
|
|
93
|
+
- Save with `DG.Project.showSaveDialog` — it leaves the workspace unsaved.
|
|
94
|
+
- Hand-write saves with `grok.dapi.tables.save` / `uploadDataFrame` / `projects.save` — the
|
|
95
|
+
dialog handles upload order, table meta, and sync dependencies; manual writes corrupt them.
|
|
96
|
+
- Set `.data-sync` / `.script` tags directly — use `setDataSync` and let it refuse when the
|
|
97
|
+
precondition fails.
|
|
98
|
+
- Re-run a save after a timeout — re-read state first (`getProjectSaveInfo`, or check the dialog
|
|
99
|
+
closed); a second dialog or a duplicate project is worse than a late answer.
|
|
100
|
+
- Promise data sync before `setDataSync` (or `dataSyncPossible`) confirms it.
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: datagrok-selection
|
|
3
|
+
description: Manipulate row selection (`df.selection`) on a Datagrok DataFrame via the datagrok_exec tool — set, clear, invert, add to, remove from, intersect, and read the selection mask. Also covers current row (`df.currentRowIdx`), the cross-skill bridges to/from the filter, and how to materialize the selected rows as a new DataFrame. Use whenever the user says "select rows", "deselect", "invert selection", "highlight rows", "selected rows", "clear selection", "current row", "currentRowIdx", "count selected", "list selected indexes", "selection from filter", "filter from selection", or asks for selected rows as a new table. Does NOT cover row filtering (separate skill `datagrok-filtering`) or generic DataFrame cloning (`datagrok-df-and-columns`).
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# datagrok-selection
|
|
7
|
+
|
|
8
|
+
The active DataFrame is `t`; row selection lives at `t.selection` (a `DG.BitSet`).
|
|
9
|
+
|
|
10
|
+
The number-one trap: **`t.selection.setAll(false)` clears the selection**.
|
|
11
|
+
`setAll(true)` *selects* every row. That is the opposite of filter, where
|
|
12
|
+
`setAll(true)` is the cleared / no-filter state.
|
|
13
|
+
|
|
14
|
+
## Quick reference
|
|
15
|
+
|
|
16
|
+
| Need | Code |
|
|
17
|
+
|--------------------------------------|----------------------------------------------------------------------------------------|
|
|
18
|
+
| select all rows | `t.selection.setAll(true)` |
|
|
19
|
+
| **clear** the selection | `t.selection.setAll(false)` |
|
|
20
|
+
| invert | `t.selection.invert()` |
|
|
21
|
+
| select by predicate (replace) | `t.selection.init(i => pred(i))` |
|
|
22
|
+
| select by index list (replace) | `t.selection.setAll(false, false); for (const i of idx) t.selection.set(i,true,false); t.selection.fireChanged();` |
|
|
23
|
+
| add by predicate (union) | `t.selection.or(DG.BitSet.create(t.rowCount, i => pred(i)))` |
|
|
24
|
+
| remove indices | `for (const i of idx) t.selection.set(i,false,false); t.selection.fireChanged();` |
|
|
25
|
+
| intersect with predicate | `t.selection.and(DG.BitSet.create(t.rowCount, i => pred(i)))` |
|
|
26
|
+
| count selected | `t.selection.trueCount` |
|
|
27
|
+
| indices of selected rows | `t.selection.getSelectedIndexes()` (returns `Int32Array`) |
|
|
28
|
+
| is row `i` selected? | `t.selection.get(i)` |
|
|
29
|
+
| any row selected? | `t.selection.anyTrue` |
|
|
30
|
+
| selected rows as a new DF | `t.clone(t.selection)` |
|
|
31
|
+
| filter → selection (select visible) | `t.selection.copyFrom(t.filter)` |
|
|
32
|
+
| selection → filter (hide unselected) | `t.filter.copyFrom(t.selection)` |
|
|
33
|
+
| move current row | `t.currentRowIdx = i` (validate `0 <= i < t.rowCount`) |
|
|
34
|
+
| current row object / cell | `t.currentRow`, `t.currentCell` |
|
|
35
|
+
| mouse-over row | `t.mouseOverRowIdx` |
|
|
36
|
+
| subscribe to selection changes | `view.subs.push(t.onSelectionChanged.subscribe(() => …))` |
|
|
37
|
+
|
|
38
|
+
## The polarity table — opposite of filter
|
|
39
|
+
|
|
40
|
+
Selection and filter use the same `DG.BitSet` class, but the *meaning of `true`*
|
|
41
|
+
differs, so "clear" goes in opposite directions:
|
|
42
|
+
|
|
43
|
+
| Action | Filter (`df.filter`) | Selection (`df.selection`) |
|
|
44
|
+
|------------------------------|------------------------------|---------------------------------|
|
|
45
|
+
| clear (return to default) | `setAll(true)` (show all) | `setAll(false)` (none selected) |
|
|
46
|
+
| meaning of bit === `true` | row **passes** (visible) | row is **selected** |
|
|
47
|
+
| meaning of bit === `false` | row hidden | row not selected |
|
|
48
|
+
|
|
49
|
+
The pair to memorize, side by side:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
t.filter.setAll(true); // clear filter → every row visible
|
|
53
|
+
t.selection.setAll(false); // clear selection → none selected
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Predicate polarity matches across skills: in both `t.filter.init(pred)` and
|
|
57
|
+
`t.selection.init(pred)`, returning `true` *includes* the row. Only the *clear*
|
|
58
|
+
idiom flips.
|
|
59
|
+
|
|
60
|
+
## Selection vs current row vs mouse-over
|
|
61
|
+
|
|
62
|
+
Three independent row pointers — none is "the selected row" in the singular:
|
|
63
|
+
|
|
64
|
+
| Concept | API | Cardinality | Event |
|
|
65
|
+
|---------------|--------------------------------------|-------------------|-----------------------------|
|
|
66
|
+
| Selection | `t.selection` (BitSet) | many rows (set) | `t.onSelectionChanged` |
|
|
67
|
+
| Current row | `t.currentRowIdx` / `t.currentRow` | one row (focus) | `t.onCurrentRowChanged` |
|
|
68
|
+
| Mouse-over | `t.mouseOverRowIdx` | one row (transient) | `t.onMouseOverRowChanged` |
|
|
69
|
+
|
|
70
|
+
Setting `t.currentRowIdx = 5` does **not** select row 5; selecting rows does
|
|
71
|
+
**not** move the current row. When a user says "highlight row 5", the intent is
|
|
72
|
+
ambiguous — pick the path matching context ("scroll to" → current row;
|
|
73
|
+
"mark" → selection) or surface the ambiguity.
|
|
74
|
+
|
|
75
|
+
## Reading selection state
|
|
76
|
+
|
|
77
|
+
| Need | Code |
|
|
78
|
+
|---------------------------|---------------------------------------------------|
|
|
79
|
+
| rows currently selected | `t.selection.trueCount` |
|
|
80
|
+
| rows not selected | `t.selection.falseCount` |
|
|
81
|
+
| total rows | `t.selection.length` (same as `t.rowCount`) |
|
|
82
|
+
| indices of selected rows | `t.selection.getSelectedIndexes()` → `Int32Array` |
|
|
83
|
+
| is row `i` selected? | `t.selection.get(i)` |
|
|
84
|
+
| any selected? | `t.selection.anyTrue` |
|
|
85
|
+
| any unselected? | `t.selection.anyFalse` |
|
|
86
|
+
| next / prev set bit | `t.selection.findNext(i, true)` / `findPrev(i, true)` |
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
// How many rows are currently selected?
|
|
90
|
+
return {selected: t.selection.trueCount, unselected: t.selection.falseCount, total: t.rowCount};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`getSelectedIndexes()` caches its result. The cache invalidates on public
|
|
94
|
+
mutators (`set`, `init`, `setAll`, `and/or/xor/andNot`, `invert`, `copyFrom`).
|
|
95
|
+
If you mutate via `getBuffer()`, call `fireChanged()` to invalidate.
|
|
96
|
+
|
|
97
|
+
## Programmatic selection — modes
|
|
98
|
+
|
|
99
|
+
The four modes map directly to BitSet operations:
|
|
100
|
+
|
|
101
|
+
| Mode | BitSet op | Pattern |
|
|
102
|
+
|-------------|----------------------------------------|--------------------------------------|
|
|
103
|
+
| replace | `init(pred)` / `copyFrom(other)` | new selection replaces current |
|
|
104
|
+
| add | `or(other)` | union with current |
|
|
105
|
+
| remove | `andNot(other)` | subtract from current |
|
|
106
|
+
| intersect | `and(other)` | keep only rows in both |
|
|
107
|
+
|
|
108
|
+
### Predicate
|
|
109
|
+
|
|
110
|
+
`t.selection.init(pred)` is the fast, buffer-direct path for **replace**:
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
// Select rows where age > 40 (replace).
|
|
114
|
+
const age = t.getCol('age');
|
|
115
|
+
t.selection.init(i => (age.get(i)) > 40);
|
|
116
|
+
return {selected: t.selection.trueCount};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
For add / remove / intersect with a predicate, build a fresh BitSet and combine:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
// Add to the current selection (union, don't replace).
|
|
123
|
+
const act = t.getCol('activity');
|
|
124
|
+
t.selection.or(DG.BitSet.create(t.rowCount, i => (act.get(i)) > 7));
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Index list
|
|
128
|
+
|
|
129
|
+
`t.selection.set(i, x, notify)` writes one bit. **Pass `notify=false` in a
|
|
130
|
+
loop, then call `fireChanged()` once** — otherwise N writes fire N events:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
// Select explicit indices (replace). Zero the buffer, set bits with notify=false,
|
|
134
|
+
// fire one change at the end.
|
|
135
|
+
const idx = [0, 3, 5, 7, 11];
|
|
136
|
+
t.selection.setAll(false, false);
|
|
137
|
+
for (const i of idx) t.selection.set(i, true, false);
|
|
138
|
+
t.selection.fireChanged();
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Anti-pattern (laggy UI):**
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
// BAD — fires N events.
|
|
145
|
+
for (const i of indices) t.selection.set(i, true);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### From another BitSet
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
t.selection.copyFrom(other); // replace
|
|
152
|
+
t.selection.or(other); // add
|
|
153
|
+
t.selection.andNot(other); // remove
|
|
154
|
+
t.selection.and(other); // intersect
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Clearing & inverting
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
// Deselect everything. setAll(FALSE), not TRUE.
|
|
161
|
+
t.selection.setAll(false);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
// Flip the current selection.
|
|
166
|
+
t.selection.invert();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`t.selection.setAll(true)` selects every row — **including rows currently
|
|
170
|
+
hidden by the filter**. For "select all currently-visible rows", copy from the
|
|
171
|
+
filter (see below).
|
|
172
|
+
|
|
173
|
+
## Selected rows as a new DataFrame
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
const subset = t.clone(t.selection);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Same shape as `t.clone(t.filter)` — different mask:
|
|
180
|
+
|
|
181
|
+
| Idiom | Mask used | Source DF modified? |
|
|
182
|
+
|------------------------|----------------|--------------------------|
|
|
183
|
+
| `t.clone(t.filter)` | `t.filter` | no — clone of visible rows |
|
|
184
|
+
| `t.clone(t.selection)` | `t.selection` | no — clone of selected rows |
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
// Open selected rows as a new table view.
|
|
188
|
+
const subset = t.clone(t.selection);
|
|
189
|
+
grok.shell.addTableView(subset);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
If the selection is empty, `clone` returns a zero-row DataFrame (no error).
|
|
193
|
+
Guard with `t.selection.anyTrue` first for user-facing flows.
|
|
194
|
+
|
|
195
|
+
## Cross-skill bridges — selection ↔ filter
|
|
196
|
+
|
|
197
|
+
| Idiom | Effect | Phrasing it answers |
|
|
198
|
+
|----------------------------------------|---------------------------------------|----------------------------------------------------|
|
|
199
|
+
| `t.filter.copyFrom(t.selection)` | hide non-selected rows in place | "show only", "filter to the selection" |
|
|
200
|
+
| `t.selection.copyFrom(t.filter)` | mark every visible row as selected | "select all currently-visible rows" |
|
|
201
|
+
|
|
202
|
+
**Critical disambiguation:**
|
|
203
|
+
|
|
204
|
+
- "select rows [by / where / top N]" → set `t.selection` via `t.selection.init(pred)` or index-list pattern.
|
|
205
|
+
- "extract" / "copy" / "open as new table" / "give me a new table" → `t.clone(t.selection)` (new DataFrame; original unchanged).
|
|
206
|
+
|
|
207
|
+
`t.selection.copyFrom(t.filter)` fires `onSelectionChanged` but does NOT fire
|
|
208
|
+
a filter event; the reverse holds for `t.filter.copyFrom(t.selection)`.
|
|
209
|
+
|
|
210
|
+
## Current row
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
// Focus row 5 (the platform usually does this on click; rarely needed in scripts).
|
|
214
|
+
if (5 >= 0 && 5 < t.rowCount)
|
|
215
|
+
t.currentRowIdx = 5;
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`t.currentRow` (a `Row` proxy) and `t.currentCell` (a `Cell`) follow
|
|
219
|
+
`currentRowIdx` — read them on demand. Setting `currentRowIdx = -1` is the
|
|
220
|
+
valid "no current row" state.
|
|
221
|
+
|
|
222
|
+
## Describing the current selection
|
|
223
|
+
|
|
224
|
+
No built-in "describe selection" — hand-roll a structured report: count, capped
|
|
225
|
+
index list, sample row from the first selected index.
|
|
226
|
+
|
|
227
|
+
```js
|
|
228
|
+
// Describe the current selection.
|
|
229
|
+
const sel = t.selection;
|
|
230
|
+
const all = sel.getSelectedIndexes();
|
|
231
|
+
const MAX_INDEXES = 50;
|
|
232
|
+
const MAX_SAMPLE_COLS = 12;
|
|
233
|
+
const indexes = Array.from(all.slice(0, MAX_INDEXES));
|
|
234
|
+
|
|
235
|
+
const out = {
|
|
236
|
+
count: sel.trueCount,
|
|
237
|
+
total: t.rowCount,
|
|
238
|
+
indexes,
|
|
239
|
+
currentRowIdx: t.currentRowIdx,
|
|
240
|
+
sample: undefined,
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
if (all.length > 0) {
|
|
244
|
+
const firstIdx = all[0];
|
|
245
|
+
const cols = t.columns;
|
|
246
|
+
const sample = {};
|
|
247
|
+
const colCap = Math.min(cols.length, MAX_SAMPLE_COLS);
|
|
248
|
+
for (let c = 0; c < colCap; c++) {
|
|
249
|
+
const col = cols.byIndex(c);
|
|
250
|
+
sample[col.name] = col.get(firstIdx);
|
|
251
|
+
}
|
|
252
|
+
out.sample = sample;
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Selection event lifecycle
|
|
258
|
+
|
|
259
|
+
One event — unlike filter:
|
|
260
|
+
|
|
261
|
+
| Event | When |
|
|
262
|
+
|-----------------------------|-----------------------------------------------------|
|
|
263
|
+
| `t.onSelectionChanged` | Any mutation on `t.selection` (`set`, `init`, `setAll`, `and/or/xor/andNot`, `invert`, `copyFrom`). Same observable as `t.selection.onChanged`. |
|
|
264
|
+
|
|
265
|
+
```js
|
|
266
|
+
// Log selection count whenever it changes.
|
|
267
|
+
const sub = t.onSelectionChanged.subscribe(() => {
|
|
268
|
+
console.log(`selected: ${t.selection.trueCount}`);
|
|
269
|
+
});
|
|
270
|
+
view.subs.push(sub);
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
In a viewer / widget, push onto `viewer.subs[]` so the subscription cancels on
|
|
274
|
+
detach (`DG.Widget` does this automatically).
|
|
275
|
+
|
|
276
|
+
**Coalescing.** Every `BitSet` mutator takes `notify: boolean = true`. Pass
|
|
277
|
+
`false` in a loop and call `fireChanged()` once at the end:
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
for (let i = 0; i < indices.length; i++)
|
|
281
|
+
t.selection.set(indices[i], true, false); // notify = false
|
|
282
|
+
t.selection.fireChanged(); // one coalesced event
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Common patterns
|
|
286
|
+
|
|
287
|
+
```js
|
|
288
|
+
// Toggle selection on a single row.
|
|
289
|
+
const i = 5;
|
|
290
|
+
t.selection.set(i, !t.selection.get(i));
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
```js
|
|
294
|
+
// Top N by a column — sort, slice, set.
|
|
295
|
+
const idx = Array.from(t.getSortedOrder(['activity'], [false])).slice(0, 5);
|
|
296
|
+
t.selection.setAll(false, false);
|
|
297
|
+
for (const i of idx) t.selection.set(i, true, false);
|
|
298
|
+
t.selection.fireChanged();
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
```js
|
|
302
|
+
// "Select what I see" → narrow → "filter to what I just selected" pipeline.
|
|
303
|
+
t.selection.copyFrom(t.filter); // visible → selection
|
|
304
|
+
const flag = t.getCol('flag');
|
|
305
|
+
t.selection.and(DG.BitSet.create(t.rowCount, i => flag.get(i) === 'ok')); // narrow
|
|
306
|
+
t.filter.copyFrom(t.selection); // push back to filter
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Anti-patterns
|
|
310
|
+
|
|
311
|
+
1. **`t.selection.setAll(true)` to "clear" the selection.** That selects every
|
|
312
|
+
row — the **opposite** of what filter's clear does. Use
|
|
313
|
+
`t.selection.setAll(false)`.
|
|
314
|
+
2. **`t.filter.setAll(false)` to "clear" the filter.** Hides every row. Use
|
|
315
|
+
`t.filter.setAll(true)`. The cross-skill pair must be memorized together.
|
|
316
|
+
3. **`t.rows.select(rowPred)` for "replace selection" in perf-critical code.**
|
|
317
|
+
Functional, but iterates the `RowList` and per-bit `set` — materially slower
|
|
318
|
+
than `t.selection.init(pred)`, which is buffer-direct.
|
|
319
|
+
4. **`t.selection.init(...)` to *add* a condition to the selection.** `init`
|
|
320
|
+
zeros the buffer first. To extend, OR in
|
|
321
|
+
`DG.BitSet.create(t.rowCount, pred)`.
|
|
322
|
+
5. **Per-bit `set` in a loop without `notify=false`.** N writes → N events →
|
|
323
|
+
laggy UI. Always `set(i, x, false)` in the loop and `fireChanged()` at the
|
|
324
|
+
end.
|
|
325
|
+
6. **`t.selection.setAll(true)` when the user means "select all visible".**
|
|
326
|
+
That includes filtered-out rows. Use `t.selection.copyFrom(t.filter)`.
|
|
327
|
+
7. **Combining selections across DataFrames of different row counts.**
|
|
328
|
+
`dfA.selection.and(dfB.selection)` only makes sense if rows are aligned
|
|
329
|
+
1:1. Cross-table sync by key columns is `grok.data.linkTables(...)`.
|
|
330
|
+
8. **Removing rows when asked to "remove from the selection".**
|
|
331
|
+
That deletes rows from the DF entirely. To narrow the selection, use
|
|
332
|
+
`andNot` or `set(i, false, false)` in a loop.
|
|
333
|
+
|
|
334
|
+
## Out of scope
|
|
335
|
+
|
|
336
|
+
- **Filter operations.** `t.filter` lives in `datagrok-filtering`. Same BitSet
|
|
337
|
+
API, **opposite clear polarity** — see the polarity table above.
|
|
338
|
+
- **Viewer-driven interactive selection.** Lasso, grid click, shift-extend,
|
|
339
|
+
ctrl-toggle — dispatched via `BitSet.handleClick(rowPred, mouseEvent, ...)`.
|
|
340
|
+
Covered by `datagrok-viewers`.
|
|
341
|
+
- **Cross-table selection sync.** `grok.data.linkTables(t1, t2, k1, k2,
|
|
342
|
+
[SYNC_TYPE.SELECTION_TO_SELECTION, ...])` establishes long-lived sync.
|
|
343
|
+
- **Generic DataFrame cloning.** For "copy of this DF with these columns" (no
|
|
344
|
+
selection involved), see `datagrok-df-and-columns`.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: datagrok-undo
|
|
3
|
+
description: How to change an open table so that Ctrl+Z (Edit | Undo) takes the change back, and what undo cannot do. Use before adding, removing or renaming columns, removing rows, overwriting a column's values, changing column metadata (format, color coding, tags), adding or closing viewers, clearing the layout or closing a view, and when the user asks to undo or redo something or asks what can be undone.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# datagrok-undo
|
|
7
|
+
|
|
8
|
+
The platform undoes its own menu actions. A change a script makes directly (`t.columns.remove`,
|
|
9
|
+
`t.rows.removeWhereIdx`, `col.init`, `view.addViewer`) is **not** undoable. Three ways make one that is, in this
|
|
10
|
+
order of preference.
|
|
11
|
+
|
|
12
|
+
## 1. The table tools
|
|
13
|
+
|
|
14
|
+
Each acts on the table of the current table view, records one undo step and returns what it read back, with
|
|
15
|
+
`undoable: true | false`.
|
|
16
|
+
|
|
17
|
+
| Change | Tool |
|
|
18
|
+
|---|---|
|
|
19
|
+
| remove columns | `table_remove_columns {columns}` |
|
|
20
|
+
| remove rows | `table_remove_rows {where}` |
|
|
21
|
+
| add a column from a per-row value or a formula | `table_add_column {name, type, value}` / `{name, formula}` |
|
|
22
|
+
| overwrite a column's values | `table_set_values {column, value}` |
|
|
23
|
+
| rename; format, units, semantic type, color coding, tags | `table_edit_column {column, ...}` |
|
|
24
|
+
| add a viewer | `table_add_viewer {type, options}` |
|
|
25
|
+
|
|
26
|
+
`where` and `value` are JS expressions run for every row: `i` is the row index, `t` the table, `v` the current
|
|
27
|
+
value (`null` when missing). Like any action, a tool call is followed by `datagrok_verify`.
|
|
28
|
+
|
|
29
|
+
## 2. The `undoable` global of `datagrok_exec`
|
|
30
|
+
|
|
31
|
+
For a change a script has to make itself, e.g. a column a platform function added:
|
|
32
|
+
|
|
33
|
+
| Change | Call |
|
|
34
|
+
|---|---|
|
|
35
|
+
| a column the script or a function it called has added | `undoable.columnAdded(col)` |
|
|
36
|
+
| anything that rewrites a column's values | `const ok = await undoable.changeValues(col, async () => { ... })` |
|
|
37
|
+
| anything that renames a column or sets its tags | `await undoable.editColumn(col, () => { ... })` |
|
|
38
|
+
| remove columns / rows, add a viewer | `undoable.removeColumns(t, names)`, `await undoable.removeRows(t, (i) => ...)`, `undoable.addViewer(view, type, options)` |
|
|
39
|
+
|
|
40
|
+
## 3. Platform actions that record their own step
|
|
41
|
+
|
|
42
|
+
| Change | Call |
|
|
43
|
+
|---|---|
|
|
44
|
+
| clear the row and column selection | `await grok.functions.call('CmdResetSelectionFilter')` |
|
|
45
|
+
| remove every viewer but the grid | `grok.shell.topMenu.find('View').find('Layout').find('Clear').click()` |
|
|
46
|
+
| close a table view | `view.close()` |
|
|
47
|
+
|
|
48
|
+
## Limits of undo
|
|
49
|
+
|
|
50
|
+
- **Not undoable at all:** filtering, sorting, a viewer's properties, closing one viewer (`v.close()`),
|
|
51
|
+
`view.resetLayout()`, opening a table, joins and aggregations (they make new tables), anything saved on the
|
|
52
|
+
server (projects, files, queries, shares), and every change made around the three ways above, including one
|
|
53
|
+
made through `call_view_function`.
|
|
54
|
+
- **One step per tool or helper call.** A request that made three changes takes three Ctrl+Z, the latest first.
|
|
55
|
+
A step in the middle cannot be undone on its own.
|
|
56
|
+
- **Size.** Removed rows are kept only up to 20 MB: above that the platform says "too large to undo", removes
|
|
57
|
+
them for good and forgets the table's earlier steps. Columns are kept or copied only up to 2.5 million cells
|
|
58
|
+
(rows × columns): beyond that they are removed or overwritten without a step. Each case returns
|
|
59
|
+
`undoable: false`.
|
|
60
|
+
- **Nothing changed.** A call that changed nothing (`removed: 0`, an edit to the same values) records no step
|
|
61
|
+
and also returns `undoable: false`.
|
|
62
|
+
- **History.** The last 20 steps are kept, 50 MB in all, in the browser's memory only: reloading the page or
|
|
63
|
+
closing the table loses them. A new change clears redo. Overwritten values have undo, not redo.
|
|
64
|
+
- **Stale steps.** Steps belong to a table. If an unrecorded change altered its rows since, the platform skips
|
|
65
|
+
the older steps ("data has changed").
|
|
66
|
+
- **Selection.** Undoing a row removal brings the rows back selected.
|
|
67
|
+
- **Keyboard.** Ctrl+Z (Cmd+Z on a Mac) in the AI prompt box edits the prompt text. The table needs focus: a
|
|
68
|
+
click on it first, or `Edit | Undo`.
|
|
69
|
+
|
|
70
|
+
## What to tell the user
|
|
71
|
+
|
|
72
|
+
Nothing: do not mention undo in a reply, neither that a change can be undone nor that it cannot. The exception
|
|
73
|
+
is a user who asks about it:
|
|
74
|
+
|
|
75
|
+
- "Can I undo this?" / "how do I take it back?": answer from the limits above; the shortcut is "Ctrl+Z (Cmd+Z on
|
|
76
|
+
a Mac), after a click on the table, or Edit | Undo".
|
|
77
|
+
- "Undo that" / "redo": read `DG.UndoService.undoName` (`redoName`). If it names the change the user means, call
|
|
78
|
+
`grok.shell.undo()` (`redo()`) and say what was undone; otherwise say that this change cannot be undone.
|