@hmharness/agent 0.5.2 → 0.5.3
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/dist/runner.d.ts +5 -0
- package/dist/runner.js +35 -3
- package/package.json +6 -6
package/dist/runner.d.ts
CHANGED
|
@@ -56,6 +56,11 @@ export interface ApprovedRule {
|
|
|
56
56
|
time: string;
|
|
57
57
|
}
|
|
58
58
|
export declare function loadApprovedRules(home: string): ApprovedRule[];
|
|
59
|
+
/** Structured rule matching (review fix: raw string prefix was exploitable -
|
|
60
|
+
* `node scripts/` prefix was hit by `node scripts/../../evil.js`). Now:
|
|
61
|
+
* parses the rule as structured args, string values match by prefix BUT the
|
|
62
|
+
* extension is checked for path traversal (`..` at the boundary blocks). */
|
|
63
|
+
export declare function matchesRule(rules: ApprovedRule[], toolName: string, args: Record<string, unknown>): boolean;
|
|
59
64
|
export declare function makeApproval(cfg: HmhConfig, yes: boolean, sharedRl?: readline.Interface): LoopApproval;
|
|
60
65
|
export interface RunnerEvents {
|
|
61
66
|
onLine?(line: string): void;
|
package/dist/runner.js
CHANGED
|
@@ -131,9 +131,36 @@ function saveApprovedRules(home, rules) {
|
|
|
131
131
|
}
|
|
132
132
|
catch { /* best effort */ }
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
/** Structured rule matching (review fix: raw string prefix was exploitable -
|
|
135
|
+
* `node scripts/` prefix was hit by `node scripts/../../evil.js`). Now:
|
|
136
|
+
* parses the rule as structured args, string values match by prefix BUT the
|
|
137
|
+
* extension is checked for path traversal (`..` at the boundary blocks). */
|
|
138
|
+
export function matchesRule(rules, toolName, args) {
|
|
139
|
+
return rules.some((r) => {
|
|
140
|
+
if (r.tool !== toolName)
|
|
141
|
+
return false;
|
|
142
|
+
try {
|
|
143
|
+
const ruleArgs = JSON.parse(r.argPrefix);
|
|
144
|
+
for (const [k, rv] of Object.entries(ruleArgs)) {
|
|
145
|
+
const av = args[k];
|
|
146
|
+
if (typeof rv === 'string' && typeof av === 'string') {
|
|
147
|
+
if (!av.startsWith(rv))
|
|
148
|
+
return false;
|
|
149
|
+
// path traversal: the extension after the approved prefix must not
|
|
150
|
+
// start with `..` (blocks `node scripts/` → `node scripts/../../x`)
|
|
151
|
+
if (av.slice(rv.length).startsWith('..'))
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
else if (rv !== av) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
137
164
|
}
|
|
138
165
|
export function makeApproval(cfg, yes, sharedRl) {
|
|
139
166
|
const t = strings(cfg.locale ?? 'zh');
|
|
@@ -201,6 +228,11 @@ export async function runAgentTask(opts) {
|
|
|
201
228
|
locale: cfg.locale,
|
|
202
229
|
agentsMd: agentsMd ?? undefined,
|
|
203
230
|
});
|
|
231
|
+
// system prompt token count: the prompt has been quietly growing (Codex 9
|
|
232
|
+
// instructions + AGENTS.md + memory + skills + insights) while no cost gate
|
|
233
|
+
// watches IT - this makes the size visible every run (review finding #5)
|
|
234
|
+
const systemTokens = Math.ceil(system.length / 4);
|
|
235
|
+
events.onLine?.(` [prompt] system: ${system.length} chars (~${systemTokens} tokens) · ${agentsMd ? 'AGENTS.md: yes' : 'no AGENTS.md'}`);
|
|
204
236
|
await session.user(opts.task);
|
|
205
237
|
// YOLO fix: when yes=true the caller's approvalAsk (TUI dialog, web remote
|
|
206
238
|
// gate) must NOT override the auto-approve gate - it used to take
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/agent",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "hmharness agent execution layer: base tools, system prompt, sub-agent spawn, and the shared task runner that frontends (cli, web) drive.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"build": "tsc -p tsconfig.build.json"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@hmharness/kernel": "0.5.
|
|
19
|
-
"@hmharness/evolution": "0.5.
|
|
20
|
-
"@hmharness/domain-harmony": "0.5.
|
|
21
|
-
"@hmharness/domain-ops": "0.5.
|
|
18
|
+
"@hmharness/kernel": "0.5.3",
|
|
19
|
+
"@hmharness/evolution": "0.5.3",
|
|
20
|
+
"@hmharness/domain-harmony": "0.5.3",
|
|
21
|
+
"@hmharness/domain-ops": "0.5.3"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist"
|
|
25
25
|
],
|
|
26
|
-
"license": "
|
|
26
|
+
"license": "MIT",
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
29
|
"url": "git+https://github.com/swsgbl/hmharness.git"
|