@shumkov/orchestra 0.10.9 → 0.10.11
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/docs/EXTRACTION.md +12 -2
- package/lib/process/cli-process.js +32 -7
- package/lib/process/factory.js +25 -10
- package/lib/process/process-manager.js +33 -6
- package/package.json +1 -1
package/docs/EXTRACTION.md
CHANGED
|
@@ -32,8 +32,18 @@ Telegram or WhatsApp:
|
|
|
32
32
|
|
|
33
33
|
- `toolDispatcher(call) => {ok, error?, message_id?}` — delivers reply/edit/react on the
|
|
34
34
|
consumer's transport (already injected in polygram/water today).
|
|
35
|
-
- `displayHint: string` — surface-rendering rules
|
|
36
|
-
(**new option**, replacing cli-process's hard
|
|
35
|
+
- `displayHint: string | (chatId, threadId, config) => string` — surface-rendering rules
|
|
36
|
+
appended to the system prompt (**new option**, replacing cli-process's hard
|
|
37
|
+
`require('../delivery/display-hint')`). A resolver is called once per spawn, so the hint
|
|
38
|
+
can vary per chat/topic.
|
|
39
|
+
**Contract for a hint that can change** (e.g. a per-chat rich-text toggle): the hint is
|
|
40
|
+
spawn-time state, so a change reaches a warm session only by respawning it. The consumer
|
|
41
|
+
must put the identical resolved string on the spawn context as `spawnContext.displayHint`.
|
|
42
|
+
That string is what `getOrSpawn` compares against the warm proc to detect the change, and
|
|
43
|
+
it is what the respawn is constructed with — the resolver is only the fallback for a
|
|
44
|
+
context that carries no hint. Two independent sources is the failure mode to avoid: if a
|
|
45
|
+
consumer's context string and its resolver disagree by one character, every message looks
|
|
46
|
+
like drift and the session respawns forever.
|
|
37
47
|
- `maxOutboundFileBytes: number` — outbound file cap (**new option**, replacing
|
|
38
48
|
`require('../attachments').resolveFileCaps`).
|
|
39
49
|
- `claudeBin`, `botName`, `tmuxRunner`, `logger`, `db` (telemetry) — as today.
|
|
@@ -351,7 +351,10 @@ class CliProcess extends Process {
|
|
|
351
351
|
// PreToolUse/PostToolUse matcher is `.*`, so the agent's own stream calls
|
|
352
352
|
// arrive here as work hooks — see _handleHookEvent for why that matters.
|
|
353
353
|
this._streamToolHookName = `mcp__${bridgeServerName}__stream`;
|
|
354
|
-
|
|
354
|
+
// Normalized to a string: the drift check compares with !== against the
|
|
355
|
+
// spawn context's string hint, so a null (from a resolver that returned
|
|
356
|
+
// one) would be drift no context could ever match — a permanent respawn.
|
|
357
|
+
this.displayHint = typeof displayHint === 'string' ? displayHint : '';
|
|
355
358
|
this._injectedMaxOutboundFileBytes = maxOutboundFileBytes;
|
|
356
359
|
this.sessionPrefix = sessionPrefix;
|
|
357
360
|
this.bridgeServerName = bridgeServerName;
|
|
@@ -1131,9 +1134,11 @@ class CliProcess extends Process {
|
|
|
1131
1134
|
'',
|
|
1132
1135
|
'Media never enters a streamed message. A streamed bubble finalizes by',
|
|
1133
1136
|
'editing, and an edited bubble can never gain media — photos degrade to',
|
|
1134
|
-
'their caption text. When your answer includes media
|
|
1135
|
-
'
|
|
1136
|
-
'
|
|
1137
|
+
'their caption text. When your answer includes media (inline images, a',
|
|
1138
|
+
'collage, a slideshow), SKIP streaming for that answer entirely: compose',
|
|
1139
|
+
'it and send ONE normal reply, where the media renders inline in the',
|
|
1140
|
+
'rich document, pictures in place. Do NOT stream the prose first and do',
|
|
1141
|
+
'NOT split the media into a separate message.',
|
|
1137
1142
|
'',
|
|
1138
1143
|
] : []),
|
|
1139
1144
|
// TEMPORARY mitigation (2026-06-08 Shumabit@UMI wedge): AskUserQuestion opens
|
|
@@ -3843,9 +3848,29 @@ class CliProcess extends Process {
|
|
|
3843
3848
|
* @returns {boolean}
|
|
3844
3849
|
*/
|
|
3845
3850
|
wouldReloadFor(spawnContext) {
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3851
|
+
return this.reloadReasonsFor(spawnContext).length > 0;
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
/**
|
|
3855
|
+
* Which spawn-time dimensions have drifted — the drift check itself, with the
|
|
3856
|
+
* answer named so telemetry can tell a rendering toggle from a /model change.
|
|
3857
|
+
* The display hint is spawn-time too (it is woven into the appended system
|
|
3858
|
+
* prompt), so a consumer that varies it per chat needs the same treatment as
|
|
3859
|
+
* model/effort. A spawn context that carries no hint at all is a consumer on
|
|
3860
|
+
* an older build: `undefined` must not read as "drifted to empty", which would
|
|
3861
|
+
* respawn every session on every message.
|
|
3862
|
+
* @returns {string[]} empty when nothing drifted or a reload is not possible
|
|
3863
|
+
*/
|
|
3864
|
+
reloadReasonsFor(spawnContext) {
|
|
3865
|
+
if (this.inFlight || this.closed) return [];
|
|
3866
|
+
const reasons = [];
|
|
3867
|
+
if (this._resolveModel(spawnContext) !== this.model) reasons.push('model');
|
|
3868
|
+
if (this._resolveEffort(spawnContext) !== this.effort) reasons.push('effort');
|
|
3869
|
+
if (
|
|
3870
|
+
typeof spawnContext?.displayHint === 'string'
|
|
3871
|
+
&& spawnContext.displayHint !== this.displayHint
|
|
3872
|
+
) reasons.push('display-hint');
|
|
3873
|
+
return reasons;
|
|
3849
3874
|
}
|
|
3850
3875
|
|
|
3851
3876
|
/**
|
package/lib/process/factory.js
CHANGED
|
@@ -420,9 +420,17 @@ function _maybeWarnR12Migration({ rawPm, canonical, chatId, threadId, chatCfg, t
|
|
|
420
420
|
* spawn, just before the CliProcess is constructed. The resolver receives the
|
|
421
421
|
* spawning chat/topic and the factory's config so the consumer can implement its
|
|
422
422
|
* own per-chat/topic precedence (e.g. a per-chat rich-text toggle) without the
|
|
423
|
-
* engine knowing anything about the consumer's config shape.
|
|
424
|
-
*
|
|
425
|
-
*
|
|
423
|
+
* engine knowing anything about the consumer's config shape. Only the 'cli'
|
|
424
|
+
* backend uses this; the 'sdk' backend gets its per-chat hint via spawnFn instead.
|
|
425
|
+
*
|
|
426
|
+
* A `spawnContext.displayHint` string OVERRIDES both forms, and a consumer whose
|
|
427
|
+
* hint can change must send one: the hint is spawn-time state, so a change reaches
|
|
428
|
+
* a warm session only through getOrSpawn's reload-on-drift, which compares the
|
|
429
|
+
* context's hint against the warm proc's. Passing the identical resolved string on
|
|
430
|
+
* the context makes the reload and the respawn one source — resolving independently
|
|
431
|
+
* here would make them two, and a one-character disagreement would respawn the
|
|
432
|
+
* session on every message forever. The resolver remains the fallback for consumers
|
|
433
|
+
* that send no hint on the context.
|
|
426
434
|
* @param {Function} [opts.codexClientFactory] — trusted Codex app-server client
|
|
427
435
|
* factory. Required only when spawnContext.runtime is exactly 'codex'.
|
|
428
436
|
* @param {Function} [opts.codexCheckpointSink] — acknowledged durability sink.
|
|
@@ -515,13 +523,20 @@ function createProcessFactory({
|
|
|
515
523
|
`falling back to SdkProcess. Pass these to createProcessFactory.`,
|
|
516
524
|
);
|
|
517
525
|
} else {
|
|
518
|
-
//
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
526
|
+
// The spawn context's hint wins whenever it carries one. getOrSpawn's
|
|
527
|
+
// reload-on-drift compares THAT string against the warm proc's, so the
|
|
528
|
+
// respawn must carry the same one — resolving independently here would
|
|
529
|
+
// make apply-path and detect-path two sources, and a one-character
|
|
530
|
+
// disagreement between them respawns the session on every message,
|
|
531
|
+
// forever. The resolver stays the fallback for consumers that send no
|
|
532
|
+
// hint on the context: a static string (same hint for every session) or
|
|
533
|
+
// a function called per spawn with the current chat/topic and config, so
|
|
534
|
+
// the consumer can vary the hint per chat (e.g. a rich-text toggle).
|
|
535
|
+
const resolvedDisplayHint = typeof ctx?.displayHint === 'string'
|
|
536
|
+
? ctx.displayHint
|
|
537
|
+
: typeof displayHint === 'function'
|
|
538
|
+
? displayHint(chatId, threadId, config)
|
|
539
|
+
: displayHint;
|
|
525
540
|
// Same string-or-resolver shape as displayHint: the optional tools a
|
|
526
541
|
// consumer can honor may vary per chat/topic (a live preview is a
|
|
527
542
|
// per-chat rollout decision), and the prompt section that teaches them
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
|
|
30
30
|
'use strict';
|
|
31
31
|
|
|
32
|
+
const { createHash } = require('node:crypto');
|
|
33
|
+
|
|
32
34
|
const DEFAULT_BUDGET = 10; // total Σ cost (SDK cost=1, tmux cost=3)
|
|
33
35
|
const DEFAULT_LRU_WAIT_MS = 300_000;
|
|
34
36
|
const DEFAULT_CODEX_RETIREMENT_TIMEOUT_MS = 30_000;
|
|
@@ -47,6 +49,19 @@ function managerError(message, code, options) {
|
|
|
47
49
|
return new ProcessManagerError(message, code, options);
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Identify a display hint in telemetry without storing it. The hint is a
|
|
54
|
+
* multi-KB system-prompt block and the events table has no retention, so only
|
|
55
|
+
* a fingerprint may be logged — enough to tell a real toggle (two reloads, two
|
|
56
|
+
* different fingerprints) from a treadmill (the same pair, over and over).
|
|
57
|
+
*/
|
|
58
|
+
function hintFingerprint(hint) {
|
|
59
|
+
return createHash('sha256')
|
|
60
|
+
.update(typeof hint === 'string' ? hint : '')
|
|
61
|
+
.digest('hex')
|
|
62
|
+
.slice(0, 8);
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
function findCodexRetirementVerificationError(error) {
|
|
51
66
|
let current = error;
|
|
52
67
|
for (let depth = 0; current && depth < 8; depth += 1) {
|
|
@@ -544,12 +559,12 @@ class ProcessManager {
|
|
|
544
559
|
if (this._identityFor(existing).key !== desired.key) {
|
|
545
560
|
return this._replaceRuntimeLocked(sessionKey, spawnContext, desired);
|
|
546
561
|
}
|
|
547
|
-
// Reload-on-drift (cli): a warm cli proc can't hot-swap model/effort
|
|
548
|
-
// (spawn-time
|
|
549
|
-
// idle, kill it (preserves session_id) and fall through to
|
|
550
|
-
// → --resume keeps the conversation, the new
|
|
551
|
-
// effect. In-flight cli procs and SDK procs
|
|
552
|
-
// apply model live) are reused unchanged.
|
|
562
|
+
// Reload-on-drift (cli): a warm cli proc can't hot-swap model/effort or
|
|
563
|
+
// its display hint (all spawn-time). If the resolved config has drifted
|
|
564
|
+
// and the proc is idle, kill it (preserves session_id) and fall through to
|
|
565
|
+
// a cold respawn → --resume keeps the conversation, the new
|
|
566
|
+
// --model/--effort/hint takes effect. In-flight cli procs and SDK procs
|
|
567
|
+
// (no wouldReloadFor — they apply model live) are reused unchanged.
|
|
553
568
|
if (this._isCodex(existing) && existing.state === 'Stopped') {
|
|
554
569
|
await this._killLocked(sessionKey, 'stopped-generation');
|
|
555
570
|
this._throwIfShuttingDown();
|
|
@@ -557,10 +572,22 @@ class ProcessManager {
|
|
|
557
572
|
typeof existing.wouldReloadFor === 'function'
|
|
558
573
|
&& existing.wouldReloadFor(spawnContext)
|
|
559
574
|
) {
|
|
575
|
+
// Which dimension(s) drifted — soak reads this to tell a per-chat
|
|
576
|
+
// rendering toggle from a /model or /effort change. A hint reload also
|
|
577
|
+
// carries both fingerprints (never the hint itself), so a session that
|
|
578
|
+
// respawns on every message is distinguishable from one that toggled.
|
|
579
|
+
const reasons = typeof existing.reloadReasonsFor === 'function'
|
|
580
|
+
? existing.reloadReasonsFor(spawnContext)
|
|
581
|
+
: null;
|
|
560
582
|
this._logEvent('cli-config-reload', {
|
|
561
583
|
sessionKey,
|
|
562
584
|
from_model: existing.model,
|
|
563
585
|
from_effort: existing.effort,
|
|
586
|
+
reason: reasons ? reasons.join(',') : null,
|
|
587
|
+
...(reasons?.includes('display-hint') && {
|
|
588
|
+
from_hint_hash: hintFingerprint(existing.displayHint),
|
|
589
|
+
to_hint_hash: hintFingerprint(spawnContext?.displayHint),
|
|
590
|
+
}),
|
|
564
591
|
});
|
|
565
592
|
await this._killLocked(sessionKey, 'config-reload');
|
|
566
593
|
this._throwIfShuttingDown();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shumkov/orchestra",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.11",
|
|
4
4
|
"description": "Transport-agnostic session engine for Claude Code and the native Codex app-server: spawn, steer, supervise, observe turns, and recover.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|