@kirkchinese/harness-forge 0.4.0 → 0.5.0

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.
Files changed (125) hide show
  1. package/README.md +4 -0
  2. package/docs/DETAIL.zh.md +47 -0
  3. package/lib/agents/presets.d.ts +7 -0
  4. package/lib/agents/presets.js +11 -1
  5. package/lib/agents/profiles.js +3 -2
  6. package/lib/agents/row.js +3 -1
  7. package/lib/client/paths.d.ts +12 -0
  8. package/lib/client/paths.js +68 -0
  9. package/lib/client/typert.d.ts +12 -1
  10. package/lib/client/typert.js +54 -6
  11. package/lib/client.js +1593 -270
  12. package/lib/commands/row.js +1 -1
  13. package/lib/context/instructions.js +5 -5
  14. package/lib/dsh/host.d.ts +3 -0
  15. package/lib/dsh/host.js +3 -0
  16. package/lib/forge/contract.d.ts +42 -2
  17. package/lib/forge/contract.js +3 -1
  18. package/lib/forge/follow.d.ts +30 -0
  19. package/lib/forge/follow.js +73 -0
  20. package/lib/forge/ledger.d.ts +70 -7
  21. package/lib/forge/ledger.js +314 -42
  22. package/lib/forge/projects.d.ts +5 -2
  23. package/lib/forge/projects.js +23 -16
  24. package/lib/forge/remote/archive.d.ts +65 -0
  25. package/lib/forge/remote/archive.js +565 -0
  26. package/lib/forge/remote/code-parts.d.ts +18 -0
  27. package/lib/forge/remote/code-parts.js +76 -0
  28. package/lib/forge/remote/fetch.d.ts +265 -0
  29. package/lib/forge/remote/fetch.js +1133 -0
  30. package/lib/forge/remote/service.d.ts +256 -0
  31. package/lib/forge/remote/service.js +868 -0
  32. package/lib/forge/service.d.ts +19 -9
  33. package/lib/forge/service.js +47 -31
  34. package/lib/forge/settings.d.ts +5 -3
  35. package/lib/forge/settings.js +11 -4
  36. package/lib/forge/state.d.ts +60 -0
  37. package/lib/forge/state.js +174 -58
  38. package/lib/hooks/broker/engine.js +2 -8
  39. package/lib/hooks/broker/session-events.d.ts +5 -0
  40. package/lib/hooks/broker/session-events.js +12 -3
  41. package/lib/hooks/broker/types.d.ts +7 -5
  42. package/lib/hooks/condition.d.ts +78 -2
  43. package/lib/hooks/condition.js +494 -73
  44. package/lib/hooks/config.d.ts +1 -1
  45. package/lib/hooks/config.js +4 -0
  46. package/lib/hooks/glob.d.ts +41 -0
  47. package/lib/hooks/glob.js +114 -0
  48. package/lib/hooks/permissions.d.ts +8 -3
  49. package/lib/hooks/permissions.js +119 -26
  50. package/lib/hooks/powershell-aliases.d.ts +19 -0
  51. package/lib/hooks/powershell-aliases.js +58 -0
  52. package/lib/hooks/process.d.ts +17 -0
  53. package/lib/hooks/process.js +156 -1
  54. package/lib/hooks/row.js +2 -0
  55. package/lib/hooks/runner.d.ts +17 -4
  56. package/lib/hooks/runner.js +42 -13
  57. package/lib/hooks/shell-commands.d.ts +10 -1
  58. package/lib/hooks/shell-commands.js +74 -10
  59. package/lib/hooks/shell.d.ts +3 -2
  60. package/lib/hooks/shell.js +5 -2
  61. package/lib/hooks/vocabulary.js +3 -1
  62. package/lib/mcp/catalog.d.ts +5 -2
  63. package/lib/mcp/catalog.js +18 -10
  64. package/lib/mcp/mount.d.ts +40 -2
  65. package/lib/mcp/mount.js +131 -31
  66. package/lib/mcp/policy.d.ts +42 -0
  67. package/lib/mcp/policy.js +43 -0
  68. package/lib/mcp/remote.js +5 -15
  69. package/lib/mcp/row.js +111 -17
  70. package/lib/mods/loader.js +4 -0
  71. package/lib/mods/service/turns.d.ts +8 -7
  72. package/lib/mods/service/turns.js +10 -35
  73. package/lib/opencode/bun.js +14 -2
  74. package/lib/opencode/row.d.ts +14 -1
  75. package/lib/opencode/row.js +38 -20
  76. package/lib/opencode/runtime/server.js +2 -1
  77. package/lib/porting/adapter-paths.d.ts +13 -0
  78. package/lib/porting/adapter-paths.js +120 -0
  79. package/lib/porting/port-gap.d.ts +10 -4
  80. package/lib/porting/port-gap.js +43 -7
  81. package/lib/porting/prompt.js +9 -7
  82. package/lib/porting/row.js +7 -5
  83. package/lib/porting/verify-port.d.ts +3 -10
  84. package/lib/porting/verify-port.js +12 -34
  85. package/lib/sessions/chat-import.d.ts +48 -0
  86. package/lib/sessions/chat-import.js +44 -0
  87. package/lib/sessions/claude.d.ts +16 -10
  88. package/lib/sessions/claude.js +76 -55
  89. package/lib/sessions/codex-discover.d.ts +34 -0
  90. package/lib/sessions/codex-discover.js +205 -0
  91. package/lib/sessions/codex-meta.d.ts +63 -0
  92. package/lib/sessions/codex-meta.js +148 -0
  93. package/lib/sessions/codex-text.d.ts +9 -0
  94. package/lib/sessions/codex-text.js +44 -0
  95. package/lib/sessions/codex.d.ts +34 -22
  96. package/lib/sessions/codex.js +150 -183
  97. package/lib/sessions/opencode.d.ts +15 -9
  98. package/lib/sessions/opencode.js +77 -58
  99. package/lib/sessions/persist.d.ts +162 -0
  100. package/lib/sessions/persist.js +377 -0
  101. package/lib/sessions/row.d.ts +2 -1
  102. package/lib/sessions/row.js +75 -9
  103. package/lib/sessions/turns.d.ts +31 -0
  104. package/lib/sessions/turns.js +63 -0
  105. package/lib/sessions/zstd.d.ts +15 -0
  106. package/lib/sessions/zstd.js +152 -0
  107. package/lib/shared/render.d.ts +30 -1
  108. package/lib/shared/render.js +813 -48
  109. package/lib/skills/provider.d.ts +2 -0
  110. package/lib/skills/provider.js +8 -2
  111. package/lib/skills/row.js +1 -1
  112. package/lib/workbench/adapter-coverage.d.ts +20 -2
  113. package/lib/workbench/adapter-coverage.js +46 -7
  114. package/lib/workbench/overview.d.ts +77 -27
  115. package/lib/workbench/overview.js +99 -12
  116. package/lib/workbench/remote.d.ts +64 -21
  117. package/lib/workbench/remote.js +181 -42
  118. package/lib/workbench/settings.d.ts +5 -1
  119. package/lib/workbench/settings.js +6 -2
  120. package/lib/workbench/workbench.d.ts +34 -4
  121. package/lib/workbench/workbench.js +147 -46
  122. package/locale/zh.json +2 -1
  123. package/package.json +3 -2
  124. package/lib/forge/marketplace-install.d.ts +0 -3
  125. package/lib/forge/marketplace-install.js +0 -64
