tryharness 0.7.58 → 0.7.60
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/lib/boardProtocol.json +5 -1
- package/lib/cards.mjs +2 -1
- package/lib/commands.mjs +33 -1
- package/lib/daemon.mjs +45 -0
- package/lib/inference.mjs +115 -205
- package/lib/library.mjs +3 -0
- package/lib/listVersions.mjs +61 -0
- package/lib/live.mjs +2 -2
- package/lib/localmodels.mjs +2 -1
- package/lib/ocr.mjs +54 -22
- package/lib/onboard.mjs +9 -6
- package/lib/onnxWorker.mjs +191 -0
- package/lib/ownMachines.mjs +209 -8
- package/lib/phones.mjs +3 -0
- package/lib/readers.mjs +15 -8
- package/lib/sessionControl.mjs +6 -4
- package/lib/sessionIndex.mjs +2 -2
- package/lib/speech.mjs +190 -175
- package/lib/swarm.mjs +34 -10
- package/lib/threadActions.mjs +11 -0
- package/lib/threadRuns.mjs +64 -9
- package/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/release.json +25 -23
package/lib/sessionIndex.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { randomBytes } from "node:crypto";
|
|
5
|
-
import {
|
|
5
|
+
import { runAsync } from "./commands.mjs";
|
|
6
6
|
import { listJsonl } from "./files.mjs";
|
|
7
7
|
import { parseSessionFile } from "./parsers.mjs";
|
|
8
8
|
import { historyRoots } from "./paths.mjs";
|
|
@@ -193,7 +193,7 @@ export function createSessionIndex({
|
|
|
193
193
|
for (const item of requested)
|
|
194
194
|
await readOpencodeSession(item.sessionId, item.cwd);
|
|
195
195
|
} else {
|
|
196
|
-
const listed =
|
|
196
|
+
const listed = await runAsync(
|
|
197
197
|
"opencode",
|
|
198
198
|
["session", "list", "--format", "json"],
|
|
199
199
|
{ timeout: 20_000, maxBuffer: 20_000_000 }
|
package/lib/speech.mjs
CHANGED
|
@@ -344,6 +344,167 @@ export function createAppleSpeech({
|
|
|
344
344
|
};
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
// The models' own work, run on the model thread (onnxWorker.mjs) beside the sessions; each returns what the daemon's
|
|
348
|
+
// side turns into words. Samples are sent as a copy of just their piece: a piece of a longer recording sent as is
|
|
349
|
+
// would copy the whole recording to the other thread.
|
|
350
|
+
/** The VAD's speech probability for each 32 ms frame: a job on the model thread (onnxWorker.mjs). */
|
|
351
|
+
export async function vadProbabilities({ ort, graph }, file, samples) {
|
|
352
|
+
const vad = await graph(file);
|
|
353
|
+
const rate = new ort.Tensor("int64", BigInt64Array.from([BigInt(RATE)]), []);
|
|
354
|
+
let state = new ort.Tensor("float32", new Float32Array(2 * 128), [2, 1, 128]);
|
|
355
|
+
const input = new Float32Array(CONTEXT + FRAME);
|
|
356
|
+
const probs = new Float32Array(Math.floor(samples.length / FRAME));
|
|
357
|
+
for (let i = 0; i < probs.length; i += 1) {
|
|
358
|
+
// Each frame carries the last 64 samples of the one before it, as the model was trained.
|
|
359
|
+
input.copyWithin(0, FRAME, FRAME + CONTEXT);
|
|
360
|
+
input.set(samples.subarray(i * FRAME, (i + 1) * FRAME), CONTEXT);
|
|
361
|
+
const out = await vad.run({
|
|
362
|
+
input: new ort.Tensor("float32", input.slice(), [1, CONTEXT + FRAME]),
|
|
363
|
+
state,
|
|
364
|
+
sr: rate,
|
|
365
|
+
});
|
|
366
|
+
probs[i] = out.output.data[0];
|
|
367
|
+
state = out.stateN;
|
|
368
|
+
}
|
|
369
|
+
return probs;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Moonshine's token ids for one piece of speech: a job on the model thread. */
|
|
373
|
+
export async function moonshineIds({ ort, graph }, files, config, samples) {
|
|
374
|
+
const [encoder, decoder] = await Promise.all([
|
|
375
|
+
graph(files.encoder),
|
|
376
|
+
graph(files.decoder),
|
|
377
|
+
]);
|
|
378
|
+
const { last_hidden_state: states } = await encoder.run({
|
|
379
|
+
input_values: new ort.Tensor("float32", samples, [1, samples.length]),
|
|
380
|
+
});
|
|
381
|
+
const layers = config.decoder_num_hidden_layers,
|
|
382
|
+
heads = config.decoder_num_key_value_heads,
|
|
383
|
+
width = config.hidden_size / config.decoder_num_attention_heads;
|
|
384
|
+
const empty = new ort.Tensor("float32", new Float32Array(0), [
|
|
385
|
+
1,
|
|
386
|
+
heads,
|
|
387
|
+
0,
|
|
388
|
+
width,
|
|
389
|
+
]);
|
|
390
|
+
const past = {};
|
|
391
|
+
for (let i = 0; i < layers; i += 1)
|
|
392
|
+
for (const part of ["decoder", "encoder"])
|
|
393
|
+
for (const kv of ["key", "value"])
|
|
394
|
+
past[`past_key_values.${i}.${part}.${kv}`] = empty;
|
|
395
|
+
const limit = Math.ceil((samples.length / RATE) * TOKENS_PER_SECOND) + 4;
|
|
396
|
+
const ids = [];
|
|
397
|
+
let token = config.decoder_start_token_id;
|
|
398
|
+
for (let step = 0; step < limit; step += 1) {
|
|
399
|
+
const out = await decoder.run({
|
|
400
|
+
input_ids: new ort.Tensor(
|
|
401
|
+
"int64",
|
|
402
|
+
BigInt64Array.from([BigInt(token)]),
|
|
403
|
+
[1, 1]
|
|
404
|
+
),
|
|
405
|
+
encoder_hidden_states: states,
|
|
406
|
+
use_cache_branch: new ort.Tensor(
|
|
407
|
+
"bool",
|
|
408
|
+
Uint8Array.from([step > 0 ? 1 : 0]),
|
|
409
|
+
[1]
|
|
410
|
+
),
|
|
411
|
+
...past,
|
|
412
|
+
});
|
|
413
|
+
const logits = out.logits.data;
|
|
414
|
+
let best = 0;
|
|
415
|
+
for (let v = 1; v < logits.length; v += 1)
|
|
416
|
+
if (logits[v] > logits[best]) best = v;
|
|
417
|
+
// The encoder's keys and values come from the first step and stay; the decoder's grow by one each step.
|
|
418
|
+
for (let i = 0; i < layers; i += 1)
|
|
419
|
+
for (const part of step === 0 ? ["decoder", "encoder"] : ["decoder"])
|
|
420
|
+
for (const kv of ["key", "value"])
|
|
421
|
+
past[`past_key_values.${i}.${part}.${kv}`] =
|
|
422
|
+
out[`present.${i}.${part}.${kv}`];
|
|
423
|
+
if (best === config.eos_token_id) break;
|
|
424
|
+
ids.push(best);
|
|
425
|
+
token = best;
|
|
426
|
+
}
|
|
427
|
+
return ids;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Parakeet's token ids for one piece of speech, a job on the model thread: its feature extractor and encoder, then a
|
|
432
|
+
* greedy token-and-duration decode over the encoder's frames (as NeMo and onnx-asr do): each step names a token (or
|
|
433
|
+
* blank) and how many frames to move. `vocabulary` is how many tokens there are; `blank` the blank's id.
|
|
434
|
+
*/
|
|
435
|
+
export async function parakeetIds(
|
|
436
|
+
{ ort, graph },
|
|
437
|
+
files,
|
|
438
|
+
{ vocabulary, blank },
|
|
439
|
+
samples
|
|
440
|
+
) {
|
|
441
|
+
const [features, encoder, joint] = await Promise.all(
|
|
442
|
+
[files.features, files.encoder, files.joint].map((file) => graph(file))
|
|
443
|
+
);
|
|
444
|
+
const count = new ort.Tensor(
|
|
445
|
+
"int64",
|
|
446
|
+
BigInt64Array.from([BigInt(samples.length)]),
|
|
447
|
+
[1]
|
|
448
|
+
);
|
|
449
|
+
const heard = await features.run({
|
|
450
|
+
waveforms: new ort.Tensor("float32", samples, [1, samples.length]),
|
|
451
|
+
waveforms_lens: count,
|
|
452
|
+
});
|
|
453
|
+
const { outputs, encoded_lengths } = await encoder.run({
|
|
454
|
+
audio_signal: heard.features,
|
|
455
|
+
length: heard.features_lens,
|
|
456
|
+
});
|
|
457
|
+
const [, width, frames] = outputs.dims,
|
|
458
|
+
length = Number(encoded_lengths.data[0]);
|
|
459
|
+
const frame = (t) => {
|
|
460
|
+
const v = new Float32Array(width);
|
|
461
|
+
for (let d = 0; d < width; d += 1) v[d] = outputs.data[d * frames + t];
|
|
462
|
+
return v;
|
|
463
|
+
};
|
|
464
|
+
let states = [1, 2].map(
|
|
465
|
+
() => new ort.Tensor("float32", new Float32Array(2 * 640), [2, 1, 640])
|
|
466
|
+
);
|
|
467
|
+
const ids = [];
|
|
468
|
+
for (let t = 0, emitted = 0; t < length;) {
|
|
469
|
+
const out = await joint.run({
|
|
470
|
+
encoder_outputs: new ort.Tensor("float32", frame(t), [1, width, 1]),
|
|
471
|
+
targets: new ort.Tensor(
|
|
472
|
+
"int32",
|
|
473
|
+
Int32Array.from([ids.at(-1) ?? blank]),
|
|
474
|
+
[1, 1]
|
|
475
|
+
),
|
|
476
|
+
target_length: new ort.Tensor("int32", Int32Array.from([1]), [1]),
|
|
477
|
+
input_states_1: states[0],
|
|
478
|
+
input_states_2: states[1],
|
|
479
|
+
});
|
|
480
|
+
const scores = out.outputs.data;
|
|
481
|
+
let token = 0,
|
|
482
|
+
step = 0;
|
|
483
|
+
for (let v = 1; v < vocabulary; v += 1)
|
|
484
|
+
if (scores[v] > scores[token]) token = v;
|
|
485
|
+
for (let k = 1; k < scores.length - vocabulary; k += 1)
|
|
486
|
+
if (scores[vocabulary + k] > scores[vocabulary + step]) step = k;
|
|
487
|
+
if (token !== blank) {
|
|
488
|
+
states = [out.output_states_1, out.output_states_2];
|
|
489
|
+
ids.push(token);
|
|
490
|
+
emitted += 1;
|
|
491
|
+
}
|
|
492
|
+
// At most ten tokens on one frame, as the model's decoding allows.
|
|
493
|
+
if (step > 0) {
|
|
494
|
+
t += step;
|
|
495
|
+
emitted = 0;
|
|
496
|
+
} else if (token === blank || emitted === 10) {
|
|
497
|
+
t += 1;
|
|
498
|
+
emitted = 0;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return ids;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const VAD_JOB = { module: import.meta.url, name: "vadProbabilities" };
|
|
505
|
+
const MOONSHINE_JOB = { module: import.meta.url, name: "moonshineIds" };
|
|
506
|
+
const PARAKEET_JOB = { module: import.meta.url, name: "parakeetIds" };
|
|
507
|
+
|
|
347
508
|
export function createSpeech({
|
|
348
509
|
inference,
|
|
349
510
|
root,
|
|
@@ -488,194 +649,48 @@ export function createSpeech({
|
|
|
488
649
|
const vadFile = fileOf(vadEntry, /\.onnx$/);
|
|
489
650
|
/** The VAD's speech probability for each 32 ms frame. */
|
|
490
651
|
const probabilities = (samples, lane) =>
|
|
491
|
-
inference.onnx(
|
|
492
|
-
"vad",
|
|
493
|
-
async ({ ort, graph }) => {
|
|
494
|
-
const vad = await graph(vadFile);
|
|
495
|
-
const rate = new ort.Tensor(
|
|
496
|
-
"int64",
|
|
497
|
-
BigInt64Array.from([BigInt(RATE)]),
|
|
498
|
-
[]
|
|
499
|
-
);
|
|
500
|
-
let state = new ort.Tensor(
|
|
501
|
-
"float32",
|
|
502
|
-
new Float32Array(2 * 128),
|
|
503
|
-
[2, 1, 128]
|
|
504
|
-
);
|
|
505
|
-
const input = new Float32Array(CONTEXT + FRAME);
|
|
506
|
-
const probs = new Float32Array(Math.floor(samples.length / FRAME));
|
|
507
|
-
for (let i = 0; i < probs.length; i += 1) {
|
|
508
|
-
// Each frame carries the last 64 samples of the one before it, as the model was trained.
|
|
509
|
-
input.copyWithin(0, FRAME, FRAME + CONTEXT);
|
|
510
|
-
input.set(samples.subarray(i * FRAME, (i + 1) * FRAME), CONTEXT);
|
|
511
|
-
const out = await vad.run({
|
|
512
|
-
input: new ort.Tensor("float32", input.slice(), [
|
|
513
|
-
1,
|
|
514
|
-
CONTEXT + FRAME,
|
|
515
|
-
]),
|
|
516
|
-
state,
|
|
517
|
-
sr: rate,
|
|
518
|
-
});
|
|
519
|
-
probs[i] = out.output.data[0];
|
|
520
|
-
state = out.stateN;
|
|
521
|
-
}
|
|
522
|
-
return probs;
|
|
523
|
-
},
|
|
524
|
-
{ lane }
|
|
525
|
-
);
|
|
652
|
+
inference.onnx("vad", VAD_JOB, [vadFile, samples.slice()], { lane });
|
|
526
653
|
|
|
527
654
|
/** Where in the samples someone spoke: [start, end) pairs, none for noise or silence. */
|
|
528
655
|
const voiced = async (samples, { lane = "interactive" } = {}) =>
|
|
529
656
|
speechSpans(await probabilities(samples, lane), { total: samples.length });
|
|
530
657
|
|
|
531
658
|
/** Moonshine's words for one piece of speech. */
|
|
532
|
-
const moonshine = (samples, { lane = "interactive" } = {}) =>
|
|
533
|
-
|
|
659
|
+
const moonshine = async (samples, { lane = "interactive" } = {}) => {
|
|
660
|
+
load();
|
|
661
|
+
const files = {
|
|
662
|
+
encoder: fileOf(speechEntry, /encoder[^/]*\.onnx$/),
|
|
663
|
+
decoder: fileOf(speechEntry, /decoder[^/]*\.onnx$/),
|
|
664
|
+
};
|
|
665
|
+
const ids = await inference.onnx(
|
|
534
666
|
"speech",
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
const [encoder, decoder] = await Promise.all([
|
|
538
|
-
graph(fileOf(speechEntry, /encoder[^/]*\.onnx$/)),
|
|
539
|
-
graph(fileOf(speechEntry, /decoder[^/]*\.onnx$/)),
|
|
540
|
-
]);
|
|
541
|
-
const { last_hidden_state: states } = await encoder.run({
|
|
542
|
-
input_values: new ort.Tensor("float32", samples, [1, samples.length]),
|
|
543
|
-
});
|
|
544
|
-
const layers = config.decoder_num_hidden_layers,
|
|
545
|
-
heads = config.decoder_num_key_value_heads,
|
|
546
|
-
width = config.hidden_size / config.decoder_num_attention_heads;
|
|
547
|
-
const empty = new ort.Tensor("float32", new Float32Array(0), [
|
|
548
|
-
1,
|
|
549
|
-
heads,
|
|
550
|
-
0,
|
|
551
|
-
width,
|
|
552
|
-
]);
|
|
553
|
-
const past = {};
|
|
554
|
-
for (let i = 0; i < layers; i += 1)
|
|
555
|
-
for (const part of ["decoder", "encoder"])
|
|
556
|
-
for (const kv of ["key", "value"])
|
|
557
|
-
past[`past_key_values.${i}.${part}.${kv}`] = empty;
|
|
558
|
-
const limit =
|
|
559
|
-
Math.ceil((samples.length / RATE) * TOKENS_PER_SECOND) + 4;
|
|
560
|
-
const ids = [];
|
|
561
|
-
let token = config.decoder_start_token_id;
|
|
562
|
-
for (let step = 0; step < limit; step += 1) {
|
|
563
|
-
const out = await decoder.run({
|
|
564
|
-
input_ids: new ort.Tensor(
|
|
565
|
-
"int64",
|
|
566
|
-
BigInt64Array.from([BigInt(token)]),
|
|
567
|
-
[1, 1]
|
|
568
|
-
),
|
|
569
|
-
encoder_hidden_states: states,
|
|
570
|
-
use_cache_branch: new ort.Tensor(
|
|
571
|
-
"bool",
|
|
572
|
-
Uint8Array.from([step > 0 ? 1 : 0]),
|
|
573
|
-
[1]
|
|
574
|
-
),
|
|
575
|
-
...past,
|
|
576
|
-
});
|
|
577
|
-
const logits = out.logits.data;
|
|
578
|
-
let best = 0;
|
|
579
|
-
for (let v = 1; v < logits.length; v += 1)
|
|
580
|
-
if (logits[v] > logits[best]) best = v;
|
|
581
|
-
// The encoder's keys and values come from the first step and stay; the decoder's grow by one each step.
|
|
582
|
-
for (let i = 0; i < layers; i += 1)
|
|
583
|
-
for (const part of step === 0
|
|
584
|
-
? ["decoder", "encoder"]
|
|
585
|
-
: ["decoder"])
|
|
586
|
-
for (const kv of ["key", "value"])
|
|
587
|
-
past[`past_key_values.${i}.${part}.${kv}`] =
|
|
588
|
-
out[`present.${i}.${part}.${kv}`];
|
|
589
|
-
if (best === config.eos_token_id) break;
|
|
590
|
-
ids.push(best);
|
|
591
|
-
token = best;
|
|
592
|
-
}
|
|
593
|
-
return tokens.decode(ids).trim();
|
|
594
|
-
},
|
|
667
|
+
MOONSHINE_JOB,
|
|
668
|
+
[files, config, samples.slice()],
|
|
595
669
|
{ lane }
|
|
596
670
|
);
|
|
671
|
+
return tokens.decode(ids).trim();
|
|
672
|
+
};
|
|
597
673
|
|
|
598
|
-
/**
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
674
|
+
/** Parakeet's words for one piece of speech. */
|
|
675
|
+
const parakeet = async (samples, { lane = "interactive" } = {}) => {
|
|
676
|
+
load();
|
|
677
|
+
const files = {
|
|
678
|
+
features: fileOf(speechEntry, /nemo\d+\.onnx$/),
|
|
679
|
+
encoder: fileOf(speechEntry, /encoder[^/]*\.onnx$/),
|
|
680
|
+
joint: fileOf(speechEntry, /decoder_joint[^/]*\.onnx$/),
|
|
681
|
+
};
|
|
682
|
+
const ids = await inference.onnx(
|
|
604
683
|
"speech",
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
/decoder_joint[^/]*\.onnx$/,
|
|
612
|
-
].map((pattern) => graph(fileOf(speechEntry, pattern)))
|
|
613
|
-
);
|
|
614
|
-
const count = new ort.Tensor(
|
|
615
|
-
"int64",
|
|
616
|
-
BigInt64Array.from([BigInt(samples.length)]),
|
|
617
|
-
[1]
|
|
618
|
-
);
|
|
619
|
-
const heard = await features.run({
|
|
620
|
-
waveforms: new ort.Tensor("float32", samples, [1, samples.length]),
|
|
621
|
-
waveforms_lens: count,
|
|
622
|
-
});
|
|
623
|
-
const { outputs, encoded_lengths } = await encoder.run({
|
|
624
|
-
audio_signal: heard.features,
|
|
625
|
-
length: heard.features_lens,
|
|
626
|
-
});
|
|
627
|
-
const [, width, frames] = outputs.dims,
|
|
628
|
-
length = Number(encoded_lengths.data[0]);
|
|
629
|
-
const frame = (t) => {
|
|
630
|
-
const v = new Float32Array(width);
|
|
631
|
-
for (let d = 0; d < width; d += 1)
|
|
632
|
-
v[d] = outputs.data[d * frames + t];
|
|
633
|
-
return v;
|
|
634
|
-
};
|
|
635
|
-
const { pieces, blank } = tokens;
|
|
636
|
-
let states = [1, 2].map(
|
|
637
|
-
() =>
|
|
638
|
-
new ort.Tensor("float32", new Float32Array(2 * 640), [2, 1, 640])
|
|
639
|
-
);
|
|
640
|
-
const ids = [];
|
|
641
|
-
for (let t = 0, emitted = 0; t < length;) {
|
|
642
|
-
const out = await joint.run({
|
|
643
|
-
encoder_outputs: new ort.Tensor("float32", frame(t), [1, width, 1]),
|
|
644
|
-
targets: new ort.Tensor(
|
|
645
|
-
"int32",
|
|
646
|
-
Int32Array.from([ids.at(-1) ?? blank]),
|
|
647
|
-
[1, 1]
|
|
648
|
-
),
|
|
649
|
-
target_length: new ort.Tensor("int32", Int32Array.from([1]), [1]),
|
|
650
|
-
input_states_1: states[0],
|
|
651
|
-
input_states_2: states[1],
|
|
652
|
-
});
|
|
653
|
-
const scores = out.outputs.data;
|
|
654
|
-
let token = 0,
|
|
655
|
-
step = 0;
|
|
656
|
-
for (let v = 1; v < pieces.length; v += 1)
|
|
657
|
-
if (scores[v] > scores[token]) token = v;
|
|
658
|
-
for (let k = 1; k < scores.length - pieces.length; k += 1)
|
|
659
|
-
if (scores[pieces.length + k] > scores[pieces.length + step])
|
|
660
|
-
step = k;
|
|
661
|
-
if (token !== blank) {
|
|
662
|
-
states = [out.output_states_1, out.output_states_2];
|
|
663
|
-
ids.push(token);
|
|
664
|
-
emitted += 1;
|
|
665
|
-
}
|
|
666
|
-
// At most ten tokens on one frame, as the model's decoding allows.
|
|
667
|
-
if (step > 0) {
|
|
668
|
-
t += step;
|
|
669
|
-
emitted = 0;
|
|
670
|
-
} else if (token === blank || emitted === 10) {
|
|
671
|
-
t += 1;
|
|
672
|
-
emitted = 0;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
return tokens.decode(ids).trim();
|
|
676
|
-
},
|
|
684
|
+
PARAKEET_JOB,
|
|
685
|
+
[
|
|
686
|
+
files,
|
|
687
|
+
{ vocabulary: tokens.pieces.length, blank: tokens.blank },
|
|
688
|
+
samples.slice(),
|
|
689
|
+
],
|
|
677
690
|
{ lane }
|
|
678
691
|
);
|
|
692
|
+
return tokens.decode(ids).trim();
|
|
693
|
+
};
|
|
679
694
|
const recognise = engine === "parakeet" ? parakeet : moonshine;
|
|
680
695
|
|
|
681
696
|
/** Speech stretches joined into pieces Moonshine can take, cut between stretches. */
|
package/lib/swarm.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
} from "./specialties.mjs";
|
|
27
27
|
import { askOfRun } from "./threadView.mjs";
|
|
28
28
|
import { createWorkFocus } from "./workFocus.mjs";
|
|
29
|
+
import { createListVersions } from "./listVersions.mjs";
|
|
29
30
|
import { createWorkLinks } from "./workLinks.mjs";
|
|
30
31
|
import {
|
|
31
32
|
DEFAULT_ROUTING,
|
|
@@ -694,6 +695,12 @@ export function createSwarm({
|
|
|
694
695
|
};
|
|
695
696
|
};
|
|
696
697
|
|
|
698
|
+
// The thread list's versions, one for each list a reader can ask for (all of it, or what is open).
|
|
699
|
+
const listVersions = {
|
|
700
|
+
all: createListVersions(),
|
|
701
|
+
open: createListVersions(),
|
|
702
|
+
};
|
|
703
|
+
|
|
697
704
|
return function swarmCommand(request, agent, machine = null) {
|
|
698
705
|
const command = String(request.command);
|
|
699
706
|
if (command === "board.swarm.list") {
|
|
@@ -702,9 +709,9 @@ export function createSwarm({
|
|
|
702
709
|
ok: false,
|
|
703
710
|
error: "only the person and Harness read the swarm",
|
|
704
711
|
};
|
|
705
|
-
const listed = () =>
|
|
706
|
-
|
|
707
|
-
threads
|
|
712
|
+
const listed = () => {
|
|
713
|
+
// activityVersion only tells this side when a T3 thread moved (focus.decorate has read it); no reader uses it.
|
|
714
|
+
const threads = [
|
|
708
715
|
...store
|
|
709
716
|
.goals({ all: request.all === true })
|
|
710
717
|
.filter((thread) => !SETUP_CHECK.test(thread.objective))
|
|
@@ -712,13 +719,30 @@ export function createSwarm({
|
|
|
712
719
|
...(!request.hostedCaller
|
|
713
720
|
? (environments?.roots() ?? []).map(focus.decorate)
|
|
714
721
|
: []),
|
|
715
|
-
],
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
+
].map(({ activityVersion, ...shown }) => shown);
|
|
723
|
+
// A reader on the person's computers that keeps the list (the buddy) sends the version its copy is at and gets
|
|
724
|
+
// what changed since (listVersions.mjs); one that sends none gets it whole, as before.
|
|
725
|
+
const sent = request.hostedCaller
|
|
726
|
+
? null
|
|
727
|
+
: listVersions[request.all === true ? "all" : "open"](threads, {
|
|
728
|
+
epoch: request.epoch,
|
|
729
|
+
after: request.after,
|
|
730
|
+
});
|
|
731
|
+
return {
|
|
732
|
+
ok: true,
|
|
733
|
+
threads: sent ? sent.items : threads,
|
|
734
|
+
...(sent
|
|
735
|
+
? { gone: sent.gone, whole: sent.whole, listVersion: sent.version }
|
|
736
|
+
: {}),
|
|
737
|
+
sessions: request.sessions === false ? [] : sessions(),
|
|
738
|
+
agents: roster(),
|
|
739
|
+
joining: request.hostedCaller ? [] : joining(),
|
|
740
|
+
// What waits on the person about an agent, outside any thread (threadView.mjs swarmNeeds).
|
|
741
|
+
needsYou: request.hostedCaller
|
|
742
|
+
? []
|
|
743
|
+
: (threadView?.swarmNeeds() ?? []),
|
|
744
|
+
};
|
|
745
|
+
};
|
|
722
746
|
// The work in T3 Code beside the board as T3 Code last said it; only the first read waits for it.
|
|
723
747
|
const loading = request.hostedCaller ? null : environments?.ready();
|
|
724
748
|
return loading ? { pending: loading.then(listed) } : listed();
|
package/lib/threadActions.mjs
CHANGED
|
@@ -147,6 +147,15 @@ export function createThreadActions({
|
|
|
147
147
|
) => {
|
|
148
148
|
const goal = store.goal(goalId);
|
|
149
149
|
const { picks } = picksIn(store, post.text, names);
|
|
150
|
+
// `@codex #pop-os`: the computer named with # is where the agents named work. A # naming no runner sets it for
|
|
151
|
+
// whoever takes the thread's work. Only the person and their own agents choose among the person's computers;
|
|
152
|
+
// another person's post (author "maya/codex") never does.
|
|
153
|
+
const ownWords = !String(author ?? "").includes("/");
|
|
154
|
+
const computer = ownWords
|
|
155
|
+
? (ownMachines()?.computerNamed(post.text) ?? null)
|
|
156
|
+
: null;
|
|
157
|
+
if (computer && !names.some((agent) => runsHere(agent)))
|
|
158
|
+
store.meta(`thread-computer:${goalId}`, computer.id);
|
|
150
159
|
const told = [];
|
|
151
160
|
for (const agent of names) {
|
|
152
161
|
if (agent === author) continue;
|
|
@@ -163,6 +172,7 @@ export function createThreadActions({
|
|
|
163
172
|
`it is not in your swarm. Add it with: npx tryharness agents add ${agent}`
|
|
164
173
|
);
|
|
165
174
|
else if (
|
|
175
|
+
!computer &&
|
|
166
176
|
runsHere(agent) &&
|
|
167
177
|
!installedAgents.includes(agent) &&
|
|
168
178
|
!ownMachines()?.placeElsewhere(agent, goal?.workspace ?? null)
|
|
@@ -186,6 +196,7 @@ export function createThreadActions({
|
|
|
186
196
|
review: limited === "review",
|
|
187
197
|
asker: author,
|
|
188
198
|
pick: picks.get(agent),
|
|
199
|
+
on: computer?.id ?? null,
|
|
189
200
|
words: post.text,
|
|
190
201
|
held:
|
|
191
202
|
guard === undefined
|
package/lib/threadRuns.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { MEMBERS, nameOf } from "./members.mjs";
|
|
5
|
+
import { computerHandle } from "./ownMachines.mjs";
|
|
5
6
|
import { oneLine } from "./oneLine.mjs";
|
|
6
7
|
import { setRunPick } from "./models.mjs";
|
|
7
8
|
import { t3Access, steerT3Run } from "./t3.mjs";
|
|
@@ -31,6 +32,9 @@ export function createThreadRuns({
|
|
|
31
32
|
// A coding agent not installed here but on another of the person's computers that has the thread's repository:
|
|
32
33
|
// { machine, folder } there (ownMachines.mjs), or null.
|
|
33
34
|
placeElsewhere = () => null,
|
|
35
|
+
// The person's computers (ownMachines.mjs): this one's id, an agent's turn placed on a named other one
|
|
36
|
+
// ({ machine, folder } or { error }), each computer's name, and the ones an agent is on. Null with one computer.
|
|
37
|
+
computers = null,
|
|
34
38
|
// Projects shared with another person's swarm (projects.mjs): their check before work, and each agent's own branch.
|
|
35
39
|
projects = () => null,
|
|
36
40
|
// The step of the thread's route an agent was last given (team.mjs), or null.
|
|
@@ -320,22 +324,61 @@ export function createThreadRuns({
|
|
|
320
324
|
// Past a shared project's check before work (projects.mjs gate); `wait` holds the run for the person's Start.
|
|
321
325
|
checked = false,
|
|
322
326
|
wait = false,
|
|
327
|
+
// The computer the person named for this turn with # (`@codex #pop-os`), by id.
|
|
328
|
+
on = null,
|
|
323
329
|
} = {}
|
|
324
330
|
) => {
|
|
325
331
|
const task = store.getTask(goalId);
|
|
332
|
+
if (!task || task.status !== "open" || !RUNNERS.has(agent)) return;
|
|
333
|
+
const noteOnce = (key, text) => {
|
|
334
|
+
if (store.meta(key)) return;
|
|
335
|
+
store.meta(key, "1");
|
|
336
|
+
store.roomPost({ goalId, author: "harness", kind: "note", text });
|
|
337
|
+
notifyBoard(store.getTask(goalId));
|
|
338
|
+
};
|
|
339
|
+
// The computer named now, else the one last named in this thread for this agent or for everyone: an agent's work
|
|
340
|
+
// in a thread stays where its checkout is until the person names another.
|
|
341
|
+
if (on) store.meta(`thread-computer:${goalId}:${agent}`, on);
|
|
342
|
+
const earlier =
|
|
343
|
+
store.meta(`thread-computer:${goalId}:${agent}`) ||
|
|
344
|
+
store.meta(`thread-computer:${goalId}`) ||
|
|
345
|
+
null;
|
|
346
|
+
const named = on ?? earlier;
|
|
347
|
+
const self = computers?.self() ?? null;
|
|
348
|
+
// Why the named computer cannot take this turn, or null when it can: { machine, folder } goes in `placed`.
|
|
349
|
+
let placed = null,
|
|
350
|
+
refused = null;
|
|
351
|
+
if (named && named === self && !installedAgents.includes(agent))
|
|
352
|
+
refused = `${nameOf(agent)} is not installed there`;
|
|
353
|
+
else if (named && named !== self) {
|
|
354
|
+
const tried = computers.placeOn(
|
|
355
|
+
agent,
|
|
356
|
+
task.goal?.workspace ?? null,
|
|
357
|
+
named
|
|
358
|
+
);
|
|
359
|
+
if (tried.error) refused = tried.error;
|
|
360
|
+
else placed = tried;
|
|
361
|
+
}
|
|
362
|
+
if (refused) {
|
|
363
|
+
const label = computers.labelOf(named) ?? "that computer";
|
|
364
|
+
// Named for this turn: it waits for the person, said once. Named earlier: it goes where it would have, said once.
|
|
365
|
+
noteOnce(
|
|
366
|
+
`computer-refused:${goalId}:${agent}:${named}:${refused}`,
|
|
367
|
+
on
|
|
368
|
+
? `${nameOf(agent)} cannot work on ${label}: ${refused}.`
|
|
369
|
+
: `${nameOf(agent)} cannot work on ${label} now (${refused}), so it works where it would have.`
|
|
370
|
+
);
|
|
371
|
+
if (on) return;
|
|
372
|
+
}
|
|
373
|
+
const chosen = Boolean(named) && !refused;
|
|
326
374
|
// An agent on another of the person's computers takes its turn there, in that computer's checkout of the thread's
|
|
327
375
|
// repository (machineRuns.mjs); here it works in the thread's own worktree.
|
|
328
376
|
const elsewhere =
|
|
329
|
-
|
|
377
|
+
placed ??
|
|
378
|
+
(!chosen && !installedAgents.includes(agent)
|
|
330
379
|
? placeElsewhere(agent, task.goal?.workspace ?? null)
|
|
331
|
-
: null;
|
|
332
|
-
if (
|
|
333
|
-
!task ||
|
|
334
|
-
task.status !== "open" ||
|
|
335
|
-
!RUNNERS.has(agent) ||
|
|
336
|
-
(!installedAgents.includes(agent) && !elsewhere)
|
|
337
|
-
)
|
|
338
|
-
return;
|
|
380
|
+
: null);
|
|
381
|
+
if (!installedAgents.includes(agent) && !elsewhere) return;
|
|
339
382
|
const goal = task.goal;
|
|
340
383
|
if (!goal.workspace) {
|
|
341
384
|
if (!store.meta(`goal-folder-note:${goalId}:${agent}`)) {
|
|
@@ -444,6 +487,18 @@ export function createThreadRuns({
|
|
|
444
487
|
asker === "user" || writers.at(-1) === asker
|
|
445
488
|
? writers
|
|
446
489
|
: [...writers, asker];
|
|
490
|
+
// The agent is on more than one computer and the person named none: the thread says once which took it, and how
|
|
491
|
+
// to name the other.
|
|
492
|
+
const choices = computers?.withAgent(agent) ?? [];
|
|
493
|
+
if (!chosen && choices.length > 1) {
|
|
494
|
+
const took = computers.labelOf(elsewhere?.machine ?? self);
|
|
495
|
+
const others = choices.filter((label) => label !== took);
|
|
496
|
+
if (took && others.length)
|
|
497
|
+
noteOnce(
|
|
498
|
+
`computer-note:${goalId}:${agent}`,
|
|
499
|
+
`${nameOf(agent)} on ${took} took this. For ${others.length > 1 ? "another" : "the one on " + others[0]}, write @${agent === "claude-code" ? "claude" : agent} #${computerHandle(others[0])}.`
|
|
500
|
+
);
|
|
501
|
+
}
|
|
447
502
|
const wake = store.postTask({
|
|
448
503
|
objective: `Room: ${task.objective}`.slice(0, 500),
|
|
449
504
|
brief,
|