shadok-ai 0.17.48 → 0.17.50

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.
@@ -123,6 +123,43 @@ export declare function rewriteCronCheckHome(check: string, oldHome: string, new
123
123
  * custom-named one — reintroducing the exact silent breakage this closes.
124
124
  */
125
125
  export declare const SHADOK_INTERNAL_DIRS: readonly string[];
126
+ /**
127
+ * Shadok's OWN credential and identity state under `~/.shadok-ai`, which the
128
+ * SERVER must keep OWNING across the commons chown. `migChownTreeToCommons` runs
129
+ * an unbounded `chown -R main:main ~/.shadok-ai` on purpose — the commons agent
130
+ * has to keep working on what it already worked on — but that sweeps the
131
+ * credential stores along with the working state, and "who may read this" is not
132
+ * the same question as "who owns this".
133
+ *
134
+ * Nothing LEAKS from it: the server's HOME stays 0700, so `main` cannot even
135
+ * traverse `/root` (the same wall that stranded the cron guards #419-#421 healed).
136
+ * What breaks is the SERVER's own use of its files, and the SSH identity is where
137
+ * that bites first: `~/.ssh` is a symlink to `~/.shadok-ai/ssh` (invariant 19,
138
+ * the only path that survives a container recreate), so once the key and its
139
+ * config belonged to `main`, every root-side `ssh` refused to run at all —
140
+ * `Bad owner or permissions on /root/.ssh/config`, because OpenSSH checks the
141
+ * OWNER of those files, not just their mode. Measured on the dogfood instance:
142
+ * `git` over SSH and every `ssh` to the host were dead while looking configured,
143
+ * and no merge noticed because `gh` speaks HTTPS.
144
+ *
145
+ * So this is re-asserted at EVERY capable boot rather than only right after the
146
+ * migration — an instance already migrated by an older build heals on its next
147
+ * update instead of needing a hand repair. Twin of `healCommonsStrandedScripts`.
148
+ *
149
+ * Every DIRECTORY here is also in `SHADOK_INTERNAL_DIRS`, the list that keeps the
150
+ * heal from COPYING it into a group HOME. The two halves answer the same question
151
+ * by different means — ownership in place, and relocation — so a test pins the
152
+ * pairing: otherwise they drift apart one entry at a time, and a credential store
153
+ * added to one list only would be half-protected in silence.
154
+ */
155
+ export declare const SERVER_OWNED_STATE: readonly string[];
156
+ /**
157
+ * Absolute paths of `SERVER_OWNED_STATE` under `home`. PURE: whether a path
158
+ * exists is the caller's business, so this needs no filesystem to test. A blank
159
+ * home yields nothing rather than paths rooted at `/.shadok-ai` — a chown there
160
+ * would be aimed at the wrong machine entirely.
161
+ */
162
+ export declare function serverOwnedStatePaths(home: string): string[];
126
163
  /**
127
164
  * The `~/.claude/<dir>` subtrees NEVER carried by the heal. `.credentials` is a
128
165
  * FILE, not a dir, so it can't match anyway — the real entries are the big
@@ -1,3 +1,4 @@
1
+ import path from "node:path";
1
2
  /**
2
3
  * Automatic migration of a running SINGLE-TENANT instance into isolated groups,
3
4
  * on the first boot of a CAPABLE (multi-tenant) instance. It is ADDITIVE: today
@@ -160,6 +161,62 @@ export const SHADOK_INTERNAL_DIRS = [
160
161
  "worktrees",
161
162
  "wt",
162
163
  ];
164
+ /**
165
+ * Shadok's OWN credential and identity state under `~/.shadok-ai`, which the
166
+ * SERVER must keep OWNING across the commons chown. `migChownTreeToCommons` runs
167
+ * an unbounded `chown -R main:main ~/.shadok-ai` on purpose — the commons agent
168
+ * has to keep working on what it already worked on — but that sweeps the
169
+ * credential stores along with the working state, and "who may read this" is not
170
+ * the same question as "who owns this".
171
+ *
172
+ * Nothing LEAKS from it: the server's HOME stays 0700, so `main` cannot even
173
+ * traverse `/root` (the same wall that stranded the cron guards #419-#421 healed).
174
+ * What breaks is the SERVER's own use of its files, and the SSH identity is where
175
+ * that bites first: `~/.ssh` is a symlink to `~/.shadok-ai/ssh` (invariant 19,
176
+ * the only path that survives a container recreate), so once the key and its
177
+ * config belonged to `main`, every root-side `ssh` refused to run at all —
178
+ * `Bad owner or permissions on /root/.ssh/config`, because OpenSSH checks the
179
+ * OWNER of those files, not just their mode. Measured on the dogfood instance:
180
+ * `git` over SSH and every `ssh` to the host were dead while looking configured,
181
+ * and no merge noticed because `gh` speaks HTTPS.
182
+ *
183
+ * So this is re-asserted at EVERY capable boot rather than only right after the
184
+ * migration — an instance already migrated by an older build heals on its next
185
+ * update instead of needing a hand repair. Twin of `healCommonsStrandedScripts`.
186
+ *
187
+ * Every DIRECTORY here is also in `SHADOK_INTERNAL_DIRS`, the list that keeps the
188
+ * heal from COPYING it into a group HOME. The two halves answer the same question
189
+ * by different means — ownership in place, and relocation — so a test pins the
190
+ * pairing: otherwise they drift apart one entry at a time, and a credential store
191
+ * added to one list only would be half-protected in silence.
192
+ */
193
+ export const SERVER_OWNED_STATE = [
194
+ // Stores (directories).
195
+ "ssh", // the persistent SSH identity; `~/.ssh` points here (invariant 19)
196
+ "users", // account hashes + the per-instance session-signing key (invariant 33)
197
+ "peers", // the inbound peer tokens this instance minted for other cockpits
198
+ "keys",
199
+ "secrets",
200
+ "tokens",
201
+ // Files.
202
+ "config.json", // the GUI password and the per-launch-dir Telegram tokens
203
+ "secrets.json", // the vault
204
+ "secret-origin.json",
205
+ "secret-audit.jsonl",
206
+ "profiles.json", // the GUARDRAILS, which an agent must never write (invariant 26)
207
+ "profiles-declined.json",
208
+ ];
209
+ /**
210
+ * Absolute paths of `SERVER_OWNED_STATE` under `home`. PURE: whether a path
211
+ * exists is the caller's business, so this needs no filesystem to test. A blank
212
+ * home yields nothing rather than paths rooted at `/.shadok-ai` — a chown there
213
+ * would be aimed at the wrong machine entirely.
214
+ */
215
+ export function serverOwnedStatePaths(home) {
216
+ if (!home)
217
+ return [];
218
+ return SERVER_OWNED_STATE.map((rel) => path.join(home, ".shadok-ai", rel));
219
+ }
163
220
  /**
164
221
  * The `~/.claude/<dir>` subtrees NEVER carried by the heal. `.credentials` is a
165
222
  * FILE, not a dir, so it can't match anyway — the real entries are the big
@@ -1 +1 @@
1
- {"version":3,"file":"migrate-groups.js","sourceRoot":"","sources":["../src/migrate-groups.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;kDACkD;AAClD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC;AAEnC;;;;;;;;;;;;GAYG;AACH,MAAM,C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AAC,CAAC;IAC/G,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzC,MAAM,IAAI,CAAC,gCAAgC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/G,CAAC;IACD,MAAM,IAAI,CAAC,uCAAuC,EAAE,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;IAE/G,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC;YACH,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,GAAG,CAAC,yFAAyF,CAAC,CAAC;QACjG,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,uCAAwC,CAAW,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,iGAAiG,CAAC,CAAC;IACzG,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function mergeAppendedPrompts(args: readonly string[]): string[];
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Claude Code's `--append-system-prompt <prompt>` takes ONE value. Given the
3
+ * flag several times, the model sees only the LAST one — measured on 2.1.319:
4
+ * three flags carrying three codewords, and the model reported only the third.
5
+ *
6
+ * shadok appended four separate blocks at spawn — the profile's role, the
7
+ * environment note, the pilot prompt and the ledger reflex — so with the ledger
8
+ * on, every agent silently kept the ledger reflex alone: no role, no cockpit
9
+ * context. Nothing errors and nothing shows; the agent just behaves as if it had
10
+ * never been told. This collapses them into ONE flag, in their order, at the
11
+ * position of the first, joined by a blank line. Pure, tested.
12
+ */
13
+ const FLAG = "--append-system-prompt";
14
+ export function mergeAppendedPrompts(args) {
15
+ const out = [];
16
+ const values = [];
17
+ let at = -1;
18
+ for (let i = 0; i < args.length; i++) {
19
+ if (args[i] === FLAG && i + 1 < args.length) {
20
+ if (at < 0) {
21
+ at = out.length;
22
+ out.push(FLAG, "");
23
+ }
24
+ values.push(args[i + 1]);
25
+ i++; // the value is consumed whatever it looks like
26
+ continue;
27
+ }
28
+ out.push(args[i]);
29
+ }
30
+ if (at >= 0)
31
+ out[at + 1] = values.join("\n\n");
32
+ return out;
33
+ }
34
+ //# sourceMappingURL=prompt-args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-args.js","sourceRoot":"","sources":["../src/prompt-args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,IAAI,GAAG,wBAAwB,CAAC;AAEtC,MAAM,UAAU,oBAAoB,CAAC,IAAuB;IAC1D,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAC5C,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;gBACX,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;gBAChB,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACrB,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC,EAAE,CAAC,CAAC,+CAA+C;YACpD,SAAS;QACX,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,EAAE,IAAI,CAAC;QAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,GAAG,CAAC;AACb,CAAC"}
package/dist/server.js CHANGED
@@ -24,6 +24,7 @@ import { backgroundTasks, screenShowsWork, moveToOption, boxText } from "./detec
24
24
  import { autoReloadVerdict, autoReloadEnabled } from "./auto-reload.js";
25
25
  import { PtyPilot } from "./session.js";
26
26
  import { ensureClaudeHome, ensureProjectTrusted, getDefaultModel, setDefaultModel, parseClaudeVersion, seedPlanForCwds, settingsPlan, } from "./claude-home.js";
27
+ import { mergeAppendedPrompts } from "./prompt-args.js";
27
28
  import { authStatus, cancelLogin, invalidateAuthStatus, startLogin, submitLoginCode } from "./claude-auth.js";
28
29
  import { startSetupToken, submitSetupTokenCode, cancelSetupToken } from "./setup-token.js";
29
30
  import { startAgentLogin, submitAgentLoginCode, cancelAgentLogin, agentLoginPending, agentLoginInfo, } from "./agent-login.js";
@@ -34,7 +35,7 @@ import { readGroundAt } from "./ground.js";
34
35
  import { homeGreetingBrief } from "./greeting.js";
35
36
  import { ensureSshIdentity } from "./ssh.js";
36
37
  import { accountsEnabled, deploymentMode, probeCanProvision } from "./capability.js";
37
- import { migrationPlan, runMigration, respawnPlan, commonsOsUser, COMMONS_USER, MIGRATION_MARKER_FILE, rewriteCronCheckHome, strandedCheckDirs, } from "./migrate-groups.js";
38
+ import { migrationPlan, runMigration, respawnPlan, commonsOsUser, COMMONS_USER, MIGRATION_MARKER_FILE, rewriteCronCheckHome, strandedCheckDirs, serverOwnedStatePaths, } from "./migrate-groups.js";
38
39
  import { relayOAuthCallback } from "./oauth-relay.js";
39
40
  import { openBrowser } from "./open-browser.js";
40
41
  import { parseSkillMeta, prepromptParts, prepromptFingerprint, stalenessReasons, LEGACY_FINGERPRINT, } from "./preprompt.js";
@@ -3014,6 +3015,9 @@ async function ensureGroupsProvisioned() {
3014
3015
  // And heal the commons agent's own helper scripts + cron guards, which the HOME
3015
3016
  // move off /root left stranded (see below).
3016
3017
  await healCommonsStrandedScripts();
3018
+ // Then take back the ownership of the server's OWN credentials, which the
3019
+ // commons chown swept (see below) — the SSH identity first of all.
3020
+ await healServerOwnedState();
3017
3021
  }
3018
3022
  /**
3019
3023
  * Boot self-heal for the commons agent's OWN helper scripts and cron guards after
@@ -3113,6 +3117,68 @@ async function healCommonsStrandedScripts() {
3113
3117
  console.error(`heal: rewriting cron guard paths failed (best-effort): ${e?.message ?? e}`);
3114
3118
  }
3115
3119
  }
3120
+ /**
3121
+ * Boot self-heal, twin of `healCommonsStrandedScripts`: give the SERVER back the
3122
+ * ownership of its own credential and identity state, which the migration's
3123
+ * unbounded `chown -R main:main ~/.shadok-ai` swept along with the working state
3124
+ * (`SERVER_OWNED_STATE` carries the full reasoning and the measured symptom —
3125
+ * every root-side `ssh` dying on `Bad owner or permissions on /root/.ssh/config`,
3126
+ * because OpenSSH checks the OWNER of a key and a config, not only its mode).
3127
+ *
3128
+ * Runs on EVERY capable boot, independent of the migration marker, so an instance
3129
+ * already migrated by an older build heals on its next update. Idempotent and
3130
+ * cheap in the normal case: a few `lstat`s and NO privileged spawn once everything
3131
+ * is ours again — which is what makes it safe to run unconditionally.
3132
+ *
3133
+ * A directory is judged on itself AND its immediate entries, because a hand repair
3134
+ * typically re-owns the directory and leaves the key inside it foreign — the one
3135
+ * state in which `ssh` still refuses and the top-level check alone would call it
3136
+ * healed. Best-effort per path: a failure here must never take down the boot, and
3137
+ * it is reported rather than swallowed (a silent chown is indistinguishable from
3138
+ * one that never ran — the lesson of `src/claude-home.ts`).
3139
+ */
3140
+ async function healServerOwnedState() {
3141
+ if (DEPLOYMENT_MODE !== "multi-tenant")
3142
+ return;
3143
+ const uid = process.getuid?.() ?? 0;
3144
+ const gid = process.getgid?.() ?? 0;
3145
+ const owner = `${uid}:${gid}`;
3146
+ // Is anything under `p` owned by someone else? One level deep is enough: the
3147
+ // chown that causes this is `-R`, so a subtree moves as a whole, and a partial
3148
+ // tree is a hand repair, whose usual shape is "dir re-owned, contents not".
3149
+ const foreign = (p) => {
3150
+ try {
3151
+ if (fs.lstatSync(p).uid !== uid)
3152
+ return true;
3153
+ if (!fs.statSync(p).isDirectory())
3154
+ return false;
3155
+ for (const e of fs.readdirSync(p)) {
3156
+ try {
3157
+ if (fs.lstatSync(path.join(p, e)).uid !== uid)
3158
+ return true;
3159
+ }
3160
+ catch {
3161
+ /* raced away — nothing to re-own */
3162
+ }
3163
+ }
3164
+ return false;
3165
+ }
3166
+ catch {
3167
+ return false; // unreadable or gone: not ours to repair
3168
+ }
3169
+ };
3170
+ for (const p of serverOwnedStatePaths(os.homedir())) {
3171
+ if (!fs.existsSync(p) || !foreign(p))
3172
+ continue;
3173
+ try {
3174
+ await runPrivileged("chown", ["-R", owner, p], { timeoutMs: TREE_OP_TIMEOUT_MS });
3175
+ console.log(`heal: ${p} was owned by another user; given back to the server (${owner})`);
3176
+ }
3177
+ catch (e) {
3178
+ console.error(`heal: could not re-own ${p} (best-effort): ${e?.message ?? e}`);
3179
+ }
3180
+ }
3181
+ }
3116
3182
  /** Step 1 — create the non-root commons user `main` (+ HOME). Idempotent. */
3117
3183
  async function migCreateCommonsUser() {
3118
3184
  if (osUserExistsSync(COMMONS_USER))
@@ -6237,7 +6303,9 @@ group) {
6237
6303
  instanceDefault: user ? getDefaultModel() : null,
6238
6304
  dropped: !!user,
6239
6305
  });
6240
- const fullArgs = [
6306
+ // ONE --append-system-prompt: Claude Code keeps only the last of several
6307
+ // (src/prompt-args.ts), which silently dropped the role and the pilot prompt.
6308
+ const fullArgs = mergeAppendedPrompts([
6241
6309
  ...args,
6242
6310
  ...permissionModeArgs(permissionMode),
6243
6311
  // A flag+value pair, before the profile's flags: nothing here can land
@@ -6247,7 +6315,7 @@ group) {
6247
6315
  ...(note ? ["--append-system-prompt", note] : []),
6248
6316
  ...(sp ? ["--append-system-prompt", sp] : []),
6249
6317
  ...(lr ? ["--append-system-prompt", lr] : []),
6250
- ];
6318
+ ]);
6251
6319
  // NAMES only: the values are in `env`, and never travel to a client. Built
6252
6320
  // through the shared `buildPreprompt`, so this spawn snapshot is comparable
6253
6321
  // byte-for-byte with the one the staleness check recomputes later.