@@ -0,0 +1,152 @@
1
+ /**
2
+ * zstd decoding of compressed Codex rollouts (`rollout-*.jsonl.zst`, Codex 0.167+) with Node's own `zlib`.
3
+ * A file written in pieces is several concatenated zstd frames, and Node's decoder decodes only the first; so the
4
+ * frames are found by walking their headers and block sizes as the file streams by, and decoded one by one.
5
+ * @module @kirkchinese/harness-forge
6
+ */
7
+ import { createReadStream } from 'node:fs';
8
+ import { Readable } from 'node:stream';
9
+ import * as zlib from 'node:zlib';
10
+ import { READ_CHUNK_BYTES } from '@kirkchinese/harness-forge-core';
11
+ const FRAME_MAGIC = 0xFD2FB528;
12
+ const SKIPPABLE_MASK = 0xFFFFFFF0;
13
+ const SKIPPABLE_MAGIC = 0x184D2A50;
14
+ /** Whether this Node can read compressed rollouts (`zlib.createZstdDecompress`, Node 22.15+). */
15
+ export function zstdAvailable() {
16
+ return typeof zlib.createZstdDecompress === 'function';
17
+ }
18
+ /**
19
+ * The first `maxBytes` of a zstd file's text, without decoding the rest: the compressed bytes are streamed through the
20
+ * decoder, which is dropped once enough text came out. A stream cut inside a frame (the read stops early) is fine,
21
+ * and so is the decoder's complaint about it.
22
+ */
23
+ export function decodeZstdHead(compressed, maxBytes) {
24
+ const create = zlib.createZstdDecompress;
25
+ if (create === undefined)
26
+ return Promise.reject(new Error('this Node has no zstd support (Node 22.15+ has it)'));
27
+ return new Promise((resolve) => {
28
+ const chunks = [];
29
+ let size = 0;
30
+ let done = false;
31
+ const decoder = create();
32
+ const finish = () => {
33
+ if (done)
34
+ return;
35
+ done = true;
36
+ decoder.destroy();
37
+ resolve(Buffer.concat(chunks).subarray(0, maxBytes).toString('utf8'));
38
+ };
39
+ decoder.on('data', (chunk) => {
40
+ chunks.push(chunk);
41
+ size += chunk.length;
42
+ if (size >= maxBytes)
43
+ finish();
44
+ });
45
+ decoder.on('end', finish);
46
+ decoder.on('error', finish);
47
+ decoder.on('close', finish);
48
+ Readable.from([Buffer.from(compressed.buffer, compressed.byteOffset, compressed.byteLength)]).pipe(decoder);
49
+ });
50
+ }
51
+ /** Reads exactly-sized pieces from a byte stream, holding no more than the chunk being read. */
52
+ class ByteReader {
53
+ fail;
54
+ source;
55
+ pending = Buffer.alloc(0);
56
+ constructor(source, fail) {
57
+ this.fail = fail;
58
+ this.source = source[Symbol.asyncIterator]();
59
+ }
60
+ /** The next `size` bytes; `undefined` at the end of the stream when `optional` and nothing is left, else a malformed file. */
61
+ async take(size, optional = false) {
62
+ const parts = [];
63
+ let have = 0;
64
+ while (have < size) {
65
+ if (this.pending.length === 0) {
66
+ const next = await this.source.next();
67
+ if (next.done === true) {
68
+ if (optional && have === 0)
69
+ return undefined;
70
+ return this.fail();
71
+ }
72
+ this.pending = Buffer.from(next.value.buffer, next.value.byteOffset, next.value.byteLength);
73
+ continue;
74
+ }
75
+ const piece = this.pending.subarray(0, size - have);
76
+ this.pending = this.pending.subarray(piece.length);
77
+ parts.push(piece);
78
+ have += piece.length;
79
+ }
80
+ return parts.length === 1 ? parts[0] : Buffer.concat(parts);
81
+ }
82
+ async skip(size) {
83
+ for (let left = size; left > 0; left -= 65536)
84
+ await this.take(Math.min(left, 65536));
85
+ }
86
+ }
87
+ /** The bytes of one data frame, in the pieces its structure falls into (header, then each block); `first` is its magic, already read. */
88
+ async function* framePieces(reader, first, fail) {
89
+ yield first;
90
+ const descriptor = (await reader.take(1))[0];
91
+ const contentSizeFlag = descriptor >> 6;
92
+ const singleSegment = (descriptor >> 5) & 1;
93
+ const checksum = (descriptor >> 2) & 1;
94
+ const dictionaryFlag = descriptor & 3;
95
+ const rest = (singleSegment === 1 ? 0 : 1) + [0, 1, 2, 4][dictionaryFlag] + [singleSegment === 1 ? 1 : 0, 2, 4, 8][contentSizeFlag];
96
+ yield Buffer.concat([Buffer.from([descriptor]), rest > 0 ? (await reader.take(rest)) : Buffer.alloc(0)]);
97
+ for (let last = false; !last;) {
98
+ const head = (await reader.take(3));
99
+ const header = head[0] | (head[1] << 8) | (head[2] << 16);
100
+ last = (header & 1) === 1;
101
+ const type = (header >> 1) & 3;
102
+ if (type === 3)
103
+ fail();
104
+ // A run-length block stores one byte, however long the run it stands for.
105
+ const body = (await reader.take(type === 1 ? 1 : header >>> 3));
106
+ yield Buffer.concat([head, body]);
107
+ }
108
+ if (checksum === 1)
109
+ yield (await reader.take(4));
110
+ }
111
+ /**
112
+ * The decoded bytes of a zstd file, streamed. Node's decoder stops after the first frame of a stream just as
113
+ * the one-shot decoder does, so the frames are found by walking their headers and block sizes as the file is read,
114
+ * and each is decoded by a decoder of its own: nothing but one frame's current block is held. Throws on a malformed
115
+ * or truncated file, naming `path`.
116
+ */
117
+ export async function* zstdChunks(path) {
118
+ const create = zlib.createZstdDecompress;
119
+ if (create === undefined)
120
+ throw new Error(`cannot read ${path}: this Node has no zstd support (Node 22.15+ has it)`);
121
+ const fail = () => { throw new Error(`cannot read ${path}: malformed or truncated zstd data`); };
122
+ const file = createReadStream(path, { highWaterMark: READ_CHUNK_BYTES });
123
+ const reader = new ByteReader(file, fail);
124
+ try {
125
+ for (;;) {
126
+ const magicBytes = await reader.take(4, true);
127
+ if (magicBytes === undefined)
128
+ return;
129
+ const magic = magicBytes.readUInt32LE(0);
130
+ if ((magic & SKIPPABLE_MASK) >>> 0 === SKIPPABLE_MAGIC) {
131
+ await reader.skip((await reader.take(4)).readUInt32LE(0));
132
+ continue;
133
+ }
134
+ if (magic !== FRAME_MAGIC)
135
+ fail();
136
+ const decoder = create();
137
+ const source = Readable.from(framePieces(reader, magicBytes, fail));
138
+ source.on('error', (error) => { decoder.destroy(error); });
139
+ try {
140
+ for await (const chunk of source.pipe(decoder))
141
+ yield chunk;
142
+ }
143
+ finally {
144
+ source.destroy();
145
+ decoder.destroy();
146
+ }
147
+ }
148
+ }
149
+ finally {
150
+ file.destroy();
151
+ }
152
+ }
@@ -48,12 +48,41 @@ export declare function renderCodexPrompt(body: string, rawArguments: string): R
48
48
  export declare function splitArguments(raw: string): string[];
