@excitedjs/dreamux-utils 0.2.0 → 0.3.0-beta.100

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Neutral completion-body resolution shared by every runtime and the host.
2
+ * Neutral completion-body resolution shared by host-side completion targets.
3
3
  *
4
4
  * A teammate completion is delivered back to the dispatcher as turn text. When
5
5
  * the result is short it is inlined verbatim; when it overflows the inline
@@ -7,11 +7,10 @@
7
7
  * host-supplied spill directory and only the path is inlined, so a large result
8
8
  * never floods the dispatcher's context window.
9
9
  *
10
- * The spill directory is supplied by the caller (the host through its path
11
- * context, or a runtime through the create context), so this module owns no
12
- * Dreamux layout contract — only the safe filename shape inside that directory.
10
+ * The spill directory is supplied by the host-side caller, so this module owns
11
+ * no Dreamux layout contract only the safe filename shape inside that
12
+ * directory.
13
13
  */
14
- import type { CompletionEnvelope } from '@excitedjs/dreamux-types';
15
14
  /**
16
15
  * Inline character budget, mirroring claude-code's native task-output budget
17
16
  * (`getMaxTaskOutputLength`): default 32000 chars, `TASK_MAX_OUTPUT_LENGTH`
@@ -26,14 +25,20 @@ export type ResolvedCompletionBody = {
26
25
  kind: 'spilled';
27
26
  path: string;
28
27
  };
28
+ export interface CompletionBodyInput {
29
+ source: string;
30
+ id: string;
31
+ result: string | null;
32
+ }
29
33
  /**
30
34
  * Spill file for a teammate completion result that overflows the inline budget.
31
- * Both runtimes write the full result here and inline only this path into the
32
- * dispatcher turn, so a large result never floods the dispatcher's context.
35
+ * The host writes the full result here and inlines only this path into the
36
+ * dispatcher or TeamLeader turn, so a large result never floods the target
37
+ * agent's context.
33
38
  * `spillDir` is the owning dispatcher's completion spill dir, supplied by the
34
- * caller so a teammate runtime spills under its operator dispatcher, not its
35
- * composite runtime id. `source` and `id` are sanitized for filename safety; the
36
- * id is unique per completion (teammate name + turn id).
39
+ * caller so a TeamLeader delivery target still spills under its operator
40
+ * dispatcher, not its composite runtime id. `source` and `id` are sanitized for
41
+ * filename safety; the id is unique per completion (teammate name + turn id).
37
42
  */
38
43
  export declare function teamMateCompletionOutputPath(spillDir: string, source: string, id: string): string;
39
44
  /**
@@ -52,5 +57,5 @@ export declare function completionInlineBudget(env?: NodeJS.ProcessEnv): number;
52
57
  * that path. `spillDir` is supplied by the caller, so this module stays
53
58
  * runtime-neutral and never names a dispatcher id.
54
59
  */
55
- export declare function resolveCompletionBody(completion: CompletionEnvelope, spillDir: string): Promise<ResolvedCompletionBody>;
60
+ export declare function resolveCompletionBody(completion: CompletionBodyInput, spillDir: string): Promise<ResolvedCompletionBody>;
56
61
  //# sourceMappingURL=completion-body.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"completion-body.d.ts","sourceRoot":"","sources":["../src/completion-body.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAInE;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,QAAS,CAAC;AACvD,eAAO,MAAM,4BAA4B,SAAU,CAAC;AAGpD,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAOtC;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,MAAM,CAAC,UAAmC,GAC9C,MAAM,CAUR;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,kBAAkB,EAC9B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,sBAAsB,CAAC,CAkBjC"}
