@noopolis/daimon 0.2.1 → 0.2.3

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 (35) hide show
  1. package/dist/runtime/agentSkillsDirectory.d.ts +25 -0
  2. package/dist/runtime/agentSkillsDirectory.d.ts.map +1 -0
  3. package/dist/runtime/agentSkillsDirectory.js +101 -0
  4. package/dist/runtime/engineBrokerServiceConfig.d.ts +10 -2
  5. package/dist/runtime/engineBrokerServiceConfig.d.ts.map +1 -1
  6. package/dist/runtime/engineBrokerServiceConfig.js +9 -5
  7. package/dist/runtime/grokBrokerProjection.d.ts +17 -1
  8. package/dist/runtime/grokBrokerProjection.d.ts.map +1 -1
  9. package/dist/runtime/grokBrokerProjection.js +7 -3
  10. package/dist/runtime/grokBrokerProxy.d.ts +8 -1
  11. package/dist/runtime/grokBrokerProxy.d.ts.map +1 -1
  12. package/dist/runtime/grokBrokerProxy.js +28 -10
  13. package/dist/runtime/grokBrokerProxyBodyShape.d.ts +24 -0
  14. package/dist/runtime/grokBrokerProxyBodyShape.d.ts.map +1 -0
  15. package/dist/runtime/grokBrokerProxyBodyShape.js +60 -0
  16. package/dist/runtime/grokBrokerProxyRequest.d.ts +29 -0
  17. package/dist/runtime/grokBrokerProxyRequest.d.ts.map +1 -1
  18. package/dist/runtime/grokBrokerProxyRequest.js +68 -13
  19. package/dist/runtime/grokBrokerTurnMeter.d.ts +7 -2
  20. package/dist/runtime/grokBrokerTurnMeter.d.ts.map +1 -1
  21. package/dist/runtime/grokBrokerTurnMeter.js +8 -4
  22. package/dist/runtime/grokWorkerAttestation.d.ts +3 -1
  23. package/dist/runtime/grokWorkerAttestation.d.ts.map +1 -1
  24. package/dist/runtime/grokWorkerAttestation.js +4 -2
  25. package/dist/runtime/grokWorkerHomeAttestation.d.ts +48 -4
  26. package/dist/runtime/grokWorkerHomeAttestation.d.ts.map +1 -1
  27. package/dist/runtime/grokWorkerHomeAttestation.js +95 -6
  28. package/dist/runtime/grokWorkerSkills.d.ts +86 -0
  29. package/dist/runtime/grokWorkerSkills.d.ts.map +1 -0
  30. package/dist/runtime/grokWorkerSkills.js +135 -0
  31. package/dist/runtime/index.d.ts +3 -0
  32. package/dist/runtime/index.d.ts.map +1 -1
  33. package/dist/runtime/index.js +3 -0
  34. package/dist/runtime/productionAgentTools.js +1 -1
  35. package/package.json +1 -1
@@ -2,6 +2,15 @@ import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
2
2
  import { GROK_WORKER_VISIBLE_TOOLS } from "../contracts/grokWorkerContract.js";
3
3
  import { DEFAULT_GROK_BROKER_MODEL_POLICY, parseGrokBrokerModelPolicy } from "./grokBrokerModelPolicy.js";
4
4
  const MAX_BODY = 2 * 1024 * 1024;
5
+ /** A body-gate refusal. The message is the historic one; `check` names the failed check. */
6
+ export class GrokBrokerProxyRequestRejection extends Error {
7
+ check;
8
+ constructor(check) {
9
+ super("broker proxy request rejected");
10
+ this.check = check;
11
+ }
12
+ }
13
+ function reject(check) { throw new GrokBrokerProxyRequestRejection(check); }
5
14
  /**
6
15
  * Authorizes one worker request and rebuilds it for the provider.
7
16
  *
@@ -13,23 +22,28 @@ const MAX_BODY = 2 * 1024 * 1024;
13
22
  * - the offered tool names are exactly the lean visible set. Grok 1.0.34 turns
14
23
  * an unmappable `--tools` entry into its full 19-tool set, and its per-turn
15
24
  * `session_title` request carries a single forced tool; both are refused.
25
+ *
26
+ * One other shape is admitted, and only by normalizing it into the lean one:
27
+ * Grok 1.0.34's auto-compaction summary request ({@link normalizeGrokCompactionRequest}).
16
28
  */
