shadok-ai 0.20.18 → 0.20.19

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.
@@ -883,8 +883,20 @@ export async function run(argv) {
883
883
  }
884
884
  }
885
885
 
886
- // CLI entry point — not triggered when imported by tests.
887
- if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
886
+ // Run only as a script (the test imports the pure helpers above). Compared
887
+ // through realpath: in a group HOME `~/.claude/skills/shadok-ai-agents` is a SYMLINK to
888
+ // the machine-wide copy, and Node resolves links in import.meta.url but not in
889
+ // argv[1]. A plain comparison then reads "imported", and the script exits 0
890
+ // having done NOTHING — a silent no-op the calling agent takes for success.
891
+ const real = (p) => {
892
+ try {
893
+ return fs.realpathSync(p);
894
+ } catch {
895
+ return p;
896
+ }
897
+ };
898
+ const invoked = !!process.argv[1] && real(process.argv[1]) === real(fileURLToPath(import.meta.url));
899
+ if (invoked) {
888
900
  run(process.argv.slice(2))
889
901
  .then((r) => {
890
902
  console.log(JSON.stringify(r));
@@ -227,3 +227,29 @@ test("screen returns the last screen received", async () => {
227
227
  }
228
228
  });
229
229
 
230
+
231
+ test("runs when invoked through a SYMLINKED skill directory (group HOME)", async () => {
232
+ // In a group HOME, ~/.claude/skills/shadok-ai-agents is a symlink to the
233
+ // machine-wide copy. path.resolve(argv[1]) does not follow links while
234
+ // import.meta.url does, so a naive entry guard exited 0 printing nothing.
235
+ const { execFile } = await import("node:child_process");
236
+ const { fileURLToPath } = await import("node:url");
237
+ const skillDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
238
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pilotctl-link-"));
239
+ const link = path.join(dir, "shadok-ai-agents");
240
+ fs.symlinkSync(skillDir, link);
241
+ const mock = await startMockServer({ sessions: [{ id: "old-1", mtime: 123 }] });
242
+ const res = await new Promise((resolve) => {
243
+ execFile(
244
+ process.execPath,
245
+ [path.join(link, "pilotctl.mjs"), "list"],
246
+ { env: { ...process.env, SHADOK_PORT: String(mock.port) } },
247
+ (e, out, err) => resolve({ code: e ? (e.code ?? 1) : 0, out, err }),
248
+ );
249
+ });
250
+ await mock.close();
251
+ fs.rmSync(dir, { recursive: true, force: true });
252
+ assert.equal(res.code, 0, res.err);
253
+ assert.notEqual(res.out.trim(), "", "no output through the link");
254
+ assert.deepEqual(JSON.parse(res.out).resumable, [{ id: "old-1", mtime: 123 }]);
255
+ });
@@ -8,7 +8,8 @@
8
8
  // native npm modules, not for skills — trimming it would have broken this
9
9
  // silently. See context/scheduler-skill/test/ for the tests that now guard it.
10
10
 
11
- import { pathToFileURL } from "node:url";
11
+ import { realpathSync } from "node:fs";
12
+ import { fileURLToPath } from "node:url";
12
13
 
13
14
  const TIMEOUT_MS = 15_000;
14
15
 
@@ -358,8 +359,19 @@ export async function main(argv) {
358
359
  }
359
360
  }
360
361
 
361
- // Importable by the tests, executable by the agents: only run when invoked
362
- // directly, or importing this file would exit on a missing SHADOK_PORT.
363
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
362
+ // Run only as a script (the test imports the pure helpers above). Compared
363
+ // through realpath: in a group HOME `~/.claude/skills/shadok-scheduler` is a SYMLINK to
364
+ // the machine-wide copy, and Node resolves links in import.meta.url but not in
365
+ // argv[1]. A plain comparison then reads "imported", and the script exits 0
366
+ // having done NOTHING — a silent no-op the calling agent takes for success.
367
+ const real = (p) => {
368
+ try {
369
+ return realpathSync(p);
370
+ } catch {
371
+ return p;
372
+ }
373
+ };
374
+ const invoked = !!process.argv[1] && real(process.argv[1]) === real(fileURLToPath(import.meta.url));
375
+ if (invoked) {
364
376
  await main(process.argv.slice(2));
365
377
  }
@@ -283,3 +283,30 @@ test("update end to end: resolves the prefix, posts the full cron with its id",
283
283
  await cockpit.close();
284
284
  }
285
285
  });