49
49
  /** The environment variable that will hold a placeholder's value, or undefined to leave the placeholder as written. */
50
50
  type ValueOf = (match: string, variable: string | undefined, indexed: string | undefined, short: string | undefined, name: string | undefined) => string | undefined;
51
- /** A shell line ready to run, or why it may not run. */
51
+ /**
52
+ * A shell line ready to run, or why it may not run. `operands` names the
53
+ * variables whose value starts a word where a program reads options: the
54
+ * line may run only if none of those values starts with `-`.
55
+ */
52
56
  export type ShellLine = {
53
57
  readonly command: string;
58
+ readonly operands: readonly string[];
59
+ /** Its simple commands, for the write-then-run check across the shell lines of one body. */
60
+ readonly steps: readonly ShellStep[];
61
+ /** It carries a value someone chose (an argument; not a path variable the host sets). */
62
+ readonly chosen: boolean;
54
63
  } | {
55
64
  readonly refused: string;
56
65
  };
66
+ /** One simple command of a shell text, as the write-then-run check sees it. */
67
+ export interface ShellStep {
68
+ readonly writes: boolean;
69
+ readonly executes: boolean;
70
+ /**
71
+ * Constructs whose commands run in an order not known statically: its pipeline and the outermost loop,
72
+ * conditional, subshell or group it stands in. Constructs nest, so two commands share one exactly when they
73
+ * share the outermost: a fixed number of groups per command, whatever the nesting depth.
74
+ */
75
+ readonly groups: readonly string[];
76
+ /** Run in the background: concurrently with every later command. */
77
+ readonly background: boolean;
78
+ }
79
+ /**
80
+ * Whether a command that runs a file comes after one that writes a file, in
81
+ * the order the steps are given: later, inside a common pipeline, loop,
82
+ * conditional, subshell or group, or concurrently with it (in the background).
83
+ * A value written there could then run as code.
84
+ */
85
+ export declare function writesThenRuns(steps: readonly ShellStep[]): boolean;
57
86
  /**
58
87
  * A shell line with each placeholder replaced by a reference to an
59
88
  * environment variable holding its value. Values never enter the source: a