1
+ {"version":3,"file":"completion-body.d.ts","sourceRoot":"","sources":["../src/completion-body.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,QAAS,CAAC;AACvD,eAAO,MAAM,4BAA4B,SAAU,CAAC;AAGpD,MAAM,MAAM,sBAAsB,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAOD;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,MAAM,CAAC,UAAmC,GAC9C,MAAM,CAUR;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,UAAU,EAAE,mBAAmB,EAC/B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,sBAAsB,CAAC,CAmBjC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Neutral completion-body resolution shared by every runtime and the host.
2
+ * Neutral completion-body resolution shared by host-side completion targets.
3
3
  *
4
4
  * A teammate completion is delivered back to the dispatcher as turn text. When
5
5
  * the result is short it is inlined verbatim; when it overflows the inline
@@ -7,9 +7,9 @@
7
7
  * host-supplied spill directory and only the path is inlined, so a large result
8
8
  * never floods the dispatcher's context window.
9
9
  *
10
- * The spill directory is supplied by the caller (the host through its path
11
- * context, or a runtime through the create context), so this module owns no
12
- * Dreamux layout contract — only the safe filename shape inside that directory.
10
+ * The spill directory is supplied by the host-side caller, so this module owns
11
+ * no Dreamux layout contract only the safe filename shape inside that
12
+ * directory.
13
13
  */
14
14
  import { chmod, writeFile } from 'node:fs/promises';
15
15
  import { join } from 'node:path';
@@ -28,12 +28,13 @@ function safeSegment(name) {
28
28
  }
29
29
  /**
30
30
  * Spill file for a teammate completion result that overflows the inline budget.
31
- * Both runtimes write the full result here and inline only this path into the
32
- * dispatcher turn, so a large result never floods the dispatcher's context.
31
+ * The host writes the full result here and inlines only this path into the
32
+ * dispatcher or TeamLeader turn, so a large result never floods the target
33
+ * agent's context.
33
34
  * `spillDir` is the owning dispatcher's completion spill dir, supplied by the
34
- * caller so a teammate runtime spills under its operator dispatcher, not its
35
- * composite runtime id. `source` and `id` are sanitized for filename safety; the
36
- * id is unique per completion (teammate name + turn id).
35
+ * caller so a TeamLeader delivery target still spills under its operator
36
+ * dispatcher, not its composite runtime id. `source` and `id` are sanitized for
37
+ * filename safety; the id is unique per completion (teammate name + turn id).
37
38
  */
38
39
  export function teamMateCompletionOutputPath(spillDir, source, id) {
39
40
  return join(spillDir, `teammate-${safeSegment(source)}-${safeSegment(id)}.output`);
@@ -65,9 +66,10 @@ export function completionInlineBudget(env = globalThis.process.env) {
65
66
  * runtime-neutral and never names a dispatcher id.
66
67
  */
67
68
  export async function resolveCompletionBody(completion, spillDir) {
69
+ const result = completion.result ?? '';
68
70
  const budget = completionInlineBudget();
69
- if (completion.result.length <= budget) {
70
- return { kind: 'inline', text: completion.result };
71
+ if (result.length <= budget) {
72
+ return { kind: 'inline', text: result };
71
73
  }
72
74
  const path = teamMateCompletionOutputPath(spillDir, completion.source, completion.id);
73
75
  // Owner-only spill dir: the cache may hold full teammate output. Use the
@@ -75,7 +77,7 @@ export async function resolveCompletionBody(completion, spillDir) {
75
77
  // foreign-uid dir is rejected (issue #182 — same invariant as the run tree),
76
78
  // then a 0600 file + explicit chmod (writeFile's `mode` honors the umask).
77
79
  await ensureOwnerOnlyDir(spillDir);
78
- await writeFile(path, completion.result, { mode: 0o600 });
80
+ await writeFile(path, result, { mode: 0o600 });
79
81
  await chmod(path, 0o600);
80
82
  return { kind: 'spilled', path };
81
83
  }
@@ -1 +1 @@
1
- {"version":3,"file":"completion-body.js","sourceRoot":"","sources":["../src/completion-body.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;AACvD,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AACpD,MAAM,4BAA4B,GAAG,wBAAwB,CAAC;AAM9D,uDAAuD;AACvD,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,4BAA4B,CAC1C,QAAgB,EAChB,MAAc,EACd,EAAU;IAEV,OAAO,IAAI,CAAC,QAAQ,EAAE,YAAY,WAAW,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;AACrF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAAyB,UAAU,CAAC,OAAO,CAAC,GAAG;IAE/C,MAAM,GAAG,GAAG,GAAG,CAAC,4BAA4B,CAAC,EAAE,IAAI,EAAE,CAAC;IACtD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,OAAO,gCAAgC,CAAC;IAC1C,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,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EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;IACD,MAAM,IAAI,GAAG,4BAA4B,CACvC,QAAQ,EACR,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,EAAE,CACd,CAAC;IACF,yEAAyE;IACzE,8EAA8E;IAC9E,6EAA6E;IAC7E,2EAA2E;IAC3E,MAAM,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IACnC,MAAM,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,MAAM,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excitedjs/dreamux-utils",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-beta.100",
4
4
  "description": "Pure shared utilities for Dreamux providers and host: neutral config-validation primitives, OS/filesystem helpers, completion-body resolution, and inbound-turn render helpers. Depends on @excitedjs/dreamux-types only, never on @excitedjs/dreamux core (issue excitedjs/dreamux#209).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "LICENSE"
28
28
  ],
29
29
  "dependencies": {
30
- "@excitedjs/dreamux-types": "0.2.0"
30
+ "@excitedjs/dreamux-types": "0.3.0-beta.100"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^22.10.0",