Revert "♻️ Quality: one stream-demo.js for the two Node stream.js examples (2 duplicate findings → 0)"
This reverts commit 3263ee3367181ea1452896a6b01bb6603f8708f2.
a467179 parent: a629224 modified
demo.acp.sdk/README.en.md +0 -1 | @@ -11,7 +11,6 @@ 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) | | |
| 15 | 14 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | not started | |
| 16 | 15 | |
| 17 | 16 | What every client does: |
| @@ -11,7 +11,6 @@ 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) | | ||
| 15 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | not started | | 14 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | not started | |
| 16 | 15 | ||
| 17 | What every client does: | 16 | What every client does: |
modified
demo.acp.sdk/README.fr.md +0 -1 | @@ -11,7 +11,6 @@ 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) | | |
| 15 | 14 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | pas commencés | |
| 16 | 15 | |
| 17 | 16 | Ce que fait chaque client : |
| @@ -11,7 +11,6 @@ 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) | | ||
| 15 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | pas commencés | | 14 | | `python/`, `rust/`, `swift/`, `nushell/` | tickets 169–172 | pas commencés | |
| 16 | 15 | ||
| 17 | Ce que fait chaque client : | 16 | Ce que fait chaque client : |
deleted
demo.acp.sdk/common/stream-demo.js +0 -43 | deleted file mode 100644 | ||
| @@ -1,43 +0,0 @@ | ||
| 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 | -} | |
| deleted file mode 100644 | |||
| @@ -1,43 +0,0 @@ | |||
| 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 +27 -5 | @@ -1,15 +1,37 @@ | ||
| 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; it and the printing of each event are in | |
| 4 | -// ../common/stream-demo.js, shared with the other client's stream.js. | |
| 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. | |
| 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"; | |
| 8 | 7 | |
| 9 | -const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | |
| 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 | +}); | |
| 10 | 17 | |
| 11 | 18 | try { |
| 12 | - for await (const ev of agent.stream("How many .js files are in the test folder? Use a command.")) printEvent(ev); | |
| 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 | + } | |
| 13 | 35 | } catch (err) { |
| 14 | 36 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 15 | 37 | // refused command six times): the promise is rejected with mm's words. |
| @@ -1,15 +1,37 @@ | |||
| 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; it and the printing of each event are in | 3 | +// and says what it decided. A prefix check is a demo, not a sandbox: |
| 4 | -// ../common/stream-demo.js, shared with the other client's stream.js. | 4 | +// `find . -delete` or `ls; rm x` would pass it. |
| 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"; | ||
| 8 | 7 | ||
| 9 | -const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | 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 | +}); | ||
| 10 | 17 | ||
| 11 | try { | 18 | try { |
| 12 | - for await (const ev of agent.stream("How many .js files are in the test folder? Use a command.")) printEvent(ev); | 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 | + } | ||
| 13 | } catch (err) { | 35 | } catch (err) { |
| 14 | // mm ended the turn with an error (e.g. its loop detector after the same | 36 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 15 | // refused command six times): the promise is rejected with mm's words. | 37 | // refused command six times): the promise is rejected with mm's words. |
modified
demo.acp.sdk/nodejs/stream.js +27 -5 | @@ -1,14 +1,36 @@ | ||
| 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; it and the printing of each event are in | |
| 4 | -// ../common/stream-demo.js, shared with the other client's stream.js. | |
| 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. | |
| 5 | 5 | import { Agent } from "./lib/minime.js"; |
| 6 | -import { allowReadOnly, printEvent } from "../common/stream-demo.js"; | |
| 7 | 6 | |
| 8 | -const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | |
| 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 | +}); | |
| 9 | 16 | |
| 10 | 17 | try { |
| 11 | - for await (const ev of agent.stream("How many .js files are in the examples folder? Use a command.")) printEvent(ev); | |
| 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 | + } | |
| 12 | 34 | } catch (err) { |
| 13 | 35 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 14 | 36 | // refused command six times): the promise is rejected with mm's words. |
| @@ -1,14 +1,36 @@ | |||
| 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; it and the printing of each event are in | 3 | +// and says what it decided. A prefix check is a demo, not a sandbox: |
| 4 | -// ../common/stream-demo.js, shared with the other client's stream.js. | 4 | +// `find . -delete` or `ls; rm x` would pass it. |
| 5 | import { Agent } from "./lib/minime.js"; | 5 | import { Agent } from "./lib/minime.js"; |
| 6 | -import { allowReadOnly, printEvent } from "../common/stream-demo.js"; | ||
| 7 | 6 | ||
| 8 | -const agent = await Agent.start({ config: "agent.yaml", onPermission: allowReadOnly }); | 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 | +}); | ||
| 9 | 16 | ||
| 10 | try { | 17 | try { |
| 11 | - for await (const ev of agent.stream("How many .js files are in the examples folder? Use a command.")) printEvent(ev); | 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 | + } | ||
| 12 | } catch (err) { | 34 | } catch (err) { |
| 13 | // mm ended the turn with an error (e.g. its loop detector after the same | 35 | // mm ended the turn with an error (e.g. its loop detector after the same |
| 14 | // refused command six times): the promise is rejected with mm's words. | 36 | // refused command six times): the promise is rejected with mm's words. |