@datagusto/cli 0.0.0-stage → 0.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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +186 -2
  3. package/bin/run.js +5 -0
  4. package/dist/adapters/claude-code.d.ts +47 -0
  5. package/dist/adapters/claude-code.js +533 -0
  6. package/dist/adapters/claude-code.js.map +1 -0
  7. package/dist/adapters/claude-settings.d.ts +29 -0
  8. package/dist/adapters/claude-settings.js +115 -0
  9. package/dist/adapters/claude-settings.js.map +1 -0
  10. package/dist/adapters/index.d.ts +10 -0
  11. package/dist/adapters/index.js +37 -0
  12. package/dist/adapters/index.js.map +1 -0
  13. package/dist/adapters/kiro-agent.d.ts +29 -0
  14. package/dist/adapters/kiro-agent.js +124 -0
  15. package/dist/adapters/kiro-agent.js.map +1 -0
  16. package/dist/adapters/kiro.d.ts +24 -0
  17. package/dist/adapters/kiro.js +740 -0
  18. package/dist/adapters/kiro.js.map +1 -0
  19. package/dist/adapters/types.d.ts +79 -0
  20. package/dist/adapters/types.js +14 -0
  21. package/dist/adapters/types.js.map +1 -0
  22. package/dist/api/client.d.ts +36 -0
  23. package/dist/api/client.js +85 -0
  24. package/dist/api/client.js.map +1 -0
  25. package/dist/api/errors.d.ts +4 -0
  26. package/dist/api/errors.js +25 -0
  27. package/dist/api/errors.js.map +1 -0
  28. package/dist/commands/remove.d.ts +13 -0
  29. package/dist/commands/remove.js +59 -0
  30. package/dist/commands/remove.js.map +1 -0
  31. package/dist/commands/setup.d.ts +16 -0
  32. package/dist/commands/setup.js +114 -0
  33. package/dist/commands/setup.js.map +1 -0
  34. package/dist/commands/status.d.ts +7 -0
  35. package/dist/commands/status.js +53 -0
  36. package/dist/commands/status.js.map +1 -0
  37. package/dist/display.d.ts +2 -0
  38. package/dist/display.js +8 -0
  39. package/dist/display.js.map +1 -0
  40. package/dist/fs/atomic.d.ts +17 -0
  41. package/dist/fs/atomic.js +41 -0
  42. package/dist/fs/atomic.js.map +1 -0
  43. package/dist/key-input.d.ts +24 -0
  44. package/dist/key-input.js +96 -0
  45. package/dist/key-input.js.map +1 -0
  46. package/dist/state/installs.d.ts +24 -0
  47. package/dist/state/installs.js +110 -0
  48. package/dist/state/installs.js.map +1 -0
  49. package/dist/vendor.d.ts +16 -0
  50. package/dist/vendor.js +60 -0
  51. package/dist/vendor.js.map +1 -0
  52. package/package.json +57 -4
  53. package/vendor/claude_code/.claude-plugin/plugin.json +55 -0
  54. package/vendor/claude_code/README.md +267 -0
  55. package/vendor/claude_code/dist/api-client.js +82 -0
  56. package/vendor/claude_code/dist/builtin-tools.generated.js +33 -0
  57. package/vendor/claude_code/dist/extractors.js +201 -0
  58. package/vendor/claude_code/dist/index.js +695 -0
  59. package/vendor/claude_code/dist/monitoring.js +66 -0
  60. package/vendor/claude_code/dist/state.js +71 -0
  61. package/vendor/claude_code/dist/types.js +5 -0
  62. package/vendor/claude_code/hooks/hooks.json +25 -0
  63. package/vendor/claude_code/package.json +26 -0
  64. package/vendor/kiro/.kiro/agents/kiro_default.json +20 -0
  65. package/vendor/kiro/.kiro/hooks/datagusto-post-tool-use.json +10 -0
  66. package/vendor/kiro/.kiro/hooks/datagusto-pre-tool-use.json +10 -0
  67. package/vendor/kiro/.kiro/hooks/datagusto-session-start.json +10 -0
  68. package/vendor/kiro/.kiro/hooks/datagusto-stop.json +10 -0
  69. package/vendor/kiro/.kiro/hooks/datagusto-user-prompt-submit.json +10 -0
  70. package/vendor/kiro/dist/api-client.js +82 -0
  71. package/vendor/kiro/dist/builtin-tools.generated.js +87 -0
  72. package/vendor/kiro/dist/engine.js +65 -0
  73. package/vendor/kiro/dist/extractors.js +201 -0
  74. package/vendor/kiro/dist/index.js +735 -0
  75. package/vendor/kiro/dist/monitoring.js +66 -0
  76. package/vendor/kiro/dist/state.js +71 -0
  77. package/vendor/kiro/dist/types.js +5 -0
  78. package/vendor/kiro/package.json +25 -0
  79. package/vendor/manifest.json +42 -0
