♻️ Quality: one stream-demo.js for the two Node stream.js examples (2 duplicate findings → 0)
The stream.js of nodejs/ and nodejs-sdk/ were the same example. The details — the read-only permission callback and the printing of each event — are now in demo.acp.sdk/common/stream-demo.js; each stream.js keeps what it teaches: Agent.start, agent.stream, close, the try/catch. READMEs EN+FR of demo.acp.sdk list common/. Checked: both clients' stream.js, old and new, against mm with a fake model, an allowed and a refused command: identical for nodejs/; for nodejs-sdk the 🛠️/🔐 order is the race its README documents (15 runs each: old 11/4, new 10/5); node --test 16 pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3263ee3 parent: a318e93 modified
demo.acp.sdk/README.en.md +1 -0 | @@ -11,6 +11,7 @@ Programs in other languages use mini-me as a library by driving `mm -acp`: the s | ||
| 11 | 11 | | [`go/`](go/README.en.md) | Go (ticket 168) | done: package `minime`, four examples, tests | |
| 12 | 12 | | [`kotlin/`](kotlin/README.en.md) | Kotlin (ticket 187) | done: `minime.Agent` on the official ACP Kotlin SDK, four examples, tests | |
| 13 | 13 | | [`client-tools-nodejs/`](client-tools-nodejs/README.en.md) | Node.js, no dependency (ticket 202) | demo: a client that offers mm one of its own tools (`host_info`), both discovery modes | |
| 14 | +| `common/` | Node.js | `stream-demo.js`: the permission callback and the event printing of the `stream.js` example of `nodejs/` and `nodejs-sdk/` (copy it along with either client) | | |
| 14 | 15 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | not started | |
| 15 | 16 | |
| 16 | 17 | What every client does: |
| @@ -11,6 +11,7 @@ Programs in other languages use mini-me as a library by driving `mm -acp`: the s | |||
| 11 | | [`go/`](go/README.en.md) | Go (ticket 168) | done: package `minime`, four examples, tests | | 11 | | [`go/`](go/README.en.md) | Go (ticket 168) | done: package `minime`, four examples, tests | |
| 12 | | [`kotlin/`](kotlin/README.en.md) | Kotlin (ticket 187) | done: `minime.Agent` on the official ACP Kotlin SDK, four examples, tests | | 12 | | [`kotlin/`](kotlin/README.en.md) | Kotlin (ticket 187) | done: `minime.Agent` on the official ACP Kotlin SDK, four examples, tests | |
| 13 | | [`client-tools-nodejs/`](client-tools-nodejs/README.en.md) | Node.js, no dependency (ticket 202) | demo: a client that offers mm one of its own tools (`host_info`), both discovery modes | | 13 | | [`client-tools-nodejs/`](client-tools-nodejs/README.en.md) | Node.js, no dependency (ticket 202) | demo: a client that offers mm one of its own tools (`host_info`), both discovery modes | |
| 14 | +| `common/` | Node.js | `stream-demo.js`: the permission callback and the event printing of the `stream.js` example of `nodejs/` and `nodejs-sdk/` (copy it along with either client) | | ||
| 14 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | not started | | 15 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | not started | |
| 15 | 16 | ||
| 16 | What every client does: | 17 | What every client does: |
modified
demo.acp.sdk/README.fr.md +1 -0 | @@ -11,6 +11,7 @@ Des programmes écrits dans d'autres langages utilisent mini-me comme bibliothè | ||
| 11 | 11 | | [`go/`](go/README.fr.md) | Go (ticket 168) | fait : paquet `minime`, quatre exemples, des tests | |
| 12 | 12 | | [`kotlin/`](kotlin/README.fr.md) | Kotlin (ticket 187) | fait : `minime.Agent` sur le SDK ACP officiel pour Kotlin, quatre exemples, des tests | |
| 13 | 13 | | [`client-tools-nodejs/`](client-tools-nodejs/README.fr.md) | Node.js, sans dépendance (ticket 202) | démo : un client qui propose à mm un de ses propres outils (`host_info`), les deux modes de découverte | |
| 14 | +| `common/` | Node.js | `stream-demo.js` : le callback de permission et l'affichage des événements de l'exemple `stream.js` de `nodejs/` et `nodejs-sdk/` (à copier avec l'un ou l'autre client) | | |
| 14 | 15 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | pas commencés | |
| 15 | 16 | |
| 16 | 17 | Ce que fait chaque client : |
| @@ -11,6 +11,7 @@ Des programmes écrits dans d'autres langages utilisent mini-me comme bibliothè | |||
| 11 | | [`go/`](go/README.fr.md) | Go (ticket 168) | fait : paquet `minime`, quatre exemples, des tests | | 11 | | [`go/`](go/README.fr.md) | Go (ticket 168) | fait : paquet `minime`, quatre exemples, des tests | |
| 12 | | [`kotlin/`](kotlin/README.fr.md) | Kotlin (ticket 187) | fait : `minime.Agent` sur le SDK ACP officiel pour Kotlin, quatre exemples, des tests | | 12 | | [`kotlin/`](kotlin/README.fr.md) | Kotlin (ticket 187) | fait : `minime.Agent` sur le SDK ACP officiel pour Kotlin, quatre exemples, des tests | |
| 13 | | [`client-tools-nodejs/`](client-tools-nodejs/README.fr.md) | Node.js, sans dépendance (ticket 202) | démo : un client qui propose à mm un de ses propres outils (`host_info`), les deux modes de découverte | | 13 | | [`client-tools-nodejs/`](client-tools-nodejs/README.fr.md) | Node.js, sans dépendance (ticket 202) | démo : un client qui propose à mm un de ses propres outils (`host_info`), les deux modes de découverte | |
| 14 | +| `common/` | Node.js | `stream-demo.js` : le callback de permission et l'affichage des événements de l'exemple `stream.js` de `nodejs/` et `nodejs-sdk/` (à copier avec l'un ou l'autre client) | | ||
| 14 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | pas commencés | | 15 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | pas commencés | |
| 15 | 16 | ||
| 16 | Ce que fait chaque client : | 17 | Ce que fait chaque client : |
added
demo.acp.sdk/common/stream-demo.js +43 -0 | new file mode 100644 | ||
| @@ -0,0 +1,43 @@ | ||
| 1 | +// The details of the two stream.js examples (nodejs/ and nodejs-sdk/), which | |
| 2 | +// use the two clients the same way: the permission callback, and how each | |
| 3 | +// event is printed. | |
| 4 | + | |
| 5 | +const readOnly = /^(ls|find|cat|wc|head|tail|pwd|grep)\b/; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * The permission callback of the examples: allows read-only commands only | |
| 9 | + * (ls, find, wc…) and says what it decided. A prefix check is a demo, not a | |
| 10 | + * sandbox: `find . -delete` or `ls; rm x` would pass it. | |
| 11 | + * | |
| 12 | + * @example | |
| 13 | + * const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | |
| 14 | + */ | |
| 15 | +export function allowReadOnly(call) { | |
| 16 | + const ok = readOnly.test(call.input?.command ?? ""); | |
| 17 | + console.log(`\n🔐 ${call.title} → ${ok ? "allowed (read-only)" : "refused"}`); | |
| 18 | + return ok; | |
| 19 | +} | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * Prints one event of a turn: the answer as it comes, the tool calls and | |
| 23 | + * their results, how the turn ended. | |
| 24 | + * | |
| 25 | + * @example | |
| 26 | + * for await (const ev of agent.stream("Explain main.go")) printEvent(ev); | |
| 27 | + */ | |
| 28 | +export function printEvent(ev) { | |
| 29 | + switch (ev.kind) { | |
| 30 | + case "text": | |
| 31 | + process.stdout.write(ev.text); | |
| 32 | + break; | |
| 33 | + case "tool_call": | |
| 34 | + console.log(`🛠️ ${ev.title}`); | |
| 35 | + break; | |
| 36 | + case "tool_result": | |
| 37 | + console.log(` ${ev.status}: ${String(ev.output).trim()}`); | |
| 38 | + break; | |
| 39 | + case "done": | |
| 40 | + console.log(`\n[${ev.stopReason}]`); | |
| 41 | + break; | |
| 42 | + } | |
| 43 | +} | |
| new file mode 100644 | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | +// The details of the two stream.js examples (nodejs/ and nodejs-sdk/), which | ||
| 2 | +// use the two clients the same way: the permission callback, and how each | ||
| 3 | +// event is printed. | ||
| 4 | + | ||
| 5 | +const readOnly = /^(ls|find|cat|wc|head|tail|pwd|grep)\b/; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * The permission callback of the examples: allows read-only commands only | ||
| 9 | + * (ls, find, wc…) and says what it decided. A prefix check is a demo, not a | ||
| 10 | + * sandbox: `find . -delete` or `ls; rm x` would pass it. | ||
| 11 | + * | ||
| 12 | + * @example | ||
| 13 | + * const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | ||
| 14 | + */ | ||
| 15 | +export function allowReadOnly(call) { | ||
| 16 | + const ok = readOnly.test(call.input?.command ?? ""); | ||
| 17 | + console.log(`\n🔐 ${call.title} → ${ok ? "allowed (read-only)" : "refused"}`); | ||
| 18 | + return ok; | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * Prints one event of a turn: the answer as it comes, the tool calls and | ||
| 23 | + * their results, how the turn ended. | ||
| 24 | + * | ||
| 25 | + * @example | ||
| 26 | + * for await (const ev of agent.stream("Explain main.go")) printEvent(ev); | ||
| 27 | + */ | ||
| 28 | +export function printEvent(ev) { | ||
| 29 | + switch (ev.kind) { | ||
| 30 | + case "text": | ||
| 31 | + process.stdout.write(ev.text); | ||
| 32 | + break; | ||
| 33 | + case "tool_call": | ||
| 34 | + console.log(`🛠️ ${ev.title}`); | ||
| 35 | + break; | ||
| 36 | + case "tool_result": | ||
| 37 | + console.log(` ${ev.status}: ${String(ev.output).trim()}`); | ||
| 38 | + break; | ||
| 39 | + case "done": | ||
| 40 | + console.log(`\n[${ev.stopReason}]`); | ||
| 41 | + break; | ||
| 42 | + } | ||
| 43 | +} | ||
modified
demo.acp.sdk/nodejs-sdk/stream.js +5 -27 | @@ -1,37 +1,15 @@ | ||
| 1 | 1 | // Streamed: the answer as it comes, the tool calls as they happen. |
| 2 | 2 | // The permission callback allows read-only commands only (ls, find, wc…) |
| 3 | -// and says what it decided. A prefix check is a demo, not a sandbox: | |
| 4 | -// `find . -delete` or `ls; rm x` would pass it. | |
| 3 | +// and says what it decided; it and the printing of each event are in | |
| 4 | +// ../common/stream-demo.js, shared with the other client's stream.js. | |
| 5 | 5 | // node stream.js (from demo.acp.sdk/nodejs-sdk/, after npm install) |
| 6 | 6 | import { Agent } from "./lib/minime.js"; |
| 7 | +import { allowReadOnly, printEvent } from "../common/stream-demo.js"; | |
| 7 | 8 | |
| 8 | -const readOnly = /^(ls|find|cat|wc|head|tail|pwd|grep)\b/; | |
| 9 | -const agent = await Agent.start({ | |
| 10 | - config: "agent.yaml", | |
| 11 | - onPermission: (call) => { | |
| 12 | - const ok = readOnly.test(call.input?.command ?? ""); | |
| 13 | - console.log(`\n🔐 ${call.title} → ${ok ? "allowed (read-only)" : "refused"}`); | |
| 14 | - return ok; | |
| 15 | - }, | |
| 16 | -}); | |
| 9 | +const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | |
| 17 | 10 | |
| 18 | 11 | try { |
| 19 | - for await (const ev of agent.stream("How many .js files are in the test folder? Use a command.")) { | |
| 20 | - switch (ev.kind) { | |
| 21 | - case "text": | |
| 22 | - process.stdout.write(ev.text); | |
| 23 | - break; | |
| 24 | - case "tool_call": | |
| 25 | - console.log(`🛠️ ${ev.title}`); | |
| 26 | - break; | |
| 27 | - case "tool_result": | |
| 28 | - console.log(` ${ev.status}: ${String(ev.output).trim()}`); | |
| 29 | - break; | |
| 30 | - case "done": | |
| 31 | - console.log(`\n[${ev.stopReason}]`); | |
| 32 | - break; | |
| 33 | - } | |
| 34 | - } | |
| 12 | + for await (const ev of agent.stream("How many .js files are in the test folder? Use a command.")) printEvent(ev); | |
| 35 | 13 | } catch (err) { |
| 36 | 14 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 37 | 15 | // refused command six times): the promise is rejected with mm's words. |
| @@ -1,37 +1,15 @@ | |||
| 1 | // Streamed: the answer as it comes, the tool calls as they happen. | 1 | // Streamed: the answer as it comes, the tool calls as they happen. |
| 2 | // The permission callback allows read-only commands only (ls, find, wc…) | 2 | // The permission callback allows read-only commands only (ls, find, wc…) |
| 3 | -// and says what it decided. A prefix check is a demo, not a sandbox: | 3 | +// and says what it decided; it and the printing of each event are in |
| 4 | -// `find . -delete` or `ls; rm x` would pass it. | 4 | +// ../common/stream-demo.js, shared with the other client's stream.js. |
| 5 | // node stream.js (from demo.acp.sdk/nodejs-sdk/, after npm install) | 5 | // node stream.js (from demo.acp.sdk/nodejs-sdk/, after npm install) |
| 6 | import { Agent } from "./lib/minime.js"; | 6 | import { Agent } from "./lib/minime.js"; |
| 7 | +import { allowReadOnly, printEvent } from "../common/stream-demo.js"; | ||
| 7 | 8 | ||
| 8 | -const readOnly = /^(ls|find|cat|wc|head|tail|pwd|grep)\b/; | 9 | +const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); |
| 9 | -const agent = await Agent.start({ | ||
| 10 | - config: "agent.yaml", | ||
| 11 | - onPermission: (call) => { | ||
| 12 | - const ok = readOnly.test(call.input?.command ?? ""); | ||
| 13 | - console.log(`\n🔐 ${call.title} → ${ok ? "allowed (read-only)" : "refused"}`); | ||
| 14 | - return ok; | ||
| 15 | - }, | ||
| 16 | -}); | ||
| 17 | 10 | ||
| 18 | try { | 11 | try { |
| 19 | - for await (const ev of agent.stream("How many .js files are in the test folder? Use a command.")) { | 12 | + for await (const ev of agent.stream("How many .js files are in the test folder? Use a command.")) printEvent(ev); |
| 20 | - switch (ev.kind) { | ||
| 21 | - case "text": | ||
| 22 | - process.stdout.write(ev.text); | ||
| 23 | - break; | ||
| 24 | - case "tool_call": | ||
| 25 | - console.log(`🛠️ ${ev.title}`); | ||
| 26 | - break; | ||
| 27 | - case "tool_result": | ||
| 28 | - console.log(` ${ev.status}: ${String(ev.output).trim()}`); | ||
| 29 | - break; | ||
| 30 | - case "done": | ||
| 31 | - console.log(`\n[${ev.stopReason}]`); | ||
| 32 | - break; | ||
| 33 | - } | ||
| 34 | - } | ||
| 35 | } catch (err) { | 13 | } catch (err) { |
| 36 | // mm ended the turn with an error (e.g. its loop detector after the same | 14 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 37 | // refused command six times): the promise is rejected with mm's words. | 15 | // refused command six times): the promise is rejected with mm's words. |
modified
demo.acp.sdk/nodejs/stream.js +5 -27 | @@ -1,36 +1,14 @@ | ||
| 1 | 1 | // Streamed: the answer as it comes, the tool calls as they happen. |
| 2 | 2 | // The permission callback allows read-only commands only (ls, find, wc…) |
| 3 | -// and says what it decided. A prefix check is a demo, not a sandbox: | |
| 4 | -// `find . -delete` or `ls; rm x` would pass it. | |
| 3 | +// and says what it decided; it and the printing of each event are in | |
| 4 | +// ../common/stream-demo.js, shared with the other client's stream.js. | |
| 5 | 5 | import { Agent } from "./lib/minime.js"; |
| 6 | +import { allowReadOnly, printEvent } from "../common/stream-demo.js"; | |
| 6 | 7 | |
| 7 | -const readOnly = /^(ls|find|cat|wc|head|tail|pwd|grep)\b/; | |
| 8 | -const agent = await Agent.start({ | |
| 9 | - config: "agent.yaml", | |
| 10 | - onPermission: (call) => { | |
| 11 | - const ok = readOnly.test(call.input?.command ?? ""); | |
| 12 | - console.log(`\n🔐 ${call.title} → ${ok ? "allowed (read-only)" : "refused"}`); | |
| 13 | - return ok; | |
| 14 | - }, | |
| 15 | -}); | |
| 8 | +const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | |
| 16 | 9 | |
| 17 | 10 | try { |
| 18 | - for await (const ev of agent.stream("How many .js files are in the examples folder? Use a command.")) { | |
| 19 | - switch (ev.kind) { | |
| 20 | - case "text": | |
| 21 | - process.stdout.write(ev.text); | |
| 22 | - break; | |
| 23 | - case "tool_call": | |
| 24 | - console.log(`🛠️ ${ev.title}`); | |
| 25 | - break; | |
| 26 | - case "tool_result": | |
| 27 | - console.log(` ${ev.status}: ${String(ev.output).trim()}`); | |
| 28 | - break; | |
| 29 | - case "done": | |
| 30 | - console.log(`\n[${ev.stopReason}]`); | |
| 31 | - break; | |
| 32 | - } | |
| 33 | - } | |
| 11 | + for await (const ev of agent.stream("How many .js files are in the examples folder? Use a command.")) printEvent(ev); | |
| 34 | 12 | } catch (err) { |
| 35 | 13 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 36 | 14 | // refused command six times): the promise is rejected with mm's words. |
| @@ -1,36 +1,14 @@ | |||
| 1 | // Streamed: the answer as it comes, the tool calls as they happen. | 1 | // Streamed: the answer as it comes, the tool calls as they happen. |
| 2 | // The permission callback allows read-only commands only (ls, find, wc…) | 2 | // The permission callback allows read-only commands only (ls, find, wc…) |
| 3 | -// and says what it decided. A prefix check is a demo, not a sandbox: | 3 | +// and says what it decided; it and the printing of each event are in |
| 4 | -// `find . -delete` or `ls; rm x` would pass it. | 4 | +// ../common/stream-demo.js, shared with the other client's stream.js. |
| 5 | import { Agent } from "./lib/minime.js"; | 5 | import { Agent } from "./lib/minime.js"; |
| 6 | +import { allowReadOnly, printEvent } from "../common/stream-demo.js"; | ||
| 6 | 7 | ||
| 7 | -const readOnly = /^(ls|find|cat|wc|head|tail|pwd|grep)\b/; | 8 | +const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); |
| 8 | -const agent = await Agent.start({ | ||
| 9 | - config: "agent.yaml", | ||
| 10 | - onPermission: (call) => { | ||
| 11 | - const ok = readOnly.test(call.input?.command ?? ""); | ||
| 12 | - console.log(`\n🔐 ${call.title} → ${ok ? "allowed (read-only)" : "refused"}`); | ||
| 13 | - return ok; | ||
| 14 | - }, | ||
| 15 | -}); | ||
| 16 | 9 | ||
| 17 | try { | 10 | try { |
| 18 | - for await (const ev of agent.stream("How many .js files are in the examples folder? Use a command.")) { | 11 | + for await (const ev of agent.stream("How many .js files are in the examples folder? Use a command.")) printEvent(ev); |
| 19 | - switch (ev.kind) { | ||
| 20 | - case "text": | ||
| 21 | - process.stdout.write(ev.text); | ||
| 22 | - break; | ||
| 23 | - case "tool_call": | ||
| 24 | - console.log(`🛠️ ${ev.title}`); | ||
| 25 | - break; | ||
| 26 | - case "tool_result": | ||
| 27 | - console.log(` ${ev.status}: ${String(ev.output).trim()}`); | ||
| 28 | - break; | ||
| 29 | - case "done": | ||
| 30 | - console.log(`\n[${ev.stopReason}]`); | ||
| 31 | - break; | ||
| 32 | - } | ||
| 33 | - } | ||
| 34 | } catch (err) { | 12 | } catch (err) { |
| 35 | // mm ended the turn with an error (e.g. its loop detector after the same | 13 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 36 | // refused command six times): the promise is rejected with mm's words. | 14 | // refused command six times): the promise is rejected with mm's words. |