17
29
  export function authorizeGrokBrokerProxyRequest(input, capabilities, bearer, policy = DEFAULT_GROK_BROKER_MODEL_POLICY) {
18
30
  const declared = parseGrokBrokerModelPolicy(policy);
19
- if (input.method !== "POST" || input.pathname !== "/v1/chat/completions" || input.body.byteLength < 2 || input.body.byteLength > MAX_BODY)
20
- throw new Error("broker proxy request rejected");
31
+ if (input.method !== "POST" || input.pathname !== "/v1/chat/completions")
32
+ reject("route");
33
+ if (input.body.byteLength < 2 || input.body.byteLength > MAX_BODY)
34
+ reject("body_size");
21
35
  const authorization = input.headers.authorization;
22
36
  const match = authorization?.match(/^Bearer ([A-Za-z0-9_-]{40,})$/u);
23
37
  if (match === null || match === undefined)
24
- throw new Error("broker proxy request rejected");
38
+ return reject("bearer");
25
39
  const scope = capabilities.authorizeToken(match[1]);
26
40
  if (scope === undefined || (input.agentId !== undefined && scope.agentId !== input.agentId) || (input.turnId !== undefined && scope.turnId !== input.turnId))
27
- throw new Error("broker proxy request rejected");
41
+ reject("scope");
28
42
  if (!bearer || /[\r\n]/u.test(bearer))
29
43
  throw new Error("broker credential authority unavailable");
30
44
  const clientVersion = input.headers["x-grok-client-version"];
31
45
  if (clientVersion !== GROK_ENGINE_BROKER.grokCliVersion)
32
- throw new Error("broker proxy request rejected");
46
+ reject("client_version");
33
47
  let parsed;
34
48
  // `__proto__` is refused at any depth: JSON.parse makes it an ordinary own
35
49
  // member, but an upstream JavaScript parser may treat it as a prototype.
@@ -41,16 +55,21 @@ export function authorizeGrokBrokerProxyRequest(input, capabilities, bearer, pol
41
55
  });
42
56
  }
43
57
  catch {
44
- throw new Error("broker proxy request rejected");
58
+ return reject("json");
45
59
  }
46
60
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed) || parsed.stream !== true || !Array.isArray(parsed.messages))
47
- throw new Error("broker proxy request rejected");
48
- if (parsed.model !== declared.model || parsed.reasoning_effort !== declared.reasoningEffort)
49
- throw new Error("broker proxy request rejected");
61
+ reject("envelope");
62
+ const compaction = normalizeGrokCompactionRequest(parsed, declared.reasoningEffort);
63
+ if (parsed.model !== declared.model)
64
+ reject("model");
65
+ if (parsed.reasoning_effort !== declared.reasoningEffort)
66
+ reject("reasoning_effort");
50
67
  if (!exactLeanTools(parsed.tools))
51
- throw new Error("broker proxy request rejected");
52
- if (Object.keys(parsed).some((key) => !LEAN_BODY_MEMBERS.has(key)) || !validStreamOptions(parsed.stream_options))
53
- throw new Error("broker proxy request rejected");
68
+ reject("tools");
69
+ if (Object.keys(parsed).some((key) => !LEAN_BODY_MEMBERS.has(key)))
70
+ reject("members");
71
+ if (!validStreamOptions(parsed.stream_options))
72
+ reject("stream_options");
54
73
  // Keep origin/main's production handling: UTF-8 replacement decoding, then
55
74
  // serialize the validated object (including last-member-wins duplicates).
56
75
  // Only a clocked turn takes the stricter date rewrite before this gate.
@@ -61,9 +80,45 @@ export function authorizeGrokBrokerProxyRequest(input, capabilities, bearer, pol
61
80
  "x-xai-token-auth": "xai-grok-cli", "x-grok-model-override": declared.model,
62
81
  "x-grok-client-version": clientVersion, "x-grok-client-identifier": "grok-shell"
63
82
  },
64
- body: Buffer.from(JSON.stringify(parsed))
83
+ body: Buffer.from(JSON.stringify(parsed)),
84
+ ...(compaction ? { compaction: true } : {})
65
85
  };
66
86
  }
