@kirkchinese/harness-forge-core 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 (56) hide show
  1. package/lib/assess.js +24 -4
  2. package/lib/contracts.d.ts +1 -1
  3. package/lib/dialects/claude-code/index.js +38 -41
  4. package/lib/dialects/claude-code/sessions/discover.js +31 -17
  5. package/lib/dialects/claude-code/sessions/parse.js +89 -83
  6. package/lib/dialects/claude-code/sessions/title.d.ts +23 -0
  7. package/lib/dialects/claude-code/sessions/title.js +74 -0
  8. package/lib/dialects/claude-code/statusline.d.ts +12 -0
  9. package/lib/dialects/claude-code/statusline.js +74 -0
  10. package/lib/dialects/claude-code/user-assets.d.ts +37 -6
  11. package/lib/dialects/claude-code/user-assets.js +155 -34
  12. package/lib/dialects/codex/index.js +8 -1
  13. package/lib/dialects/codex/mcp-server.d.ts +17 -0
  14. package/lib/dialects/codex/mcp-server.js +116 -0
  15. package/lib/dialects/codex/plugins.d.ts +16 -0
  16. package/lib/dialects/codex/plugins.js +120 -0
  17. package/lib/dialects/codex/user-assets.d.ts +10 -6
  18. package/lib/dialects/codex/user-assets.js +26 -42
  19. package/lib/dialects/opencode/index.js +43 -8
  20. package/lib/dialects/opencode/inventory.d.ts +100 -0
  21. package/lib/dialects/opencode/inventory.js +318 -0
  22. package/lib/dialects/opencode/plugin-id.d.ts +21 -0
  23. package/lib/dialects/opencode/plugin-id.js +296 -0
  24. package/lib/dialects/opencode/scan.d.ts +22 -0
  25. package/lib/dialects/opencode/scan.js +119 -121
  26. package/lib/dialects/types.d.ts +60 -6
  27. package/lib/discover.d.ts +32 -7
  28. package/lib/discover.js +58 -17
  29. package/lib/fingerprint.js +7 -0
  30. package/lib/harness-installs.d.ts +42 -0
  31. package/lib/harness-installs.js +59 -0
  32. package/lib/index.d.ts +6 -0
  33. package/lib/index.js +5 -0
  34. package/lib/instructions.d.ts +28 -2
  35. package/lib/instructions.js +202 -30
  36. package/lib/license.js +12 -11
  37. package/lib/manifest.d.ts +6 -0
  38. package/lib/manifest.js +41 -12
  39. package/lib/marketplace.d.ts +15 -1
  40. package/lib/marketplace.js +55 -38
  41. package/lib/paths.d.ts +65 -0
  42. package/lib/paths.js +152 -2
  43. package/lib/plan.js +3 -1
  44. package/lib/port-brief.d.ts +28 -5
  45. package/lib/port-brief.js +52 -10
  46. package/lib/remote.d.ts +121 -0
  47. package/lib/remote.js +352 -0
  48. package/lib/sessions/index.d.ts +1 -0
  49. package/lib/sessions/index.js +1 -0
  50. package/lib/sessions/lines.d.ts +57 -0
  51. package/lib/sessions/lines.js +122 -0
  52. package/lib/text.d.ts +9 -0
  53. package/lib/text.js +19 -0
  54. package/lib/trust.js +19 -6
  55. package/lib/types.d.ts +48 -1
  56. package/package.json +1 -1
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The largest transcript, in bytes, that is imported (decompressed, for a compressed one). Decimal megabytes, as the
3
+ * messages say them. Measured on synthetic rollouts (Node 22, parse + synthesize, peak RSS over a 44 MB idle process):
4
+ * 100 MB of plain conversation text peaks at 207 MB, 200 MB at 323 MB; the same 200 MB of mostly reasoning blobs, 126 MB
5
+ * (the old whole-file read: 467 MB either way). The conversation is then written to, and held by, the DSH server in
6
+ * several copies, so the ceiling leaves room for that.
7
+ */
8
+ export declare const MAX_SESSION_BYTES = 100000000;
9
+ /** The longest single line kept. A longer one is a pasted image or an opaque blob, never prose; it is skipped. */
10
+ export declare const MAX_LINE_BYTES: number;
11
+ /**
12
+ * How much of a transcript file is read at a time. A megabyte keeps the number of reads of a gigabyte rollout in
13
+ * the thousands while staying small next to the line limit and the server's memory.
14
+ */
15
+ export declare const READ_CHUNK_BYTES: number;
16
+ /** A byte count as the person reads it: `463 MB`, `1.2 GB`, `38 KB`. */
17
+ export declare function formatBytes(bytes: number): string;
18
+ /** A transcript above the ceiling; thrown before it is read (or, compressed, as soon as the decoded size shows it). */
19
+ export declare class SessionTooLargeError extends Error {
20
+ /** The transcript's size; absent when only "more than the limit" is known (a compressed one, cut off while decoding). */
21
+ readonly bytes: number | undefined;
22
+ readonly limit: number;
23
+ readonly code = "session-too-large";
24
+ constructor(
25
+ /** The transcript's size; absent when only "more than the limit" is known (a compressed one, cut off while decoding). */
26
+ bytes: number | undefined, limit?: number);
27
+ }
28
+ /** Throw a {@link SessionTooLargeError} when `bytes` is above the ceiling. */
29
+ export declare function assertSessionSize(bytes: number, limit?: number): void;
30
+ /** The size of a file, and throws when it is above the ceiling: call before reading anything. */
31
+ export declare function assertFileImportable(path: string, limit?: number): Promise<number>;
32
+ /** One line of a transcript. `oversized` lines are not read: their `text` is empty. */
33
+ export interface TranscriptLine {
34
+ /** 1-based position in the file, counting blank lines. */
35
+ readonly number: number;
36
+ readonly text: string;
37
+ readonly oversized: boolean;
38
+ }
39
+ /** Watches what a line splitter holds, so a test can bound it without sampling the process's memory. */
40
+ export interface LineObserver {
41
+ /** The splitter holds `bytes` at once: the chunk it is splitting and the start of a line carried over from before. */
42
+ held(bytes: number): void;
43
+ }
44
+ /**
45
+ * Split a byte stream into lines on `\n`, holding at most one line (and never more than `maxLine` bytes of it) at a
46
+ * time. A line above `maxLine` is skipped to its end and reported as `oversized`.
47
+ */
48
+ export declare function splitLines(chunks: AsyncIterable<Uint8Array>, maxLine?: number, observer?: LineObserver): AsyncGenerator<TranscriptLine>;
49
+ /** How a transcript file is read. */
50
+ export interface FileLinesOptions {
51
+ readonly signal?: AbortSignal;
52
+ readonly observer?: LineObserver;
53
+ }
54
+ /** The lines of a plain-text transcript, streamed from disk; a file that grows past the ceiling while it is read stops the read. */
55
+ export declare function fileLines(path: string, options?: FileLinesOptions): AsyncGenerator<TranscriptLine>;
56
+ /** Counts the bytes of a stream as they pass and throws {@link SessionTooLargeError} past the ceiling. */
57
+ export declare function limitBytes(chunks: AsyncIterable<Uint8Array>, limit?: number): AsyncGenerator<Uint8Array>;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Reading a session transcript without holding it: a size ceiling decided before anything is read, and a line
3
+ * splitter over a byte stream, so an importer sees one record at a time. Importers run inside the DSH server, whose
4
+ * memory they must not take: a rollout can be a gigabyte.
5
+ * @module @kirkchinese/harness-forge-core
6
+ */
7
+ import { createReadStream } from 'node:fs';
8
+ import { stat } from 'node:fs/promises';
9
+ /**
10
+ * The largest transcript, in bytes, that is imported (decompressed, for a compressed one). Decimal megabytes, as the
11
+ * messages say them. Measured on synthetic rollouts (Node 22, parse + synthesize, peak RSS over a 44 MB idle process):
12
+ * 100 MB of plain conversation text peaks at 207 MB, 200 MB at 323 MB; the same 200 MB of mostly reasoning blobs, 126 MB
13
+ * (the old whole-file read: 467 MB either way). The conversation is then written to, and held by, the DSH server in
14
+ * several copies, so the ceiling leaves room for that.
15
+ */
16
+ export const MAX_SESSION_BYTES = 100_000_000;
17
+ /** The longest single line kept. A longer one is a pasted image or an opaque blob, never prose; it is skipped. */
18
+ export const MAX_LINE_BYTES = 64 * 1024 * 1024;
19
+ /**
20
+ * How much of a transcript file is read at a time. A megabyte keeps the number of reads of a gigabyte rollout in
21
+ * the thousands while staying small next to the line limit and the server's memory.
22
+ */
23
+ export const READ_CHUNK_BYTES = 1024 * 1024;
24
+ /** A byte count as the person reads it: `463 MB`, `1.2 GB`, `38 KB`. */
25
+ export function formatBytes(bytes) {
26
+ if (bytes >= 1e9)
27
+ return `${(bytes / 1e9).toFixed(1)} GB`;
28
+ if (bytes >= 1e6)
29
+ return `${Math.round(bytes / 1e6)} MB`;
30
+ if (bytes >= 1e3)
31
+ return `${Math.round(bytes / 1e3)} KB`;
32
+ return `${bytes} B`;
33
+ }
34
+ /** A transcript above the ceiling; thrown before it is read (or, compressed, as soon as the decoded size shows it). */
35
+ export class SessionTooLargeError extends Error {
36
+ bytes;
37
+ limit;
38
+ code = 'session-too-large';
39
+ constructor(
40
+ /** The transcript's size; absent when only "more than the limit" is known (a compressed one, cut off while decoding). */
41
+ bytes, limit = MAX_SESSION_BYTES) {
42
+ super(`This session is too large to import (${bytes === undefined ? `over ${formatBytes(limit)} once decompressed` : formatBytes(bytes)}; the limit is ${formatBytes(limit)}).`);
43
+ this.bytes = bytes;
44
+ this.limit = limit;
45
+ this.name = 'SessionTooLargeError';
46
+ }
47
+ }
48
+ /** Throw a {@link SessionTooLargeError} when `bytes` is above the ceiling. */
49
+ export function assertSessionSize(bytes, limit = MAX_SESSION_BYTES) {
50
+ if (bytes > limit)
51
+ throw new SessionTooLargeError(bytes, limit);
52
+ }
53
+ /** The size of a file, and throws when it is above the ceiling: call before reading anything. */
54
+ export async function assertFileImportable(path, limit = MAX_SESSION_BYTES) {
55
+ const { size } = await stat(path);
56
+ assertSessionSize(size, limit);
57
+ return size;
58
+ }
59
+ /**
60
+ * Split a byte stream into lines on `\n`, holding at most one line (and never more than `maxLine` bytes of it) at a
61
+ * time. A line above `maxLine` is skipped to its end and reported as `oversized`.
62
+ */
63
+ export async function* splitLines(chunks, maxLine = MAX_LINE_BYTES, observer) {
64
+ let parts = [];
65
+ let size = 0;
66
+ let skipping = false;
67
+ let number = 0;
68
+ for await (const chunk of chunks) {
69
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
70
+ observer?.held(size + buffer.length);
71
+ let start = 0;
72
+ for (;;) {
73
+ const end = buffer.indexOf(10, start);
74
+ if (end < 0) {
75
+ const rest = buffer.subarray(start);
76
+ if (!skipping) {
77
+ size += rest.length;
78
+ if (size > maxLine) {
79
+ skipping = true;
80
+ parts = [];
81
+ }
82
+ else if (rest.length > 0) {
83
+ parts.push(rest);
84
+ }
85
+ }
86
+ break;
87
+ }
88
+ number += 1;
89
+ const piece = buffer.subarray(start, end);
90
+ if (skipping || size + piece.length > maxLine) {
91
+ yield { number, text: '', oversized: true };
92
+ }
93
+ else {
94
+ const text = (parts.length === 0 ? piece : Buffer.concat([...parts, piece])).toString('utf8');
95
+ yield { number, text, oversized: false };
96
+ }
97
+ parts = [];
98
+ size = 0;
99
+ skipping = false;
100
+ start = end + 1;
101
+ }
102
+ }
103
+ if (skipping)
104
+ yield { number: number + 1, text: '', oversized: true };
105
+ else if (size > 0)
106
+ yield { number: number + 1, text: Buffer.concat(parts).toString('utf8'), oversized: false };
107
+ }
108
+ /** The lines of a plain-text transcript, streamed from disk; a file that grows past the ceiling while it is read stops the read. */
109
+ export function fileLines(path, options = {}) {
110
+ const { signal, observer } = options;
111
+ return splitLines(limitBytes(createReadStream(path, { highWaterMark: READ_CHUNK_BYTES, ...(signal !== undefined ? { signal } : {}) })), MAX_LINE_BYTES, observer);
112
+ }
113
+ /** Counts the bytes of a stream as they pass and throws {@link SessionTooLargeError} past the ceiling. */
114
+ export async function* limitBytes(chunks, limit = MAX_SESSION_BYTES) {
115
+ let total = 0;
116
+ for await (const chunk of chunks) {
117
+ total += chunk.length;
118
+ if (total > limit)
119
+ throw new SessionTooLargeError(undefined, limit);
120
+ yield chunk;
121
+ }
122
+ }
package/lib/text.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Small text scans used instead of patterns such as `/x+$/`, which an engine
3
+ * tries from every position: quadratic on a long run of `x` that something follows.
4
+ * @module @kirkchinese/harness-forge-core
5
+ */
6
+ /** `text` without the run of `chars` characters at its end. */
7
+ export declare function stripTrailing(text: string, chars: string): string;
8
+ /** `text` without the runs of `chars` characters at its start and end. */
9
+ export declare function stripAround(text: string, chars: string): string;
package/lib/text.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Small text scans used instead of patterns such as `/x+$/`, which an engine
3
+ * tries from every position: quadratic on a long run of `x` that something follows.
4
+ * @module @kirkchinese/harness-forge-core
5
+ */
6
+ /** `text` without the run of `chars` characters at its end. */
7
+ export function stripTrailing(text, chars) {
8
+ let end = text.length;
9
+ while (end > 0 && chars.includes(text[end - 1] ?? ''))
10
+ end--;
11
+ return text.slice(0, end);
12
+ }
13
+ /** `text` without the runs of `chars` characters at its start and end. */
14
+ export function stripAround(text, chars) {
15
+ let start = 0;
16
+ while (start < text.length && chars.includes(text[start] ?? ''))
17
+ start++;
18
+ return stripTrailing(text.slice(start), chars);
19
+ }
package/lib/trust.js CHANGED
@@ -22,7 +22,7 @@ import { lstatSync } from 'node:fs';
22
22
  import { homedir } from 'node:os';