@@ -0,0 +1,66 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Datagusto Safety Plugin - Monitoring-mode resolution
3
+ // ---------------------------------------------------------------------------
4
+ //
5
+ // Two independent switches can turn enforcement off:
6
+ //
7
+ // - the plugin's own `monitorOnly` config (a local staging-rollout knob), and
8
+ // - the platform's per-agent monitoring mode, surfaced by the server as
9
+ // `monitoring_mode_enabled` on /sessions/alignment and /sessions/validate
10
+ // responses.
11
+ //
12
+ // Either one being true means a verdict (deny / ask / block / inject) is
13
+ // logged but not enforced. The platform value is resolved per request:
14
+ // the validate response of the current call wins, then the value most
15
+ // recently reported by any alignment / validate response for this session
16
+ // (kept in session state), then false — older servers that omit the field
17
+ // behave as before.
18
+ //
19
+ // The platform value never changes fail-closed handling of API errors: the
20
+ // server's monitoring mode only says whether *verdicts* are enforced, and
21
+ // an errored request carries no verdict (and no flag) to begin with.
22
+ /**
23
+ * Read `monitoring_mode_enabled` from an API response body. Returns undefined
24
+ * when the field is absent or not a boolean so callers can fall back to the
25
+ * value cached in session state.
26
+ */
27
+ export function readMonitoringFlag(data) {
28
+ if (data && typeof data === "object") {
29
+ const v = data.monitoring_mode_enabled;
30
+ if (typeof v === "boolean")
31
+ return v;
32
+ }
33
+ return undefined;
34
+ }
35
+ /**
36
+ * Combine the plugin's `monitorOnly` config with the platform's monitoring
37
+ * mode. `responseFlag` is the value from the current request's response (or
38
+ * undefined when that response has none), `stateFlag` the value cached from
39
+ * alignment (null when never seen).
40
+ */
41
+ export function resolveMonitoring(pluginMonitorOnly, responseFlag, stateFlag) {
42
+ const platformEnabled = typeof responseFlag === "boolean" ? responseFlag : stateFlag === true;
43
+ const plugin = pluginMonitorOnly === true;
44
+ let source;
45
+ if (plugin && platformEnabled)
46
+ source = "plugin+platform";
47
+ else if (plugin)
48
+ source = "plugin";
49
+ else if (platformEnabled)
50
+ source = "platform";
51
+ return { active: plugin || platformEnabled, source, platformEnabled };
52
+ }
53
+ /** Human-readable label for log lines, e.g. "platform monitoring mode". */
54
+ export function describeMonitoring(decision) {
55
+ switch (decision.source) {
56
+ case "plugin":
57
+ return "plugin monitorOnly";
58
+ case "platform":
59
+ return "platform monitoring mode";
60
+ case "plugin+platform":
61
+ return "plugin monitorOnly + platform monitoring mode";
62
+ default:
63
+ return "enforcing";
64
+ }
65
+ }
66
+ //# sourceMappingURL=monitoring.js.map
@@ -0,0 +1,71 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Datagusto Safety Plugin - Persisted Per-Session State
3
+ // ---------------------------------------------------------------------------
4
+ //
5
+ // OpenClaw's plugin keeps state in memory inside one long-running process
6
+ // and has to detect session boundaries itself (see the OpenClaw plugin's
7
+ // `onNewTurn`). Claude Code hooks are the opposite: every invocation is a
8
+ // brand-new process that exits after handling one event, but each payload
9
+ // already carries a stable `session_id` for the lifetime of the
10
+ // conversation. So instead of an in-memory class with manual session-change
11
+ // detection, state is a small JSON blob on disk, namespaced by that
12
+ // session_id — no reset hook is needed because a new session simply reads
13
+ // and writes its own file.
14
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
15
+ import { tmpdir } from "node:os";
16
+ import { join } from "node:path";
17
+ const EMPTY_STATE = {
18
+ sessionId: null,
19
+ registeredToolsHash: null,
20
+ lastUserInstructionHash: null,
21
+ lastPreToolUseCheck: null,
22
+ monitoringModeEnabled: null,
23
+ monitoringNoticeShown: false,
24
+ };
25
+ const STATE_DIR = join(tmpdir(), "datagusto-safety-plugin");
26
+ function statePath(claudeSessionId) {
27
+ return join(STATE_DIR, `${claudeSessionId}.json`);
28
+ }
29
+ /** Load this Claude Code session's state, or an empty one if none exists yet. */
30
+ export function loadState(claudeSessionId) {
31
+ try {
32
+ const raw = readFileSync(statePath(claudeSessionId), "utf8");
33
+ return { ...EMPTY_STATE, ...JSON.parse(raw) };
34
+ }
35
+ catch {
36
+ return { ...EMPTY_STATE };
37
+ }
38
+ }
39
+ /** Persist this Claude Code session's state for the next hook invocation. */
40
+ export function saveState(claudeSessionId, state) {
41
+ mkdirSync(STATE_DIR, { recursive: true });
42
+ writeFileSync(statePath(claudeSessionId), JSON.stringify(state), "utf8");
43
+ }
44
+ /**
45
+ * Re-read the state file, apply `mutate` to the fresh copy, and write it back.
46
+ *
47
+ * Claude Code can run several hook processes for one session concurrently
48
+ * (parallel tool calls), and each handler awaits HTTP round-trips between
49
+ * its initial loadState() and any save. Writing back that stale snapshot
50
+ * would clobber fields another process persisted in the meantime, so
51
+ * handlers that only need to update a few fields after their awaits use
52
+ * this instead of saveState(). The read-modify-write is still unlocked —
53
+ * the window is the microseconds between the read and the write rather
54
+ * than the whole HTTP round-trip — which is adequate for these hints.
55
+ */
56
+ export function mutateState(claudeSessionId, mutate) {
57
+ const fresh = loadState(claudeSessionId);
58
+ mutate(fresh);
59
+ saveState(claudeSessionId, fresh);
60
+ return fresh;
61
+ }
62
+ /** Remove this Claude Code session's state file (called from SessionEnd). */
63
+ export function deleteState(claudeSessionId) {
64
+ try {
65
+ rmSync(statePath(claudeSessionId), { force: true });
66
+ }
67
+ catch {
68
+ // Best-effort cleanup — a failure here should never block SessionEnd.
69
+ }
70
+ }
71
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1,5 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Datagusto Safety Plugin - Type Definitions
3
+ // ---------------------------------------------------------------------------
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "datagusto-safety-plugin-kiro",
3
+ "version": "1.0.0",
4
+ "description": "Datagusto safety validation plugin for Kiro IDE",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "typecheck": "tsc --noEmit",
10
+ "build": "tsc",
11
+ "prepublishOnly": "npm run build",
12
+ "test": "npm run build && node --test tests/*.test.mjs"
13
+ },
14
+ "files": [
15
+ "dist/",
16
+ "src/",
17
+ ".kiro/hooks/",
18
+ "README.md"
19
+ ],
20
+ "license": "MIT",
21
+ "devDependencies": {
22
+ "@types/node": "^22.0.0",
23
+ "typescript": "^6.0.3"
24
+ }
25
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "version": 1,
3
+ "sourceCommit": "2d11c9f",
4
+ "plugins": {
5
+ "claude_code": {
6
+ "pluginVersion": "1.0.0",
7
+ "files": {
8
+ ".claude-plugin/plugin.json": "62621afc1dfc683bcf4afdac43d6efea0ec85e55b66c7e69a85a0fe708f9f991",
9
+ "README.md": "465c4c2b4aa1ba0e5a9b05573460168f67edda21977a9343f981f08ebb85999a",
10
+ "dist/api-client.js": "22f46fc31fc61aa6e9c4219032b41a321ce324630fb8235cc2572797b73d29da",
11
+ "dist/builtin-tools.generated.js": "870422c2a4403627486e48834fdae6ea5a1cd63dbfe707fa4db613a87028c214",
12
+ "dist/extractors.js": "58c40eaad7e755b723f4f924ba56b2f37affbe42c6389bca369a62fb1c4fd1ac",
13
+ "dist/index.js": "f0439bc13cc48d98037d013860b95b3ace49939c2ee2ff9f78b5d81c4bddad64",
14
+ "dist/monitoring.js": "81e82124624e0deca9d11472c9ba4cd3ac7b2711b55fa10c45c22bd25f95a9d7",
15
+ "dist/state.js": "66e724266b61fa73760a597d9ca328dd6fc31c7dfe2fb9370c764fadb20b190c",
16
+ "dist/types.js": "a76a10af480d422f5f301cfc7d91a02db1d87695fcbf6d7475063faeb82f76a8",
17
+ "hooks/hooks.json": "d50d298053754ddc6076d84fd94a35fe9c56468f5e9870a625edac6fbac65df9",
18
+ "package.json": "a00fc1f5ff39648223a4fc517cda118216694074b40b8e25bbf1a11af051bce7"
19
+ }
20
+ },
21
+ "kiro": {
22
+ "pluginVersion": "1.0.0",
23
+ "files": {
24
+ ".kiro/agents/kiro_default.json": "f5cccf42d4f1a4b1a2268685ac74bae0b1068bf18dea7ff4965518a6c7b8d770",
25
+ ".kiro/hooks/datagusto-post-tool-use.json": "58dacc6b875e733d63fd13f0f47cb2385eecea1ec29b076f71e8b9d137676258",
26
+ ".kiro/hooks/datagusto-pre-tool-use.json": "2597f6eb980d1f17f11f7a2b74faeeca69511345d5cfcd420266a8c165b6da93",
27
+ ".kiro/hooks/datagusto-session-start.json": "992697cb2504e5527b26400c7aebe7e41f80d410bc0150520503897f6ff33a27",
28
+ ".kiro/hooks/datagusto-stop.json": "f416a77d84fd74d97af8fba7b08161bc39d963fe1e4bfa86f9ed49589a16ae51",
29
+ ".kiro/hooks/datagusto-user-prompt-submit.json": "752b562e871b19996ec0c63e90d43fdaec9930ed0871db32a95e4cd849c7237a",
30
+ "dist/api-client.js": "22f46fc31fc61aa6e9c4219032b41a321ce324630fb8235cc2572797b73d29da",
31
+ "dist/builtin-tools.generated.js": "d13ae530ed33a55ec2e7d04c2f78e3b34505f68a952ecdb30a979cb9e26b3493",
32
+ "dist/engine.js": "db0fca121485a6065c6626b4c3b114f06bd9cc8b374fad2d63f6c39565a4e891",
33
+ "dist/extractors.js": "58c40eaad7e755b723f4f924ba56b2f37affbe42c6389bca369a62fb1c4fd1ac",
34
+ "dist/index.js": "116d7d3e15e6fea78e830d2a6c9a101fe93207e4e6e37329c68086043f4fac64",
35
+ "dist/monitoring.js": "81e82124624e0deca9d11472c9ba4cd3ac7b2711b55fa10c45c22bd25f95a9d7",
36
+ "dist/state.js": "66e724266b61fa73760a597d9ca328dd6fc31c7dfe2fb9370c764fadb20b190c",
37
+ "dist/types.js": "a76a10af480d422f5f301cfc7d91a02db1d87695fcbf6d7475063faeb82f76a8",
38
+ "package.json": "a0e6d2748fec919edbdb446f3e7b1184843a4e25d76230d0ff955951466e4f36"
39
+ }
40
+ }
41
+ }
42
+ }