87
+ /**
88
+ * Top-level members of Grok 1.0.34's auto-compaction summary request (live stub
89
+ * capture against the pinned binary in the training image, 2026-10-21). When a
90
+ * session nears the model's `context_window`, Grok asks the same model for a
91
+ * summary — single-pass, or a second "two-pass" request — and sends it with
92
+ * the lean tool set, `tool_choice: "auto"` and `temperature: 1`, and *without*
93
+ * `reasoning_effort`. Refusing it does not stop the session: Grok gives up on
94
+ * compaction and carries the whole history forward, so every refusal was a
95
+ * wasted round trip and the context kept growing.
96
+ */
97
+ const COMPACTION_BODY_MEMBERS = new Set(["messages", "model", "stream", "stream_options", "temperature", "tool_choice", "tools"]);
98
+ /**
99
+ * Rewrites, in place, exactly the captured compaction shape into the lean
100
+ * worker shape, and reports whether it did. The two extra members are each
101
+ * the provider's default value (`tool_choice: "auto"` with tools offered,
102
+ * `temperature: 1`), so removing them changes nothing the model is asked; the
103
+ * missing effort is set to the declared one, so the request cannot fall back
104
+ * to a provider default effort. Every other check — model, tools, stream
105
+ * options — then runs on the result exactly as for any worker request, and
106
+ * the forwarded body is indistinguishable from an ordinary lean request: the
107
+ * spend envelope is unchanged. Any other value of either member (a forced
108
+ * `tool_choice`, another temperature) or any other member set is left as is,
109
+ * and refused by the ordinary checks.
110
+ */
111
+ export function normalizeGrokCompactionRequest(parsed, reasoningEffort) {
112
+ const keys = Object.keys(parsed);
113
+ if (keys.length !== COMPACTION_BODY_MEMBERS.size || keys.some((key) => !COMPACTION_BODY_MEMBERS.has(key)))
114
+ return false;
115
+ if (parsed.temperature !== 1 || parsed.tool_choice !== "auto")
116
+ return false;
117
+ delete parsed.temperature;
118
+ delete parsed.tool_choice;
119
+ parsed.reasoning_effort = reasoningEffort;
120
+ return true;
121
+ }
67
122
  /** Top-level members of a Grok 1.0.34 lean worker chat-completions body (live stub capture). */
68
123
  const LEAN_BODY_MEMBERS = new Set(["messages", "model", "reasoning_effort", "stream", "stream_options", "tools"]);
69
124
  /** Members of each lean tool `function` entry (live stub capture). */
