shadok-ai 0.20.17 → 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.
- package/README.md +18 -3
- package/context/agents-skill/pilotctl.mjs +14 -2
- package/context/agents-skill/test/mgmt.test.mjs +26 -0
- package/context/scheduler-skill/scripts/schedule.mjs +16 -4
- package/context/scheduler-skill/test/schedule.test.mjs +27 -0
- package/context/secrets-skill/scripts/secret.mjs +16 -4
- package/context/secrets-skill/test/secret.test.mjs +26 -0
- package/dist/server.js +26 -3
- package/dist/server.js.map +1 -1
- package/dist/tg-guests.d.ts +1 -1
- package/dist/tg-guests.js +20 -0
- package/dist/tg-guests.js.map +1 -1
- package/dist/wa-baileys.d.ts +3 -3
- package/dist/wa-baileys.js +68 -7
- package/dist/wa-baileys.js.map +1 -1
- package/dist/wa-bridge.d.ts +24 -1
- package/dist/wa-bridge.js +391 -41
- package/dist/wa-bridge.js.map +1 -1
- package/dist/wa-fake.d.ts +9 -0
- package/dist/wa-fake.js +17 -0
- package/dist/wa-fake.js.map +1 -1
- package/dist/wa-format.d.ts +54 -0
- package/dist/wa-format.js +87 -1
- package/dist/wa-format.js.map +1 -1
- package/dist/wa-guests.d.ts +38 -0
- package/dist/wa-guests.js +24 -3
- package/dist/wa-guests.js.map +1 -1
- package/dist/wa-inbox.d.ts +10 -0
- package/dist/wa-inbox.js.map +1 -1
- package/dist/wa-transport.d.ts +13 -0
- package/dist/wa-transport.js.map +1 -1
- package/dist/wa-worker-host.js +8 -0
- package/dist/wa-worker-host.js.map +1 -1
- package/dist/wa-worker.js +5 -1
- package/dist/wa-worker.js.map +1 -1
- package/dist/whatsapp.d.ts +3 -1
- package/dist/whatsapp.js +6 -0
- package/dist/whatsapp.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -967,9 +967,24 @@ from the phone's *Linked devices* list too.
|
|
|
967
967
|
being started, or while the server was updating, is answered once it is back.
|
|
968
968
|
- **Closing a guest's agent in the cockpit** ends that conversation: their next
|
|
969
969
|
message starts a new agent. A link that drops ends nothing.
|
|
970
|
-
- **
|
|
971
|
-
|
|
972
|
-
|
|
970
|
+
- **Pictures, documents, voice notes and videos** reach the person's agent the
|
|
971
|
+
way Telegram attachments do (a voice note is transcribed, and what was
|
|
972
|
+
understood is echoed back to the person; a video is looked at through a few
|
|
973
|
+
stills). Up to **50 MB** per file; a larger one gets a line asking for a
|
|
974
|
+
smaller file or a link.
|
|
975
|
+
- **Files the agent hands over** reach the person as a picture or a document.
|
|
976
|
+
Pictures go out without WhatsApp's blurred preview thumbnail, because the
|
|
977
|
+
WhatsApp library is installed without an image-processing library; the
|
|
978
|
+
picture itself is intact.
|
|
979
|
+
- **Questions** the agent asks arrive as a numbered list: the person answers
|
|
980
|
+
with the number (several numbers for a multiple choice), or with their own
|
|
981
|
+
words where the question offers that.
|
|
982
|
+
- **A first message that arrives unreadable** (WhatsApp sometimes delivers the
|
|
983
|
+
first messages from a new sender before they are readable by a linked
|
|
984
|
+
device) gets one line asking the person to send it again — at most once
|
|
985
|
+
every ten minutes, never with the door shut.
|
|
986
|
+
- **Closing a guest's agent** tells the person, once, that their next message
|
|
987
|
+
starts a new conversation.
|
|
973
988
|
- The panel always shows the link's true state, one at a time: *Not linked*,
|
|
974
989
|
*Linking*, *Connected*, *Reconnecting* (a link that stops answering leaves
|
|
975
990
|
*Connected* within about two minutes, even with no disconnect event),
|
|
@@ -883,8 +883,20 @@ export async function run(argv) {
|
|
|
883
883
|
}
|
|
884
884
|
}
|
|
885
885
|
|
|
886
|
-
//
|
|
887
|
-
|
|
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 {
|
|
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
|
-
//
|
|
362
|
-
//
|
|
363
|
-
|
|
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 {
|
|
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
|
-
//
|
|
185
|
-
//
|
|
186
|
-
|
|
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/dist/server.js
CHANGED
|
@@ -7341,6 +7341,13 @@ function startWhatsAppHandle() {
|
|
|
7341
7341
|
channels: { load: loadChannels, upsert: upsertChannel },
|
|
7342
7342
|
inbox: openInbox(path.join(waFake ? `${stateDir}-fake` : stateDir, "inbox.json")),
|
|
7343
7343
|
sessionAlive: (id) => tmuxHasSession("sk-" + id),
|
|
7344
|
+
// Step 3: a received medium waits beside the inbox, then lands in the
|
|
7345
|
+
// agent's GROUP media directory; a file an agent hands over is read with
|
|
7346
|
+
// the agent's rights — both exactly Telegram's rules (invariant 60).
|
|
7347
|
+
stagingDir: path.join(waFake ? `${stateDir}-fake` : stateDir, "media"),
|
|
7348
|
+
mediaDirFor: mediaDirForSession,
|
|
7349
|
+
readAgentFile: readSessionFile,
|
|
7350
|
+
multiTenant: DEPLOYMENT_MODE === "multi-tenant",
|
|
7344
7351
|
});
|
|
7345
7352
|
}
|
|
7346
7353
|
// The boot breaker (src/whatsapp.ts) reads a resume cut short by the process
|
|
@@ -7387,6 +7394,7 @@ app.get("/whatsapp", async (req, res) => {
|
|
|
7387
7394
|
// the bridge's answers. Fake mode only: a real instance never echoes a
|
|
7388
7395
|
// guest's conversation through this route.
|
|
7389
7396
|
out.fakeSent = waFake.sent.slice(-20);
|
|
7397
|
+
out.fakeFiles = waFake.files.slice(-20);
|
|
7390
7398
|
}
|
|
7391
7399
|
res.json(out);
|
|
7392
7400
|
});
|
|
@@ -7493,7 +7501,22 @@ app.post("/whatsapp/fake/:action", (req, res) => {
|
|
|
7493
7501
|
const chat = str("chat");
|
|
7494
7502
|
if (!chat)
|
|
7495
7503
|
return res.status(400).json({ error: "chat is required" });
|
|
7496
|
-
|
|
7504
|
+
// A medium for the side instance: `media` = image | document | audio |
|
|
7505
|
+
// video (`voice: true` for a voice note), its bytes as base64 `data`.
|
|
7506
|
+
const kind = str("media");
|
|
7507
|
+
const media = kind === "image" || kind === "document" || kind === "audio" || kind === "video"
|
|
7508
|
+
? { kind: kind, ...(str("mime") ? { mime: str("mime") } : {}), ...(str("fileName") ? { fileName: str("fileName") } : {}), ...(b.voice === true ? { voice: true } : {}) }
|
|
7509
|
+
: undefined;
|
|
7510
|
+
waFake.script.deliver({
|
|
7511
|
+
chat,
|
|
7512
|
+
chatAlt: str("chatAlt"),
|
|
7513
|
+
text: str("text"),
|
|
7514
|
+
pushName: str("pushName"),
|
|
7515
|
+
id: str("id"),
|
|
7516
|
+
...(media ? { media } : {}),
|
|
7517
|
+
...(str("data") ? { mediaData: Buffer.from(str("data"), "base64") } : {}),
|
|
7518
|
+
...(b.unreadable === true ? { unreadable: true } : {}),
|
|
7519
|
+
});
|
|
7497
7520
|
}
|
|
7498
7521
|
else if (action === "mapLid") {
|
|
7499
7522
|
const pn = str("pn"), lid = str("lid");
|
|
@@ -8215,7 +8238,7 @@ async function readSessionFile(sessionId, p) {
|
|
|
8215
8238
|
if (!st?.isFile)
|
|
8216
8239
|
throw new Error("not a readable file");
|
|
8217
8240
|
if (st.size > MAX)
|
|
8218
|
-
throw new Error("file too large
|
|
8241
|
+
throw new Error("file too large to send (over 50 MB)");
|
|
8219
8242
|
const { cmd, argv } = readAsUserArgv(user, p);
|
|
8220
8243
|
return new Promise((resolve, reject) => execFile(cmd, argv, { encoding: "buffer", maxBuffer: MAX + 1, timeout: 60_000 }, (err, out) => err ? reject(new Error("could not read the file as the agent's user")) : resolve(out)));
|
|
8221
8244
|
}
|
|
@@ -8224,7 +8247,7 @@ async function readSessionFile(sessionId, p) {
|
|
|
8224
8247
|
throw new Error("not a readable file");
|
|
8225
8248
|
try {
|
|
8226
8249
|
if (opened.stat.size > MAX)
|
|
8227
|
-
throw new Error("file too large
|
|
8250
|
+
throw new Error("file too large to send (over 50 MB)");
|
|
8228
8251
|
const buf = Buffer.alloc(opened.stat.size);
|
|
8229
8252
|
let off = 0;
|
|
8230
8253
|
while (off < buf.length) {
|