@kirkchinese/harness-forge 0.0.0-stage → 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.
- package/LICENSE +21 -0
- package/README.md +46 -2
- package/assets/icon.svg +12 -0
- package/cordis.patch.yml +28 -0
- package/docs/DETAIL.zh.md +47 -0
- package/lib/agents/presets.d.ts +98 -0
- package/lib/agents/presets.js +292 -0
- package/lib/agents/profiles.d.ts +58 -0
- package/lib/agents/profiles.js +279 -0
- package/lib/agents/row.d.ts +17 -0
- package/lib/agents/row.js +148 -0
- package/lib/client/paths.d.ts +12 -0
- package/lib/client/paths.js +68 -0
- package/lib/client/styles.d.ts +8 -0
- package/lib/client/styles.js +89 -0
- package/lib/client/typert.d.ts +25 -0
- package/lib/client/typert.js +158 -0
- package/lib/client.js +23823 -0
- package/lib/commands/definition.d.ts +40 -0
- package/lib/commands/definition.js +113 -0
- package/lib/commands/output-styles.d.ts +42 -0
- package/lib/commands/output-styles.js +152 -0
- package/lib/commands/row.d.ts +9 -0
- package/lib/commands/row.js +157 -0
- package/lib/context/instructions.d.ts +32 -0
- package/lib/context/instructions.js +88 -0
- package/lib/context/row.d.ts +16 -0
- package/lib/context/row.js +17 -0
- package/lib/dsh/commands.d.ts +30 -0
- package/lib/dsh/commands.js +61 -0
- package/lib/dsh/host.d.ts +110 -0
- package/lib/dsh/host.js +217 -0
- package/lib/dsh/model-route.d.ts +21 -0
- package/lib/dsh/model-route.js +37 -0
- package/lib/dsh/session-records.d.ts +78 -0
- package/lib/dsh/session-records.js +36 -0
- package/lib/dsh/subagents.d.ts +46 -0
- package/lib/dsh/subagents.js +14 -0
- package/lib/forge/contract.d.ts +271 -0
- package/lib/forge/contract.js +45 -0
- package/lib/forge/follow.d.ts +30 -0
- package/lib/forge/follow.js +73 -0
- package/lib/forge/ledger.d.ts +206 -0
- package/lib/forge/ledger.js +1005 -0
- package/lib/forge/live-mounts.d.ts +45 -0
- package/lib/forge/live-mounts.js +78 -0
- package/lib/forge/npm.d.ts +31 -0
- package/lib/forge/npm.js +60 -0
- package/lib/forge/projects.d.ts +97 -0
- package/lib/forge/projects.js +343 -0
- package/lib/forge/receipts.d.ts +5 -0
- package/lib/forge/receipts.js +31 -0
- package/lib/forge/remote/archive.d.ts +65 -0
- package/lib/forge/remote/archive.js +565 -0
- package/lib/forge/remote/code-parts.d.ts +18 -0
- package/lib/forge/remote/code-parts.js +76 -0
- package/lib/forge/remote/fetch.d.ts +265 -0
- package/lib/forge/remote/fetch.js +1133 -0
- package/lib/forge/remote/service.d.ts +256 -0
- package/lib/forge/remote/service.js +868 -0
- package/lib/forge/row.d.ts +32 -0
- package/lib/forge/row.js +59 -0
- package/lib/forge/service.d.ts +115 -0
- package/lib/forge/service.js +290 -0
- package/lib/forge/settings.d.ts +43 -0
- package/lib/forge/settings.js +122 -0
- package/lib/forge/state.d.ts +129 -0
- package/lib/forge/state.js +266 -0
- package/lib/forge/trust.d.ts +48 -0
- package/lib/forge/trust.js +107 -0
- package/lib/forge/turns.d.ts +13 -0
- package/lib/forge/turns.js +56 -0
- package/lib/hooks/broker/engine.d.ts +112 -0
- package/lib/hooks/broker/engine.js +722 -0
- package/lib/hooks/broker/helpers.d.ts +10 -0
- package/lib/hooks/broker/helpers.js +22 -0
- package/lib/hooks/broker/lifecycle.d.ts +65 -0
- package/lib/hooks/broker/lifecycle.js +342 -0
- package/lib/hooks/broker/session-events.d.ts +27 -0
- package/lib/hooks/broker/session-events.js +205 -0
- package/lib/hooks/broker/tools.d.ts +52 -0
- package/lib/hooks/broker/tools.js +424 -0
- package/lib/hooks/broker/types.d.ts +264 -0
- package/lib/hooks/broker/types.js +1 -0
- package/lib/hooks/broker.d.ts +80 -0
- package/lib/hooks/broker.js +95 -0
- package/lib/hooks/codex-user.d.ts +5 -0
- package/lib/hooks/codex-user.js +109 -0
- package/lib/hooks/condition.d.ts +87 -0
- package/lib/hooks/condition.js +602 -0
- package/lib/hooks/config.d.ts +85 -0
- package/lib/hooks/config.js +154 -0
- package/lib/hooks/glob.d.ts +41 -0
- package/lib/hooks/glob.js +114 -0
- package/lib/hooks/matcher.d.ts +20 -0
- package/lib/hooks/matcher.js +39 -0
- package/lib/hooks/notice.d.ts +17 -0
- package/lib/hooks/notice.js +39 -0
- package/lib/hooks/output.d.ts +56 -0
- package/lib/hooks/output.js +214 -0
- package/lib/hooks/permissions.d.ts +19 -0
- package/lib/hooks/permissions.js +202 -0
- package/lib/hooks/powershell-aliases.d.ts +19 -0
- package/lib/hooks/powershell-aliases.js +58 -0
- package/lib/hooks/process.d.ts +64 -0
- package/lib/hooks/process.js +289 -0
- package/lib/hooks/row.d.ts +17 -0
- package/lib/hooks/row.js +96 -0
- package/lib/hooks/runner.d.ts +98 -0
- package/lib/hooks/runner.js +322 -0
- package/lib/hooks/shell-commands.d.ts +28 -0
- package/lib/hooks/shell-commands.js +241 -0
- package/lib/hooks/shell.d.ts +44 -0
- package/lib/hooks/shell.js +129 -0
- package/lib/hooks/transcript.d.ts +28 -0
- package/lib/hooks/transcript.js +141 -0
- package/lib/hooks/vocabulary.d.ts +57 -0
- package/lib/hooks/vocabulary.js +366 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.js +287 -0
- package/lib/mcp/auth.d.ts +35 -0
- package/lib/mcp/auth.js +178 -0
- package/lib/mcp/catalog.d.ts +39 -0
- package/lib/mcp/catalog.js +69 -0
- package/lib/mcp/mount.d.ts +113 -0
- package/lib/mcp/mount.js +317 -0
- package/lib/mcp/policy.d.ts +42 -0
- package/lib/mcp/policy.js +43 -0
- package/lib/mcp/remote.d.ts +45 -0
- package/lib/mcp/remote.js +133 -0
- package/lib/mcp/row.d.ts +9 -0
- package/lib/mcp/row.js +225 -0
- package/lib/mods/bundler.d.ts +38 -0
- package/lib/mods/bundler.js +157 -0
- package/lib/mods/chain.d.ts +103 -0
- package/lib/mods/chain.js +436 -0
- package/lib/mods/claude.d.ts +27 -0
- package/lib/mods/claude.js +56 -0
- package/lib/mods/engine.d.ts +160 -0
- package/lib/mods/engine.js +701 -0
- package/lib/mods/expect.d.ts +8 -0
- package/lib/mods/expect.js +248 -0
- package/lib/mods/host.d.ts +105 -0
- package/lib/mods/host.js +462 -0
- package/lib/mods/loader.d.ts +53 -0
- package/lib/mods/loader.js +231 -0
- package/lib/mods/ops.d.ts +13 -0
- package/lib/mods/ops.js +117 -0
- package/lib/mods/row.d.ts +9 -0
- package/lib/mods/row.js +77 -0
- package/lib/mods/runtime.d.ts +60 -0
- package/lib/mods/runtime.js +133 -0
- package/lib/mods/service/commands.d.ts +17 -0
- package/lib/mods/service/commands.js +121 -0
- package/lib/mods/service/drawings.d.ts +36 -0
- package/lib/mods/service/drawings.js +64 -0
- package/lib/mods/service/sessions.d.ts +63 -0
- package/lib/mods/service/sessions.js +345 -0
- package/lib/mods/service/tools.d.ts +32 -0
- package/lib/mods/service/tools.js +253 -0
- package/lib/mods/service/turns.d.ts +33 -0
- package/lib/mods/service/turns.js +136 -0
- package/lib/mods/service/types.d.ts +151 -0
- package/lib/mods/service/types.js +1 -0
- package/lib/mods/service.d.ts +72 -0
- package/lib/mods/service.js +104 -0
- package/lib/mods/surfaces.d.ts +93 -0
- package/lib/mods/surfaces.js +309 -0
- package/lib/mods/values.d.ts +30 -0
- package/lib/mods/values.js +95 -0
- package/lib/opencode/bun.d.ts +40 -0
- package/lib/opencode/bun.js +168 -0
- package/lib/opencode/convert.d.ts +53 -0
- package/lib/opencode/convert.js +255 -0
- package/lib/opencode/row.d.ts +22 -0
- package/lib/opencode/row.js +104 -0
- package/lib/opencode/runtime/core.d.ts +74 -0
- package/lib/opencode/runtime/core.js +249 -0
- package/lib/opencode/runtime/events.d.ts +80 -0
- package/lib/opencode/runtime/events.js +281 -0
- package/lib/opencode/runtime/mount.d.ts +27 -0
- package/lib/opencode/runtime/mount.js +283 -0
- package/lib/opencode/runtime/server.d.ts +27 -0
- package/lib/opencode/runtime/server.js +354 -0
- package/lib/opencode/runtime/types.d.ts +109 -0
- package/lib/opencode/runtime/types.js +1 -0
- package/lib/opencode/runtime.d.ts +55 -0
- package/lib/opencode/runtime.js +79 -0
- package/lib/porting/adapter-paths.d.ts +13 -0
- package/lib/porting/adapter-paths.js +120 -0
- package/lib/porting/port-gap.d.ts +36 -0
- package/lib/porting/port-gap.js +158 -0
- package/lib/porting/port-sessions.d.ts +41 -0
- package/lib/porting/port-sessions.js +98 -0
- package/lib/porting/prompt.d.ts +23 -0
- package/lib/porting/prompt.js +51 -0
- package/lib/porting/row.d.ts +16 -0
- package/lib/porting/row.js +27 -0
- package/lib/porting/verify-port.d.ts +46 -0
- package/lib/porting/verify-port.js +82 -0
- package/lib/presets/fs-search.d.ts +25 -0
- package/lib/presets/fs-search.js +17 -0
- package/lib/presets/tool-filter.d.ts +35 -0
- package/lib/presets/tool-filter.js +91 -0
- package/lib/sessions/chat-import.d.ts +48 -0
- package/lib/sessions/chat-import.js +44 -0
- package/lib/sessions/claude.d.ts +35 -0
- package/lib/sessions/claude.js +104 -0
- package/lib/sessions/codex-discover.d.ts +34 -0
- package/lib/sessions/codex-discover.js +205 -0
- package/lib/sessions/codex-meta.d.ts +63 -0
- package/lib/sessions/codex-meta.js +148 -0
- package/lib/sessions/codex-text.d.ts +9 -0
- package/lib/sessions/codex-text.js +44 -0
- package/lib/sessions/codex.d.ts +42 -0
- package/lib/sessions/codex.js +270 -0
- package/lib/sessions/opencode.d.ts +38 -0
- package/lib/sessions/opencode.js +339 -0
- package/lib/sessions/persist.d.ts +162 -0
- package/lib/sessions/persist.js +377 -0
- package/lib/sessions/row.d.ts +15 -0
- package/lib/sessions/row.js +101 -0
- package/lib/sessions/turns.d.ts +31 -0
- package/lib/sessions/turns.js +63 -0
- package/lib/sessions/zstd.d.ts +15 -0
- package/lib/sessions/zstd.js +152 -0
- package/lib/shared/invocation.d.ts +169 -0
- package/lib/shared/invocation.js +325 -0
- package/lib/shared/render.d.ts +101 -0
- package/lib/shared/render.js +1353 -0
- package/lib/shared/util.d.ts +21 -0
- package/lib/shared/util.js +32 -0
- package/lib/skills/bundled.d.ts +3 -0
- package/lib/skills/bundled.js +42 -0
- package/lib/skills/provider.d.ts +74 -0
- package/lib/skills/provider.js +346 -0
- package/lib/skills/row.d.ts +22 -0
- package/lib/skills/row.js +204 -0
- package/lib/workbench/adapter-coverage.d.ts +65 -0
- package/lib/workbench/adapter-coverage.js +141 -0
- package/lib/workbench/model-tools.d.ts +10 -0
- package/lib/workbench/model-tools.js +122 -0
- package/lib/workbench/overview.d.ts +153 -0
- package/lib/workbench/overview.js +246 -0
- package/lib/workbench/remote.d.ts +161 -0
- package/lib/workbench/remote.js +561 -0
- package/lib/workbench/row.d.ts +15 -0
- package/lib/workbench/row.js +16 -0
- package/lib/workbench/settings.d.ts +19 -0
- package/lib/workbench/settings.js +60 -0
- package/lib/workbench/workbench.d.ts +130 -0
- package/lib/workbench/workbench.js +361 -0
- package/locale/agents/en.json +6 -0
- package/locale/agents/zh.json +6 -0
- package/locale/commands/en.json +6 -0
- package/locale/commands/zh.json +6 -0
- package/locale/context/en.json +6 -0
- package/locale/context/zh.json +6 -0
- package/locale/en.json +6 -0
- package/locale/hooks/en.json +6 -0
- package/locale/hooks/zh.json +6 -0
- package/locale/mcp/en.json +6 -0
- package/locale/mcp/zh.json +6 -0
- package/locale/mods/en.json +6 -0
- package/locale/mods/zh.json +6 -0
- package/locale/opencode/en.json +6 -0
- package/locale/opencode/zh.json +6 -0
- package/locale/porter/en.json +6 -0
- package/locale/porter/zh.json +6 -0
- package/locale/sessions/en.json +6 -0
- package/locale/sessions/zh.json +6 -0
- package/locale/skills/en.json +6 -0
- package/locale/skills/zh.json +6 -0
- package/locale/workbench/en.json +6 -0
- package/locale/workbench/zh.json +6 -0
- package/locale/zh.json +7 -0
- package/package.json +247 -3
- package/runtime/opencode-host.mjs +270 -0
- package/skills/harness-forge/SKILL.md +47 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A failed check. */
|
|
2
|
+
export declare class ExpectationError extends Error {
|
|
3
|
+
readonly name = "ExpectationError";
|
|
4
|
+
}
|
|
5
|
+
/** `toEqual`: recursive equality, undefined properties ignored; `strict` keeps them and checks arrays' holes and types. */
|
|
6
|
+
export declare function equals(a: unknown, b: unknown, strict?: boolean): boolean;
|
|
7
|
+
/** Build an `expect` that reports each failed check to `fail` before throwing. */
|
|
8
|
+
export declare function createExpect(fail: (error: ExpectationError) => void): unknown;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `expect` of `claude-code/testing`: the checks claude-code.d.ts `Matchers`
|
|
3
|
+
* and `Matching` declare, comparing plain data across environments.
|
|
4
|
+
* @module @kirkchinese/harness-forge/mods
|
|
5
|
+
*/
|
|
6
|
+
import { isRegExp, isThenable } from './values.js';
|
|
7
|
+
/** A failed check. */
|
|
8
|
+
export class ExpectationError extends Error {
|
|
9
|
+
name = 'ExpectationError';
|
|
10
|
+
}
|
|
11
|
+
const ASYMMETRIC = Symbol.for('claude-code.testing.asymmetric');
|
|
12
|
+
function asymmetric(text, test) {
|
|
13
|
+
return Object.freeze({ [ASYMMETRIC]: test, text, toString: () => text, toJSON: () => text });
|
|
14
|
+
}
|
|
15
|
+
function isAsymmetric(value) {
|
|
16
|
+
return typeof value === 'object' && value !== null && ASYMMETRIC in value;
|
|
17
|
+
}
|
|
18
|
+
function describe(value) {
|
|
19
|
+
if (isAsymmetric(value))
|
|
20
|
+
return value.text;
|
|
21
|
+
if (typeof value === 'string')
|
|
22
|
+
return JSON.stringify(value);
|
|
23
|
+
if (typeof value === 'function')
|
|
24
|
+
return `[Function ${value.name ?? ''}]`;
|
|
25
|
+
if (isRegExp(value))
|
|
26
|
+
return String(value);
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
return 'undefined';
|
|
29
|
+
try {
|
|
30
|
+
const text = JSON.stringify(value, (_key, item) => (item === undefined ? '__undefined__' : isAsymmetric(item) ? item.text : typeof item === 'bigint' ? `${item}n` : item));
|
|
31
|
+
return (text ?? String(value)).replace(/"__undefined__"/gu, 'undefined');
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return String(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function tag(value) {
|
|
38
|
+
return Object.prototype.toString.call(value);
|
|
39
|
+
}
|
|
40
|
+
/** `toEqual`: recursive equality, undefined properties ignored; `strict` keeps them and checks arrays' holes and types. */
|
|
41
|
+
export function equals(a, b, strict = false) {
|
|
42
|
+
if (isAsymmetric(b))
|
|
43
|
+
return b[ASYMMETRIC](a);
|
|
44
|
+
if (isAsymmetric(a))
|
|
45
|
+
return a[ASYMMETRIC](b);
|
|
46
|
+
if (Object.is(a, b))
|
|
47
|
+
return true;
|
|
48
|
+
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)
|
|
49
|
+
return false;
|
|
50
|
+
if (tag(a) !== tag(b))
|
|
51
|
+
return false;
|
|
52
|
+
if (isRegExp(a))
|
|
53
|
+
return String(a) === String(b);
|
|
54
|
+
if (a instanceof Date || tag(a) === '[object Date]')
|
|
55
|
+
return a.getTime() === b.getTime();
|
|
56
|
+
if (Array.isArray(a)) {
|
|
57
|
+
const other = b;
|
|
58
|
+
if (a.length !== other.length)
|
|
59
|
+
return false;
|
|
60
|
+
return a.every((item, index) => equals(item, other[index], strict));
|
|
61
|
+
}
|
|
62
|
+
if (tag(a) === '[object Map]') {
|
|
63
|
+
const left = a;
|
|
64
|
+
const right = b;
|
|
65
|
+
return left.size === right.size && [...left].every(([key, item]) => right.has(key) && equals(item, right.get(key), strict));
|
|
66
|
+
}
|
|
67
|
+
if (tag(a) === '[object Set]') {
|
|
68
|
+
const left = [...a];
|
|
69
|
+
const right = [...b];
|
|
70
|
+
return left.length === right.length && left.every(item => right.some(other => equals(item, other, strict)));
|
|
71
|
+
}
|
|
72
|
+
if (ArrayBuffer.isView(a)) {
|
|
73
|
+
const left = a;
|
|
74
|
+
const right = b;
|
|
75
|
+
return left.length === right.length && Array.from(left).every((item, index) => item === right[index]);
|
|
76
|
+
}
|
|
77
|
+
const keys = (value) => Object.keys(value).filter(key => strict || value[key] !== undefined);
|
|
78
|
+
const left = keys(a);
|
|
79
|
+
const right = keys(b);
|
|
80
|
+
if (left.length !== right.length)
|
|
81
|
+
return false;
|
|
82
|
+
if (strict && Object.getPrototypeOf(a)?.constructor?.name !== Object.getPrototypeOf(b)?.constructor?.name)
|
|
83
|
+
return false;
|
|
84
|
+
return left.every(key => Object.prototype.hasOwnProperty.call(b, key) && equals(a[key], b[key], strict));
|
|
85
|
+
}
|
|
86
|
+
/** `toMatchObject`: every property of the pattern matches, recursively. */
|
|
87
|
+
function matchesObject(value, pattern) {
|
|
88
|
+
if (isAsymmetric(pattern))
|
|
89
|
+
return pattern[ASYMMETRIC](value);
|
|
90
|
+
if (Array.isArray(pattern)) {
|
|
91
|
+
return Array.isArray(value) && value.length === pattern.length && pattern.every((item, index) => matchesObject(value[index], item));
|
|
92
|
+
}
|
|
93
|
+
if (typeof pattern === 'object' && pattern !== null && !isRegExp(pattern) && tag(pattern) === '[object Object]') {
|
|
94
|
+
if (typeof value !== 'object' || value === null)
|
|
95
|
+
return false;
|
|
96
|
+
return Object.keys(pattern).every(key => key in value && matchesObject(value[key], pattern[key]));
|
|
97
|
+
}
|
|
98
|
+
return equals(value, pattern);
|
|
99
|
+
}
|
|
100
|
+
function hasPath(value, path) {
|
|
101
|
+
const parts = Array.isArray(path) ? path : String(path).replace(/\[(\d+)\]/gu, '.$1').split('.').filter(part => part.length > 0);
|
|
102
|
+
let current = value;
|
|
103
|
+
for (const part of parts) {
|
|
104
|
+
if (current === null || current === undefined || !(typeof current === 'object' || typeof current === 'function') || !(part in current))
|
|
105
|
+
return { found: false, value: undefined };
|
|
106
|
+
current = current[part];
|
|
107
|
+
}
|
|
108
|
+
return { found: true, value: current };
|
|
109
|
+
}
|
|
110
|
+
function thrownMatches(error, expected) {
|
|
111
|
+
if (expected === undefined)
|
|
112
|
+
return true;
|
|
113
|
+
const message = typeof error === 'object' && error !== null && 'message' in error ? String(error.message) : String(error);
|
|
114
|
+
if (typeof expected === 'string')
|
|
115
|
+
return message.includes(expected);
|
|
116
|
+
if (isRegExp(expected))
|
|
117
|
+
return expected.test(message);
|
|
118
|
+
if (typeof expected === 'function')
|
|
119
|
+
return error instanceof expected || (typeof error === 'object' && error !== null && error.name === expected.name);
|
|
120
|
+
if (typeof expected === 'object' && expected !== null && 'message' in expected)
|
|
121
|
+
return message === String(expected.message);
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const CHECKS = {
|
|
125
|
+
toBe: (r, e) => ({ pass: Object.is(r, e), message: `expected ${describe(r)} to be ${describe(e)}` }),
|
|
126
|
+
toEqual: (r, e) => ({ pass: equals(r, e), message: `expected ${describe(r)} to equal ${describe(e)}` }),
|
|
127
|
+
toStrictEqual: (r, e) => ({ pass: equals(r, e, true), message: `expected ${describe(r)} to strictly equal ${describe(e)}` }),
|
|
128
|
+
toMatchObject: (r, e) => ({ pass: matchesObject(r, e), message: `expected ${describe(r)} to match object ${describe(e)}` }),
|
|
129
|
+
toContain: (r, e) => ({
|
|
130
|
+
pass: typeof r === 'string' ? r.includes(String(e)) : r !== null && typeof r === 'object' && Symbol.iterator in r ? [...r].some(item => item === e) : false,
|
|
131
|
+
message: `expected ${describe(r)} to contain ${describe(e)}`,
|
|
132
|
+
}),
|
|
133
|
+
toContainEqual: (r, e) => ({ pass: r !== null && typeof r === 'object' && Symbol.iterator in r && [...r].some(item => equals(item, e)), message: `expected ${describe(r)} to contain an item equal to ${describe(e)}` }),
|
|
134
|
+
toHaveLength: (r, e) => ({ pass: r !== null && r !== undefined && r.length === e, message: `expected ${describe(r)} to have length ${describe(e)} (it has ${String(r?.length)})` }),
|
|
135
|
+
toHaveProperty: (r, path, ...value) => {
|
|
136
|
+
const found = hasPath(r, path);
|
|
137
|
+
return { pass: found.found && (value.length === 0 || equals(found.value, value[0])), message: `expected ${describe(r)} to have property ${describe(path)}${value.length > 0 ? ` equal to ${describe(value[0])}` : ''}` };
|
|
138
|
+
},
|
|
139
|
+
toBeUndefined: r => ({ pass: r === undefined, message: `expected ${describe(r)} to be undefined` }),
|
|
140
|
+
toBeDefined: r => ({ pass: r !== undefined, message: `expected ${describe(r)} to be defined` }),
|
|
141
|
+
toBeNull: r => ({ pass: r === null, message: `expected ${describe(r)} to be null` }),
|
|
142
|
+
toBeTruthy: r => ({ pass: Boolean(r), message: `expected ${describe(r)} to be truthy` }),
|
|
143
|
+
toBeFalsy: r => ({ pass: !r, message: `expected ${describe(r)} to be falsy` }),
|
|
144
|
+
toBeNaN: r => ({ pass: Number.isNaN(r), message: `expected ${describe(r)} to be NaN` }),
|
|
145
|
+
toBeGreaterThan: (r, e) => ({ pass: r > e, message: `expected ${describe(r)} to be greater than ${describe(e)}` }),
|
|
146
|
+
toBeGreaterThanOrEqual: (r, e) => ({ pass: r >= e, message: `expected ${describe(r)} to be at least ${describe(e)}` }),
|
|
147
|
+
toBeLessThan: (r, e) => ({ pass: r < e, message: `expected ${describe(r)} to be less than ${describe(e)}` }),
|
|
148
|
+
toBeLessThanOrEqual: (r, e) => ({ pass: r <= e, message: `expected ${describe(r)} to be at most ${describe(e)}` }),
|
|
149
|
+
toMatch: (r, e) => ({ pass: typeof r === 'string' && (isRegExp(e) ? new RegExp(e.source, e.flags.replace('g', '')).test(r) : r.includes(String(e))), message: `expected ${describe(r)} to match ${describe(e)}` }),
|
|
150
|
+
toStartWith: (r, e) => ({ pass: typeof r === 'string' && r.startsWith(String(e)), message: `expected ${describe(r)} to start with ${describe(e)}` }),
|
|
151
|
+
toEndWith: (r, e) => ({ pass: typeof r === 'string' && r.endsWith(String(e)), message: `expected ${describe(r)} to end with ${describe(e)}` }),
|
|
152
|
+
toBeInstanceOf: (r, e) => ({ pass: typeof e === 'function' && (r instanceof e || (typeof r === 'object' && r !== null && Object.getPrototypeOf(r)?.constructor?.name === e.name)), message: `expected ${describe(r)} to be an instance of ${e.name ?? 'the class'}` }),
|
|
153
|
+
};
|
|
154
|
+
/** Build an `expect` that reports each failed check to `fail` before throwing. */
|
|
155
|
+
export function createExpect(fail) {
|
|
156
|
+
const raise = (message, note) => {
|
|
157
|
+
const error = new ExpectationError(note === undefined ? message : `${note}: ${message}`);
|
|
158
|
+
fail(error);
|
|
159
|
+
throw error;
|
|
160
|
+
};
|
|
161
|
+
const matchers = (received, note, negate) => {
|
|
162
|
+
const table = {};
|
|
163
|
+
for (const [name, check] of Object.entries(CHECKS)) {
|
|
164
|
+
table[name] = (...args) => {
|
|
165
|
+
const { pass, message } = check(received, ...args);
|
|
166
|
+
if (pass === negate)
|
|
167
|
+
raise(negate ? message.replace(/^expected (.*?) to /u, 'expected $1 not to ') : message, note);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
table['toThrow'] = (expected) => {
|
|
171
|
+
if (typeof received !== 'function')
|
|
172
|
+
return raise(`expected a function to call, got ${describe(received)}`, note);
|
|
173
|
+
let thrown = false;
|
|
174
|
+
let error;
|
|
175
|
+
try {
|
|
176
|
+
const out = received();
|
|
177
|
+
if (isThenable(out))
|
|
178
|
+
out.catch(() => { });
|
|
179
|
+
}
|
|
180
|
+
catch (caught) {
|
|
181
|
+
thrown = true;
|
|
182
|
+
error = caught;
|
|
183
|
+
}
|
|
184
|
+
const pass = thrown && thrownMatches(error, expected);
|
|
185
|
+
if (pass === negate)
|
|
186
|
+
raise(negate ? `expected the function not to throw${expected === undefined ? '' : ` ${describe(expected)}`}` : `expected the function to throw${expected === undefined ? '' : ` ${describe(expected)}`}${thrown ? `, it threw ${describe(error?.message ?? error)}` : ''}`, note);
|
|
187
|
+
};
|
|
188
|
+
return table;
|
|
189
|
+
};
|
|
190
|
+
const settled = (received, note, mode, negate) => {
|
|
191
|
+
const table = {};
|
|
192
|
+
for (const name of [...Object.keys(CHECKS), 'toThrow']) {
|
|
193
|
+
table[name] = async (...args) => {
|
|
194
|
+
let value;
|
|
195
|
+
try {
|
|
196
|
+
const resolved = await received;
|
|
197
|
+
if (mode === 'rejects')
|
|
198
|
+
return raise(`expected the promise to reject, it resolved ${describe(resolved)}`, note);
|
|
199
|
+
value = resolved;
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (error instanceof ExpectationError)
|
|
203
|
+
throw error;
|
|
204
|
+
if (mode === 'resolves')
|
|
205
|
+
return raise(`expected the promise to resolve, it rejected ${describe(error?.message ?? error)}`, note);
|
|
206
|
+
value = error;
|
|
207
|
+
}
|
|
208
|
+
if (name === 'toThrow') {
|
|
209
|
+
const pass = thrownMatches(value, args[0]);
|
|
210
|
+
if (pass === negate)
|
|
211
|
+
raise(`expected the rejection ${describe(value?.message ?? value)} ${negate ? 'not ' : ''}to match ${describe(args[0])}`, note);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
matchers(value, note, negate)[name](...args);
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return table;
|
|
218
|
+
};
|
|
219
|
+
const expect = (received, note) => Object.freeze({
|
|
220
|
+
...matchers(received, note, false),
|
|
221
|
+
not: Object.freeze(matchers(received, note, true)),
|
|
222
|
+
resolves: Object.freeze({ ...settled(received, note, 'resolves', false), not: Object.freeze(settled(received, note, 'resolves', true)) }),
|
|
223
|
+
rejects: Object.freeze({ ...settled(received, note, 'rejects', false), not: Object.freeze(settled(received, note, 'rejects', true)) }),
|
|
224
|
+
});
|
|
225
|
+
return Object.freeze(Object.assign(expect, {
|
|
226
|
+
any: (type) => asymmetric(`Any<${type.name ?? '?'}>`, (value) => {
|
|
227
|
+
const name = type.name;
|
|
228
|
+
if (name === 'Number')
|
|
229
|
+
return typeof value === 'number' || value instanceof Number;
|
|
230
|
+
if (name === 'String')
|
|
231
|
+
return typeof value === 'string' || value instanceof String;
|
|
232
|
+
if (name === 'Boolean')
|
|
233
|
+
return typeof value === 'boolean';
|
|
234
|
+
if (name === 'Function')
|
|
235
|
+
return typeof value === 'function';
|
|
236
|
+
if (name === 'Object')
|
|
237
|
+
return typeof value === 'object' && value !== null;
|
|
238
|
+
if (name === 'Array')
|
|
239
|
+
return Array.isArray(value);
|
|
240
|
+
return typeof type === 'function' && (value instanceof type || Object.getPrototypeOf(value ?? {})?.constructor?.name === name);
|
|
241
|
+
}),
|
|
242
|
+
anything: () => asymmetric('Anything', value => value !== null && value !== undefined),
|
|
243
|
+
stringContaining: (text) => asymmetric(`StringContaining ${JSON.stringify(text)}`, value => typeof value === 'string' && value.includes(text)),
|
|
244
|
+
stringMatching: (pattern) => asymmetric(`StringMatching ${String(pattern)}`, value => typeof value === 'string' && (isRegExp(pattern) ? new RegExp(pattern.source, pattern.flags.replace('g', '')).test(value) : value.includes(pattern))),
|
|
245
|
+
objectContaining: (shape) => asymmetric(`ObjectContaining ${describe(shape)}`, value => typeof value === 'object' && value !== null && Object.keys(shape).every(key => key in value && equals(value[key], shape[key]))),
|
|
246
|
+
arrayContaining: (items) => asymmetric(`ArrayContaining ${describe(items)}`, value => Array.isArray(value) && items.every(item => value.some(entry => equals(entry, item)))),
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { ForeignShell } from '../hooks/shell.js';
|
|
3
|
+
import type { CoreContext } from './engine.js';
|
|
4
|
+
/** The root agent of the session the engine serves. */
|
|
5
|
+
export interface SessionAgent {
|
|
6
|
+
readonly id?: string;
|
|
7
|
+
readonly ctx?: unknown;
|
|
8
|
+
readonly options?: {
|
|
9
|
+
readonly provider?: string;
|
|
10
|
+
readonly model?: string;
|
|
11
|
+
};
|
|
12
|
+
readonly session: {
|
|
13
|
+
readonly id?: string;
|
|
14
|
+
readonly header: {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly cwd?: string;
|
|
17
|
+
readonly createdAt?: number | string;
|
|
18
|
+
readonly parentSession?: string;
|
|
19
|
+
};
|
|
20
|
+
deriveMessages?(): ReadonlyArray<{
|
|
21
|
+
readonly role: string;
|
|
22
|
+
readonly content: unknown;
|
|
23
|
+
}>;
|
|
24
|
+
requestHeader?(): {
|
|
25
|
+
readonly config?: {
|
|
26
|
+
readonly model?: string;
|
|
27
|
+
};
|
|
28
|
+
} | undefined;
|
|
29
|
+
};
|
|
30
|
+
inject(message: unknown): void;
|
|
31
|
+
followup(message: unknown): void;
|
|
32
|
+
cancel?(cause: {
|
|
33
|
+
kind: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
}, options?: {
|
|
36
|
+
keepInbox?: boolean;
|
|
37
|
+
}): unknown;
|
|
38
|
+
}
|
|
39
|
+
/** What the session host needs from Harness Forge. */
|
|
40
|
+
export interface SessionServices {
|
|
41
|
+
readonly ctx: Context;
|
|
42
|
+
readonly shell: ForeignShell;
|
|
43
|
+
/** Where each plugin's `$.store` file lives. */
|
|
44
|
+
readonly storeRoot: string;
|
|
45
|
+
directory(agent: unknown, signal: AbortSignal): Promise<string>;
|
|
46
|
+
/** Claude settings merged for the session, or one source's. */
|
|
47
|
+
settings(source: string | undefined): Record<string, unknown>;
|
|
48
|
+
/** A line a mod shows (transcript, debug, toast, status). */
|
|
49
|
+
show(kind: 'transcript' | 'debug' | 'toast' | 'status', plugin: string, text: string | undefined): void;
|
|
50
|
+
/** A pane a mod opened or closed; the client draws it. */
|
|
51
|
+
pane(plugin: string, action: 'open' | 'close', args: Record<string, unknown>): {
|
|
52
|
+
isPlaced: boolean;
|
|
53
|
+
reason?: string;
|
|
54
|
+
};
|
|
55
|
+
/** The open panes. */
|
|
56
|
+
panes(): unknown[];
|
|
57
|
+
/** Register a slash command for the session; returns the withdrawal. */
|
|
58
|
+
registerCommand(plugin: string, spec: Record<string, unknown>): () => void;
|
|
59
|
+
/** Redraw what a plugin drew. */
|
|
60
|
+
invalidate(plugin: string): void;
|
|
61
|
+
}
|
|
62
|
+
/** The core of one session's mods engine. */
|
|
63
|
+
export declare class SessionHost {
|
|
64
|
+
private readonly services;
|
|
65
|
+
readonly agent: SessionAgent;
|
|
66
|
+
readonly interactive: boolean;
|
|
67
|
+
/** Withdrawals of what the session's mods registered. */
|
|
68
|
+
readonly registrations: Array<() => void>;
|
|
69
|
+
private readonly stores;
|
|
70
|
+
constructor(services: SessionServices, agent: SessionAgent, interactive: boolean);
|
|
71
|
+
private get ctx();
|
|
72
|
+
/** Core at an op event: `{ value }` or `{ deny }`. */
|
|
73
|
+
op(event: string, e: Record<string, unknown>, context: CoreContext): Promise<unknown>;
|
|
74
|
+
private cwd;
|
|
75
|
+
private path;
|
|
76
|
+
private serve;
|
|
77
|
+
/**
|
|
78
|
+
* The account the session is signed in as: DSH's DeepSeek account where one
|
|
79
|
+
* is signed in (its contact, when an email address), as Claude Code answers
|
|
80
|
+
* with its own login; an API-key or keyless session has none.
|
|
81
|
+
*/
|
|
82
|
+
private identity;
|
|
83
|
+
private scoped;
|
|
84
|
+
private turns;
|
|
85
|
+
private messages;
|
|
86
|
+
private usage;
|
|
87
|
+
private repo;
|
|
88
|
+
/** `$.fs.ancestors`: the named instruction files from the root down to `of`, with their `@` imports. */
|
|
89
|
+
private ancestors;
|
|
90
|
+
private store;
|
|
91
|
+
private saveStore;
|
|
92
|
+
private run;
|
|
93
|
+
private fetch;
|
|
94
|
+
private registerTool;
|
|
95
|
+
private complete;
|
|
96
|
+
private classify;
|
|
97
|
+
/** Run a slash command line in the session (`$.command.run`). */
|
|
98
|
+
runCommand(command: string, args: string, signal: AbortSignal): Promise<{
|
|
99
|
+
text?: string;
|
|
100
|
+
}>;
|
|
101
|
+
/** A note a plugin appends (`$.session.append`): kept in the conversation. */
|
|
102
|
+
appendNote(plugin: string, e: Record<string, unknown>): unknown;
|
|
103
|
+
/** Relative path a mod sees for a file, from the session's root. */
|
|
104
|
+
relativePath(path: string): string;
|
|
105
|
+
}
|