286
+
287
+ test("runs when invoked through a SYMLINKED skill directory (group HOME)", async () => {
288
+ // In a group HOME, ~/.claude/skills/shadok-scheduler is a symlink to the
289
+ // machine-wide copy. Node resolves links in import.meta.url but not in
290
+ // argv[1]: a naive entry guard saw "imported, not run" and exited 0 having
291
+ // done NOTHING — an agent announced a cron that was never created.
292
+ const { mkdtempSync, symlinkSync, rmSync } = await import("node:fs");
293
+ const { tmpdir } = await import("node:os");
294
+ const dir = mkdtempSync(path.join(tmpdir(), "sched-link-"));
295
+ const link = path.join(dir, "shadok-scheduler");
296
+ symlinkSync(path.dirname(path.dirname(SCRIPT)), link);
297
+ const srv = await fakeCockpit({
298
+ "GET /crons": { body: [{ id: "aaaaaaaa1111", sessionId: "sess-1", enabled: true, schedule: { kind: "interval", everyMin: 5 }, prompt: "mine" }] },
299
+ "GET /timezone": { body: { timezone: "UTC", system: "UTC" } },
300
+ });
301
+ const res = await new Promise((resolve) => {
302
+ execFile(
303
+ process.execPath,
304
+ [path.join(link, "scripts", "schedule.mjs"), "list"],
305
+ { env: { ...process.env, SHADOK_PORT: "", SHADOK_SESSION_ID: "", SHADOK_AUTH: "", ...AGENT(srv.port) } },
306
+ (e, out, err) => resolve({ code: e ? (e.code ?? 1) : 0, out, err }),
307
+ );
308
+ });
309
+ await srv.close();
310
+ rmSync(dir, { recursive: true, force: true });
311
+ assert.match(res.out, /\[aaaaaaaa\] every 5m/, `no output through the link (code ${res.code}): ${res.err}`);
312
+ });
@@ -13,7 +13,8 @@
13
13
  // present wherever a skill runs — the image's python3 exists to build native
14
14
  // npm modules, and dropping it would have broken this in silence.
15
15
 
16
- import { pathToFileURL } from "node:url";
16
+ import { realpathSync } from "node:fs";
17
+ import { fileURLToPath } from "node:url";
17
18
 
18
19
  const TIMEOUT_MS = 15_000;
19
20
 
@@ -181,8 +182,19 @@ export async function main(argv) {
181
182
  console.log("process: node ~/.claude/skills/shadok-reload/reload.mjs");
182
183
  }
183
184
 
184
- // Importable by the tests, executable by the agents: only run when invoked
185
- // directly, or importing this file would exit on a missing SHADOK_PORT.
186
- if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
185
+ // Run only as a script (the test imports the pure helpers above). Compared
186
+ // through realpath: in a group HOME `~/.claude/skills/shadok-secrets` is a SYMLINK to
187
+ // the machine-wide copy, and Node resolves links in import.meta.url but not in
188
+ // argv[1]. A plain comparison then reads "imported", and the script exits 0
189
+ // having done NOTHING — a silent no-op the calling agent takes for success.
190
+ const real = (p) => {
191
+ try {
192
+ return realpathSync(p);
193
+ } catch {
194
+ return p;
195
+ }
196
+ };
197
+ const invoked = !!process.argv[1] && real(process.argv[1]) === real(fileURLToPath(import.meta.url));
198
+ if (invoked) {
187
199
  await main(process.argv.slice(2));
188
200
  }
@@ -124,3 +124,29 @@ test("refuses to run outside a shadok-ai agent", async () => {
124
124
  assert.notEqual(res.code, 0);
125
125
  assert.match(res.err, /SHADOK_PORT/);
126
126
  });
127
+
128
+ test("runs when invoked through a SYMLINKED skill directory (group HOME)", async () => {
129
+ // In a group HOME, ~/.claude/skills/shadok-secrets is a symlink to the
130
+ // machine-wide copy. Node resolves links in import.meta.url but not in
131
+ // argv[1]: a naive entry guard exited 0 having done NOTHING — a silent
132
+ // no-op on a write tool, which the agent cannot tell from success.
133
+ const { mkdtempSync, symlinkSync, rmSync } = await import("node:fs");
134
+ const { tmpdir } = await import("node:os");
135
+ const dir = mkdtempSync(path.join(tmpdir(), "secret-link-"));
136
+ const link = path.join(dir, "shadok-secrets");
137
+ symlinkSync(path.dirname(path.dirname(SCRIPT)), link);
138
+ const srv = await fakeCockpit(200, { names: ["A", "B"] });
139
+ const res = await new Promise((resolve) => {
140
+ const child = execFile(
141
+ process.execPath,
142
+ [path.join(link, "scripts", "secret.mjs"), "list"],
143
+ { env: { ...process.env, SHADOK_PORT: String(srv.port), SHADOK_AUTH: "sk_auth=tok" } },
144
+ (e, out, err) => resolve({ code: e ? (e.code ?? 1) : 0, out, err }),
145
+ );
146
+ child.stdin.end("");
147
+ });
148
+ await srv.close();
149
+ rmSync(dir, { recursive: true, force: true });
150
+ assert.equal(res.code, 0, res.err);
151
+ assert.equal(res.out.trim(), "A\nB", "no output through the link");
152
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.20.18",
3
+ "version": "0.20.19",
4
4
  "main": "dist/session.js",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test --test-timeout=120000 test/*.ts context/*/test/*.test.mjs",