@kirkchinese/harness-forge 0.0.0-stage → 0.4.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 +42 -2
- package/assets/icon.svg +12 -0
- package/cordis.patch.yml +28 -0
- package/lib/agents/presets.d.ts +91 -0
- package/lib/agents/presets.js +282 -0
- package/lib/agents/profiles.d.ts +58 -0
- package/lib/agents/profiles.js +278 -0
- package/lib/agents/row.d.ts +17 -0
- package/lib/agents/row.js +146 -0
- package/lib/client/styles.d.ts +8 -0
- package/lib/client/styles.js +89 -0
- package/lib/client/typert.d.ts +14 -0
- package/lib/client/typert.js +110 -0
- package/lib/client.js +22500 -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 +107 -0
- package/lib/dsh/host.js +214 -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 +231 -0
- package/lib/forge/contract.js +43 -0
- package/lib/forge/ledger.d.ts +143 -0
- package/lib/forge/ledger.js +733 -0
- package/lib/forge/live-mounts.d.ts +45 -0
- package/lib/forge/live-mounts.js +78 -0
- package/lib/forge/marketplace-install.d.ts +3 -0
- package/lib/forge/marketplace-install.js +64 -0
- package/lib/forge/npm.d.ts +31 -0
- package/lib/forge/npm.js +60 -0
- package/lib/forge/projects.d.ts +94 -0
- package/lib/forge/projects.js +336 -0
- package/lib/forge/receipts.d.ts +5 -0
- package/lib/forge/receipts.js +31 -0
- package/lib/forge/row.d.ts +32 -0
- package/lib/forge/row.js +59 -0
- package/lib/forge/service.d.ts +105 -0
- package/lib/forge/service.js +274 -0
- package/lib/forge/settings.d.ts +41 -0
- package/lib/forge/settings.js +115 -0
- package/lib/forge/state.d.ts +69 -0
- package/lib/forge/state.js +150 -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 +728 -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 +22 -0
- package/lib/hooks/broker/session-events.js +196 -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 +262 -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 +11 -0
- package/lib/hooks/condition.js +181 -0
- package/lib/hooks/config.d.ts +85 -0
- package/lib/hooks/config.js +150 -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 +14 -0
- package/lib/hooks/permissions.js +109 -0
- package/lib/hooks/process.d.ts +47 -0
- package/lib/hooks/process.js +134 -0
- package/lib/hooks/row.d.ts +17 -0
- package/lib/hooks/row.js +94 -0
- package/lib/hooks/runner.d.ts +85 -0
- package/lib/hooks/runner.js +293 -0
- package/lib/hooks/shell-commands.d.ts +19 -0
- package/lib/hooks/shell-commands.js +177 -0
- package/lib/hooks/shell.d.ts +43 -0
- package/lib/hooks/shell.js +126 -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 +364 -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 +36 -0
- package/lib/mcp/catalog.js +61 -0
- package/lib/mcp/mount.d.ts +75 -0
- package/lib/mcp/mount.js +217 -0
- package/lib/mcp/remote.d.ts +45 -0
- package/lib/mcp/remote.js +143 -0
- package/lib/mcp/row.d.ts +9 -0
- package/lib/mcp/row.js +131 -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 +227 -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 +32 -0
- package/lib/mods/service/turns.js +161 -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 +156 -0
- package/lib/opencode/convert.d.ts +53 -0
- package/lib/opencode/convert.js +255 -0
- package/lib/opencode/row.d.ts +9 -0
- package/lib/opencode/row.js +86 -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 +353 -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/port-gap.d.ts +30 -0
- package/lib/porting/port-gap.js +122 -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 +49 -0
- package/lib/porting/row.d.ts +16 -0
- package/lib/porting/row.js +25 -0
- package/lib/porting/verify-port.d.ts +53 -0
- package/lib/porting/verify-port.js +104 -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/claude.d.ts +29 -0
- package/lib/sessions/claude.js +83 -0
- package/lib/sessions/codex.d.ts +30 -0
- package/lib/sessions/codex.js +303 -0
- package/lib/sessions/opencode.d.ts +32 -0
- package/lib/sessions/opencode.js +320 -0
- package/lib/sessions/row.d.ts +14 -0
- package/lib/sessions/row.js +35 -0
- package/lib/shared/invocation.d.ts +169 -0
- package/lib/shared/invocation.js +325 -0
- package/lib/shared/render.d.ts +72 -0
- package/lib/shared/render.js +588 -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 +72 -0
- package/lib/skills/provider.js +340 -0
- package/lib/skills/row.d.ts +22 -0
- package/lib/skills/row.js +204 -0
- package/lib/workbench/adapter-coverage.d.ts +47 -0
- package/lib/workbench/adapter-coverage.js +102 -0
- package/lib/workbench/model-tools.d.ts +10 -0
- package/lib/workbench/model-tools.js +122 -0
- package/lib/workbench/overview.d.ts +103 -0
- package/lib/workbench/overview.js +159 -0
- package/lib/workbench/remote.d.ts +118 -0
- package/lib/workbench/remote.js +422 -0
- package/lib/workbench/row.d.ts +15 -0
- package/lib/workbench/row.js +16 -0
- package/lib/workbench/settings.d.ts +15 -0
- package/lib/workbench/settings.js +56 -0
- package/lib/workbench/workbench.d.ts +100 -0
- package/lib/workbench/workbench.js +260 -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 +6 -0
- package/package.json +246 -3
- package/runtime/opencode-host.mjs +270 -0
- package/skills/harness-forge/SKILL.md +47 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A handler's `if` field: one permission rule (`Bash(git *)`, `Edit(src/**)`,
|
|
3
|
+
* `WebFetch(domain:example.com)`, `mcp__server__tool`, a bare tool name)
|
|
4
|
+
* matched against the tool name and its input together.
|
|
5
|
+
*
|
|
6
|
+
* - Shell rules match each subcommand (after stripping `VAR=value`), commands
|
|
7
|
+
* inside `$(…)` and backticks; when the input cannot be read, or the rule
|
|
8
|
+
* names more than the command and the input expands something at run time,
|
|
9
|
+
* the hook runs.
|
|
10
|
+
* - File rules follow gitignore semantics relative to the working directory:
|
|
11
|
+
* a pattern without `/` matches the file name at any depth, `src/**` only
|
|
12
|
+
* under `<cwd>/src`, `//abs` an absolute path, `~/x` the home directory.
|
|
13
|
+
* `Edit` rules cover every file-writing tool and `Read` rules every reader.
|
|
14
|
+
* @module @kirkchinese/harness-forge
|
|
15
|
+
*/
|
|
16
|
+
import { homedir } from 'node:os';
|
|
17
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
18
|
+
import { shellCommands } from './shell-commands.js';
|
|
19
|
+
import { isShellTool } from './vocabulary.js';
|
|
20
|
+
const WRITE_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'apply_patch']);
|
|
21
|
+
const READ_TOOLS = new Set(['Read', 'Glob', 'Grep', 'NotebookRead']);
|
|
22
|
+
/**
|
|
23
|
+
* Whether `rule` selects this tool call.
|
|
24
|
+
* @param cwd - the session's working directory, for relative file rules.
|
|
25
|
+
*/
|
|
26
|
+
export function conditionMatches(rule, tool, cwd) {
|
|
27
|
+
const match = /^\s*([A-Za-z0-9_\-:.*]+?)\s*(?:\((.*)\))?\s*$/su.exec(rule);
|
|
28
|
+
if (match === null)
|
|
29
|
+
return false;
|
|
30
|
+
const name = match[1] ?? '';
|
|
31
|
+
const specifier = match[2];
|
|
32
|
+
if (name.startsWith('mcp__'))
|
|
33
|
+
return mcpRuleMatches(name, specifier, tool.name);
|
|
34
|
+
if (!ruleNamesTool(name, tool))
|
|
35
|
+
return false;
|
|
36
|
+
if (specifier === undefined || specifier === '' || specifier === '*')
|
|
37
|
+
return true;
|
|
38
|
+
if (isShellTool(tool.dshName) && name !== 'PowerShell')
|
|
39
|
+
return shellRuleMatches(specifier, String(tool.input['command'] ?? ''));
|
|
40
|
+
if (name === 'PowerShell')
|
|
41
|
+
return globRegex(specifier, true).test(String(tool.input['command'] ?? ''));
|
|
42
|
+
if (name === 'WebFetch' && specifier.startsWith('domain:'))
|
|
43
|
+
return domainMatches(specifier.slice('domain:'.length), String(tool.input['url'] ?? ''));
|
|
44
|
+
const path = tool.input['file_path'] ?? tool.input['path'];
|
|
45
|
+
if (typeof path === 'string' && (WRITE_TOOLS.has(name) || READ_TOOLS.has(name)))
|
|
46
|
+
return pathRuleMatches(specifier, path, cwd);
|
|
47
|
+
const subject = tool.input['subagent_type'] ?? tool.input['skill'] ?? tool.input['query'] ?? tool.input['url'] ?? tool.input['pattern'] ?? '';
|
|
48
|
+
return globRegex(specifier, true).test(String(subject));
|
|
49
|
+
}
|
|
50
|
+
function ruleNamesTool(name, tool) {
|
|
51
|
+
if (tool.aliases.includes(name))
|
|
52
|
+
return true;
|
|
53
|
+
if (name === 'Edit')
|
|
54
|
+
return tool.aliases.some(alias => WRITE_TOOLS.has(alias));
|
|
55
|
+
if (name === 'Read')
|
|
56
|
+
return tool.aliases.some(alias => READ_TOOLS.has(alias));
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
function mcpRuleMatches(name, specifier, toolName) {
|
|
60
|
+
if (specifier !== undefined && specifier !== '' && specifier !== '*')
|
|
61
|
+
return false;
|
|
62
|
+
if (name === toolName)
|
|
63
|
+
return true;
|
|
64
|
+
const server = name.endsWith('__*') ? name.slice(0, -1) : `${name}__`;
|
|
65
|
+
return name.split('__').length === 2 || name.endsWith('__*') ? toolName.startsWith(server) : false;
|
|
66
|
+
}
|
|
67
|
+
/** Shell rule: any subcommand matches; unreadable or run-time-expanding input runs the hook. */
|
|
68
|
+
function shellRuleMatches(specifier, command) {
|
|
69
|
+
const parsed = shellCommands(command);
|
|
70
|
+
if (parsed === undefined)
|
|
71
|
+
return true;
|
|
72
|
+
const words = specifier.trim().replace(/:\*$/u, '').split(/\s+/u).filter(word => word !== '*' && word.length > 0);
|
|
73
|
+
if (parsed.dynamic && words.length > 1)
|
|
74
|
+
return true;
|
|
75
|
+
const pattern = shellPattern(specifier);
|
|
76
|
+
return parsed.commands.some(sub => pattern.test(sub));
|
|
77
|
+
}
|
|
78
|
+
/** `git *` matches `git` and `git <anything>`; `prefix:*` is the legacy prefix form. */
|
|
79
|
+
function shellPattern(specifier) {
|
|
80
|
+
const trimmed = specifier.trim();
|
|
81
|
+
if (trimmed.endsWith(':*'))
|
|
82
|
+
return new RegExp(`^${escape(trimmed.slice(0, -2))}(\\s.*)?$`, 'su');
|
|
83
|
+
if (trimmed.endsWith(' *'))
|
|
84
|
+
return new RegExp(`^${globSource(trimmed.slice(0, -2), true)}(\\s.*)?$`, 'su');
|
|
85
|
+
return new RegExp(`^${globSource(trimmed, true)}$`, 'su');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* `domain:example.com` is that host only, `*.example.com` any subdomain at
|
|
89
|
+
* any depth but not the domain itself, `*` every host; any other `*` stays
|
|
90
|
+
* between two dots. Case and a trailing dot are ignored.
|
|
91
|
+
*/
|
|
92
|
+
function domainMatches(domain, url) {
|
|
93
|
+
try {
|
|
94
|
+
const host = new URL(url).hostname.toLowerCase().replace(/\.$/u, '');
|
|
95
|
+
const wanted = domain.trim().toLowerCase().replace(/\.$/u, '');
|
|
96
|
+
if (wanted === '*')
|
|
97
|
+
return true;
|
|
98
|
+
if (wanted.startsWith('*.'))
|
|
99
|
+
return host.endsWith(wanted.slice(1));
|
|
100
|
+
return new RegExp(`^${wanted.split('*').map(escape).join('[^.]*')}$`, 'u').test(host);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Whether a gitignore-style pattern, relative to the working directory,
|
|
108
|
+
* matches a path (skill `paths`, `Read(...)`/`Edit(...)` rules).
|
|
109
|
+
*/
|
|
110
|
+
export function pathPatternMatches(pattern, path, cwd) {
|
|
111
|
+
return pathRuleMatches(pattern, path, cwd);
|
|
112
|
+
}
|
|
113
|
+
/** Gitignore-style path rule, relative to the working directory. */
|
|
114
|
+
function pathRuleMatches(specifier, path, cwd) {
|
|
115
|
+
const windows = process.platform === 'win32';
|
|
116
|
+
const normalize = (value) => {
|
|
117
|
+
const posix = value.replace(/\\/gu, '/');
|
|
118
|
+
return windows ? posix.toLowerCase() : posix;
|
|
119
|
+
};
|
|
120
|
+
const target = isAbsolute(path) ? resolve(path) : resolve(cwd, path);
|
|
121
|
+
let pattern = specifier.trim();
|
|
122
|
+
let base = cwd;
|
|
123
|
+
if (pattern.startsWith('//')) {
|
|
124
|
+
pattern = pattern.slice(1);
|
|
125
|
+
base = '';
|
|
126
|
+
}
|
|
127
|
+
else if (pattern.startsWith('~/')) {
|
|
128
|
+
base = homedir();
|
|
129
|
+
pattern = pattern.slice(2);
|
|
130
|
+
}
|
|
131
|
+
else if (pattern.startsWith('./')) {
|
|
132
|
+
pattern = pattern.slice(2);
|
|
133
|
+
}
|
|
134
|
+
else if (pattern.startsWith('/') && !windows) {
|
|
135
|
+
pattern = pattern.slice(1);
|
|
136
|
+
}
|
|
137
|
+
const anchored = pattern.replace(/\/$/u, '').includes('/');
|
|
138
|
+
if (base === '')
|
|
139
|
+
return globRegex(normalize(pattern), false).test(normalize(target));
|
|
140
|
+
const rel = normalize(relative(base, target));
|
|
141
|
+
if (!anchored) {
|
|
142
|
+
const name = rel.split('/').at(-1) ?? rel;
|
|
143
|
+
return globRegex(normalize(pattern), false).test(name) || globRegex(`**/${normalize(pattern)}`, false).test(rel);
|
|
144
|
+
}
|
|
145
|
+
return globRegex(normalize(pattern), false).test(rel);
|
|
146
|
+
}
|
|
147
|
+
function globRegex(pattern, shell) {
|
|
148
|
+
return new RegExp(`^${globSource(pattern, shell)}$`, 'su');
|
|
149
|
+
}
|
|
150
|
+
/** Glob → regex source. In shell rules `*` spans anything; in path rules it stays within a segment. */
|
|
151
|
+
function globSource(pattern, shell) {
|
|
152
|
+
let source = '';
|
|
153
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
154
|
+
const char = pattern[index] ?? '';
|
|
155
|
+
if (char === '*') {
|
|
156
|
+
if (pattern[index + 1] === '*') {
|
|
157
|
+
index++;
|
|
158
|
+
if (pattern[index + 1] === '/') {
|
|
159
|
+
index++;
|
|
160
|
+
source += '(?:.*/)?';
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
source += '.*';
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
source += shell ? '.*' : '[^/]*';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (char === '?') {
|
|
171
|
+
source += shell ? '.' : '[^/]';
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
source += escape(char);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return source;
|
|
178
|
+
}
|
|
179
|
+
function escape(text) {
|
|
180
|
+
return text.replace(/[.+^${}()|[\]\\]/gu, '\\$&');
|
|
181
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { ForeignPlugin } from '@kirkchinese/harness-forge-core';
|
|
2
|
+
/** Fields every handler type accepts. */
|
|
3
|
+
interface HandlerCommon {
|
|
4
|
+
/** The `if` permission rule. */
|
|
5
|
+
readonly condition?: string;
|
|
6
|
+
readonly timeoutSec?: number;
|
|
7
|
+
readonly statusMessage?: string;
|
|
8
|
+
/** Only honored for skill-frontmatter hooks. */
|
|
9
|
+
readonly once?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** A `type: "command"` handler. */
|
|
12
|
+
export interface CommandHandler extends HandlerCommon {
|
|
13
|
+
readonly type: 'command';
|
|
14
|
+
readonly command: string;
|
|
15
|
+
/** Exec form when present: `command` is spawned directly with these arguments. */
|
|
16
|
+
readonly args?: readonly string[];
|
|
17
|
+
readonly shell?: 'bash' | 'powershell';
|
|
18
|
+
readonly async?: boolean;
|
|
19
|
+
readonly asyncRewake?: boolean;
|
|
20
|
+
readonly rewakeMessage?: string;
|
|
21
|
+
readonly onFailure?: 'continue' | 'block';
|
|
22
|
+
/** Codex: Windows-only command override. */
|
|
23
|
+
readonly commandWindows?: string;
|
|
24
|
+
/** Codex: approximate token threshold before additionalContext spills to a file; 0 disables it. */
|
|
25
|
+
readonly additionalContextLimit?: number;
|
|
26
|
+
}
|
|
27
|
+
/** A `type: "http"` handler. */
|
|
28
|
+
export interface HttpHandler extends HandlerCommon {
|
|
29
|
+
readonly type: 'http';
|
|
30
|
+
readonly url: string;
|
|
31
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
32
|
+
readonly allowedEnvVars?: readonly string[];
|
|
33
|
+
readonly onFailure?: 'continue' | 'block';
|
|
34
|
+
}
|
|
35
|
+
/** A `type: "mcp_tool"` handler. */
|
|
36
|
+
export interface McpToolHandler extends HandlerCommon {
|
|
37
|
+
readonly type: 'mcp_tool';
|
|
38
|
+
readonly server: string;
|
|
39
|
+
readonly tool: string;
|
|
40
|
+
readonly input?: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** A `type: "prompt"` or `type: "agent"` handler. */
|
|
43
|
+
export interface ModelHandler extends HandlerCommon {
|
|
44
|
+
readonly type: 'prompt' | 'agent';
|
|
45
|
+
readonly prompt: string;
|
|
46
|
+
readonly model?: string;
|
|
47
|
+
readonly continueOnBlock?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A handler the configuration does not describe validly. */
|
|
50
|
+
export interface InvalidHandler extends HandlerCommon {
|
|
51
|
+
readonly type: 'invalid';
|
|
52
|
+
readonly reason: string;
|
|
53
|
+
}
|
|
54
|
+
/** One configured handler. */
|
|
55
|
+
export type HookHandler = CommandHandler | HttpHandler | McpToolHandler | ModelHandler | InvalidHandler;
|
|
56
|
+
/** One matcher group. */
|
|
57
|
+
export interface HookGroup {
|
|
58
|
+
readonly matcher?: string;
|
|
59
|
+
readonly handlers: readonly HookHandler[];
|
|
60
|
+
}
|
|
61
|
+
/** Event name → matcher groups, in configuration order. */
|
|
62
|
+
export type HookTable = ReadonlyMap<string, readonly HookGroup[]>;
|
|
63
|
+
/** Read a hooks file or settings file. */
|
|
64
|
+
export declare function readHookTable(path: string): HookTable;
|
|
65
|
+
/**
|
|
66
|
+
* Parse an already-loaded hooks value: `{ hooks: { Event: [...] } }` or the
|
|
67
|
+
* bare `{ Event: [...] }` table (frontmatter form).
|
|
68
|
+
*/
|
|
69
|
+
export declare function parseHookTable(raw: unknown): HookTable;
|
|
70
|
+
/** Every handler type a table uses, for the compatibility report. */
|
|
71
|
+
export declare function handlerTypes(table: HookTable): string[];
|
|
72
|
+
/** A hook source for one plugin's hooks file or one skill's, agent's or command's frontmatter. */
|
|
73
|
+
export declare function hookSource(componentId: string, plugin: ForeignPlugin, dataDir: string, table: HookTable, origin: 'plugin' | 'settings' | 'skill' | 'agent'): HookConfigSource;
|
|
74
|
+
/** One hooks configuration with where it comes from: what the hooks row runs. */
|
|
75
|
+
export interface HookConfigSource {
|
|
76
|
+
readonly componentId: string;
|
|
77
|
+
readonly pluginId: string;
|
|
78
|
+
readonly dialect: 'claude-code' | 'codex';
|
|
79
|
+
readonly pluginRoot: string;
|
|
80
|
+
readonly dataDir: string;
|
|
81
|
+
readonly table: HookTable;
|
|
82
|
+
readonly origin?: 'plugin' | 'settings' | 'skill' | 'agent';
|
|
83
|
+
readonly options?: Readonly<Record<string, string>>;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a foreign hooks configuration (a Claude Code or Codex `hooks.json`, a
|
|
3
|
+
* settings file's `hooks` key, an inline `plugin.json#hooks` object, or a
|
|
4
|
+
* skill's or agent's frontmatter `hooks`) into the broker's handler model,
|
|
5
|
+
* keeping every field the hook reference defines.
|
|
6
|
+
* @module @kirkchinese/harness-forge
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
/** Read a hooks file or settings file. */
|
|
10
|
+
export function readHookTable(path) {
|
|
11
|
+
return parseHookTable(JSON.parse(readFileSync(path, 'utf8').replace(/^\uFEFF/u, '')));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse an already-loaded hooks value: `{ hooks: { Event: [...] } }` or the
|
|
15
|
+
* bare `{ Event: [...] }` table (frontmatter form).
|
|
16
|
+
*/
|
|
17
|
+
export function parseHookTable(raw) {
|
|
18
|
+
const root = record(raw);
|
|
19
|
+
const hooks = record(root?.['hooks']) ?? root ?? {};
|
|
20
|
+
const table = new Map();
|
|
21
|
+
for (const [event, value] of Object.entries(hooks)) {
|
|
22
|
+
if (!Array.isArray(value))
|
|
23
|
+
continue;
|
|
24
|
+
const groups = [];
|
|
25
|
+
for (const entry of value) {
|
|
26
|
+
const group = record(entry);
|
|
27
|
+
if (group === undefined)
|
|
28
|
+
continue;
|
|
29
|
+
const handlers = Array.isArray(group['hooks']) ? group['hooks'].map(parseHandler) : [];
|
|
30
|
+
const matcher = typeof group['matcher'] === 'string' ? group['matcher'] : undefined;
|
|
31
|
+
groups.push({ ...(matcher !== undefined ? { matcher } : {}), handlers });
|
|
32
|
+
}
|
|
33
|
+
if (groups.length > 0)
|
|
34
|
+
table.set(event, groups);
|
|
35
|
+
}
|
|
36
|
+
return table;
|
|
37
|
+
}
|
|
38
|
+
/** Every handler type a table uses, for the compatibility report. */
|
|
39
|
+
export function handlerTypes(table) {
|
|
40
|
+
const types = new Set();
|
|
41
|
+
for (const groups of table.values())
|
|
42
|
+
for (const group of groups)
|
|
43
|
+
for (const handler of group.handlers)
|
|
44
|
+
types.add(handler.type);
|
|
45
|
+
return [...types];
|
|
46
|
+
}
|
|
47
|
+
function parseHandler(value) {
|
|
48
|
+
const handler = record(value) ?? {};
|
|
49
|
+
const common = commonFields(handler);
|
|
50
|
+
const type = handler['type'];
|
|
51
|
+
switch (type) {
|
|
52
|
+
case 'command': {
|
|
53
|
+
if (typeof handler['command'] !== 'string' || handler['command'].length === 0)
|
|
54
|
+
return invalid(common, 'command handler has no "command"');
|
|
55
|
+
const args = handler['args'];
|
|
56
|
+
const shell = handler['shell'];
|
|
57
|
+
const onFailure = handler['onFailure'];
|
|
58
|
+
const limit = handler['additionalContextLimit'];
|
|
59
|
+
const windows = handler['commandWindows'] ?? handler['command_windows'];
|
|
60
|
+
return {
|
|
61
|
+
...common,
|
|
62
|
+
type,
|
|
63
|
+
command: handler['command'],
|
|
64
|
+
...(Array.isArray(args) ? { args: args.map(item => String(item)) } : {}),
|
|
65
|
+
...(shell === 'bash' || shell === 'powershell' ? { shell } : {}),
|
|
66
|
+
...(handler['async'] === true ? { async: true } : {}),
|
|
67
|
+
...(handler['asyncRewake'] === true ? { asyncRewake: true } : {}),
|
|
68
|
+
...(typeof handler['rewakeMessage'] === 'string' ? { rewakeMessage: handler['rewakeMessage'] } : {}),
|
|
69
|
+
...(onFailure === 'continue' || onFailure === 'block' ? { onFailure } : {}),
|
|
70
|
+
...(typeof windows === 'string' && windows.length > 0 ? { commandWindows: windows } : {}),
|
|
71
|
+
...(typeof limit === 'number' && limit >= 0 ? { additionalContextLimit: limit } : {}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
case 'http': {
|
|
75
|
+
if (typeof handler['url'] !== 'string' || handler['url'].length === 0)
|
|
76
|
+
return invalid(common, 'http handler has no "url"');
|
|
77
|
+
const headers = record(handler['headers']);
|
|
78
|
+
const allowed = handler['allowedEnvVars'];
|
|
79
|
+
const onFailure = handler['onFailure'];
|
|
80
|
+
return {
|
|
81
|
+
...common,
|
|
82
|
+
type,
|
|
83
|
+
url: handler['url'],
|
|
84
|
+
...(headers !== undefined ? { headers: Object.fromEntries(Object.entries(headers).map(([key, item]) => [key, String(item)])) } : {}),
|
|
85
|
+
...(Array.isArray(allowed) ? { allowedEnvVars: allowed.map(item => String(item)) } : {}),
|
|
86
|
+
...(onFailure === 'continue' || onFailure === 'block' ? { onFailure } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
case 'mcp_tool': {
|
|
90
|
+
if (typeof handler['server'] !== 'string' || typeof handler['tool'] !== 'string')
|
|
91
|
+
return invalid(common, 'mcp_tool handler needs "server" and "tool"');
|
|
92
|
+
return { ...common, type, server: handler['server'], tool: handler['tool'], ...('input' in handler ? { input: handler['input'] } : {}) };
|
|
93
|
+
}
|
|
94
|
+
case 'prompt':
|
|
95
|
+
case 'agent': {
|
|
96
|
+
if (typeof handler['prompt'] !== 'string' || handler['prompt'].length === 0)
|
|
97
|
+
return invalid(common, `${type} handler has no "prompt"`);
|
|
98
|
+
return {
|
|
99
|
+
...common,
|
|
100
|
+
type,
|
|
101
|
+
prompt: handler['prompt'],
|
|
102
|
+
...(typeof handler['model'] === 'string' ? { model: handler['model'] } : {}),
|
|
103
|
+
...(handler['continueOnBlock'] === true ? { continueOnBlock: true } : {}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
default:
|
|
107
|
+
return invalid(common, typeof type === 'string' ? `unknown handler type "${type}"` : 'handler has no "type"');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function commonFields(handler) {
|
|
111
|
+
const timeout = handler['timeout'];
|
|
112
|
+
const condition = handler['if'];
|
|
113
|
+
return {
|
|
114
|
+
...(typeof condition === 'string' && condition.trim().length > 0 ? { condition: condition.trim() } : {}),
|
|
115
|
+
...(typeof timeout === 'number' && timeout > 0 ? { timeoutSec: timeout } : {}),
|
|
116
|
+
...(typeof handler['statusMessage'] === 'string' ? { statusMessage: handler['statusMessage'] } : {}),
|
|
117
|
+
...(handler['once'] === true ? { once: true } : {}),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function invalid(common, reason) {
|
|
121
|
+
return { ...common, type: 'invalid', reason };
|
|
122
|
+
}
|
|
123
|
+
function record(value) {
|
|
124
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : undefined;
|
|
125
|
+
}
|
|
126
|
+
/** A hook source for one plugin's hooks file or one skill's, agent's or command's frontmatter. */
|
|
127
|
+
export function hookSource(componentId, plugin, dataDir, table, origin) {
|
|
128
|
+
return {
|
|
129
|
+
componentId,
|
|
130
|
+
pluginId: plugin.id,
|
|
131
|
+
dialect: plugin.source === 'codex' ? 'codex' : 'claude-code',
|
|
132
|
+
pluginRoot: plugin.root,
|
|
133
|
+
dataDir,
|
|
134
|
+
table,
|
|
135
|
+
origin,
|
|
136
|
+
options: userConfigDefaults(plugin.manifest['userConfig']),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Plugin `userConfig` option values: the declared defaults. */
|
|
140
|
+
function userConfigDefaults(value) {
|
|
141
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
142
|
+
return {};
|
|
143
|
+
const out = {};
|
|
144
|
+
for (const [key, option] of Object.entries(value)) {
|
|
145
|
+
const fallback = typeof option === 'object' && option !== null ? option.default : undefined;
|
|
146
|
+
if (fallback !== undefined && fallback !== null)
|
|
147
|
+
out[key] = typeof fallback === 'string' ? fallback : JSON.stringify(fallback);
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matcher-group selection, as each harness defines it.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code: `*`, `""` or no matcher match everything; a matcher made only
|
|
5
|
+
* of letters, digits, `_`, `-`, spaces, `,` and `|` is a list of exact
|
|
6
|
+
* strings (`FileChanged` and `StopFailure` use the narrower `[A-Za-z0-9_|]`
|
|
7
|
+
* set); anything else is an unanchored JavaScript regular expression. Events
|
|
8
|
+
* without matcher support ignore the matcher.
|
|
9
|
+
*
|
|
10
|
+
* Codex: the matcher is always a regular expression, tested against the tool
|
|
11
|
+
* name and its aliases.
|
|
12
|
+
* @module @kirkchinese/harness-forge
|
|
13
|
+
*/
|
|
14
|
+
import type { HookDialect } from './vocabulary.js';
|
|
15
|
+
/**
|
|
16
|
+
* Whether a matcher group runs for this occurrence.
|
|
17
|
+
* @param subjects - the value the event matches on; tool events pass every
|
|
18
|
+
* name the tool answers to.
|
|
19
|
+
*/
|
|
20
|
+
export declare function matcherSelects(dialect: HookDialect, event: string, matcher: string | undefined, subjects: readonly string[]): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Claude Code events whose matcher is ignored. */
|
|
2
|
+
const CLAUDE_UNMATCHED = new Set([
|
|
3
|
+
'UserPromptSubmit', 'PostToolBatch', 'Stop', 'TeammateIdle', 'TaskCreated', 'TaskCompleted',
|
|
4
|
+
'WorktreeCreate', 'WorktreeRemove', 'MessageDisplay', 'CwdChanged',
|
|
5
|
+
]);
|
|
6
|
+
/** Codex events whose matcher is ignored. */
|
|
7
|
+
const CODEX_UNMATCHED = new Set(['UserPromptSubmit', 'Stop', 'Interrupt', 'PreModelRequest', 'PostModelRequest']);
|
|
8
|
+
const NARROW_EXACT = new Set(['FileChanged', 'StopFailure']);
|
|
9
|
+
/**
|
|
10
|
+
* Whether a matcher group runs for this occurrence.
|
|
11
|
+
* @param subjects - the value the event matches on; tool events pass every
|
|
12
|
+
* name the tool answers to.
|
|
13
|
+
*/
|
|
14
|
+
export function matcherSelects(dialect, event, matcher, subjects) {
|
|
15
|
+
if (matcher === undefined || matcher === '' || matcher === '*')
|
|
16
|
+
return true;
|
|
17
|
+
if ((dialect === 'codex' ? CODEX_UNMATCHED : CLAUDE_UNMATCHED).has(event))
|
|
18
|
+
return true;
|
|
19
|
+
if (dialect === 'claude-code') {
|
|
20
|
+
const exact = NARROW_EXACT.has(event) ? /^[A-Za-z0-9_|]+$/u : /^[A-Za-z0-9_\- ,|]+$/u;
|
|
21
|
+
if (exact.test(matcher)) {
|
|
22
|
+
const options = matcher.split(NARROW_EXACT.has(event) ? /\|/u : /[|,]/u).map(item => item.trim()).filter(item => item.length > 0);
|
|
23
|
+
return subjects.some(subject => options.includes(subject));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
let pattern;
|
|
27
|
+
try {
|
|
28
|
+
pattern = new RegExp(matcher, 'u');
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
try {
|
|
32
|
+
pattern = new RegExp(matcher);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return subjects.some(subject => pattern.test(subject));
|
|
39
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What hooks show the user rather than the model — a `systemMessage`, a
|
|
3
|
+
* `<event> hook error` notice, a block or stop reason, a terminal
|
|
4
|
+
* notification — recorded in the session as `plugin:harness-forge/notice`
|
|
5
|
+
* records. A reader that does not know the record skips it; the Harness
|
|
6
|
+
* Forge client renders it in the conversation.
|
|
7
|
+
* @module @kirkchinese/harness-forge
|
|
8
|
+
*/
|
|
9
|
+
import { type HookNotice } from '../dsh/session-records.js';
|
|
10
|
+
export type { HookNotice, HookOutputRecord } from '../dsh/session-records.js';
|
|
11
|
+
/** Record one notice in a session; a session that refuses the record loses only the notice. */
|
|
12
|
+
export declare function appendNotice(session: unknown, notice: HookNotice): void;
|
|
13
|
+
/** Parse the notification a `terminalSequence` carries (OSC 9, 99, 777 and titles). */
|
|
14
|
+
export declare function terminalNotification(sequence: string): {
|
|
15
|
+
title?: string;
|
|
16
|
+
body: string;
|
|
17
|
+
} | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What hooks show the user rather than the model — a `systemMessage`, a
|
|
3
|
+
* `<event> hook error` notice, a block or stop reason, a terminal
|
|
4
|
+
* notification — recorded in the session as `plugin:harness-forge/notice`
|
|
5
|
+
* records. A reader that does not know the record skips it; the Harness
|
|
6
|
+
* Forge client renders it in the conversation.
|
|
7
|
+
* @module @kirkchinese/harness-forge
|
|
8
|
+
*/
|
|
9
|
+
import { appendRecord } from '../dsh/session-records.js';
|
|
10
|
+
/** Record one notice in a session; a session that refuses the record loses only the notice. */
|
|
11
|
+
export function appendNotice(session, notice) {
|
|
12
|
+
try {
|
|
13
|
+
appendRecord(session, 'plugin:harness-forge/notice', notice);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// The notice is informational.
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Parse the notification a `terminalSequence` carries (OSC 9, 99, 777 and titles). */
|
|
20
|
+
export function terminalNotification(sequence) {
|
|
21
|
+
// eslint-disable-next-line no-control-regex
|
|
22
|
+
const osc = /\u001b\](\d+);([^\u0007\u001b]*)(?:\u0007|\u001b\\)/gu;
|
|
23
|
+
for (const match of sequence.matchAll(osc)) {
|
|
24
|
+
const code = match[1];
|
|
25
|
+
const payload = match[2] ?? '';
|
|
26
|
+
if (code === '777') {
|
|
27
|
+
const [, title, ...body] = payload.split(';');
|
|
28
|
+
return { ...(title !== undefined ? { title } : {}), body: body.join(';') };
|
|
29
|
+
}
|
|
30
|
+
if (code === '9' && !payload.startsWith('4;'))
|
|
31
|
+
return { body: payload };
|
|
32
|
+
if (code === '99')
|
|
33
|
+
return { body: payload.replace(/^[^;]*;/u, '') };
|
|
34
|
+
if (code === '0' || code === '2')
|
|
35
|
+
return { title: payload, body: '' };
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line no-control-regex
|
|
38
|
+
return sequence.includes('\u0007') ? { body: '' } : undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode one hook run into what its harness would act on: the stdout
|
|
3
|
+
* classification (JSON object, parse failure, plain text), the JSON output
|
|
4
|
+
* schema check, and the exit-code table of the hook reference.
|
|
5
|
+
*
|
|
6
|
+
* | stdout \ exit | 0 | 2 | other |
|
|
7
|
+
* | valid JSON object | success, fields apply | block; fields still read | success; fields decide (failure for `onFailure`) |
|
|
8
|
+
* | invalid / bad schema | non-blocking error | block; stderr is the reason | non-blocking error |
|
|
9
|
+
* | plain text or nothing | success | block; stderr is the reason | non-blocking error |
|
|
10
|
+
* @module @kirkchinese/harness-forge
|
|
11
|
+
*/
|
|
12
|
+
import type { HookDialect } from './vocabulary.js';
|
|
13
|
+
/** The raw outcome of one handler, whatever its type. */
|
|
14
|
+
export interface RawRun {
|
|
15
|
+
/** Exit status: a process exit code, 0 for a 2xx HTTP response or a successful tool/model call. */
|
|
16
|
+
readonly exitCode?: number;
|
|
17
|
+
readonly stdout: string;
|
|
18
|
+
readonly stderr: string;
|
|
19
|
+
/** The handler could not produce a result. */
|
|
20
|
+
readonly failure?: {
|
|
21
|
+
readonly kind: 'start' | 'timeout' | 'transport' | 'cancelled';
|
|
22
|
+
readonly message: string;
|
|
23
|
+
};
|
|
24
|
+
/** The process exited while a child still held its output (see {@link ../process}). */
|
|
25
|
+
readonly suspectCapture?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** What a harness acts on after one run. */
|
|
28
|
+
export interface Decoded {
|
|
29
|
+
/** Validated JSON output fields. */
|
|
30
|
+
readonly json?: Readonly<Record<string, unknown>>;
|
|
31
|
+
/** Plain stdout (only on success). */
|
|
32
|
+
readonly plain?: string;
|
|
33
|
+
/** The run blocks the action (exit 2): its reason. */
|
|
34
|
+
readonly block?: string;
|
|
35
|
+
/** The run is a hook error, with its notice text. */
|
|
36
|
+
readonly error?: string;
|
|
37
|
+
/** The run counts as a failure for `onFailure: "block"`. */
|
|
38
|
+
readonly failed: boolean;
|
|
39
|
+
/** The run was cancelled; it has no effect. */
|
|
40
|
+
readonly cancelled?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Decode a synchronous run. */
|
|
43
|
+
export declare function decodeRun(event: string, dialect: HookDialect, run: RawRun): Decoded;
|
|
44
|
+
/**
|
|
45
|
+
* Decode a background (`async`) run: the JSON response may span stdout alone
|
|
46
|
+
* or sit on one line among other text; fields of the wrong type are dropped.
|
|
47
|
+
*/
|
|
48
|
+
export declare function decodeAsyncRun(event: string, dialect: HookDialect, run: RawRun): Decoded;
|
|
49
|
+
/** Whether plain stdout of a successful run becomes context on this event. */
|
|
50
|
+
export declare function plainIsContext(event: string, dialect: HookDialect): boolean;
|
|
51
|
+
/** The `hookSpecificOutput` object of a decoded run. */
|
|
52
|
+
export declare function specific(decoded: Decoded): Readonly<Record<string, unknown>> | undefined;
|
|
53
|
+
/** The context strings a run adds: `additionalContext`, plus plain stdout where the event reads it. */
|
|
54
|
+
export declare function contextsOf(event: string, dialect: HookDialect, decoded: Decoded): string[];
|
|
55
|
+
/** The first non-empty line, trimmed and bounded. */
|
|
56
|
+
export declare function firstLine(text: string): string;
|