@dirgha/code 1.43.3 → 2.0.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/CHANGELOG.md +22 -0
- package/LICENSE +202 -101
- package/NOTICE +9 -0
- package/README.md +184 -97
- package/THIRD_PARTY_NOTICES.md +28 -0
- package/bin/build-native.mjs +43 -0
- package/bin/dirgha.mjs +241 -0
- package/dist/cli/flows/full-cycle.d.ts +0 -3
- package/dist/cli/flows/full-cycle.js +1 -9
- package/dist/cli/flows/full-cycle.js.map +1 -1
- package/dist/cli/main.js +1 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/slash/index.js +0 -2
- package/dist/cli/slash/index.js.map +1 -1
- package/dist/cli/subcommands/index.js +0 -2
- package/dist/cli/subcommands/index.js.map +1 -1
- package/dist/integrations/entitlements.d.ts +1 -2
- package/dist/integrations/entitlements.js.map +1 -1
- package/dist/integrations/index.d.ts +0 -1
- package/dist/integrations/index.js +0 -1
- package/dist/integrations/index.js.map +1 -1
- package/dist/mcp/mcp-config.js +27 -3
- package/dist/mcp/mcp-config.js.map +1 -1
- package/dist/safety/policy.d.ts +18 -0
- package/dist/safety/policy.js +95 -1
- package/dist/safety/policy.js.map +1 -1
- package/dist/tools/index.d.ts +1 -2
- package/dist/tools/index.js +1 -8
- package/dist/tools/index.js.map +1 -1
- package/extensions/firefox-mv3/background.js +144 -0
- package/extensions/firefox-mv3/content-agent-dom.js +161 -0
- package/extensions/firefox-mv3/lokahi_gate.wasm +0 -0
- package/extensions/firefox-mv3/manifest.json +33 -0
- package/include/dirgha_kernel.h +41 -0
- package/package.json +65 -56
- package/plugins/dsh-plugin-dirgha/cordis.patch.yml +11 -0
- package/plugins/dsh-plugin-dirgha/index.ts +135 -0
- package/plugins/dsh-plugin-dirgha/package.json +18 -0
- package/plugins/robotics-physical-ai/README.md +11 -0
- package/plugins/robotics-physical-ai/mujoco_eval_sidecar.py +848 -0
- package/plugins/robotics-physical-ai/plugin.toml +23 -0
- package/plugins/robotics-skills-pack/README.md +15 -0
- package/plugins/robotics-skills-pack/plugin.toml +36 -0
- package/vendor/rtk/README.md +7 -0
- package/dist/cli/slash/goal.d.ts +0 -14
- package/dist/cli/slash/goal.js +0 -74
- package/dist/cli/slash/goal.js.map +0 -1
- package/dist/cli/slash/gpu.d.ts +0 -11
- package/dist/cli/slash/gpu.js +0 -58
- package/dist/cli/slash/gpu.js.map +0 -1
- package/dist/cli/subcommands/gpu.d.ts +0 -15
- package/dist/cli/subcommands/gpu.js +0 -187
- package/dist/cli/subcommands/gpu.js.map +0 -1
- package/dist/context/goal.d.ts +0 -27
- package/dist/context/goal.js +0 -77
- package/dist/context/goal.js.map +0 -1
- package/dist/gpu/market.d.ts +0 -30
- package/dist/gpu/market.js +0 -120
- package/dist/gpu/market.js.map +0 -1
- package/dist/integrations/bucky-client.d.ts +0 -105
- package/dist/integrations/bucky-client.js +0 -76
- package/dist/integrations/bucky-client.js.map +0 -1
- package/dist/providers/presets.d.ts +0 -30
- package/dist/providers/presets.js +0 -80
- package/dist/providers/presets.js.map +0 -1
- package/dist/tools/goal.d.ts +0 -11
- package/dist/tools/goal.js +0 -69
- package/dist/tools/goal.js.map +0 -1
- package/dist/tools/gpu-compute.d.ts +0 -19
- package/dist/tools/gpu-compute.js +0 -380
- package/dist/tools/gpu-compute.js.map +0 -1
- package/dist/tui/ink/components/GoalIndicator.d.ts +0 -7
- package/dist/tui/ink/components/GoalIndicator.js +0 -34
- package/dist/tui/ink/components/GoalIndicator.js.map +0 -1
- package/vendor/rtk/linux-x64/rtk +0 -0
package/dist/safety/policy.d.ts
CHANGED
|
@@ -5,6 +5,23 @@
|
|
|
5
5
|
* config load time.
|
|
6
6
|
*/
|
|
7
7
|
import type { PermissionCheck, PermissionDecision } from "../tools/permission.js";
|
|
8
|
+
interface LokahiWasmMemory {
|
|
9
|
+
buffer: ArrayBuffer;
|
|
10
|
+
grow(delta: number): number;
|
|
11
|
+
}
|
|
12
|
+
export interface LokahiWasmSyncExports {
|
|
13
|
+
memory: LokahiWasmMemory;
|
|
14
|
+
lokahi_c_abi_evaluate_utf8: (ptr: number, len: number, isS2Critical: number) => number;
|
|
15
|
+
lokahi_alloc?: (size: number) => number;
|
|
16
|
+
alloc?: (size: number) => number;
|
|
17
|
+
malloc?: (size: number) => number;
|
|
18
|
+
}
|
|
19
|
+
export interface LokahiGateResult {
|
|
20
|
+
allowed: boolean;
|
|
21
|
+
reason: string;
|
|
22
|
+
}
|
|
23
|
+
/** Evaluate the WASM gate and fail closed for missing, malformed, throwing, or unknown verdicts. */
|
|
24
|
+
export declare function evaluateLokahiGateSync(payload: string, isS2Critical: boolean, wasmOrLoader?: LokahiWasmSyncExports | null | (() => LokahiWasmSyncExports | null)): LokahiGateResult;
|
|
8
25
|
export interface PolicyRule {
|
|
9
26
|
id: string;
|
|
10
27
|
applies: {
|
|
@@ -30,3 +47,4 @@ export interface PolicyEngine {
|
|
|
30
47
|
}
|
|
31
48
|
export declare const DEFAULT_RULES: PolicyRule[];
|
|
32
49
|
export declare function createPolicyEngine(opts: PolicyEngineOptions): PolicyEngine;
|
|
50
|
+
export {};
|
package/dist/safety/policy.js
CHANGED
|
@@ -4,7 +4,89 @@
|
|
|
4
4
|
* default ruleset ships in-code; user and project rules are merged at
|
|
5
5
|
* config load time.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join, resolve } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
const WasmApi = globalThis.WebAssembly;
|
|
11
|
+
let cachedLokahiSync;
|
|
12
|
+
function getLokahiWasmSync() {
|
|
13
|
+
if (cachedLokahiSync !== undefined)
|
|
14
|
+
return cachedLokahiSync;
|
|
15
|
+
try {
|
|
16
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
const rootDir = resolve(here, "..", "..");
|
|
18
|
+
const wasmPath = join(rootDir, "extensions", "firefox-mv3", "lokahi_gate.wasm");
|
|
19
|
+
if (!existsSync(wasmPath)) {
|
|
20
|
+
cachedLokahiSync = null;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const bytes = readFileSync(wasmPath);
|
|
24
|
+
const mod = new WasmApi.Module(bytes);
|
|
25
|
+
const inst = new WasmApi.Instance(mod, {
|
|
26
|
+
wasi_snapshot_preview1: {
|
|
27
|
+
args_get: () => 0,
|
|
28
|
+
args_sizes_get: () => 0,
|
|
29
|
+
environ_get: () => 0,
|
|
30
|
+
environ_sizes_get: () => 0,
|
|
31
|
+
clock_time_get: () => 0,
|
|
32
|
+
fd_close: () => 0,
|
|
33
|
+
fd_fdstat_get: () => 0,
|
|
34
|
+
fd_seek: () => 0,
|
|
35
|
+
fd_write: () => 0,
|
|
36
|
+
proc_exit: () => { },
|
|
37
|
+
random_get: () => 0,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
cachedLokahiSync = inst.exports;
|
|
41
|
+
return cachedLokahiSync;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
cachedLokahiSync = null;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function allowUngatedForDevelopment() {
|
|
49
|
+
if (process.env.DIRGHA_ALLOW_UNGATED === "1") {
|
|
50
|
+
console.warn("[DIRGHA SECURITY WARNING] DIRGHA_ALLOW_UNGATED=1 bypasses the Lokahi WASM gate; use only for local development.");
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
/** Evaluate the WASM gate and fail closed for missing, malformed, throwing, or unknown verdicts. */
|
|
56
|
+
export function evaluateLokahiGateSync(payload, isS2Critical, wasmOrLoader) {
|
|
57
|
+
try {
|
|
58
|
+
const wasm = typeof wasmOrLoader === "function"
|
|
59
|
+
? wasmOrLoader()
|
|
60
|
+
: wasmOrLoader === undefined ? getLokahiWasmSync() : wasmOrLoader;
|
|
61
|
+
if (!wasm || typeof wasm.lokahi_c_abi_evaluate_utf8 !== "function" || !wasm.memory) {
|
|
62
|
+
return allowUngatedForDevelopment()
|
|
63
|
+
? { allowed: true, reason: "lokahi_gate_unavailable_opt_out" }
|
|
64
|
+
: { allowed: false, reason: "lokahi_gate_unavailable" };
|
|
65
|
+
}
|
|
66
|
+
const encoded = new TextEncoder().encode(payload);
|
|
67
|
+
const allocator = wasm.lokahi_alloc ?? wasm.alloc ?? wasm.malloc;
|
|
68
|
+
const pointer = allocator ? allocator(encoded.length) : 65536;
|
|
69
|
+
if (!Number.isInteger(pointer) || pointer < 0 || pointer + encoded.length > wasm.memory.buffer.byteLength) {
|
|
70
|
+
return allowUngatedForDevelopment()
|
|
71
|
+
? { allowed: true, reason: "lokahi_gate_memory_unavailable_opt_out" }
|
|
72
|
+
: { allowed: false, reason: "lokahi_gate_memory_unavailable" };
|
|
73
|
+
}
|
|
74
|
+
new Uint8Array(wasm.memory.buffer, pointer, encoded.length).set(encoded);
|
|
75
|
+
const verdict = wasm.lokahi_c_abi_evaluate_utf8(pointer, encoded.length, isS2Critical ? 1 : 0);
|
|
76
|
+
if (verdict === 1)
|
|
77
|
+
return { allowed: true, reason: "lokahi_gate_allow" };
|
|
78
|
+
if (verdict === 0)
|
|
79
|
+
return { allowed: false, reason: "lokahi_gate_denied" };
|
|
80
|
+
return allowUngatedForDevelopment()
|
|
81
|
+
? { allowed: true, reason: "lokahi_gate_unknown_opt_out" }
|
|
82
|
+
: { allowed: false, reason: "lokahi_gate_unavailable" };
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return allowUngatedForDevelopment()
|
|
86
|
+
? { allowed: true, reason: "lokahi_gate_error_opt_out" }
|
|
87
|
+
: { allowed: false, reason: "lokahi_gate_unavailable" };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
8
90
|
export const DEFAULT_RULES = [
|
|
9
91
|
{
|
|
10
92
|
id: "read-inside-cwd",
|
|
@@ -66,6 +148,18 @@ export function createPolicyEngine(opts) {
|
|
|
66
148
|
const cwd = resolve(opts.cwd);
|
|
67
149
|
const rules = [...(opts.rules ?? []), ...DEFAULT_RULES];
|
|
68
150
|
const evaluate = (req) => {
|
|
151
|
+
// The WASM capability firewall is mandatory unless the explicit local-development opt-out is set.
|
|
152
|
+
const gate = evaluateLokahiGateSync(req.target, false);
|
|
153
|
+
if (!gate.allowed && gate.reason !== "lokahi_gate_denied") {
|
|
154
|
+
return { allowed: false, reason: gate.reason, requiresApproval: false };
|
|
155
|
+
}
|
|
156
|
+
if (!gate.allowed) {
|
|
157
|
+
return {
|
|
158
|
+
allowed: false,
|
|
159
|
+
reason: "lokahi-gate-wasm: blocked by the WebAssembly safety gate",
|
|
160
|
+
requiresApproval: false,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
69
163
|
for (const rule of rules) {
|
|
70
164
|
if (!appliesTo(rule, req))
|
|
71
165
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/safety/policy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/safety/policy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAazC,MAAM,OAAO,GAAI,UAAwD,CAAC,WAAW,CAAC;AAetF,IAAI,gBAA0D,CAAC;AAE/D,SAAS,iBAAiB;IACxB,IAAI,gBAAgB,KAAK,SAAS;QAAE,OAAO,gBAAgB,CAAC;IAC5D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MA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IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,WAAW,CAAC,IAAgB;IACnC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACpB,KAAK,OAAO;YACV,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE;gBACpC,gBAAgB,EAAE,KAAK;aACxB,CAAC;QACJ,KAAK,MAAM;YACT,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE;gBACpC,gBAAgB,EAAE,KAAK;aACxB,CAAC;QACJ,KAAK,kBAAkB;YACrB,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE;gBACpC,gBAAgB,EAAE,IAAI;aACvB,CAAC;IACN,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,MAAc,EAAE,GAAW;IACzD,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1C,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -27,7 +27,6 @@ import { transactionalWriteTool } from "./transactional-write.js";
|
|
|
27
27
|
import { dbWorkspaceInfoTool } from "./db-workspace-info.js";
|
|
28
28
|
import { agentServerTool } from "./agent-server.js";
|
|
29
29
|
import { imageGenerateTool, videoGenerateTool, audioGenerateTool, speechToTextTool } from "./studio.js";
|
|
30
|
-
import { gpuListTool, gpuComputeTool, gpuStatusTool, gpuDestroyTool, gpuMarketListTool, gpuMarketPostTool } from "./gpu-compute.js";
|
|
31
30
|
export { createMultimodalTool } from "./multimodal.js";
|
|
32
31
|
export { createCronTool } from "./cron.js";
|
|
33
32
|
export { createCheckpointTool } from "./checkpoint.js";
|
|
@@ -44,4 +43,4 @@ export * from "./lsp-references.js";
|
|
|
44
43
|
export * from "./lsp-hover.js";
|
|
45
44
|
export * from "./lsp-symbols.js";
|
|
46
45
|
export declare const builtInTools: Tool[];
|
|
47
|
-
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, githubTool, browserTool, checkpointTool, cronTool, lspGoToDefinitionTool, lspFindReferencesTool, lspHoverTool, lspDocumentSymbolsTool, rtkTool, qmdTool, kbSearchTool, graphNeighborsTool, graphTraverseTool, transactionalWriteTool, dbWorkspaceInfoTool, agentServerTool, imageGenerateTool, videoGenerateTool, audioGenerateTool, speechToTextTool,
|
|
46
|
+
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, githubTool, browserTool, checkpointTool, cronTool, lspGoToDefinitionTool, lspFindReferencesTool, lspHoverTool, lspDocumentSymbolsTool, rtkTool, qmdTool, kbSearchTool, graphNeighborsTool, graphTraverseTool, transactionalWriteTool, dbWorkspaceInfoTool, agentServerTool, imageGenerateTool, videoGenerateTool, audioGenerateTool, speechToTextTool, };
|
package/dist/tools/index.js
CHANGED
|
@@ -28,7 +28,6 @@ import { transactionalWriteTool } from "./transactional-write.js";
|
|
|
28
28
|
import { dbWorkspaceInfoTool } from "./db-workspace-info.js";
|
|
29
29
|
import { agentServerTool } from "./agent-server.js";
|
|
30
30
|
import { imageGenerateTool, videoGenerateTool, audioGenerateTool, speechToTextTool } from "./studio.js";
|
|
31
|
-
import { gpuListTool, gpuComputeTool, gpuStatusTool, gpuDestroyTool, gpuMarketListTool, gpuMarketPostTool } from "./gpu-compute.js";
|
|
32
31
|
export { createMultimodalTool } from "./multimodal.js";
|
|
33
32
|
export { createCronTool } from "./cron.js";
|
|
34
33
|
export { createCheckpointTool } from "./checkpoint.js";
|
|
@@ -73,12 +72,6 @@ export const builtInTools = [
|
|
|
73
72
|
videoGenerateTool,
|
|
74
73
|
audioGenerateTool,
|
|
75
74
|
speechToTextTool,
|
|
76
|
-
gpuListTool,
|
|
77
|
-
gpuComputeTool,
|
|
78
|
-
gpuStatusTool,
|
|
79
|
-
gpuDestroyTool,
|
|
80
|
-
gpuMarketListTool,
|
|
81
|
-
gpuMarketPostTool,
|
|
82
75
|
];
|
|
83
|
-
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, githubTool, browserTool, checkpointTool, cronTool, lspGoToDefinitionTool, lspFindReferencesTool, lspHoverTool, lspDocumentSymbolsTool, rtkTool, qmdTool, kbSearchTool, graphNeighborsTool, graphTraverseTool, transactionalWriteTool, dbWorkspaceInfoTool, agentServerTool, imageGenerateTool, videoGenerateTool, audioGenerateTool, speechToTextTool,
|
|
76
|
+
export { fsReadTool, fsWriteTool, fsEditTool, fsLsTool, shellTool, searchGrepTool, searchGlobTool, gitTool, githubTool, browserTool, checkpointTool, cronTool, lspGoToDefinitionTool, lspFindReferencesTool, lspHoverTool, lspDocumentSymbolsTool, rtkTool, qmdTool, kbSearchTool, graphNeighborsTool, graphTraverseTool, transactionalWriteTool, dbWorkspaceInfoTool, agentServerTool, imageGenerateTool, videoGenerateTool, audioGenerateTool, speechToTextTool, };
|
|
84
77
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA;;;;GA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jB,gBAAgB;CACjB,CAAC;AAEF,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,SAAS,EACT,cAAc,EACd,cAAc,EACd,OAAO,EACP,UAAU,EACV,WAAW,EACX,cAAc,EACd,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,OAAO,EACP,OAAO,EACP,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Dirgha v2 — Firefox/Chrome MV3 Background Service Worker, In-Browser WASM Gate & Native Host Bridge
|
|
2
|
+
// Loads `lokahi_gate.wasm` (`lokahi_c_abi_evaluate_utf8`) directly in the browser extension and bridges to `ai.dirgha.native_host`.
|
|
3
|
+
|
|
4
|
+
const runtimeApi = globalThis.browser?.runtime || globalThis.chrome?.runtime;
|
|
5
|
+
const NATIVE_HOST_ID = "ai.dirgha.native_host";
|
|
6
|
+
|
|
7
|
+
let wasmInstancePromise = null;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Instantiate `lokahi_gate.wasm` inside the MV3 Service Worker for `<1 ms` local C-ABI pre-filtering.
|
|
11
|
+
*/
|
|
12
|
+
async function getLokahiWasmExports() {
|
|
13
|
+
if (wasmInstancePromise) return wasmInstancePromise;
|
|
14
|
+
wasmInstancePromise = (async () => {
|
|
15
|
+
try {
|
|
16
|
+
const wasmUrl = runtimeApi?.getURL ? runtimeApi.getURL("lokahi_gate.wasm") : "lokahi_gate.wasm";
|
|
17
|
+
const resp = await fetch(wasmUrl);
|
|
18
|
+
const bytes = await resp.arrayBuffer();
|
|
19
|
+
const wasiStub = {
|
|
20
|
+
args_get: () => 0,
|
|
21
|
+
args_sizes_get: () => 0,
|
|
22
|
+
environ_get: () => 0,
|
|
23
|
+
environ_sizes_get: () => 0,
|
|
24
|
+
clock_time_get: () => 0,
|
|
25
|
+
fd_close: () => 0,
|
|
26
|
+
fd_fdstat_get: () => 0,
|
|
27
|
+
fd_seek: () => 0,
|
|
28
|
+
fd_write: () => 0,
|
|
29
|
+
proc_exit: () => {},
|
|
30
|
+
random_get: () => 0,
|
|
31
|
+
};
|
|
32
|
+
const { instance } = await WebAssembly.instantiate(bytes, {
|
|
33
|
+
wasi_snapshot_preview1: wasiStub,
|
|
34
|
+
});
|
|
35
|
+
return instance.exports;
|
|
36
|
+
} catch (_err) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
return wasmInstancePromise;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Evaluate a UTF-8 command/URL payload locally in `<1 ms` using `lokahi_gate.wasm`.
|
|
45
|
+
*/
|
|
46
|
+
async function evaluateLocalWasmGate(payload, isS2Critical = false) {
|
|
47
|
+
const exports = await getLokahiWasmExports();
|
|
48
|
+
if (!exports || !exports.lokahi_c_abi_evaluate_utf8 || !exports.memory) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const encoded = new TextEncoder().encode(payload);
|
|
52
|
+
const scratchOffset = 65536;
|
|
53
|
+
const view = new Uint8Array(exports.memory.buffer, scratchOffset, encoded.length);
|
|
54
|
+
view.set(encoded);
|
|
55
|
+
const code = exports.lokahi_c_abi_evaluate_utf8(scratchOffset, encoded.length, isS2Critical ? 1 : 0);
|
|
56
|
+
return code === 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Send a JSON-RPC 2.0 request to the Rust `dirgha-native-host` binary over Native Messaging.
|
|
61
|
+
*/
|
|
62
|
+
async function callNativeKernel(method, params) {
|
|
63
|
+
if (!runtimeApi || !runtimeApi.sendNativeMessage) {
|
|
64
|
+
throw new Error("WebExtensions nativeMessaging permission not available");
|
|
65
|
+
}
|
|
66
|
+
return runtimeApi.sendNativeMessage(NATIVE_HOST_ID, {
|
|
67
|
+
jsonrpc: "2.0",
|
|
68
|
+
id: Date.now(),
|
|
69
|
+
method,
|
|
70
|
+
params,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Execute an authenticated in-session fetch (`fetch_via_session`, harvested from Traycer `traycer-browser`),
|
|
76
|
+
* gated first by in-browser `lokahi_gate.wasm` and then logged in the Rust micro-kernel `AuditLedger`.
|
|
77
|
+
*/
|
|
78
|
+
async function fetchViaSession(url, options = {}) {
|
|
79
|
+
const payload = `${options.method || "GET"} ${url}`;
|
|
80
|
+
const isS2 = Boolean(options.method && options.method !== "GET");
|
|
81
|
+
|
|
82
|
+
// 1. Fast `<1 ms` in-browser WASM pre-check
|
|
83
|
+
const wasmAllowed = await evaluateLocalWasmGate(payload, isS2 && !options.humanApproved);
|
|
84
|
+
if (wasmAllowed === false) {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
blocked_by_lokahi_wasm: true,
|
|
88
|
+
verdict: { Deny: { rule_id: "LOKAHI-WASM-C-ABI", reason: "Blocked by in-browser lokahi_gate.wasm" } },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 2. Native Host verification + BLAKE3/Ed25519 audit ledger append
|
|
93
|
+
const gateCheck = await callNativeKernel("lokahi_verify_action", {
|
|
94
|
+
tool_name: "fetch_via_session",
|
|
95
|
+
payload,
|
|
96
|
+
safety_class: isS2 ? "S2HardwareOrCritical" : "S0ReadOnly",
|
|
97
|
+
human_signature_verified: Boolean(options.humanApproved),
|
|
98
|
+
approval_wait_ms: options.waitedMs || 0,
|
|
99
|
+
joint_velocity_rad_s: null,
|
|
100
|
+
max_joint_velocity_limit: null,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (!gateCheck?.result?.allowed) {
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
blocked_by_lokahi: true,
|
|
107
|
+
verdict: gateCheck?.result?.verdict,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const resp = await fetch(url, {
|
|
112
|
+
method: options.method || "GET",
|
|
113
|
+
headers: options.headers || {},
|
|
114
|
+
body: options.body,
|
|
115
|
+
credentials: "include",
|
|
116
|
+
});
|
|
117
|
+
const bodyText = await resp.text();
|
|
118
|
+
return {
|
|
119
|
+
ok: resp.ok,
|
|
120
|
+
status: resp.status,
|
|
121
|
+
bodyText,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (runtimeApi && runtimeApi.onMessage) {
|
|
126
|
+
runtimeApi.onMessage.addListener((msg, _sender, sendResponse) => {
|
|
127
|
+
if (msg.type === "DIRGHA_FETCH_VIA_SESSION") {
|
|
128
|
+
fetchViaSession(msg.url, msg.options).then(sendResponse);
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (msg.type === "DIRGHA_WASM_RED_TEAM_50") {
|
|
132
|
+
getLokahiWasmExports().then((exp) => {
|
|
133
|
+
const score = exp?.lokahi_wasm_run_red_team_50 ? exp.lokahi_wasm_run_red_team_50() : -1;
|
|
134
|
+
sendResponse({ ok: score === 50, passed: score });
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (msg.type === "DIRGHA_RPC") {
|
|
139
|
+
callNativeKernel(msg.method, msg.params).then(sendResponse);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Dirgha v2 — Generation-Bound Compact Agent-DOM & Lokahi Rule 14 Approval Ribbon
|
|
2
|
+
// Harvests Traycer's monotonic `generation` snapshot contract + Xiryn's `<untrusted>` & origin-bound vault check.
|
|
3
|
+
|
|
4
|
+
(() => {
|
|
5
|
+
let domGeneration = 0;
|
|
6
|
+
|
|
7
|
+
// Bump generation automatically whenever the DOM mutates so stale `idx` refs fail closed
|
|
8
|
+
const observer = new MutationObserver(() => {
|
|
9
|
+
domGeneration += 1;
|
|
10
|
+
});
|
|
11
|
+
if (document.documentElement) {
|
|
12
|
+
observer.observe(document.documentElement, {
|
|
13
|
+
childList: true,
|
|
14
|
+
subtree: true,
|
|
15
|
+
attributes: true,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extract Compact Agent-DOM (~350 tokens vs 25,000+ raw HTML tokens).
|
|
21
|
+
*/
|
|
22
|
+
function extractCompactAgentDom() {
|
|
23
|
+
domGeneration += 1;
|
|
24
|
+
const selector = 'a, button, input, select, textarea, [role="button"], [role="link"], h1, h2, h3';
|
|
25
|
+
const elements = Array.from(document.querySelectorAll(selector));
|
|
26
|
+
const nodes = [];
|
|
27
|
+
let idx = 1;
|
|
28
|
+
|
|
29
|
+
for (const el of elements) {
|
|
30
|
+
const rect = el.getBoundingClientRect();
|
|
31
|
+
if (rect.width === 0 && rect.height === 0) continue;
|
|
32
|
+
|
|
33
|
+
const tag = el.tagName.toLowerCase();
|
|
34
|
+
const role = el.getAttribute("role") || tag;
|
|
35
|
+
const label =
|
|
36
|
+
el.getAttribute("aria-label") ||
|
|
37
|
+
el.getAttribute("placeholder") ||
|
|
38
|
+
(el.innerText ? el.innerText.trim().slice(0, 80) : null);
|
|
39
|
+
const interactive = ["a", "button", "input", "select", "textarea"].includes(tag) ||
|
|
40
|
+
["button", "link", "checkbox", "textbox"].includes(role);
|
|
41
|
+
|
|
42
|
+
// Classify payment/submit/delete buttons as S2HardwareOrCritical (triggers Lokahi Rule 14 45s Ribbon)
|
|
43
|
+
const lowerLabel = (label || "").toLowerCase();
|
|
44
|
+
const isCritical =
|
|
45
|
+
interactive &&
|
|
46
|
+
(lowerLabel.includes("pay") ||
|
|
47
|
+
lowerLabel.includes("checkout") ||
|
|
48
|
+
lowerLabel.includes("delete") ||
|
|
49
|
+
lowerLabel.includes("promote") ||
|
|
50
|
+
lowerLabel.includes("transfer"));
|
|
51
|
+
|
|
52
|
+
el.setAttribute("data-dirgha-gen", String(domGeneration));
|
|
53
|
+
el.setAttribute("data-dirgha-idx", String(idx));
|
|
54
|
+
|
|
55
|
+
nodes.push({
|
|
56
|
+
idx,
|
|
57
|
+
role,
|
|
58
|
+
label,
|
|
59
|
+
text: label,
|
|
60
|
+
value: "value" in el ? String(el.value || "").slice(0, 64) : null,
|
|
61
|
+
interactive,
|
|
62
|
+
safety_class: isCritical ? "S2HardwareOrCritical" : "S0ReadOnly",
|
|
63
|
+
});
|
|
64
|
+
idx += 1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
generation: domGeneration,
|
|
69
|
+
tab_id: window.location.pathname || "active_tab",
|
|
70
|
+
origin: window.location.origin,
|
|
71
|
+
dom_blake3: "client_pending_native_hash",
|
|
72
|
+
nodes,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Render the Lokahi Rule 14 Approval Ribbon (45-second Ahimsa countdown; silence = DENY_TIMEOUT).
|
|
78
|
+
*/
|
|
79
|
+
function showLokahiApprovalRibbon(actionSummary) {
|
|
80
|
+
return new Promise((resolve) => {
|
|
81
|
+
const existing = document.getElementById("dirgha-lokahi-ribbon");
|
|
82
|
+
if (existing) existing.remove();
|
|
83
|
+
|
|
84
|
+
const bar = document.createElement("div");
|
|
85
|
+
bar.id = "dirgha-lokahi-ribbon";
|
|
86
|
+
bar.style.cssText = [
|
|
87
|
+
"position:fixed",
|
|
88
|
+
"top:0",
|
|
89
|
+
"left:0",
|
|
90
|
+
"right:0",
|
|
91
|
+
"z-index:2147483647",
|
|
92
|
+
"background:#111827",
|
|
93
|
+
"color:#f9fafb",
|
|
94
|
+
"padding:10px 16px",
|
|
95
|
+
"font-family:system-ui,sans-serif",
|
|
96
|
+
"font-size:13px",
|
|
97
|
+
"display:flex",
|
|
98
|
+
"justify-content:space-between",
|
|
99
|
+
"align-items:center",
|
|
100
|
+
"border-bottom:2px solid #f59e0b",
|
|
101
|
+
].join(";");
|
|
102
|
+
|
|
103
|
+
let remaining = 45;
|
|
104
|
+
const textSpan = document.createElement("span");
|
|
105
|
+
textSpan.textContent = `[Lokahi Rule 14] Approve S2 Action (${actionSummary})? Auto-deny in ${remaining}s`;
|
|
106
|
+
|
|
107
|
+
const btnGroup = document.createElement("div");
|
|
108
|
+
btnGroup.style.cssText = "display:flex;gap:8px;";
|
|
109
|
+
|
|
110
|
+
const approveBtn = document.createElement("button");
|
|
111
|
+
approveBtn.textContent = "Approve (Sign)";
|
|
112
|
+
approveBtn.style.cssText = "background:#059669;color:#fff;border:none;padding:4px 10px;border-radius:4px;cursor:pointer;";
|
|
113
|
+
|
|
114
|
+
const denyBtn = document.createElement("button");
|
|
115
|
+
denyBtn.textContent = "Deny";
|
|
116
|
+
denyBtn.style.cssText = "background:#dc2626;color:#fff;border:none;padding:4px 10px;border-radius:4px;cursor:pointer;";
|
|
117
|
+
|
|
118
|
+
const timer = setInterval(() => {
|
|
119
|
+
remaining -= 1;
|
|
120
|
+
textSpan.textContent = `[Lokahi Rule 14] Approve S2 Action (${actionSummary})? Auto-deny in ${remaining}s`;
|
|
121
|
+
if (remaining <= 0) {
|
|
122
|
+
clearInterval(timer);
|
|
123
|
+
bar.remove();
|
|
124
|
+
resolve({ approved: false, waited_ms: 45000 });
|
|
125
|
+
}
|
|
126
|
+
}, 1000);
|
|
127
|
+
|
|
128
|
+
approveBtn.onclick = () => {
|
|
129
|
+
clearInterval(timer);
|
|
130
|
+
bar.remove();
|
|
131
|
+
resolve({ approved: true, waited_ms: (45 - remaining) * 1000 });
|
|
132
|
+
};
|
|
133
|
+
denyBtn.onclick = () => {
|
|
134
|
+
clearInterval(timer);
|
|
135
|
+
bar.remove();
|
|
136
|
+
resolve({ approved: false, waited_ms: (45 - remaining) * 1000 });
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
btnGroup.appendChild(approveBtn);
|
|
140
|
+
btnGroup.appendChild(denyBtn);
|
|
141
|
+
bar.appendChild(textSpan);
|
|
142
|
+
bar.appendChild(btnGroup);
|
|
143
|
+
document.body.appendChild(bar);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const runtime = globalThis.browser?.runtime || globalThis.chrome?.runtime;
|
|
148
|
+
if (runtime && runtime.onMessage) {
|
|
149
|
+
runtime.onMessage.addListener((msg, _sender, sendResponse) => {
|
|
150
|
+
if (msg.type === "DIRGHA_SNAPSHOT_DOM") {
|
|
151
|
+
sendResponse(extractCompactAgentDom());
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (msg.type === "DIRGHA_RULE14_APPROVAL") {
|
|
155
|
+
showLokahiApprovalRibbon(msg.summary || "Critical Action").then(sendResponse);
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 3,
|
|
3
|
+
"name": "Dirgha v2 Sovereign Agentic Runtime & Lokahi Gate",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"description": "Auditable local-first agentic harness for Firefox & Chromium: Generation-Bound Compact Agent-DOM, <1ms Lokahi WASM Gate, and Origin-Verified OS Vault.",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"permissions": [
|
|
8
|
+
"activeTab",
|
|
9
|
+
"nativeMessaging",
|
|
10
|
+
"scripting",
|
|
11
|
+
"storage"
|
|
12
|
+
],
|
|
13
|
+
"host_permissions": [
|
|
14
|
+
"<all_urls>"
|
|
15
|
+
],
|
|
16
|
+
"background": {
|
|
17
|
+
"scripts": ["background.js"],
|
|
18
|
+
"service_worker": "background.js"
|
|
19
|
+
},
|
|
20
|
+
"content_scripts": [
|
|
21
|
+
{
|
|
22
|
+
"matches": ["<all_urls>"],
|
|
23
|
+
"js": ["content-agent-dom.js"],
|
|
24
|
+
"run_at": "document_idle"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"browser_specific_settings": {
|
|
28
|
+
"gecko": {
|
|
29
|
+
"id": "dirgha-v2@dirgha.ai",
|
|
30
|
+
"strict_min_version": "128.0"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Dirgha v2 Sovereign Agent Kernel — C-ABI Header (`include/dirgha_kernel.h`)
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*
|
|
5
|
+
* Provides zero-copy C-ABI bindings for C/C++, Python (`ctypes` / `PyO3`), and Node.js (`N-API` / `ffi-rs`)
|
|
6
|
+
* to invoke `lokahi-gate` (`wasm32-wasip1` & native `cdylib`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef DIRGHA_KERNEL_H
|
|
10
|
+
#define DIRGHA_KERNEL_H
|
|
11
|
+
|
|
12
|
+
#include <stddef.h>
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
|
|
15
|
+
#ifdef __cplusplus
|
|
16
|
+
extern "C" {
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Execute the 50-scenario `Lokahi-50` adversarial red-team suite inside `lokahi-gate`.
|
|
21
|
+
* Returns `50` when all 50 normative software, network, and Physical AI rules pass.
|
|
22
|
+
*/
|
|
23
|
+
int32_t lokahi_wasm_run_red_team_50(void);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Evaluate a UTF-8 command or tool payload buffer `(ptr, len)` against the 18 Lokahi
|
|
27
|
+
* safety rules (shell flag permutation tokenizer, base64 pipe decoder, cloud metadata SSRF,
|
|
28
|
+
* path traversal, Shannon entropy secret check, and Rule 14/18 S2 hardware gating) in `<1 ms`.
|
|
29
|
+
*
|
|
30
|
+
* @param ptr Pointer to UTF-8 payload bytes.
|
|
31
|
+
* @param len Byte length of `ptr`.
|
|
32
|
+
* @param is_s2_critical Non-zero if the action is classified as `S2HardwareOrCritical`.
|
|
33
|
+
* @return `1` if `Allow`, `0` if `Deny`, `-1` if `ptr` is null or invalid UTF-8.
|
|
34
|
+
*/
|
|
35
|
+
int32_t lokahi_c_abi_evaluate_utf8(const uint8_t *ptr, size_t len, int32_t is_s2_critical);
|
|
36
|
+
|
|
37
|
+
#ifdef __cplusplus
|
|
38
|
+
}
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#endif /* DIRGHA_KERNEL_H */
|