@llblab/pi-actors 0.51.0 → 0.52.1
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/AGENTS.md +6 -3
- package/BACKLOG.md +1 -1
- package/CHANGELOG.md +14 -0
- package/README.md +3 -3
- package/dist/index.js +3 -0
- package/dist/lib/async-runs.d.ts +2 -2
- package/dist/lib/async-runs.js +42 -19
- package/dist/lib/extension-runtime.d.ts +1 -0
- package/dist/lib/extension-runtime.js +6 -1
- package/dist/lib/limits.d.ts +9 -0
- package/dist/lib/limits.js +9 -0
- package/dist/lib/observability.d.ts +10 -11
- package/dist/lib/observability.js +79 -56
- package/dist/lib/pi.d.ts +31 -0
- package/dist/lib/pi.js +180 -0
- package/dist/lib/run-delivery.d.ts +115 -0
- package/dist/lib/run-delivery.js +623 -0
- package/dist/lib/run-ui-runtime.d.ts +3 -0
- package/dist/lib/run-ui-runtime.js +341 -13
- package/dist/lib/runs-trace.d.ts +1 -1
- package/dist/lib/runs-trace.js +5 -3
- package/dist/lib/session-evidence.d.ts +16 -0
- package/dist/lib/session-evidence.js +143 -0
- package/dist/lib/temp.js +1 -1
- package/dist/lib/tools-inspect.js +3 -1
- package/dist/skills/actors/SKILL.md +17 -7
- package/dist/skills/actors/references/runs.md +1 -1
- package/dist/skills/music-player/SKILL.md +3 -3
- package/dist/skills/music-player/genapps/music-player.mjs +6 -4
- package/dist/skills/music-player/scripts/playback.mjs +85 -18
- package/dist/skills/swarm/SKILL.md +2 -6
- package/dist/skills/swarm/references/development-swarm.md +2 -31
- package/docs/README.md +1 -0
- package/docs/async-runs.md +4 -3
- package/docs/coordinator-delivery.md +207 -0
- package/docs/recipe-library.md +1 -1
- package/index.ts +3 -0
- package/lib/async-runs.ts +42 -21
- package/lib/extension-runtime.ts +6 -1
- package/lib/limits.ts +9 -0
- package/lib/observability.ts +96 -78
- package/lib/pi.ts +210 -0
- package/lib/run-delivery.ts +800 -0
- package/lib/run-ui-runtime.ts +370 -18
- package/lib/runs-trace.ts +6 -4
- package/lib/session-evidence.ts +153 -0
- package/lib/temp.ts +1 -1
- package/lib/tools-inspect.ts +4 -1
- package/package.json +1 -1
- package/skills/actors/SKILL.md +17 -7
- package/skills/actors/references/runs.md +1 -1
- package/skills/music-player/SKILL.md +3 -3
- package/skills/music-player/genapps/music-player.mjs +6 -4
- package/skills/music-player/scripts/playback.mjs +85 -18
- package/skills/swarm/SKILL.md +2 -6
- package/skills/swarm/references/development-swarm.md +2 -31
- package/dist/skills/music-player/scripts/playback-client.mjs +0 -143
- package/skills/music-player/scripts/playback-client.mjs +0 -143
package/package.json
CHANGED
package/skills/actors/SKILL.md
CHANGED
|
@@ -76,16 +76,26 @@ Then:
|
|
|
76
76
|
|
|
77
77
|
Use direct delegation for the same maintained capability under a persistent name or narrower defaults. Use named imports only when one Recipe graph contains reusable child nodes. See [persistent tools](./references/persistent-tools.md) and [Recipes](./references/recipes.md).
|
|
78
78
|
|
|
79
|
-
##
|
|
79
|
+
## Capability map
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
Recipes remain with the Skill that owns their behavior. Load that Skill for selection and caller inputs; this map is routing, not a copied Recipe contract.
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
| Owner | Recipe families |
|
|
84
|
+
| --- | --- |
|
|
85
|
+
| `actors` | `command-validate`, `recipe-validate`, `jsonl-tail`, `run-summary`, `run-state-files`, `run-ops-snapshot`, `resource-locker`, `resource-locker-snapshot` |
|
|
86
|
+
| `swarm` | Lens and quorum reviews, research synthesis, architecture, development tasking, readiness, and supporting `subagent-*` components |
|
|
87
|
+
| `artifacts` | Report, write, manifest, bundle, and supporting file-write |
|
|
88
|
+
| `project-work` | Repository health, docs maintenance, release readiness/summary, Run reports, and supporting deterministic snapshots |
|
|
89
|
+
| `music-player` | The controlled `playback` singleton |
|
|
90
|
+
| `recipe-memory` | Internal automatic reviewers; use its Skill only for diagnosis/recovery |
|
|
85
91
|
|
|
86
|
-
|
|
92
|
+
Use the `actors/*` helpers only for their narrow requested result or intentional composition. Prefer public `inspect` for ordinary runtime diagnosis and the capability's primary workflow for a complete outcome.
|
|
87
93
|
|
|
88
|
-
Delegation
|
|
94
|
+
## Delegation boundary
|
|
95
|
+
|
|
96
|
+
The current Pi instance owns user authority and the final result; pi-actors creates explicit local Runs, while companion transports provide presence rather than hidden instance creation. Keep short single-boundary work inline when delegation adds no value. For several participants, reasoning allocation, quorum, or integration methodology, read `swarm`.
|
|
97
|
+
|
|
98
|
+
Treat `attention: "steer"` as an actor-authored urgent semantic checkpoint at Pi's next safe boundary, never as a status-derived completion signal; the later root terminal still arrives through its ordinary completion batch.
|
|
89
99
|
|
|
90
100
|
## Run workflow
|
|
91
101
|
|
|
@@ -97,7 +107,7 @@ Run = Recipe + Trace + Control
|
|
|
97
107
|
```
|
|
98
108
|
|
|
99
109
|
1. Spawn with the exact logical Recipe identity and caller-owned values.
|
|
100
|
-
2. Retain the returned `run:<id>` and normally wait for
|
|
110
|
+
2. Retain the returned `run:<id>` and normally wait for its settled completion batch instead of polling.
|
|
101
111
|
3. Inspect `view=trace` when retained observations or attention matter.
|
|
102
112
|
4. Inspect `view=control` before diagnosing service readiness, stale work, or saturation.
|
|
103
113
|
5. Send `message` only for an action declared and consumed by that controlled Recipe.
|
|
@@ -14,7 +14,7 @@ A rare Skill Recipe may declare `singleton: true`. Do not pass `as`: the runtime
|
|
|
14
14
|
|
|
15
15
|
## Observe
|
|
16
16
|
|
|
17
|
-
Normally wait for
|
|
17
|
+
Normally wait for the settled completion batch. Inspect only when requested, when meaningful attention arrives, or when the Run is overdue or blocked:
|
|
18
18
|
|
|
19
19
|
```text
|
|
20
20
|
inspect target=run:<id> view=recipe
|
|
@@ -13,7 +13,7 @@ When a Telegram-originated turn or explicit Telegram-control question makes repe
|
|
|
13
13
|
|
|
14
14
|
## Playback
|
|
15
15
|
|
|
16
|
-
`music-player/playback` is a singleton async controlled service with the canonical address `run:music-player`. The Recipe is the sole lifecycle owner: it starts the service, supervises it, and stops playback when the Run closes. The service owns queue, backend, checkpoint, and playback state. `playback
|
|
16
|
+
`music-player/playback` is a singleton async controlled service with the canonical address `run:music-player`. The Recipe is the sole lifecycle owner: it starts the service, supervises it, and stops playback when the Run closes. The service owns queue, backend, checkpoint, and playback state. `scripts/playback.mjs` owns both foreground playback and the bounded control CLI. Its `control <state-dir> <action> [percent]` entrypoint observes or controls an existing owner without starting, adopting, or supervising it. Explicit foreground `serve` supports a caller-owned standalone host without importing the Actor runtime; Actor and standalone ownership of one state directory are mutually exclusive.
|
|
17
17
|
|
|
18
18
|
```text
|
|
19
19
|
spawn recipe=music-player/playback values={"source":"~/Music","player":"auto"}
|
|
@@ -35,14 +35,14 @@ Use only declared actions: `play`, `pause`, `resume`, `toggle`, `next`, `previou
|
|
|
35
35
|
- `status` is read-only and exposes bounded machine-readable player state, including the current absolute volume and a duration-derived progress percentage projected at read time.
|
|
36
36
|
- `stop` ends the live process without silently deleting the saved queue.
|
|
37
37
|
|
|
38
|
-
External local views use
|
|
38
|
+
External local views use `playback.mjs control <state-dir> <action> [percent]`. For Actor-owned playback, the script validates Run availability, queues canonical Control, and waits for that exact record to become handled or failed. For standalone playback, it sends a bounded generation-fenced command to the service endpoint without creating Run, Control, or Trace state. Views themselves never read or edit Run files, signal processes, construct Control records, or import pi-actors internals. `status` is read-only and reports `actor_available` separately from playback state.
|
|
39
39
|
|
|
40
40
|
## Maintained Telegram View
|
|
41
41
|
|
|
42
42
|
> [!NOTE]
|
|
43
43
|
> This Skill includes a ready Music Player Generative App at `genapps/music-player.mjs`. When `telegram_bind` is available and Telegram interaction is relevant, use it to copy and install the app as `music-player`; hot replacement keeps the same app name with `replace: true`.
|
|
44
44
|
|
|
45
|
-
Bind with absolute `control
|
|
45
|
+
Bind with absolute `control` (the `scripts/playback.mjs` path), `stateDir`, and `node` arguments. This maintained adapter targets Actor-owned playback and uses the unified `control` entrypoint above for status and mutation; it displays controls only when `actor_available` is true. Exact terminal Control evidence remains visible in the Run inspector and failures reach Telegram. The adapter neither imports extension internals nor starts playback. Its stopped-state Start button returns to Pi so the composition root can spawn `music-player/playback`, while active controls remain deterministic Generative App actions that bypass the model. `pi-telegram` owns only the generic Generative App runtime.
|
|
46
46
|
|
|
47
47
|
## Sources And Backends
|
|
48
48
|
|
|
@@ -70,7 +70,7 @@ function normalizePlayback(status) {
|
|
|
70
70
|
async function readPlayback(adapter, run) {
|
|
71
71
|
const result = await run({
|
|
72
72
|
command: adapter.node,
|
|
73
|
-
args: [adapter.control, "
|
|
73
|
+
args: [adapter.control, "control", adapter.stateDir, "status"],
|
|
74
74
|
cwd: dirname(adapter.control),
|
|
75
75
|
timeoutMs: 5_000,
|
|
76
76
|
});
|
|
@@ -188,8 +188,9 @@ async function applyVolume(percent, context) {
|
|
|
188
188
|
command: context.state.adapter.node,
|
|
189
189
|
args: [
|
|
190
190
|
context.state.adapter.control,
|
|
191
|
-
"
|
|
191
|
+
"control",
|
|
192
192
|
context.state.adapter.stateDir,
|
|
193
|
+
"volume",
|
|
193
194
|
String(percent),
|
|
194
195
|
],
|
|
195
196
|
cwd: dirname(context.state.adapter.control),
|
|
@@ -224,8 +225,9 @@ async function applySeek(percent, context) {
|
|
|
224
225
|
command: context.state.adapter.node,
|
|
225
226
|
args: [
|
|
226
227
|
context.state.adapter.control,
|
|
227
|
-
"
|
|
228
|
+
"control",
|
|
228
229
|
context.state.adapter.stateDir,
|
|
230
|
+
"seek",
|
|
229
231
|
String(percent),
|
|
230
232
|
],
|
|
231
233
|
cwd: dirname(context.state.adapter.control),
|
|
@@ -253,7 +255,7 @@ async function apply(action, context) {
|
|
|
253
255
|
const before = await readPlayback(context.state.adapter, context.run);
|
|
254
256
|
const result = await context.run({
|
|
255
257
|
command: context.state.adapter.node,
|
|
256
|
-
args: [context.state.adapter.control,
|
|
258
|
+
args: [context.state.adapter.control, "control", context.state.adapter.stateDir, action],
|
|
257
259
|
cwd: dirname(context.state.adapter.control),
|
|
258
260
|
timeoutMs: 5_000,
|
|
259
261
|
});
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
watch,
|
|
28
28
|
writeFileSync,
|
|
29
29
|
} from "node:fs";
|
|
30
|
-
import { createServer } from "node:net";
|
|
30
|
+
import { createConnection, createServer } from "node:net";
|
|
31
31
|
import { homedir } from "node:os";
|
|
32
32
|
import {
|
|
33
33
|
basename,
|
|
@@ -66,7 +66,7 @@ let updateRunControlStatusInStateDir;
|
|
|
66
66
|
let isAlive;
|
|
67
67
|
let verifyRunProcessIdentity;
|
|
68
68
|
let appendRunTraceEvent = () => {};
|
|
69
|
-
|
|
69
|
+
async function loadActorAdapter() {
|
|
70
70
|
({
|
|
71
71
|
appendRunControlInStateDir,
|
|
72
72
|
claimRunControlByIdInStateDir,
|
|
@@ -110,8 +110,9 @@ function usage() {
|
|
|
110
110
|
playback.mjs control <state-dir> <play|pause|toggle|next|previous|seek|volume|stop|status> [percent]
|
|
111
111
|
|
|
112
112
|
Runs a foreground music player so pi-actors can own it as a controlled Run.
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
Actor-owned controls use canonical records in <state-dir>/controls.jsonl.
|
|
114
|
+
Standalone controls use the generation-fenced playback service endpoint.
|
|
115
|
+
Prefer message target=run:<run> action=<command> for Actors; external adapters use control <state-dir> <action>.
|
|
115
116
|
Supported players: auto, mpv, afplay, ffplay, cvlc, play, wmp.
|
|
116
117
|
`);
|
|
117
118
|
}
|
|
@@ -1134,6 +1135,7 @@ function readAndClearCommand(ctx) {
|
|
|
1134
1135
|
}
|
|
1135
1136
|
|
|
1136
1137
|
async function playMain(args) {
|
|
1138
|
+
if (actorAdapterEnabled) await loadActorAdapter();
|
|
1137
1139
|
const [
|
|
1138
1140
|
sourceArg,
|
|
1139
1141
|
loopArg = "true",
|
|
@@ -1333,30 +1335,74 @@ function projectCurrentProgress(status, nowMs = Date.now()) {
|
|
|
1333
1335
|
};
|
|
1334
1336
|
}
|
|
1335
1337
|
|
|
1336
|
-
function actorControlAvailability(stateDir) {
|
|
1338
|
+
async function actorControlAvailability(stateDir) {
|
|
1337
1339
|
const run = readJsonFile(join(stateDir, "run.json"), {});
|
|
1338
1340
|
const result = readJsonFile(join(stateDir, "result.json"), {});
|
|
1339
1341
|
const endpoint = readJsonFile(join(stateDir, "control-endpoint.json"), {});
|
|
1340
1342
|
const playerStatus = readJsonFile(join(stateDir, "player.json"), {});
|
|
1343
|
+
const runInstanceId = typeof run.run_instance_id === "string"
|
|
1344
|
+
? run.run_instance_id
|
|
1345
|
+
: undefined;
|
|
1346
|
+
// Inactive status must remain readable without an installed Actor runtime,
|
|
1347
|
+
// including standalone state beside metadata from a rejected Actor launch.
|
|
1348
|
+
if (!runInstanceId || typeof result.completedAt === "string" ||
|
|
1349
|
+
endpoint.run_instance_id !== runInstanceId ||
|
|
1350
|
+
!["playing", "paused"].includes(playerStatus.state)) {
|
|
1351
|
+
return { available: false, runInstanceId };
|
|
1352
|
+
}
|
|
1353
|
+
if (!verifyRunProcessIdentity) {
|
|
1354
|
+
await loadActorAdapter();
|
|
1355
|
+
// Re-read authority after the asynchronous import before admitting control.
|
|
1356
|
+
return actorControlAvailability(stateDir);
|
|
1357
|
+
}
|
|
1341
1358
|
const pid = Number(run.pid || 0);
|
|
1342
1359
|
const hasProcessIdentity = pid > 0 || run.process_identity !== undefined;
|
|
1343
1360
|
const processIdentity = pid > 0
|
|
1344
1361
|
? verifyRunProcessIdentity(pid, run.process_identity)
|
|
1345
1362
|
: { valid: false };
|
|
1346
|
-
const available =
|
|
1347
|
-
typeof run.run_instance_id === "string" &&
|
|
1348
|
-
typeof result.completedAt !== "string" &&
|
|
1349
|
-
(!hasProcessIdentity || (pid > 0 && isAlive(pid) && processIdentity.valid === true)) &&
|
|
1350
|
-
endpoint.run_instance_id === run.run_instance_id &&
|
|
1351
|
-
["playing", "paused"].includes(playerStatus.state);
|
|
1352
1363
|
return {
|
|
1353
|
-
available
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
: undefined,
|
|
1364
|
+
available: !hasProcessIdentity ||
|
|
1365
|
+
(pid > 0 && isAlive(pid) && processIdentity.valid === true),
|
|
1366
|
+
runInstanceId,
|
|
1357
1367
|
};
|
|
1358
1368
|
}
|
|
1359
1369
|
|
|
1370
|
+
async function sendPlaybackCommand(endpoint, action, input) {
|
|
1371
|
+
const payload = `${JSON.stringify({
|
|
1372
|
+
action,
|
|
1373
|
+
...(input !== undefined ? { input } : {}),
|
|
1374
|
+
service_instance_id: endpoint.service_instance_id,
|
|
1375
|
+
})}\n`;
|
|
1376
|
+
const response = await new Promise((resolveResponse, rejectResponse) => {
|
|
1377
|
+
const socket = createConnection(endpoint.path);
|
|
1378
|
+
let content = "";
|
|
1379
|
+
const timeout = setTimeout(() => {
|
|
1380
|
+
socket.destroy(new Error("playback service command timed out"));
|
|
1381
|
+
}, 5_000);
|
|
1382
|
+
timeout.unref?.();
|
|
1383
|
+
socket.setEncoding("utf8");
|
|
1384
|
+
socket.on("connect", () => socket.write(payload));
|
|
1385
|
+
socket.on("data", (chunk) => {
|
|
1386
|
+
content += chunk;
|
|
1387
|
+
if (Buffer.byteLength(content, "utf8") > 4096) {
|
|
1388
|
+
socket.destroy(new Error("playback service response is too large"));
|
|
1389
|
+
}
|
|
1390
|
+
});
|
|
1391
|
+
socket.on("close", () => clearTimeout(timeout));
|
|
1392
|
+
socket.on("error", rejectResponse);
|
|
1393
|
+
socket.on("end", () => {
|
|
1394
|
+
try {
|
|
1395
|
+
resolveResponse(JSON.parse(content.trim()));
|
|
1396
|
+
} catch {
|
|
1397
|
+
rejectResponse(new Error("playback service returned invalid JSON"));
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
});
|
|
1401
|
+
if (response?.ok !== true) {
|
|
1402
|
+
throw new Error(response?.error || "playback service rejected the command");
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1360
1406
|
async function controlMain(args) {
|
|
1361
1407
|
const stateDir = expandPath(args[0] || "");
|
|
1362
1408
|
const command = args[1] || "status";
|
|
@@ -1365,13 +1411,20 @@ async function controlMain(args) {
|
|
|
1365
1411
|
usage();
|
|
1366
1412
|
process.exit(2);
|
|
1367
1413
|
}
|
|
1368
|
-
|
|
1414
|
+
if (!CONTROL_COMMANDS.has(command)) fail(`unsupported command: ${command}`, 2);
|
|
1415
|
+
const endpoint = readJsonFile(join(stateDir, "playback-endpoint.json"), {});
|
|
1416
|
+
// A standalone service retains authority even if an unsuccessful Actor launch
|
|
1417
|
+
// left Run metadata beside its endpoint. Clients never start or adopt it.
|
|
1418
|
+
const actorOwned = endpoint.owner_mode !== "standalone" &&
|
|
1419
|
+
existsSync(join(stateDir, "run.json"));
|
|
1369
1420
|
if (command === "status") {
|
|
1370
1421
|
const statusFile = join(stateDir, "player.json");
|
|
1371
1422
|
const status = exists(statusFile)
|
|
1372
1423
|
? readJsonFile(statusFile, { state: "unknown" })
|
|
1373
1424
|
: { state: "unknown" };
|
|
1374
|
-
const actor =
|
|
1425
|
+
const actor = actorOwned
|
|
1426
|
+
? await actorControlAvailability(stateDir)
|
|
1427
|
+
: { available: false };
|
|
1375
1428
|
process.stdout.write(`${JSON.stringify({
|
|
1376
1429
|
...projectCurrentProgress(status),
|
|
1377
1430
|
actor_available: actor.available,
|
|
@@ -1381,7 +1434,7 @@ async function controlMain(args) {
|
|
|
1381
1434
|
})}\n`);
|
|
1382
1435
|
return;
|
|
1383
1436
|
}
|
|
1384
|
-
if (!actorControlAvailability(stateDir).available) {
|
|
1437
|
+
if (actorOwned && !(await actorControlAvailability(stateDir)).available) {
|
|
1385
1438
|
fail(`Run playback is not active: ${stateDir}`, 3);
|
|
1386
1439
|
}
|
|
1387
1440
|
let input;
|
|
@@ -1396,6 +1449,20 @@ async function controlMain(args) {
|
|
|
1396
1449
|
fail(error instanceof Error ? error.message : String(error), 2);
|
|
1397
1450
|
}
|
|
1398
1451
|
}
|
|
1452
|
+
if (!actorOwned) {
|
|
1453
|
+
if (endpoint.owner_mode !== "standalone" ||
|
|
1454
|
+
typeof endpoint.path !== "string" || !endpoint.path ||
|
|
1455
|
+
typeof endpoint.service_instance_id !== "string" || !endpoint.service_instance_id) {
|
|
1456
|
+
fail(`standalone playback service is not active: ${stateDir}`, 3);
|
|
1457
|
+
}
|
|
1458
|
+
try {
|
|
1459
|
+
await sendPlaybackCommand(endpoint, command === "resume" ? "play" : command, input);
|
|
1460
|
+
console.log(`music-player: command=${command} handled state_dir=${stateDir}`);
|
|
1461
|
+
return;
|
|
1462
|
+
} catch (error) {
|
|
1463
|
+
fail(error instanceof Error ? error.message : String(error), 3);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1399
1466
|
const queued = appendControl(
|
|
1400
1467
|
{ controlsFile: join(stateDir, "controls.jsonl"), stateDir },
|
|
1401
1468
|
command,
|
package/skills/swarm/SKILL.md
CHANGED
|
@@ -9,13 +9,9 @@ Use multi-actor execution only when at least two scopes or evidence lenses are m
|
|
|
9
9
|
|
|
10
10
|
Read `actors` first for generic Recipe, spawn, Run, Trace, Control, artifact, and lifecycle operation. This Skill owns only multi-actor methodology: decomposition, scope ownership, independence, synthesis, integration, and completion proof.
|
|
11
11
|
|
|
12
|
-
## Coordinator
|
|
12
|
+
## Coordinator and participants
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
This resembles gateway orchestration in dependency direction but not in ownership: the coordinator is itself an agent instance with inspectable Runs, not an infrastructure service that implicitly creates sessions. Preserve that distinction in prompts, docs, recovery, and target routing.
|
|
17
|
-
|
|
18
|
-
Once work is delegated, keep the coordinator available for decisions and integration instead of duplicating participant implementation. Wait for terminal follow-up by default; use meaningful attention or evidence-based timers for overdue work rather than a tight inspection loop.
|
|
14
|
+
The coordinator owns decomposition, shared contracts, integration order, and final validation. Participants own bounded tasks or evidence lenses. Keep the coordinator available for decisions instead of duplicating participant implementation; use `actors` for launch, observation, and lifecycle mechanics.
|
|
19
15
|
|
|
20
16
|
## Reasoning allocation
|
|
21
17
|
|
|
@@ -14,38 +14,9 @@ Use a development swarm only when all are true:
|
|
|
14
14
|
|
|
15
15
|
Do not parallelize implementation when tasks need the same central files, semantic ordering dominates wall-clock time, or the likely conflicts would invalidate the decomposition. Use planning or review first.
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Roles and reasoning
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
The coordinator should:
|
|
22
|
-
|
|
23
|
-
- Translate high-level intent into bounded task cards and dependency edges.
|
|
24
|
-
- Keep user authority, shared contracts, integration order, and final validation local.
|
|
25
|
-
- Remain available for checkpoints, permissions, conflicts, and changing evidence.
|
|
26
|
-
- Consume terminal handoffs, durable artifacts, and Trace attention instead of mirroring participant work.
|
|
27
|
-
- Check overdue work on an evidence-based timer; never replace event-driven completion with a rapid polling loop.
|
|
28
|
-
|
|
29
|
-
A participant should:
|
|
30
|
-
|
|
31
|
-
- Own one concrete execution or evidence boundary.
|
|
32
|
-
- Avoid global orchestration and undeclared participant creation.
|
|
33
|
-
- Return a bounded handoff that lets the coordinator decide without replaying the entire task.
|
|
34
|
-
|
|
35
|
-
Use one ordinary Run under `actors` when only one worker is delegated. Activate this development-swarm protocol when two or more participants, parallel ownership, or explicit integration edges exist. Keep trivial single-boundary work inline when delegation overhead has no compensating value.
|
|
36
|
-
|
|
37
|
-
## Reasoning profiles
|
|
38
|
-
|
|
39
|
-
| Role | Default | Raise or fan out when |
|
|
40
|
-
| --- | --- | --- |
|
|
41
|
-
| Bounded implementation author | Reasoning off | The card explicitly owns unresolved diagnosis or design judgement |
|
|
42
|
-
| Reviewer | Medium reasoning, clean context | Stakes require independent lenses or repeated judges |
|
|
43
|
-
| Synthesizer / integrator | Medium reasoning | Evidence conflicts, shared contracts move, or merge order is semantic |
|
|
44
|
-
| Coordinator | Sufficient for decomposition and decisions | Scope, authority, or architecture remains unresolved |
|
|
45
|
-
|
|
46
|
-
Prefer independent review after implementation over asking one author thread to implement, retain all local assumptions, and then certify itself. When risk justifies the cost, use multiple independent reviewers: different lenses increase breadth, while repeated judges increase confidence. Preserve minority high-impact findings and merge only evidence-backed conclusions.
|
|
47
|
-
|
|
48
|
-
More reviewers are not automatically better. Do not fan out when they would inspect unstable code, share contaminated context, repeat one unsupported claim, or exceed the value of the decision. Never change an already-running participant solely to enforce a newer profile; add a fresh review boundary if evidence remains open.
|
|
19
|
+
Apply [Swarm's coordinator and reasoning contract](../SKILL.md#reasoning-allocation). Task cards record those profiles and the owned execution boundary; participants return evidence without undeclared orchestration. Do not fan out review over unstable code or contaminated context. The sections below specify development-only task cards, ownership transfers, conflict reports, and integration.
|
|
49
20
|
|
|
50
21
|
## Decompose by ownership
|
|
51
22
|
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Actor-neutral client for the local Music Player playback protocol.
|
|
5
|
-
*
|
|
6
|
-
* Reads portable JSON status and sends bounded generation-fenced commands to
|
|
7
|
-
* the playback service endpoint without reading pi-actors Run or Control state.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
11
|
-
import { createConnection } from "node:net";
|
|
12
|
-
import { homedir } from "node:os";
|
|
13
|
-
import { join } from "node:path";
|
|
14
|
-
|
|
15
|
-
const ACTIONS = new Set([
|
|
16
|
-
"play",
|
|
17
|
-
"resume",
|
|
18
|
-
"pause",
|
|
19
|
-
"toggle",
|
|
20
|
-
"next",
|
|
21
|
-
"previous",
|
|
22
|
-
"seek",
|
|
23
|
-
"volume",
|
|
24
|
-
"stop",
|
|
25
|
-
"status",
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
function fail(message, code = 1) {
|
|
29
|
-
console.error(`music-player: ${message}`);
|
|
30
|
-
process.exit(code);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function expandPath(value) {
|
|
34
|
-
if (value === "~") return homedir();
|
|
35
|
-
if (value.startsWith("~/")) return join(homedir(), value.slice(2));
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function readJson(path, fallback) {
|
|
40
|
-
try {
|
|
41
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
42
|
-
} catch {
|
|
43
|
-
return fallback;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function parsePercent(value, label) {
|
|
48
|
-
if (!/^\d+$/.test(String(value))) {
|
|
49
|
-
fail(`${label} percent must be an integer 0..100`, 2);
|
|
50
|
-
}
|
|
51
|
-
const percent = Number(value);
|
|
52
|
-
if (percent < 0 || percent > 100) {
|
|
53
|
-
fail(`${label} percent must be an integer 0..100`, 2);
|
|
54
|
-
}
|
|
55
|
-
return percent;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function projectCurrentProgress(status, nowMs = Date.now()) {
|
|
59
|
-
const duration = Number(status.duration_seconds);
|
|
60
|
-
let position = Number(status.position_seconds);
|
|
61
|
-
const updatedAtMs = Number(status.position_updated_at_ms);
|
|
62
|
-
if (!Number.isFinite(position)) position = 0;
|
|
63
|
-
if (status.state === "playing" && Number.isFinite(updatedAtMs)) {
|
|
64
|
-
position += Math.max(0, nowMs - updatedAtMs) / 1000;
|
|
65
|
-
}
|
|
66
|
-
if (!Number.isFinite(duration) || duration <= 0) {
|
|
67
|
-
return { ...status, progress_percent: null };
|
|
68
|
-
}
|
|
69
|
-
position = Math.min(Math.max(position, 0), duration);
|
|
70
|
-
return {
|
|
71
|
-
...status,
|
|
72
|
-
progress_percent: Math.round((position / duration) * 100),
|
|
73
|
-
position_seconds: position,
|
|
74
|
-
position_updated_at_ms: nowMs,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function sendCommand(endpoint, action, input) {
|
|
79
|
-
const payload = `${JSON.stringify({
|
|
80
|
-
action,
|
|
81
|
-
...(input !== undefined ? { input } : {}),
|
|
82
|
-
service_instance_id: endpoint.service_instance_id,
|
|
83
|
-
})}\n`;
|
|
84
|
-
const response = await new Promise((resolveResponse, rejectResponse) => {
|
|
85
|
-
const socket = createConnection(endpoint.path);
|
|
86
|
-
let content = "";
|
|
87
|
-
const timeout = setTimeout(() => {
|
|
88
|
-
socket.destroy();
|
|
89
|
-
rejectResponse(new Error("playback service command timed out"));
|
|
90
|
-
}, 5_000);
|
|
91
|
-
timeout.unref?.();
|
|
92
|
-
socket.setEncoding("utf8");
|
|
93
|
-
socket.on("connect", () => socket.write(payload));
|
|
94
|
-
socket.on("data", (chunk) => {
|
|
95
|
-
content += chunk;
|
|
96
|
-
if (Buffer.byteLength(content, "utf8") > 4096) {
|
|
97
|
-
socket.destroy(new Error("playback service response is too large"));
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
socket.on("error", rejectResponse);
|
|
101
|
-
socket.on("end", () => {
|
|
102
|
-
clearTimeout(timeout);
|
|
103
|
-
try {
|
|
104
|
-
resolveResponse(JSON.parse(content.trim()));
|
|
105
|
-
} catch {
|
|
106
|
-
rejectResponse(new Error("playback service returned invalid JSON"));
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
if (!response?.ok) {
|
|
111
|
-
throw new Error(response?.error || "playback service rejected the command");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const [action = "status", rawStateDir, ...actionArgs] = process.argv.slice(2);
|
|
116
|
-
if (!ACTIONS.has(action) || !rawStateDir) {
|
|
117
|
-
fail("usage: playback-client.mjs <status|play|resume|pause|toggle|next|previous|seek|volume|stop> <state-dir> [action args]", 2);
|
|
118
|
-
}
|
|
119
|
-
const stateDir = expandPath(rawStateDir);
|
|
120
|
-
if (action === "status") {
|
|
121
|
-
const status = readJson(join(stateDir, "player.json"), { state: "unknown" });
|
|
122
|
-
process.stdout.write(`${JSON.stringify(projectCurrentProgress(status))}\n`);
|
|
123
|
-
process.exit(0);
|
|
124
|
-
}
|
|
125
|
-
const endpointPath = join(stateDir, "playback-endpoint.json");
|
|
126
|
-
if (!existsSync(endpointPath)) fail(`playback service is not active: ${stateDir}`, 3);
|
|
127
|
-
const endpoint = readJson(endpointPath, {});
|
|
128
|
-
if (
|
|
129
|
-
typeof endpoint.path !== "string" ||
|
|
130
|
-
!endpoint.path ||
|
|
131
|
-
typeof endpoint.service_instance_id !== "string" ||
|
|
132
|
-
!endpoint.service_instance_id
|
|
133
|
-
) fail(`playback service endpoint is invalid: ${stateDir}`, 3);
|
|
134
|
-
let input;
|
|
135
|
-
if (action === "seek" || action === "volume") {
|
|
136
|
-
input = { percent: parsePercent(actionArgs[0], action) };
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
await sendCommand(endpoint, action === "resume" ? "play" : action, input);
|
|
140
|
-
console.log(`music-player: command=${action} handled state_dir=${stateDir}`);
|
|
141
|
-
} catch (error) {
|
|
142
|
-
fail(error instanceof Error ? error.message : String(error), 3);
|
|
143
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Actor-neutral client for the local Music Player playback protocol.
|
|
5
|
-
*
|
|
6
|
-
* Reads portable JSON status and sends bounded generation-fenced commands to
|
|
7
|
-
* the playback service endpoint without reading pi-actors Run or Control state.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
11
|
-
import { createConnection } from "node:net";
|
|
12
|
-
import { homedir } from "node:os";
|
|
13
|
-
import { join } from "node:path";
|
|
14
|
-
|
|
15
|
-
const ACTIONS = new Set([
|
|
16
|
-
"play",
|
|
17
|
-
"resume",
|
|
18
|
-
"pause",
|
|
19
|
-
"toggle",
|
|
20
|
-
"next",
|
|
21
|
-
"previous",
|
|
22
|
-
"seek",
|
|
23
|
-
"volume",
|
|
24
|
-
"stop",
|
|
25
|
-
"status",
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
function fail(message, code = 1) {
|
|
29
|
-
console.error(`music-player: ${message}`);
|
|
30
|
-
process.exit(code);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function expandPath(value) {
|
|
34
|
-
if (value === "~") return homedir();
|
|
35
|
-
if (value.startsWith("~/")) return join(homedir(), value.slice(2));
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function readJson(path, fallback) {
|
|
40
|
-
try {
|
|
41
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
42
|
-
} catch {
|
|
43
|
-
return fallback;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function parsePercent(value, label) {
|
|
48
|
-
if (!/^\d+$/.test(String(value))) {
|
|
49
|
-
fail(`${label} percent must be an integer 0..100`, 2);
|
|
50
|
-
}
|
|
51
|
-
const percent = Number(value);
|
|
52
|
-
if (percent < 0 || percent > 100) {
|
|
53
|
-
fail(`${label} percent must be an integer 0..100`, 2);
|
|
54
|
-
}
|
|
55
|
-
return percent;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function projectCurrentProgress(status, nowMs = Date.now()) {
|
|
59
|
-
const duration = Number(status.duration_seconds);
|
|
60
|
-
let position = Number(status.position_seconds);
|
|
61
|
-
const updatedAtMs = Number(status.position_updated_at_ms);
|
|
62
|
-
if (!Number.isFinite(position)) position = 0;
|
|
63
|
-
if (status.state === "playing" && Number.isFinite(updatedAtMs)) {
|
|
64
|
-
position += Math.max(0, nowMs - updatedAtMs) / 1000;
|
|
65
|
-
}
|
|
66
|
-
if (!Number.isFinite(duration) || duration <= 0) {
|
|
67
|
-
return { ...status, progress_percent: null };
|
|
68
|
-
}
|
|
69
|
-
position = Math.min(Math.max(position, 0), duration);
|
|
70
|
-
return {
|
|
71
|
-
...status,
|
|
72
|
-
progress_percent: Math.round((position / duration) * 100),
|
|
73
|
-
position_seconds: position,
|
|
74
|
-
position_updated_at_ms: nowMs,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function sendCommand(endpoint, action, input) {
|
|
79
|
-
const payload = `${JSON.stringify({
|
|
80
|
-
action,
|
|
81
|
-
...(input !== undefined ? { input } : {}),
|
|
82
|
-
service_instance_id: endpoint.service_instance_id,
|
|
83
|
-
})}\n`;
|
|
84
|
-
const response = await new Promise((resolveResponse, rejectResponse) => {
|
|
85
|
-
const socket = createConnection(endpoint.path);
|
|
86
|
-
let content = "";
|
|
87
|
-
const timeout = setTimeout(() => {
|
|
88
|
-
socket.destroy();
|
|
89
|
-
rejectResponse(new Error("playback service command timed out"));
|
|
90
|
-
}, 5_000);
|
|
91
|
-
timeout.unref?.();
|
|
92
|
-
socket.setEncoding("utf8");
|
|
93
|
-
socket.on("connect", () => socket.write(payload));
|
|
94
|
-
socket.on("data", (chunk) => {
|
|
95
|
-
content += chunk;
|
|
96
|
-
if (Buffer.byteLength(content, "utf8") > 4096) {
|
|
97
|
-
socket.destroy(new Error("playback service response is too large"));
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
socket.on("error", rejectResponse);
|
|
101
|
-
socket.on("end", () => {
|
|
102
|
-
clearTimeout(timeout);
|
|
103
|
-
try {
|
|
104
|
-
resolveResponse(JSON.parse(content.trim()));
|
|
105
|
-
} catch {
|
|
106
|
-
rejectResponse(new Error("playback service returned invalid JSON"));
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
if (!response?.ok) {
|
|
111
|
-
throw new Error(response?.error || "playback service rejected the command");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const [action = "status", rawStateDir, ...actionArgs] = process.argv.slice(2);
|
|
116
|
-
if (!ACTIONS.has(action) || !rawStateDir) {
|
|
117
|
-
fail("usage: playback-client.mjs <status|play|resume|pause|toggle|next|previous|seek|volume|stop> <state-dir> [action args]", 2);
|
|
118
|
-
}
|
|
119
|
-
const stateDir = expandPath(rawStateDir);
|
|
120
|
-
if (action === "status") {
|
|
121
|
-
const status = readJson(join(stateDir, "player.json"), { state: "unknown" });
|
|
122
|
-
process.stdout.write(`${JSON.stringify(projectCurrentProgress(status))}\n`);
|
|
123
|
-
process.exit(0);
|
|
124
|
-
}
|
|
125
|
-
const endpointPath = join(stateDir, "playback-endpoint.json");
|
|
126
|
-
if (!existsSync(endpointPath)) fail(`playback service is not active: ${stateDir}`, 3);
|
|
127
|
-
const endpoint = readJson(endpointPath, {});
|
|
128
|
-
if (
|
|
129
|
-
typeof endpoint.path !== "string" ||
|
|
130
|
-
!endpoint.path ||
|
|
131
|
-
typeof endpoint.service_instance_id !== "string" ||
|
|
132
|
-
!endpoint.service_instance_id
|
|
133
|
-
) fail(`playback service endpoint is invalid: ${stateDir}`, 3);
|
|
134
|
-
let input;
|
|
135
|
-
if (action === "seek" || action === "volume") {
|
|
136
|
-
input = { percent: parsePercent(actionArgs[0], action) };
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
await sendCommand(endpoint, action === "resume" ? "play" : action, input);
|
|
140
|
-
console.log(`music-player: command=${action} handled state_dir=${stateDir}`);
|
|
141
|
-
} catch (error) {
|
|
142
|
-
fail(error instanceof Error ? error.message : String(error), 3);
|
|
143
|
-
}
|