@@ -83,8 +83,13 @@ export declare class GrokBrokerTurnMeter {
83
83
  private final;
84
84
  private activityAt;
85
85
  constructor(limits: EngineBrokerTurnLimits, onLimit?: (reason: Exclude<EngineBrokerLimitReason, "none">) => void, now?: () => number);
86
- /** Returns the request index and its upstream abort signal when admitted, the limit that refused it, or `busy` while another request is in flight. */
87
- admit(): Readonly<{
86
+ /**
87
+ * Returns the request index and its upstream abort signal when admitted, the limit that refused it, or `busy` while another request is in flight.
88
+ * `keepFinal` admits a request that cannot replace the answer (a compaction summary), so a final reply already recorded survives it.
89
+ */
90
+ admit(options?: Readonly<{
91
+ keepFinal?: boolean;
92
+ }>): Readonly<{
88
93
  index: number;
89
94
  signal: AbortSignal;
90
95
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"grokBrokerTurnMeter.d.ts","sourceRoot":"","sources":["../../src/runtime/grokBrokerTurnMeter.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,uBAAuB,EAAE,KAAK,sBAAsB,EAAE,KAAK,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAElK;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,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,sIAAsI;AACtI,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,SAA6B,GAAG,MAAM,CAQ/F"}
@@ -63,8 +63,11 @@ export class GrokBrokerTurnMeter {
63
63
  this.startedAt = now();
64
64
  this.activityAt = this.startedAt;
65
65
  }
66
- /** Returns the request index and its upstream abort signal when admitted, the limit that refused it, or `busy` while another request is in flight. */
67
- admit() {
66
+ /**
67
+ * Returns the request index and its upstream abort signal when admitted, the limit that refused it, or `busy` while another request is in flight.
68
+ * `keepFinal` admits a request that cannot replace the answer (a compaction summary), so a final reply already recorded survives it.
69
+ */
70
+ admit(options = {}) {
68
71
  if (this.reason === "none") {
69
72
  if (this.now() - this.startedAt >= this.limits.timeoutMs)
70
73
  this.trip("timeout");
@@ -78,8 +81,9 @@ export class GrokBrokerTurnMeter {
78
81
  if (this.inFlight !== undefined)
79
82
  return { busy: true };
80
83
  this.timings.push({ startedAt: new Date(this.now()).toISOString() });
81
- // A new request means the previous answer was not the last one.
82
- this.final = undefined;
84
+ // A new sampling request means the previous answer was not the last one.
85
+ if (options.keepFinal !== true)
86
+ this.final = undefined;
83
87
  this.activityAt = this.now();
84
88
  const controller = new AbortController();
85
89
  this.inFlight = { index: this.timings.length - 1, controller };
@@ -53,7 +53,8 @@ export declare function parseGrokWorkerSandboxProfile(bytes: Uint8Array, profile
53
53
  * the events watermark it requires the 1.0.34 layout: events under
54
54
  * `$GROK_HOME/sessions/` (the root `sandbox-events.jsonl` stays empty on
55
55
  * 1.0.34), and a root-owned read-only worker home whose `config.toml` hashes to
56
- * the declared renderer output (`grokWorkerHomeAttestation.ts`).
56
+ * the declared renderer output and whose `skills/` is exactly the declared
57
+ * skills (`skillsSha256`; absent for none) (`grokWorkerHomeAttestation.ts`).
57
58
  *
58
59
  * It also refuses a deny list bubblewrap could not materialize
59
60
  * (`grokWorkerDenyPlacement.ts`), naming the entry and the ancestor that stops
@@ -73,6 +74,7 @@ export declare function prepareGrokWorkerAttestation(input: Readonly<{
73
74
  workerGid?: number;
74
75
  brokerGid: number;
75
76
  configSha256: GrokWorkerConfigPins;
77
+ skillsSha256?: string;
76
78
  registeredWorkers?: readonly Readonly<{
77
79
  profilePath: string;
78
80
  workerUid: number;
@@ -1 +1 @@
1
- {"version":3,"file":"grokWorkerAttestation.d.ts","sourceRoot":"","sources":["../../src/runtime/grokWorkerAttestation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAOnF,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACjG,OAAO,EAAiD,KAAK,oBAAoB,EAA4B,MAAM,+BAA+B,CAAC;AAGnJ;;;;;GAKG;AACH,MAAM,MAAM,6BAA6B,GAAC,QAAQ,CAAC;IAAC,GAAG,EAAC,MAAM,CAAC;IAAA,GAAG,EAAC,MAAM,CAAC;IAAA,IAAI,EAAC,MAAM,CAAC;IAAA,SAAS,EAAC,SAAS,MAAM,EAAE,CAAC;IAAA,aAAa,CAAC,EAAC,uBAAuB,CAAA;CAAC,CAAC,CAAC;AAC3J,KAAK,QAAQ,GAAC,6BAA6B,CAAC;AAC5C,qBAAa,4BAA6B,SAAQ,KAAK;IAAe,QAAQ,CAAC,YAAY,EAAC,iBAAiB,GAAC,iBAAiB;gBAAhD,YAAY,EAAC,iBAAiB,GAAC,iBAAiB;CAA4D;AAC3L;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAC,UAAU,EAAC,aAAa,EAAC,MAAM,GAAE,SAAS,MAAM,EAAE,CAUrG;AACD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,4BAA4B,CAAC,KAAK,EAAC,QAAQ,CAAC;IAAC,WAAW,EAAC,MAAM,CAAC;IAAA,UAAU,EAAC,MAAM,CAAC;IAAA,aAAa,EAAC,MAAM,CAAC;IAAA,SAAS,EAAC,MAAM,CAAC;IAAA,SAAS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AC,MAAM,EAAC,MAAM,CAAC;IAAA,MAAM,EAAC,MAAM,CAAA;CAAC,CAAC,CAavJ"}
@@ -64,7 +64,8 @@ export function parseGrokWorkerSandboxProfile(bytes, profileSha256) {
64
64
  * the events watermark it requires the 1.0.34 layout: events under
65
65
  * `$GROK_HOME/sessions/` (the root `sandbox-events.jsonl` stays empty on
66
66
  * 1.0.34), and a root-owned read-only worker home whose `config.toml` hashes to
67
- * the declared renderer output (`grokWorkerHomeAttestation.ts`).
67
+ * the declared renderer output and whose `skills/` is exactly the declared
68
+ * skills (`skillsSha256`; absent for none) (`grokWorkerHomeAttestation.ts`).
68
69
  *
69
70
  * It also refuses a deny list bubblewrap could not materialize
70
71
  * (`grokWorkerDenyPlacement.ts`), naming the entry and the ancestor that stops
@@ -100,7 +101,8 @@ export async function prepareGrokWorkerAttestation(input, profileOwner = { uid:
100
101
  if (workers.some((worker) => worker.home === undefined))
101
102
  throw new Error("Grok worker isolation attestation unavailable");
102
103
  await verifyGrokWorkerTmp(workers, profileOwner.tmp);
103
- const configVariant = await verifyGrokWorkerHome(path.dirname(input.profilePath), input.configSha256);
104
+ // The home's read-only files share the profile's owner (root in production: `sandbox.toml` is one of them).
105
+ const configVariant = await verifyGrokWorkerHome(path.dirname(input.profilePath), input.configSha256, profileOwner.uid, input.skillsSha256);
104
106
  const events = await secureOpen(input.eventsPath, input.workerUid, input.brokerGid, 0o640, 16 * 1024 * 1024);
105
107
  try {
106
108
  const stat = await events.stat();
@@ -13,7 +13,7 @@ type Entry = Pick<Stats, "uid" | "mode" | "nlink"> & Partial<Pick<Stats, "dev" |
13
13
  * so the directory is worker-group writable — but root-owned and sticky, so a
14
14
  * worker can neither rename nor unlink a root-owned file in it. Every file
15
15
  * that decides a turn's behaviour is root-owned with no write bit: `config.toml`
16
- * (model, effort, MCP, skills), `sandbox.toml`, `trusted_folders.toml` (trust
16
+ * (model, effort, MCP, bundled-skill toggles), `sandbox.toml`, `trusted_folders.toml` (trust
17
17
  * would re-enable cwd `AGENTS.md` and project skills), and the managed and
18
18
  * requirements layers that can override user config. A missing file fails
19
19
  * too: the worker could create it.
@@ -24,9 +24,53 @@ export declare function assertGrokWorkerHomeEntries(entries: Readonly<Record<str
24
24
  /** The worker's `config.toml` must be exactly the renderer's bytes for the declared policy. */
25
25
  export declare function assertGrokWorkerConfigBytes(bytes: Uint8Array, pins: GrokWorkerConfigPins): GrokWorkerConfigVariant;
26
26
  /**
27
- * Attests the worker home layout and that `config.toml` is exactly the
28
- * renderer's bytes for the declared model policy (`configSha256`).
27
+ * The worker's `$GROK_HOME/skills` must be exactly the declared skills.
28
+ *
29
+ * Grok loads that directory as user-scoped skills even in an untrusted
30
+ * workspace, and `$GROK_HOME` is worker-group writable, so a worker could plant
31
+ * a skill there for its next turn. With no `skillsSha256` declared the
32
+ * directory must be absent (or an empty root-owned read-only directory); with
33
+ * one declared, every entry must be root-owned with no write bit and the tree
34
+ * must hash to it. A worker-created or worker-modified tree fails either way.
35
+ */
36
+ export declare function verifyGrokWorkerSkills(grokHome: string, skillsSha256: string | undefined, rootUid?: number): Promise<void>;
37
+ /**
38
+ * Every other skill root Grok discovers at user scope, which the worker could
39
+ * plant into: under `$GROK_HOME` (root-owned but worker-group writable and
40
+ * sticky, so the worker can create new entries) and under the worker's own
41
+ * `$HOME` (the launcher exports `HOME=<home>` and `GROK_HOME=<home>/.grok`;
42
+ * `<home>` is worker-owned). Only `$GROK_HOME/skills` may carry skills, and only
43
+ * the declared ones; each root here must be absent, or an empty root-owned
44
+ * directory with no write bit.
45
+ *
46
+ * Set from `grok inspect` with scratch `HOME`/`GROK_HOME` and no network
47
+ * (1.0.60: every root below listed a planted skill or command; `.codex/skills`,
48
+ * `.ai/skills`, `$HOME/.config/*` and `$HOME/.agents/plugins` did not) and from
49
+ * the pinned 1.0.34 binary's own skills table (`~/.grok/{skills,commands}`,
50
+ * `~/.claude/{skills,commands}`, `~/.cursor/skills`, `.agents/{skills,commands}`
51
+ * at each tier). `bundled/skills` is the bundled-skill cache: never created on
52
+ * 1.0.34 (P0 container evidence), but a skill planted there loads with a name
53
+ * `[skills] disabled` does not cover. `plugins/` folders load their skills and
54
+ * commands as trusted user plugins.
55
+ */
56
+ export declare const GROK_WORKER_FOREIGN_SKILL_ROOTS: Readonly<{
57
+ grokHome: readonly ["commands", "bundled/skills", "plugins"];
58
+ home: readonly [".agents/skills", ".agents/commands", ".claude/skills", ".claude/commands", ".cursor/skills", ".cursor/commands"];
59
+ }>;
60
+ /**
61
+ * Refuses a foreign skill root (`GROK_WORKER_FOREIGN_SKILL_ROOTS`) that exists
62
+ * and is not an empty root-owned read-only directory. A deployment that never
63
+ * creates them passes unchanged. `grokHome` must be `<home>/.grok`, the
64
+ * launcher's layout, so `<home>` is its parent.
65
+ */
66
+ export declare function verifyGrokWorkerForeignSkillRoots(grokHome: string, rootUid?: number): Promise<void>;
67
+ /**
68
+ * Attests the worker home layout, that `config.toml` is exactly the
69
+ * renderer's bytes for the declared model policy (`configSha256`), that
70
+ * `skills/` is exactly the declared skills (`skillsSha256`, absent for none),
71
+ * and that no other user skill root holds anything
72
+ * (`verifyGrokWorkerForeignSkillRoots`).
29
73
  */
30
- export declare function verifyGrokWorkerHome(grokHome: string, configSha256: GrokWorkerConfigPins, rootUid?: number): Promise<GrokWorkerConfigVariant>;
74
+ export declare function verifyGrokWorkerHome(grokHome: string, configSha256: GrokWorkerConfigPins, rootUid?: number, skillsSha256?: string): Promise<GrokWorkerConfigVariant>;
31
75
  export {};
32
76
  //# sourceMappingURL=grokWorkerHomeAttestation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"grokWorkerHomeAttestation.d.ts","sourceRoot":"","sources":["../../src/runtime/grokWorkerHomeAttestation.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAEnF,MAAM,MAAM,oBAAoB,GAAG,MAAM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C,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC;IAAE,MAAM,IAAI,OAAO,CAAC;IAAC,WAAW,IAAI,OAAO,CAAC;IAAC,cAAc,IAAI,OAAO,CAAA;CAAE,CAAC,CAAC;AAG9K;;;;;;;;;;;;;GAaG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC,EAAE,OAAO,GAAE,MAA2B,GAAG,IAAI,CAS5I;AAED,+FAA+F;AAC/F,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,oBAAoB,GAAG,uBAAuB,CAQlH;AAED;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,GAAE,MAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAKpJ;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,+BAA+B;;;EAG1C,CAAC;AAEH;;;;;GAKG;AACH,wBAAsB,iCAAiC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,MAA2B,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB7H;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,oBAAoB,EAAE,OAAO,GAAE,MAA2B,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAkB9L"}
@@ -1,8 +1,10 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { constants } from "node:fs";
3
- import { lstat, open } from "node:fs/promises";
3
+ import { lstat, open, readdir } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { GROK_ENGINE_BROKER } from "../contracts/runtimeContractManifest.js";
6
+ import { readAgentSkillsDirectory } from "./agentSkillsDirectory.js";
7
+ import { GROK_WORKER_SKILLS_LAYOUT, grokWorkerSkillsSha256 } from "./grokWorkerSkills.js";
6
8
  const HOME = GROK_ENGINE_BROKER.worker.home;
7
9
  /**
8
10
  * The worker must not be able to change what Grok reads before its next turn.
@@ -11,7 +13,7 @@ const HOME = GROK_ENGINE_BROKER.worker.home;
11
13
  * so the directory is worker-group writable — but root-owned and sticky, so a
12
14
  * worker can neither rename nor unlink a root-owned file in it. Every file
13
15
  * that decides a turn's behaviour is root-owned with no write bit: `config.toml`
14
- * (model, effort, MCP, skills), `sandbox.toml`, `trusted_folders.toml` (trust
16
+ * (model, effort, MCP, bundled-skill toggles), `sandbox.toml`, `trusted_folders.toml` (trust
15
17
  * would re-enable cwd `AGENTS.md` and project skills), and the managed and
16
18
  * requirements layers that can override user config. A missing file fails
17
19
  * too: the worker could create it.
@@ -41,10 +43,94 @@ export function assertGrokWorkerConfigBytes(bytes, pins) {
41
43
  throw unavailable();
42
44
  }
43
45
  /**
44
- * Attests the worker home layout and that `config.toml` is exactly the
45
- * renderer's bytes for the declared model policy (`configSha256`).
46
+ * The worker's `$GROK_HOME/skills` must be exactly the declared skills.
47
+ *
48
+ * Grok loads that directory as user-scoped skills even in an untrusted
49
+ * workspace, and `$GROK_HOME` is worker-group writable, so a worker could plant
50
+ * a skill there for its next turn. With no `skillsSha256` declared the
51
+ * directory must be absent (or an empty root-owned read-only directory); with
52
+ * one declared, every entry must be root-owned with no write bit and the tree
53
+ * must hash to it. A worker-created or worker-modified tree fails either way.
54
+ */
55
+ export async function verifyGrokWorkerSkills(grokHome, skillsSha256, rootUid = HOME.directory.uid) {
56
+ if (skillsSha256 !== undefined && !/^[0-9a-f]{64}$/u.test(skillsSha256))
57
+ throw unavailable();
58
+ let skills;
59
+ try {
60
+ skills = await readAgentSkillsDirectory(path.join(grokHome, GROK_WORKER_SKILLS_LAYOUT.relativePath), { ownerUid: rootUid, readOnly: true });
61
+ }
62
+ catch {
63
+ throw unavailable();
64
+ }
65
+ if (grokWorkerSkillsSha256(skills ?? []) !== (skillsSha256 ?? grokWorkerSkillsSha256([])))
66
+ throw unavailable();
67
+ }
68
+ /**
69
+ * Every other skill root Grok discovers at user scope, which the worker could
70
+ * plant into: under `$GROK_HOME` (root-owned but worker-group writable and
71
+ * sticky, so the worker can create new entries) and under the worker's own
72
+ * `$HOME` (the launcher exports `HOME=<home>` and `GROK_HOME=<home>/.grok`;
73
+ * `<home>` is worker-owned). Only `$GROK_HOME/skills` may carry skills, and only
74
+ * the declared ones; each root here must be absent, or an empty root-owned
75
+ * directory with no write bit.
76
+ *
77
+ * Set from `grok inspect` with scratch `HOME`/`GROK_HOME` and no network
78
+ * (1.0.60: every root below listed a planted skill or command; `.codex/skills`,
79
+ * `.ai/skills`, `$HOME/.config/*` and `$HOME/.agents/plugins` did not) and from
80
+ * the pinned 1.0.34 binary's own skills table (`~/.grok/{skills,commands}`,
81
+ * `~/.claude/{skills,commands}`, `~/.cursor/skills`, `.agents/{skills,commands}`
82
+ * at each tier). `bundled/skills` is the bundled-skill cache: never created on
83
+ * 1.0.34 (P0 container evidence), but a skill planted there loads with a name
84
+ * `[skills] disabled` does not cover. `plugins/` folders load their skills and
85
+ * commands as trusted user plugins.
86
+ */
87
+ export const GROK_WORKER_FOREIGN_SKILL_ROOTS = Object.freeze({
88
+ grokHome: Object.freeze(["commands", "bundled/skills", "plugins"]),
89
+ home: Object.freeze([".agents/skills", ".agents/commands", ".claude/skills", ".claude/commands", ".cursor/skills", ".cursor/commands"])
90
+ });
91
+ /**
92
+ * Refuses a foreign skill root (`GROK_WORKER_FOREIGN_SKILL_ROOTS`) that exists
93
+ * and is not an empty root-owned read-only directory. A deployment that never
94
+ * creates them passes unchanged. `grokHome` must be `<home>/.grok`, the
95
+ * launcher's layout, so `<home>` is its parent.
96
+ */
97
+ export async function verifyGrokWorkerForeignSkillRoots(grokHome, rootUid = HOME.directory.uid) {
98
+ if (path.basename(grokHome) !== ".grok")
99
+ throw unavailable();
100
+ const home = path.dirname(grokHome);
101
+ const roots = [...GROK_WORKER_FOREIGN_SKILL_ROOTS.grokHome.map((root) => path.join(grokHome, root)), ...GROK_WORKER_FOREIGN_SKILL_ROOTS.home.map((root) => path.join(home, root))];
102
+ for (const root of roots) {
103
+ let entry;
104
+ try {
105
+ entry = await lstat(root);
106
+ }
107
+ catch (error) {
108
+ // Absent, or a parent that is not a directory: Grok finds nothing there either.
109
+ if (["ENOENT", "ENOTDIR"].includes(error.code ?? ""))
110
+ continue;
111
+ throw unavailable();
112
+ }
113
+ if (entry.isSymbolicLink() || !entry.isDirectory() || entry.uid !== rootUid || (Number(entry.mode) & 0o7222) !== 0)
114
+ throw unavailable();
115
+ let children;
116
+ try {
117
+ children = await readdir(root);
118
+ }
119
+ catch {
120
+ throw unavailable();
121
+ }
122
+ if (children.length !== 0)
123
+ throw unavailable();
124
+ }
125
+ }
126
+ /**
127
+ * Attests the worker home layout, that `config.toml` is exactly the
128
+ * renderer's bytes for the declared model policy (`configSha256`), that
129
+ * `skills/` is exactly the declared skills (`skillsSha256`, absent for none),
130
+ * and that no other user skill root holds anything
131
+ * (`verifyGrokWorkerForeignSkillRoots`).
46
132
  */
47
- export async function verifyGrokWorkerHome(grokHome, configSha256, rootUid = HOME.directory.uid) {
133
+ export async function verifyGrokWorkerHome(grokHome, configSha256, rootUid = HOME.directory.uid, skillsSha256) {
48
134
  const entries = {};
49
135
  for (const name of [".", HOME.sessionsDirectory.relativePath, ...HOME.readOnlyFiles.names]) {
50
136
  try {
@@ -63,7 +149,10 @@ export async function verifyGrokWorkerHome(grokHome, configSha256, rootUid = HOM
63
149
  // Same inode as the lstat above, as in `secureOpen`: a rename between the two cannot swap in other bytes.
64
150
  if (!opened.isFile() || opened.size > 65_536 || opened.dev !== before.dev || opened.ino !== before.ino || opened.uid !== before.uid || opened.mode !== before.mode || opened.nlink !== 1)
65
151
  throw unavailable();
66
- return assertGrokWorkerConfigBytes(await handle.readFile(), configSha256);
152
+ const variant = assertGrokWorkerConfigBytes(await handle.readFile(), configSha256);
153
+ await verifyGrokWorkerSkills(grokHome, skillsSha256, rootUid);
154
+ await verifyGrokWorkerForeignSkillRoots(grokHome, rootUid);
155
+ return variant;
67
156
  }
68
157
  catch {
69
158
  throw unavailable();
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Where root provisioning renders the agent's declared skills inside the worker
3
+ * home (`$GROK_HOME/skills`), and what every entry must be: root-owned, no
4
+ * write bit. Grok discovers that directory as user-scoped skills even in an
5
+ * untrusted workspace. Absent when the registration declares no `skillsSha256`.
6
+ *
7
+ * Deliberately *not* folded into `RUNTIME_CONTRACT_MANIFEST`, as with
8
+ * `TURN_USAGE_LEDGER`: the manifest's canonical bytes are digest-pinned by
9
+ * Spawnfile and attested against the selected runtime image, so a new key
10
+ * there makes every pinned image fail to attest. Only Daimon reads this layout
11
+ * (the renderer below and the broker's pre-turn attestation); Spawnfile
12
+ * consumes it through `renderGrokWorkerSkillsTree`.
13
+ */
14
+ export declare const GROK_WORKER_SKILLS_LAYOUT: Readonly<{
15
+ readonly relativePath: "skills";
16
+ readonly uid: 0;
17
+ readonly gid: 0;
18
+ readonly directoryMode: 365;
19
+ readonly fileMode: 292;
20
+ readonly digestVersion: "noopolis.daimon.grok-worker-skills.v1";
21
+ }>;
22
+ /**
23
+ * One file of a declared agent skill, relative to the skill's own directory.
24
+ * `SKILL.md` is required; supporting files (references, scripts) are optional.
25
+ */
26
+ export type AgentSkillFile = Readonly<{
27
+ path: string;
28
+ content: string;
29
+ }>;
30
+ /** One declared agent skill: its directory name and every file under it. */
31
+ export type AgentSkill = Readonly<{
32
+ name: string;
33
+ files: readonly AgentSkillFile[];
34
+ }>;
35
+ /**
36
+ * The engine-neutral skills input. It is the compiled workspace tree every
37
+ * engine is given — Spawnfile lowers declared skills (and Moltnet installs its
38
+ * own) into `<workspace>/.agents/skills/<name>/SKILL.md`, which Codex reads in
39
+ * place. A brokered Grok worker cannot read it there: its workspace stays
40
+ * untrusted, so root provisioning renders the same skills into
41
+ * `$GROK_HOME/skills` instead.
42
+ */
43
+ export declare const AGENT_SKILLS_WORKSPACE_DIRECTORY: ".agents/skills";
44
+ export declare const GROK_WORKER_SKILLS_VERSION: "noopolis.daimon.grok-worker-skills.v1";
45
+ export declare const AGENT_SKILLS_BOUNDS: Readonly<{
46
+ skills: 64;
47
+ filesPerSkill: 64;
48
+ fileBytes: 262144;
49
+ totalBytes: 4194304;
50
+ depth: 8;
51
+ }>;
52
+ /**
53
+ * Strict, canonicalizing parser: names and path components are plain
54
+ * identifiers (no `.`/`..`, no hidden entries, no separators other than `/`),
55
+ * every skill carries `SKILL.md`, nothing collides, and the sizes are bounded.
56
+ * Output is sorted by name and path so equal sets digest equally.
57
+ */
58
+ export declare function parseAgentSkills(value: unknown): readonly AgentSkill[];
59
+ /**
60
+ * sha256 over the canonical description of the rendered tree: every skill's
61
+ * name and, per file, its path, byte length and content digest. The broker
62
+ * attests `$GROK_HOME/skills` against it before every turn, and the Grok broker
63
+ * projection carries it, so the slot preflight receipt and every recomputed
64
+ * projection bind the exact skills a subject was given.
65
+ */
66
+ export declare function grokWorkerSkillsSha256(skills: readonly AgentSkill[]): string;
67
+ /** One entry root provisioning creates, relative to `$GROK_HOME`, owned `uid:gid`. */
68
+ export type GrokWorkerSkillsEntry = Readonly<{
69
+ path: string;
70
+ kind: "directory" | "file";
71
+ uid: number;
72
+ gid: number;
73
+ mode: number;
74
+ content?: string;
75
+ }>;
76
+ /**
77
+ * Every directory and file root provisioning writes for these skills, parents
78
+ * before children: `skills/` itself, each `skills/<name>/`, any intermediate
79
+ * directory, and each file. Directories are `root:root 0555` and files
80
+ * `root:root 0444` (single link), so a worker-uid process can read them but
81
+ * neither change nor replace them; `$GROK_HOME` is root-owned and sticky, so the
82
+ * worker cannot rename `skills/` away either. No skills renders nothing: the
83
+ * directory must then be absent, exactly as before this layout existed.
84
+ */
85
+ export declare function renderGrokWorkerSkillsTree(skills: readonly AgentSkill[]): readonly GrokWorkerS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