23
23
  import { basename, dirname, join, resolve } from 'node:path';
24
24
  import { codexHome, readCodexConfig } from './dialects/codex/user-assets.js';
25
- import { isDirectory, isFile, isPlainObject, readJsonObject, readText, realOrLexical, stringArrayField } from './paths.js';
25
+ import { contentPath, isDirectory, isFile, isPlainObject, readJsonObject, readText, realOrLexical, stringArrayField } from './paths.js';
26
26
  function samePath(left, right) {
27
27
  const normalize = (path) => {
28
28
  const value = resolve(path).replace(/[\\/]+$/u, '');
@@ -55,21 +55,34 @@ export function repositoryRootOf(dir) {
55
55
  * stand in for the marker (a symbolic-link marker never claims a main checkout).
56
56
  */
57
57
  function linkedMainCheckout(marker) {
58
- const target = /^gitdir:\s*(.+?)\s*$/mu.exec(readText(marker) ?? '')?.[1];
59
- if (target === undefined)
58
+ const target = gitdirOf(readText(marker) ?? '');
59
+ // The `.git` file's own content: never followed to a network share the checkout is not on (see `contentPath`).
60
+ const named = target === undefined ? undefined : contentPath(target, dirname(marker));
61
+ if (named === undefined)
60
62
  return undefined;
61
- const gitdir = realOrLexical(resolve(dirname(marker), target));
63
+ const gitdir = realOrLexical(named);
62
64
  const main = /^(.*)[\\/]\.git[\\/]worktrees[\\/][^\\/]+$/u.exec(gitdir)?.[1];
63
65
  if (main === undefined || main.length === 0 || !isDirectory(join(main, '.git')))
64
66
  return undefined;
65
67
  const back = readText(join(gitdir, 'gitdir'))?.trim();
66
68
  if (back === undefined || back.length === 0)
67
69
  return undefined;
68
- const backPath = resolve(gitdir, back);
69
- if (basename(backPath) !== '.git')
70
+ const backPath = contentPath(back, gitdir);
71
+ if (backPath === undefined || basename(backPath) !== '.git')
70
72
  return undefined;
71
73
  return samePath(join(realOrLexical(dirname(backPath)), '.git'), marker) ? realOrLexical(main) : undefined;
72
74
  }
75
+ /** The path of the first `gitdir:` line (a scan: `/^gitdir:\s*(.+?)\s*$/m` is quadratic on a long line). */
76
+ function gitdirOf(text) {
77
+ for (const line of text.split(/\r?\n|\r/u)) {
78
+ if (!line.startsWith('gitdir:'))
79
+ continue;
80
+ const value = line.slice('gitdir:'.length).trim();
81
+ if (value.length > 0)
82
+ return value;
83
+ }
84
+ return undefined;
85
+ }
73
86
  function isSymbolicLink(path) {
74
87
  try {
75
88
  return lstatSync(path).isSymbolicLink();
package/lib/types.d.ts CHANGED
@@ -44,6 +44,8 @@ export interface ForeignPlugin {
44
44
  readonly id: string;
45
45
  readonly source: SourceId;
46
46
  readonly name: string;
47
+ /** The plugin's own name, when `name` carries a suffix that tells it from another installed plugin of the same name. What people see. */
48
+ readonly displayName?: string;
47
49
  readonly version?: string;
48
50
  readonly description?: string;
49
51
  readonly license?: string;
@@ -101,6 +103,11 @@ export interface SkillComponent extends ComponentBase {
101
103
  /** One MCP server entry. */
102
104
  export interface McpComponent extends ComponentBase {
103
105
  readonly kind: 'mcp';
106
+ /**
107
+ * The server's name as its plugin or configuration declares it (`cua_repl`), which `name` (the name Forge
108
+ * registers it under, `cua-repl`) may differ from: what the plugin's own hooks call it by.
109
+ */
110
+ readonly declaredName?: string;
104
111
  readonly transport: 'stdio' | 'streamable-http' | 'sse' | 'unknown';
105
112
  readonly command?: string;
106
113
  readonly args?: readonly string[];
@@ -108,7 +115,37 @@ export interface McpComponent extends ComponentBase {
108
115
  readonly cwd?: string;
109
116
  readonly url?: string;
110
117
  readonly headers?: Readonly<Record<string, string>>;
118
+ /** Only these tools may run (Codex `enabled_tools`). */
119
+ readonly enabledTools?: readonly string[];
120
+ /** These tools never run, applied after {@link enabledTools} (Codex `disabled_tools`). */
121
+ readonly disabledTools?: readonly string[];
122
+ /**
123
+ * Which tool calls ask the user first (Codex `default_tools_approval_mode`
124
+ * and `tools.<tool>.approval_mode`): `askByDefault` for every tool, `tools`
125
+ * overriding it per tool.
126
+ */
127
+ readonly toolApproval?: {
128
+ readonly askByDefault: boolean;
129
+ readonly tools: Readonly<Record<string, boolean>>;
130
+ };
131
+ /** How long the server may take to start and list its tools (Codex `startup_timeout_sec`). */
132
+ readonly startupTimeoutMs?: number;
133
+ /** How long one tool call may run (Codex `tool_timeout_sec`). */
134
+ readonly toolTimeoutMs?: number;
135
+ /**
136
+ * Why DSH does not start this server: the configuration switched it off
137
+ * (`disabled`), or it needs something DSH cannot provide (`unsupported`,
138
+ * reported as a gap). `code` is what screens translate; `detail` is the
139
+ * same in English, for logs, plans and agents.
140
+ */
141
+ readonly notStarted?: {
142
+ readonly reason: 'disabled' | 'unsupported';
143
+ readonly code: McpNotStartedCode;
144
+ readonly detail: string;
145
+ };
111
146
  }
147
+ /** Why an MCP server is not started, as a code a screen words in the person's language. */
148
+ export type McpNotStartedCode = 'disabled-in-plugin' | 'disabled-in-config' | 'needs-chatgpt-sign-in';
112
149
  /** One Markdown slash command. */
113
150
  export interface CommandComponent extends ComponentBase {
114
151
  readonly kind: 'command';
@@ -181,6 +218,12 @@ export interface SettingsComponent extends ComponentBase {
181
218
  /** The settings files the values were read from, lowest precedence first. */
182
219
  readonly files: readonly string[];
183
220
  readonly permissions: PermissionRules;
221
+ /**
222
+ * Where a `/path` file rule of these settings anchors, as in Claude Code:
223
+ * `~/.claude` for user settings, the project root for project and local
224
+ * settings. Absent: the session's working directory.
225
+ */
226
+ readonly ruleRoot?: string;
184
227
  readonly env: Readonly<Record<string, string>>;
185
228
  /** `disableAllHooks: true` turns off this scope's hooks. */
186
229
  readonly disableAllHooks?: boolean;
@@ -205,7 +248,9 @@ export interface ComponentCounts {
205
248
  export interface Gap {
206
249
  readonly id: string;
207
250
  readonly componentId: string;
208
- readonly kind: 'missing-host-api' | 'semantic-difference' | 'ui-surface' | 'unsupported-transport' | 'unsupported-handler' | 'unsupported-event' | 'unsupported-component' | 'runtime-failure' | 'license' | 'version' | 'other';
251
+ readonly kind: 'missing-host-api' | 'semantic-difference' | 'ui-surface' | 'unsupported-transport' | 'unsupported-handler' | 'unsupported-event' | 'unsupported-component'
252
+ /** The part needs something outside DSH (an account, a hosted service) that neither DSH nor an adapter can provide. */
253
+ | 'external-requirement' | 'runtime-failure' | 'license' | 'version' | 'other';
209
254
  readonly summary: string;
210
255
  readonly detail: string;
211
256
  readonly suggestedAction: 'bridge' | 'rewrite' | 'generate' | 'accept-difference' | 'skip';
@@ -265,6 +310,8 @@ export interface ComponentOutcome {
265
310
  readonly level: CompatibilityLevel;
266
311
  readonly evidence: EvidenceLevel;
267
312
  readonly message?: string;
313
+ /** Why a skipped part was left out, as a code a screen words in the person's language; `message` says it in English. */
314
+ readonly skippedBy?: 'disabled-in-claude-code';
268
315
  /** The latest runtime observation per signal, newest last. */
269
316
  readonly observations?: readonly Observation[];
270
317
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kirkchinese/harness-forge-core",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Dialect-neutral IR, plugin manifest parsing, discovery and compatibility planning for Harness Forge",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",