@staix/agent-hub 0.42.0 → 0.44.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/CHANGELOG.md +42 -0
- package/README.md +2 -1
- package/docs/adding-an-ai-tool.md +2 -0
- package/docs/agent-notes/daemon.md +3 -3
- package/docs/agent-notes/local-worker.md +1 -0
- package/docs/agent-notes/tasks.md +3 -2
- package/docs/agent-notes/tests.md +2 -2
- package/docs/design/adapters.md +3 -0
- package/docs/design/agent-hub-architecture.md +2 -0
- package/docs/design/bus.md +2 -0
- package/docs/design/supervision.md +13 -1
- package/docs/design/task-board.md +13 -1
- package/docs/dogfood.md +13 -3
- package/docs/events.md +4 -2
- package/docs/memory.md +5 -3
- package/docs/operations.md +97 -17
- package/docs/quickstart.md +18 -2
- package/docs/research.md +2 -0
- package/docs/sdlc.md +6 -3
- package/docs/security.md +2 -2
- package/docs/verification/2026-11-11-supervision-pilot-1221.md +864 -0
- package/docs/verification/2026-11-18-0.43.0.md +56 -0
- package/docs/verification/2026-11-19-0.44.0.md +60 -0
- package/docs/verified.json +25 -25
- package/package.json +2 -2
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +486 -218
- package/plugins/agent-hub/server.js +505 -234
- package/src/adapters/claude-implementer.ts +11 -1
- package/src/adapters/claude-print-child.ts +4 -1
- package/src/adapters/conformance/fakes/acp-server.ts +2 -1
- package/src/adapters/conformance/fakes/app-server.ts +1 -1
- package/src/adapters/local-worker.ts +7 -3
- package/src/adapters/reviewer-print.ts +3 -1
- package/src/cli/help.ts +3 -3
- package/src/cli/identity.ts +2 -0
- package/src/cli/main.ts +57 -5
- package/src/cli/output.ts +2 -2
- package/src/cli/sdlc-output.ts +7 -1
- package/src/cli/upgrade-output.ts +43 -2
- package/src/cli/upgrade-stopped.ts +162 -0
- package/src/cli/upgrade-wait.ts +37 -0
- package/src/cli/upgrade.ts +9 -3
- package/src/hub/board.ts +17 -2
- package/src/hub/bus.ts +4 -0
- package/src/hub/claude-shell-wrapper.ts +2 -1
- package/src/hub/config-apply.ts +1 -0
- package/src/hub/control-write-trace.ts +39 -2
- package/src/hub/daemon.ts +141 -37
- package/src/hub/envelope.ts +1 -0
- package/src/hub/facts.ts +30 -0
- package/src/hub/handoff.ts +14 -0
- package/src/hub/hub-tools.ts +1 -1
- package/src/hub/questions.ts +7 -0
- package/src/hub/quota-events.ts +40 -0
- package/src/hub/recovery-store.ts +57 -0
- package/src/hub/report.ts +1 -1
- package/src/hub/research-quality.ts +5 -1
- package/src/hub/research-record.ts +5 -3
- package/src/hub/restart.ts +49 -2
- package/src/hub/runtime-capture-prune.ts +123 -4
- package/src/hub/runtime-prune-health.ts +10 -2
- package/src/hub/sdlc-merge.ts +7 -3
- package/src/hub/sdlc-metrics.ts +17 -8
- package/src/hub/sdlc.ts +18 -6
- package/src/hub/settings.ts +2 -0
- package/src/hub/snapshots.ts +43 -0
- package/src/hub/supervision-rules.ts +2 -2
- package/src/hub/task-shell-command.ts +124 -0
- package/src/hub/task-sweep.ts +6 -2
- package/src/hub/tasks.ts +131 -22
- package/src/hub/turn-attribution.ts +46 -0
- package/src/hub/worktree-shelf.ts +2 -1
- package/src/local/sandbox.ts +2 -1
- package/src/local/shell-environment.ts +6 -0
- package/src/memory/brief.ts +10 -1
- package/templates/AGENTS.block.md +1 -1
package/src/hub/sdlc.ts
CHANGED
|
@@ -65,8 +65,14 @@ export interface MergeRecord {
|
|
|
65
65
|
/** #481 S7: the merged PR's review and CI figures, read once at merge by the host. Absent when the PR could not be read; fields inside are null when unknown. */
|
|
66
66
|
cost?: import("./cost-governance.ts").MergeCost;
|
|
67
67
|
}
|
|
68
|
+
/** A merge observed by readback, with no locally executed merge or cleanup. */
|
|
69
|
+
export interface ReadbackMergeRecord {
|
|
70
|
+
repo: string; pr: number; head: string; at: number; state: "merged";
|
|
71
|
+
mergeCommit?: string; cost?: import("./cost-governance.ts").MergeCost;
|
|
72
|
+
}
|
|
68
73
|
export interface SdlcReceipt {
|
|
69
74
|
merge?: MergeRecord;
|
|
75
|
+
mergeReadback?: ReadbackMergeRecord;
|
|
70
76
|
stage: SdlcStage;
|
|
71
77
|
planReview?: PlanReviewReceipt;
|
|
72
78
|
criteria?: CriteriaReceipt;
|
|
@@ -284,7 +290,7 @@ export function sdlcReceipt(value: unknown, previous: SdlcReceipt | undefined =
|
|
|
284
290
|
|
|
285
291
|
function receiptIdentity(next: SdlcReceipt, previous: SdlcReceipt, raw: Record<string, unknown>): SdlcReceipt {
|
|
286
292
|
const checklist = raw.criteria ?? raw.phase;
|
|
287
|
-
if (next.repo !== previous.repo || next.pr !== previous.pr || next.head !== previous.head || next.reviewedHead !== previous.reviewedHead || next.localHead !== previous.localHead) delete next.merge;
|
|
293
|
+
if (next.repo !== previous.repo || next.pr !== previous.pr || next.head !== previous.head || next.reviewedHead !== previous.reviewedHead || next.localHead !== previous.localHead) { delete next.merge; delete next.mergeReadback; }
|
|
288
294
|
// A test receipt never carries across a different linked issue or artifact.
|
|
289
295
|
if (raw.redFirst === undefined && (next.repo !== previous.repo || next.issue !== previous.issue || next.pr !== previous.pr)) delete next.redFirst;
|
|
290
296
|
// An acceptance names one spec issue; relinking the receipt to another drops it (#481 S1).
|
|
@@ -739,15 +745,21 @@ async function identicalTreeGate(repository: string, tree: string, run: SdlcGh,
|
|
|
739
745
|
}
|
|
740
746
|
|
|
741
747
|
/** PR cost evidence excludes titles, bodies and comment text; unknown/truncated coverage never becomes zero. */
|
|
742
|
-
export async function readPrCostHistory(repository: string, number: number, run: SdlcGh = sdlcGh): Promise<import("./cost-governance.ts").CostPr | undefined> {
|
|
748
|
+
export async function readPrCostHistory(repository: string, number: number, run: SdlcGh = sdlcGh, snapshot?: unknown, expectedHead?: string): Promise<import("./cost-governance.ts").CostPr | undefined> {
|
|
743
749
|
if (!repo(repository) || !id(number)) return;
|
|
744
750
|
const [owner, name] = repository.split("/");
|
|
745
751
|
try {
|
|
746
752
|
const query = "query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){number state headRefOid mergedAt commits(first:100){nodes{commit{oid}} pageInfo{hasNextPage}} reviews(first:100){nodes{databaseId commit{oid}} pageInfo{hasNextPage}}}}}";
|
|
747
|
-
|
|
748
|
-
if (
|
|
749
|
-
|
|
750
|
-
|
|
753
|
+
let pr: any;
|
|
754
|
+
if (snapshot !== undefined) pr = snapshot;
|
|
755
|
+
else {
|
|
756
|
+
const reply = await run(["api", "graphql", "-f", `query=${query}`, "-f", `owner=${owner}`, "-f", `name=${name}`, "-F", `number=${number}`], 10_000, undefined, 128 * 1024);
|
|
757
|
+
if (reply.code !== 0) return;
|
|
758
|
+
const parsed = JSON.parse(reply.stdout);
|
|
759
|
+
if (parsed.errors) return;
|
|
760
|
+
pr = parsed.data?.repository?.pullRequest;
|
|
761
|
+
}
|
|
762
|
+
if (pr?.number !== number || !["OPEN", "CLOSED", "MERGED"].includes(pr.state) || (expectedHead !== undefined && pr.headRefOid !== expectedHead)) return;
|
|
751
763
|
const result: import("./cost-governance.ts").CostPr = { repo: repository, pr: number, state: pr.state, complete: false,
|
|
752
764
|
...(typeof pr.mergedAt === "string" && Number.isFinite(Date.parse(pr.mergedAt)) ? { mergedAt: Date.parse(pr.mergedAt) } : {}) };
|
|
753
765
|
if (pr.state !== "MERGED") return result; // Cost metrics count merged PRs, not an active work queue.
|
package/src/hub/settings.ts
CHANGED
|
@@ -58,6 +58,7 @@ const perClass = (name: TaskClass): SettingDef[] => [
|
|
|
58
58
|
{ key: `routing.classes.${name}.pi_backend`, group: "Routing", label: `${name}: Pi backend`, type: "enum", values: ["dgx", "mlx"], store: "routing", applies: "live", risk: "raises", path: ["classes", name, "pi_backend"] },
|
|
59
59
|
];
|
|
60
60
|
export const SETTINGS: readonly SettingDef[] = [
|
|
61
|
+
{ key: "memory.sync_interval_min", group: "Switches", label: "Memory sync interval in minutes (0 disables)", type: "integer", min: 0, max: 1440, store: "config", applies: "live", risk: "raises", path: ["memory", "sync_interval_min"] },
|
|
61
62
|
...["enabled", "auto_reassign"].map((key): SettingDef => ({ key: `task_sweep.${key}`, group: "Switches", label: `Task sweep: ${key}`, type: "boolean", store: "config", applies: "live", risk: "raises", floor: false, path: ["task_sweep", key] })),
|
|
62
63
|
{ key: "task_sweep.no_writes_turns", group: "Switches", label: "Consecutive owner turns without writes (0 disables)", type: "integer", min: 0, max: Number.MAX_SAFE_INTEGER, store: "config", applies: "live", risk: "raises", path: ["task_sweep", "no_writes_turns"] },
|
|
63
64
|
...["interval_s", "unaccepted_min", "idle_min", "review_min", "ready_min", "ladder_min"].map((key): SettingDef => ({ key: `task_sweep.${key}`, group: "Switches", label: `Task sweep: ${key}`, type: "number", min: 1, max: 2_147_483_647 / (key === "interval_s" ? 1000 : 60_000), store: "config", applies: "live", risk: "raises", path: ["task_sweep", key] })),
|
|
@@ -193,6 +194,7 @@ export function checkSettingValue(def: SettingDef, raw: unknown, routes: readonl
|
|
|
193
194
|
if (def.store === "runtime") throw new Error(`${def.key} has no stored value to remove`);
|
|
194
195
|
return null;
|
|
195
196
|
}
|
|
197
|
+
if (def.key === "memory.sync_interval_min" && (typeof raw !== "number" || !Number.isInteger(raw) || raw < 0 || raw > 1440)) throw new Error("memory.sync_interval_min must be 0 (off) or a whole number of minutes up to 1440");
|
|
196
198
|
if (def.type === "number-or-off" && raw === "off") return raw;
|
|
197
199
|
if (def.type === "integer" || def.type === "number" || def.type === "number-or-off") {
|
|
198
200
|
if (typeof raw !== "number" || !(def.type === "integer" ? Number.isSafeInteger(raw) : Number.isFinite(raw)) || raw < (def.min ?? 0) || raw > (def.max ?? Number.MAX_SAFE_INTEGER)) throw new Error(`${def.key} takes ${def.type === "integer" ? "an integer" : def.type === "number-or-off" ? "off or a finite number" : "a number"} from ${def.min ?? 0} to ${def.max ?? Number.MAX_SAFE_INTEGER}`);
|
package/src/hub/snapshots.ts
CHANGED
|
@@ -26,6 +26,49 @@ export const budgetNow = (budget: SnapshotBudget): number => budget.now ? budget
|
|
|
26
26
|
export class SnapshotBudgetExceeded extends Error {
|
|
27
27
|
constructor() { super("snapshot burst budget exhausted; boundary evidence is unknown"); }
|
|
28
28
|
}
|
|
29
|
+
// ponytail: five consecutive exhausted bursts suspend a repository for ten minutes; an isolated capture worker is the upgrade path to avoiding this evidence-loss ceiling.
|
|
30
|
+
export const SNAPSHOT_COOLDOWN_FAILURES = 5;
|
|
31
|
+
export const SNAPSHOT_COOLDOWN_MS = 10 * 60_000;
|
|
32
|
+
|
|
33
|
+
/** In-memory, per-repository circuit breaker; a restart begins with no observations. */
|
|
34
|
+
export class SnapshotCooldown {
|
|
35
|
+
private readonly states = new Map<string, { failures: number; until: number }>();
|
|
36
|
+
private readonly observed = new WeakMap<SnapshotBudget, Set<string>>();
|
|
37
|
+
private readonly successful = new WeakMap<SnapshotBudget, Set<string>>();
|
|
38
|
+
blocked(repository: string, now: number): boolean {
|
|
39
|
+
const state = this.states.get(repository);
|
|
40
|
+
return !!state && now < state.until;
|
|
41
|
+
}
|
|
42
|
+
/** True only when this observation starts a cooldown and needs one diagnostic. */
|
|
43
|
+
exhausted(repository: string, budget: SnapshotBudget): boolean {
|
|
44
|
+
let repositories = this.observed.get(budget);
|
|
45
|
+
if (!repositories) { repositories = new Set(); this.observed.set(budget, repositories); }
|
|
46
|
+
if (repositories.has(repository)) return false;
|
|
47
|
+
repositories.add(repository);
|
|
48
|
+
const now = budgetNow(budget);
|
|
49
|
+
const state = this.states.get(repository) ?? { failures: 0, until: 0 };
|
|
50
|
+
state.failures = Math.min(SNAPSHOT_COOLDOWN_FAILURES, state.failures + 1);
|
|
51
|
+
if (state.failures >= SNAPSHOT_COOLDOWN_FAILURES) {
|
|
52
|
+
state.until = now + SNAPSHOT_COOLDOWN_MS;
|
|
53
|
+
this.states.set(repository, state);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
this.states.set(repository, state);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
success(repository: string, budget: SnapshotBudget): void {
|
|
60
|
+
let repositories = this.successful.get(budget);
|
|
61
|
+
if (!repositories) { repositories = new Set(); this.successful.set(budget, repositories); }
|
|
62
|
+
repositories.add(repository);
|
|
63
|
+
}
|
|
64
|
+
finish(budget: SnapshotBudget): void {
|
|
65
|
+
for (const repository of this.successful.get(budget) ?? []) {
|
|
66
|
+
if (!this.observed.get(budget)?.has(repository)) this.reset(repository);
|
|
67
|
+
}
|
|
68
|
+
this.successful.delete(budget);
|
|
69
|
+
}
|
|
70
|
+
reset(repository: string): void { this.states.delete(repository); }
|
|
71
|
+
}
|
|
29
72
|
const SNAPSHOT_TIMEOUT_MS = 10_000;
|
|
30
73
|
/**
|
|
31
74
|
* The wall-clock timeout of one git child. Production (no `budget.now`): the remaining budget, between 1 ms and the 10 s ceiling, so a child is killed at the budget.
|
|
@@ -15,7 +15,7 @@ import type { DeliverableRecord } from "./deliverables.ts";
|
|
|
15
15
|
export const SUPERVISION_RULES = ["repeated_failure", "deliverable_invalidated_check", "declared_overlap_without_integration"] as const;
|
|
16
16
|
export type SupervisionRuleId = (typeof SUPERVISION_RULES)[number];
|
|
17
17
|
/** Bump one rule when its trigger, refs or reason codes change meaning: a stored observation names the version it was made under. */
|
|
18
|
-
export const SUPERVISION_RULE_VERSION: Readonly<Record<SupervisionRuleId, number>> = { repeated_failure: 1, deliverable_invalidated_check:
|
|
18
|
+
export const SUPERVISION_RULE_VERSION: Readonly<Record<SupervisionRuleId, number>> = { repeated_failure: 1, deliverable_invalidated_check: 2, declared_overlap_without_integration: 1 };
|
|
19
19
|
|
|
20
20
|
/** The existing hub operation an observation names. T1 names one; nothing in this module runs it. */
|
|
21
21
|
export const SUPERVISION_ACTIONS = ["escalate", "recheck", "request_integration"] as const;
|
|
@@ -213,7 +213,7 @@ function invalidatedCheck(side: Side, measurement: DeliverableMeasurementFact |
|
|
|
213
213
|
let check: number | undefined;
|
|
214
214
|
const recorded = new Set<string>();
|
|
215
215
|
for (const [offset, entry] of side.window.entries()) {
|
|
216
|
-
if (entry.event === "check passed") check = offset;
|
|
216
|
+
if (entry.event === "check passed" || entry.event === "check run passed") check = offset;
|
|
217
217
|
for (const record of (entry.deliverables ?? []) as readonly DeliverableRecord[]) recorded.add(record.id);
|
|
218
218
|
}
|
|
219
219
|
if (check === undefined || !recorded.size) return {};
|
|
@@ -83,3 +83,127 @@ export function taskShellCommand(command: unknown, binding: TaskShellBinding): T
|
|
|
83
83
|
const file = flags.get("--body-file")!;
|
|
84
84
|
return literalPath(file) ? result("pr-create", "gh", [file]) : undefined;
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
export interface ShellWriteClass { kind: "write" | "read" | "unknown"; targets: string[] }
|
|
88
|
+
|
|
89
|
+
const SINK = /^(?:\/dev\/(?:null|stdout|stderr|tty)|&\d+|-)$/;
|
|
90
|
+
const unq = (w: string) => w.replace(/^(['"])(.*)\1$/, "$2");
|
|
91
|
+
|
|
92
|
+
/** Words of one simple command, quotes kept whole (a quoted `>` is not a redirection). */
|
|
93
|
+
function words(cmd: string): string[] | undefined {
|
|
94
|
+
const out: string[] = [];
|
|
95
|
+
let cur = "", q = "";
|
|
96
|
+
for (const c of cmd) {
|
|
97
|
+
if (q) { cur += c; if (c === q) q = ""; continue; }
|
|
98
|
+
if (c === "'" || c === '"') { q = c; cur += c; continue; }
|
|
99
|
+
if (/\s/.test(c)) { if (cur) out.push(cur), (cur = ""); continue; }
|
|
100
|
+
if (c === "`" || c === "$") return undefined; // substitution: not guessed
|
|
101
|
+
if (c === ">" && cur && !/^\d+$/.test(cur) && !/[>&]$/.test(cur)) { out.push(cur); cur = ""; } // `echo hi>f`: the redirection is its own word
|
|
102
|
+
cur += c;
|
|
103
|
+
}
|
|
104
|
+
if (q) return undefined;
|
|
105
|
+
if (cur) out.push(cur);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const CODE_RUNNER = /(?:^|[\s|;&(])(?:sh|bash|zsh|dash|ksh|python[\d.]*|node|bun|deno|ruby|perl|php)(?:\s|$)/;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* One quote-aware pass: split only at unquoted newline, `;`, `&&`, `||` and `|`, and find `<<WORD` only outside quotes.
|
|
113
|
+
* A heredoc body is data and is skipped, unless its start line runs a shell or interpreter (then it is code) or it
|
|
114
|
+
* never ends: both are unknown. Unbalanced quotes are unknown too.
|
|
115
|
+
*/
|
|
116
|
+
function segment(command: string): { parts: string[]; unknown: boolean } {
|
|
117
|
+
const parts: string[] = [];
|
|
118
|
+
let cur = "", q = "", unknown = false, lineStart = 0;
|
|
119
|
+
const heredocs: { word: string; strip: boolean }[] = [];
|
|
120
|
+
const push = () => { if (cur.trim()) parts.push(cur); cur = ""; };
|
|
121
|
+
for (let i = 0; i < command.length; i++) {
|
|
122
|
+
const c = command[i]!;
|
|
123
|
+
if (q) {
|
|
124
|
+
cur += c;
|
|
125
|
+
if (c === "\\" && q === '"' && i + 1 < command.length) cur += command[++i]!;
|
|
126
|
+
else if (c === q) q = "";
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (c === "\\" && i + 1 < command.length) { cur += c + command[++i]!; continue; }
|
|
130
|
+
if (c === "'" || c === '"') { q = c; cur += c; continue; }
|
|
131
|
+
if (c === "<" && command[i + 1] === "<" && command[i + 2] !== "<") {
|
|
132
|
+
const m = /^<<(-?)[ \t]*(?:'([^']+)'|"([^"]+)"|([A-Za-z_][A-Za-z0-9_]*))/.exec(command.slice(i));
|
|
133
|
+
if (m) { heredocs.push({ word: (m[2] ?? m[3] ?? m[4])!, strip: m[1] === "-" }); cur += " "; i += m[0].length - 1; continue; }
|
|
134
|
+
unknown = true; cur += c; continue;
|
|
135
|
+
}
|
|
136
|
+
if (c === "\n") {
|
|
137
|
+
const line = command.slice(lineStart, i);
|
|
138
|
+
push();
|
|
139
|
+
if (heredocs.length) {
|
|
140
|
+
if (CODE_RUNNER.test(line)) unknown = true;
|
|
141
|
+
for (const h of heredocs) {
|
|
142
|
+
let ended = false;
|
|
143
|
+
while (i + 1 < command.length) {
|
|
144
|
+
const end = command.indexOf("\n", i + 1);
|
|
145
|
+
const text = command.slice(i + 1, end < 0 ? command.length : end);
|
|
146
|
+
i = end < 0 ? command.length : end;
|
|
147
|
+
if ((h.strip ? text.replace(/^\t+/, "") : text) === h.word) { ended = true; break; }
|
|
148
|
+
}
|
|
149
|
+
if (!ended) unknown = true;
|
|
150
|
+
}
|
|
151
|
+
heredocs.length = 0;
|
|
152
|
+
}
|
|
153
|
+
lineStart = i + 1;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (c === ";") { push(); continue; }
|
|
157
|
+
if ((c === "&" || c === "|") && command[i + 1] === c) { push(); i++; continue; }
|
|
158
|
+
if (c === "|") { push(); continue; }
|
|
159
|
+
cur += c;
|
|
160
|
+
}
|
|
161
|
+
if (q) unknown = true;
|
|
162
|
+
if (heredocs.length) { unknown = true; if (CODE_RUNNER.test(command.slice(lineStart))) unknown = true; }
|
|
163
|
+
push();
|
|
164
|
+
return { parts, unknown };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Pure classifier of in-place shell writes (#1556 T1, observation only). A write is named only when certain;
|
|
169
|
+
* anything it cannot parse is unknown, never a guess. Targets under /tmp or /dev sinks are not worktree writes.
|
|
170
|
+
*/
|
|
171
|
+
export function classifyShellWrite(command: string): ShellWriteClass {
|
|
172
|
+
const targets: string[] = [];
|
|
173
|
+
const seg = segment(command);
|
|
174
|
+
let unknown = seg.unknown;
|
|
175
|
+
for (const part of seg.parts) {
|
|
176
|
+
const w = words(part);
|
|
177
|
+
if (!w) { unknown = true; continue; }
|
|
178
|
+
for (let i = 0; i < w.length; i++) {
|
|
179
|
+
const m = /^(\d*)(>>?|&>>?)(.*)$/.exec(w[i]!);
|
|
180
|
+
if (!m || w[i]!.startsWith("'") || w[i]!.startsWith('"')) continue;
|
|
181
|
+
const t = unq(m[3] || w[++i] || "");
|
|
182
|
+
if (!t || SINK.test(t) || /^>?&\d*$/.test(m[3] ?? "") || /^&/.test(t)) continue;
|
|
183
|
+
targets.push(t);
|
|
184
|
+
}
|
|
185
|
+
const args = w.filter((x) => !/^\d*(>>?|&>>?)/.test(x));
|
|
186
|
+
const head = args[0] === "sudo" || args[0] === "env" ? args.slice(1) : args;
|
|
187
|
+
const [c, ...rest] = head;
|
|
188
|
+
const files = rest.filter((x) => !x.startsWith("-")).map(unq);
|
|
189
|
+
if (!c) continue;
|
|
190
|
+
if (c === "sed" && rest.some((x) => /^-[a-zA-Z]*i/.test(x) || x.startsWith("--in-place"))) {
|
|
191
|
+
// -e/-f/--expression make every positional a file; an unusual suffix form is not guessed: unknown, never a wrong target.
|
|
192
|
+
if (rest.some((x) => /^-[a-zA-Z]*[ef]/.test(x) || x.startsWith("--expression") || x.startsWith("--file"))) unknown = true;
|
|
193
|
+
else targets.push(...files.filter((x) => x !== "").slice(1));
|
|
194
|
+
}
|
|
195
|
+
else if (c === "perl" && rest.some((x) => /^-[a-zA-Z]*i/.test(x))) targets.push(...files.slice(1));
|
|
196
|
+
else if (c === "awk" && rest.includes("inplace") && rest.includes("-i")) targets.push(...files.slice(1).filter((x) => x !== "inplace"));
|
|
197
|
+
else if (c === "tee") targets.push(...files);
|
|
198
|
+
else if (c === "dd") { for (const x of rest) if (x.startsWith("of=")) targets.push(unq(x.slice(3))); }
|
|
199
|
+
else if (c === "cp" || c === "mv" || c === "install") { if (files.length) targets.push(files[files.length - 1]!); }
|
|
200
|
+
else if (c === "patch") targets.push(...files);
|
|
201
|
+
else if (c === "git" && rest[0] === "apply" && !rest.includes("--check")) targets.push("(git apply)");
|
|
202
|
+
else if (/^(python3?|node|bun|ruby|perl)$/.test(c) && rest.some((x) => x === "-c" || x === "-e")) {
|
|
203
|
+
if (/write_text|write\(|writeFile|fs\.write|open\([^)]*['"][wa]|File\.write/.test(part)) unknown = true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const real = targets.filter((t) => !/^\/(?:tmp|private\/tmp|var\/folders)\//.test(t));
|
|
207
|
+
if (real.length) return { kind: "write", targets: real };
|
|
208
|
+
return { kind: unknown ? "unknown" : "read", targets: [] };
|
|
209
|
+
}
|
package/src/hub/task-sweep.ts
CHANGED
|
@@ -50,7 +50,7 @@ export function taskSweepConfig(input: unknown): TaskSweepConfig {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/** Pure time/kind ladder; Tasks decides whether the responsible peer is available. */
|
|
53
|
-
export function nextSweep(task: Task, config: TaskSweepConfig, now: number, ready = true): SweepRecord | undefined {
|
|
53
|
+
export function nextSweep(task: Task, config: TaskSweepConfig, now: number, ready = true, questionWait?: { open: boolean; settled?: number }): SweepRecord | undefined {
|
|
54
54
|
if (!config.enabled || !Number.isFinite(now)) return undefined;
|
|
55
55
|
// #1176: a person-run leg waits on the person, so no idle step ever escalates it to an agent.
|
|
56
56
|
if (task.needsPerson) return undefined;
|
|
@@ -61,7 +61,10 @@ export function nextSweep(task: Task, config: TaskSweepConfig, now: number, read
|
|
|
61
61
|
let activity = task.history.length - 1;
|
|
62
62
|
while (activity >= 0 && (task.history[activity]?.sweep || task.history[activity]?.event === "memory reference started")) activity--;
|
|
63
63
|
let at = task.history[activity]?.at ?? task.created;
|
|
64
|
+
let questionSettled: number | undefined;
|
|
64
65
|
if (kind === "idle-owner") {
|
|
66
|
+
if (questionWait?.open) return undefined;
|
|
67
|
+
if (questionWait?.settled !== undefined && questionWait.settled > at) { questionSettled = questionWait.settled; at = questionSettled; }
|
|
65
68
|
// #1454: a pending wait suspends the ladder; once it passes, the ladder restarts from `until`, not from the activity before it.
|
|
66
69
|
const wait = taskWait(task);
|
|
67
70
|
if (wait) {
|
|
@@ -71,7 +74,8 @@ export function nextSweep(task: Task, config: TaskSweepConfig, now: number, read
|
|
|
71
74
|
}
|
|
72
75
|
const threshold = kind === "ready-unassigned" ? config.ready_min ?? 60 : kind === "unaccepted-assignment" ? config.unaccepted_min : kind === "idle-owner" ? config.idle_min : config.review_min;
|
|
73
76
|
if (now - at < threshold * 60_000) return undefined;
|
|
74
|
-
|
|
77
|
+
let previous = task.history.flatMap((h) => h.sweep?.kind === kind && h.sweep.activity === activity ? [h.sweep] : []).at(-1);
|
|
78
|
+
if (questionSettled !== undefined && previous && previous.at <= questionSettled) previous = undefined;
|
|
75
79
|
if (previous && (previous.step === 3 || now - previous.at < config.ladder_min * 60_000)) return undefined;
|
|
76
80
|
return { kind, activity, step: previous ? (previous.step + 1) as 2 | 3 : 1, at: now };
|
|
77
81
|
}
|