@oyasmi/pipiclaw 0.9.2-beta.3 → 0.9.2-beta.6
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/README.md +3 -0
- package/dist/agent/channel-runner.d.ts +45 -19
- package/dist/agent/channel-runner.js +156 -102
- package/dist/agent/command-extension.js +1 -1
- package/dist/agent/context-budget.d.ts +17 -1
- package/dist/agent/context-budget.js +20 -6
- package/dist/agent/job-manager.d.ts +3 -1
- package/dist/agent/job-manager.js +7 -1
- package/dist/agent/prompt/builder.d.ts +0 -1
- package/dist/agent/prompt/builder.js +1 -14
- package/dist/agent/prompt/manifest.js +2 -1
- package/dist/agent/prompt/sections.js +1 -1
- package/dist/agent/runner-factory.d.ts +19 -1
- package/dist/agent/runner-factory.js +8 -1
- package/dist/agent/session-events.d.ts +2 -2
- package/dist/agent/session-events.js +2 -22
- package/dist/agent/turn-prompt.d.ts +35 -0
- package/dist/agent/turn-prompt.js +37 -0
- package/dist/agent/turn-recovery.js +1 -1
- package/dist/agent/turn-state.d.ts +60 -0
- package/dist/agent/turn-state.js +95 -0
- package/dist/agent/types.d.ts +5 -4
- package/dist/{runtime → channel}/channel-context.d.ts +10 -2
- package/dist/{runtime → channel}/channel-context.js +6 -2
- package/dist/{runtime → channel}/channel-event.d.ts +39 -0
- package/dist/channel/channel-event.js +11 -0
- package/dist/channel/channel-paths.d.ts +16 -0
- package/dist/{runtime → channel}/channel-paths.js +20 -0
- package/dist/{runtime → channel}/project-scope-store.js +6 -11
- package/dist/{runtime → channel}/store.d.ts +7 -0
- package/dist/{agent/commands.d.ts → commands/catalog.d.ts} +17 -2
- package/dist/{agent/commands.js → commands/catalog.js} +30 -0
- package/dist/index.d.ts +1 -1
- package/dist/log.js +14 -5
- package/dist/main.js +29 -0
- package/dist/memory/bootstrap.js +3 -5
- package/dist/memory/candidates.js +2 -4
- package/dist/memory/commands.js +2 -2
- package/dist/memory/files.d.ts +0 -1
- package/dist/memory/files.js +6 -9
- package/dist/memory/maintenance-state.d.ts +8 -0
- package/dist/memory/maintenance-state.js +51 -4
- package/dist/memory/scheduler.d.ts +6 -0
- package/dist/memory/scheduler.js +19 -16
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/bootstrap.d.ts +14 -8
- package/dist/runtime/bootstrap.js +158 -81
- package/dist/runtime/delivery.d.ts +3 -3
- package/dist/runtime/delivery.js +1 -0
- package/dist/runtime/dingtalk.d.ts +62 -6
- package/dist/runtime/dingtalk.js +194 -85
- package/dist/runtime/durable-dispatch.d.ts +7 -1
- package/dist/runtime/durable-dispatch.js +12 -2
- package/dist/runtime/event-commands.js +2 -2
- package/dist/runtime/events.d.ts +8 -1
- package/dist/runtime/events.js +15 -3
- package/dist/runtime/inbound-media.d.ts +60 -0
- package/dist/runtime/inbound-media.js +95 -0
- package/dist/runtime/project-commands.js +2 -2
- package/dist/runtime/skill-commands.d.ts +27 -0
- package/dist/runtime/skill-commands.js +72 -0
- package/dist/runtime/subagent-commands.js +1 -1
- package/dist/runtime/task-commands.js +2 -2
- package/dist/runtime/task-driver.d.ts +12 -1
- package/dist/runtime/task-driver.js +36 -56
- package/dist/runtime/task-migration.d.ts +11 -0
- package/dist/runtime/task-migration.js +14 -2
- package/dist/runtime/task-wake.d.ts +1 -1
- package/dist/runtime/task-wake.js +1 -1
- package/dist/security/command-guard.js +1 -3
- package/dist/security/config.d.ts +1 -1
- package/dist/security/config.js +8 -32
- package/dist/security/path-guard.js +1 -6
- package/dist/security/project-scope.js +1 -3
- package/dist/settings.d.ts +3 -2
- package/dist/settings.js +82 -20
- package/dist/shared/atomic-file.d.ts +2 -3
- package/dist/shared/atomic-file.js +8 -9
- package/dist/shared/config-diagnostic.d.ts +21 -0
- package/dist/shared/config-diagnostic.js +32 -0
- package/dist/shared/numeric.d.ts +7 -0
- package/dist/shared/numeric.js +19 -0
- package/dist/shared/text-utils.d.ts +10 -0
- package/dist/shared/text-utils.js +16 -0
- package/dist/shared/token-estimate.d.ts +1 -0
- package/dist/shared/token-estimate.js +19 -0
- package/dist/shared/types.d.ts +23 -0
- package/dist/shared/types.js +12 -0
- package/dist/shared/with-timeout.d.ts +3 -0
- package/dist/shared/with-timeout.js +8 -0
- package/dist/subagents/discovery.d.ts +7 -7
- package/dist/subagents/discovery.js +27 -59
- package/dist/subagents/runs.d.ts +15 -4
- package/dist/subagents/runs.js +118 -11
- package/dist/subagents/tool.js +199 -131
- package/dist/subagents/workspace-lease.js +1 -3
- package/dist/tasks/control.d.ts +2 -0
- package/dist/tasks/control.js +2 -0
- package/dist/tasks/ledger.d.ts +0 -9
- package/dist/tasks/ledger.js +92 -158
- package/dist/tools/config.d.ts +1 -1
- package/dist/tools/config.js +9 -46
- package/dist/tools/glob-match.d.ts +25 -4
- package/dist/tools/glob-match.js +175 -53
- package/dist/tools/glob.js +5 -2
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/send-media.d.ts +1 -1
- package/dist/tools/skill.d.ts +15 -0
- package/dist/tools/skill.js +17 -11
- package/dist/tools/truncate.js +24 -28
- package/dist/tui/app.js +6 -4
- package/dist/tui/commands.d.ts +1 -0
- package/dist/tui/commands.js +3 -1
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +2 -1
- package/dist/tui/turn-controller.js +2 -1
- package/dist/web/config.js +3 -15
- package/examples/sub-agents/README.md +2 -2
- package/examples/sub-agents/builder.md +1 -1
- package/examples/sub-agents/documenter.md +1 -1
- package/examples/sub-agents/explorer.md +4 -4
- package/examples/sub-agents/git-committer.md +5 -4
- package/examples/sub-agents/log-sifter.md +4 -4
- package/examples/sub-agents/planner.md +1 -1
- package/examples/sub-agents/reviewer.md +1 -1
- package/examples/sub-agents/verifier.md +1 -1
- package/examples/sub-agents/worker.md +3 -3
- package/package.json +3 -2
- package/dist/agent/index.d.ts +0 -2
- package/dist/agent/index.js +0 -1
- package/dist/runtime/channel-event.js +0 -1
- package/dist/runtime/channel-paths.d.ts +0 -4
- /package/dist/{runtime → channel}/active-session-store.d.ts +0 -0
- /package/dist/{runtime → channel}/active-session-store.js +0 -0
- /package/dist/{runtime → channel}/channel-index.d.ts +0 -0
- /package/dist/{runtime → channel}/channel-index.js +0 -0
- /package/dist/{runtime → channel}/project-scope-store.d.ts +0 -0
- /package/dist/{runtime → channel}/store.js +0 -0
- /package/dist/{agent → commands}/reply-limits.d.ts +0 -0
- /package/dist/{agent → commands}/reply-limits.js +0 -0
package/dist/tasks/ledger.js
CHANGED
|
@@ -23,6 +23,7 @@ export const STANDARD_TASK_SECTIONS = [
|
|
|
23
23
|
* task or any pre-existing task simply has no Plan.
|
|
24
24
|
*/
|
|
25
25
|
const PLAN_SECTION_NAMES = ["Plan", "计划"];
|
|
26
|
+
const CURRENT_CYCLE_SECTION_NAMES = ["Current Cycle", "当前周期"];
|
|
26
27
|
/** Recurring task files are working context, not an unbounded audit log. */
|
|
27
28
|
export const MAX_INLINE_TASK_HISTORY_ENTRIES = 8;
|
|
28
29
|
export const MAX_INLINE_TASK_HISTORY_CHARS = 24 * 1024;
|
|
@@ -64,7 +65,7 @@ export function taskContractSegment(body) {
|
|
|
64
65
|
const match = /^#{1,6}\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
65
66
|
if (match &&
|
|
66
67
|
(matchesTaskSectionTitle(match[1] ?? "", PLAN_SECTION_NAMES) ||
|
|
67
|
-
matchesTaskSectionTitle(match[1] ?? "",
|
|
68
|
+
matchesTaskSectionTitle(match[1] ?? "", CURRENT_CYCLE_SECTION_NAMES))) {
|
|
68
69
|
return lines.slice(0, index).join("\n").replace(/\s+$/, "");
|
|
69
70
|
}
|
|
70
71
|
}
|
|
@@ -114,29 +115,12 @@ function parsePlanStepLine(line, lineIndex, fallbackId) {
|
|
|
114
115
|
*/
|
|
115
116
|
export function parseTaskPlan(content) {
|
|
116
117
|
const lines = content.split("\n");
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
for (let index = 0; index < lines.length; index++) {
|
|
120
|
-
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
121
|
-
if (!match || !matchesTaskSectionTitle(match[2] ?? "", PLAN_SECTION_NAMES))
|
|
122
|
-
continue;
|
|
123
|
-
sectionStart = index;
|
|
124
|
-
sectionLevel = match[1]?.length ?? 0;
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
if (sectionStart === -1)
|
|
118
|
+
const bounds = findTaskSectionBounds(lines, PLAN_SECTION_NAMES);
|
|
119
|
+
if (!bounds)
|
|
128
120
|
return undefined;
|
|
129
|
-
let sectionEnd = lines.length;
|
|
130
|
-
for (let index = sectionStart + 1; index < lines.length; index++) {
|
|
131
|
-
const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
132
|
-
if (match && (match[1]?.length ?? 7) <= sectionLevel) {
|
|
133
|
-
sectionEnd = index;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
121
|
const steps = [];
|
|
138
122
|
let position = 0;
|
|
139
|
-
for (let index =
|
|
123
|
+
for (let index = bounds.headingIndex + 1; index < bounds.end; index++) {
|
|
140
124
|
const line = lines[index] ?? "";
|
|
141
125
|
if (!/^\s*[-*]\s+\[/.test(line))
|
|
142
126
|
continue;
|
|
@@ -164,7 +148,7 @@ function insertEmptyPlanSection(body) {
|
|
|
164
148
|
const lines = body.split("\n");
|
|
165
149
|
for (let index = 0; index < lines.length; index++) {
|
|
166
150
|
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
167
|
-
if (match && matchesTaskSectionTitle(match[2] ?? "",
|
|
151
|
+
if (match && matchesTaskSectionTitle(match[2] ?? "", CURRENT_CYCLE_SECTION_NAMES)) {
|
|
168
152
|
lines.splice(index, 0, "## Plan", "");
|
|
169
153
|
return lines.join("\n");
|
|
170
154
|
}
|
|
@@ -208,25 +192,10 @@ export function applyTaskPlanPatch(body, patches) {
|
|
|
208
192
|
}
|
|
209
193
|
const id = trimmedId.toUpperCase();
|
|
210
194
|
const lines = working.split("\n");
|
|
211
|
-
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (match && matchesTaskSectionTitle(match[2] ?? "", PLAN_SECTION_NAMES)) {
|
|
216
|
-
sectionStart = index;
|
|
217
|
-
sectionLevel = match[1]?.length ?? 0;
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
let insertAt = lines.length;
|
|
222
|
-
for (let index = sectionStart + 1; index < lines.length; index++) {
|
|
223
|
-
const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
224
|
-
if (match && (match[1]?.length ?? 7) <= sectionLevel) {
|
|
225
|
-
insertAt = index;
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
while (insertAt > sectionStart + 1 && (lines[insertAt - 1] ?? "").trim() === "")
|
|
195
|
+
const bounds = findTaskSectionBounds(lines, PLAN_SECTION_NAMES);
|
|
196
|
+
let insertAt = bounds?.end ?? lines.length;
|
|
197
|
+
const afterHeading = (bounds?.headingIndex ?? -1) + 1;
|
|
198
|
+
while (insertAt > afterHeading && (lines[insertAt - 1] ?? "").trim() === "")
|
|
230
199
|
insertAt--;
|
|
231
200
|
lines.splice(insertAt, 0, renderPlanStepLine(id, patch.status ?? "todo", text));
|
|
232
201
|
working = lines.join("\n");
|
|
@@ -346,6 +315,58 @@ function matchesTaskSectionTitle(title, names) {
|
|
|
346
315
|
normalized.startsWith(`${expected}(`));
|
|
347
316
|
});
|
|
348
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Find the first heading matching one of `names` and the exclusive end of its body — the next
|
|
320
|
+
* heading at the same or a shallower level, or end of document. Every task-document section scan
|
|
321
|
+
* (Plan, Current Cycle, DoD, Verification) shares this exact rule; only what a caller does with
|
|
322
|
+
* the bounds differs.
|
|
323
|
+
*/
|
|
324
|
+
function findTaskSectionBounds(lines, names) {
|
|
325
|
+
for (let index = 0; index < lines.length; index++) {
|
|
326
|
+
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
327
|
+
if (!match || !matchesTaskSectionTitle(match[2] ?? "", names))
|
|
328
|
+
continue;
|
|
329
|
+
const level = match[1]?.length ?? 0;
|
|
330
|
+
let end = lines.length;
|
|
331
|
+
for (let cursor = index + 1; cursor < lines.length; cursor++) {
|
|
332
|
+
const headingMatch = /^(#{1,6})\s+/.exec(lines[cursor] ?? "");
|
|
333
|
+
if (headingMatch && (headingMatch[1]?.length ?? 7) <= level) {
|
|
334
|
+
end = cursor;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return { headingIndex: index, level, end };
|
|
339
|
+
}
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* For every line, which of `sections` (each a label plus its heading aliases) it falls under,
|
|
344
|
+
* using the same heading-scoping rule as {@link findTaskSectionBounds}. A heading line itself is
|
|
345
|
+
* never "in" a section. Shared by the per-line DoD/Verification scans below so the scoping rule
|
|
346
|
+
* lives in exactly one place.
|
|
347
|
+
*/
|
|
348
|
+
function classifyTaskSectionLines(lines, sections) {
|
|
349
|
+
const result = new Array(lines.length);
|
|
350
|
+
let current;
|
|
351
|
+
let currentLevel = 0;
|
|
352
|
+
for (let index = 0; index < lines.length; index++) {
|
|
353
|
+
const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
354
|
+
if (heading) {
|
|
355
|
+
const level = heading[1]?.length ?? 7;
|
|
356
|
+
const match = sections.find((section) => matchesTaskSectionTitle(heading[2] ?? "", section.names));
|
|
357
|
+
if (match) {
|
|
358
|
+
current = match.label;
|
|
359
|
+
currentLevel = level;
|
|
360
|
+
}
|
|
361
|
+
else if (current && level <= currentLevel) {
|
|
362
|
+
current = undefined;
|
|
363
|
+
}
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
result[index] = current;
|
|
367
|
+
}
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
349
370
|
export function hasTaskHeading(content, names) {
|
|
350
371
|
return content.split("\n").some((line) => {
|
|
351
372
|
const match = /^#{1,6}\s+(.+?)\s*$/.exec(line);
|
|
@@ -364,31 +385,21 @@ export function missingStandardTaskSections(content) {
|
|
|
364
385
|
* indistinguishable from "everything is checked" — which would silently let
|
|
365
386
|
* `task_close outcome=complete` through with nothing ever actually verified.
|
|
366
387
|
*/
|
|
388
|
+
const DOD_VERIFICATION_SECTIONS = [
|
|
389
|
+
{ label: "DoD", names: ["DoD"] },
|
|
390
|
+
{ label: "Verification", names: ["Verification", "验收"] },
|
|
391
|
+
];
|
|
367
392
|
export function uncheckedTaskAcceptanceItems(content) {
|
|
368
393
|
const unchecked = [];
|
|
369
|
-
|
|
370
|
-
|
|
394
|
+
const lines = content.split("\n");
|
|
395
|
+
const sectionOf = classifyTaskSectionLines(lines, DOD_VERIFICATION_SECTIONS);
|
|
371
396
|
let dodHasContent = false;
|
|
372
397
|
let dodHasCheckbox = false;
|
|
373
|
-
for (
|
|
374
|
-
const
|
|
375
|
-
if (heading) {
|
|
376
|
-
const level = heading[1]?.length ?? 7;
|
|
377
|
-
if (matchesTaskSectionTitle(heading[2] ?? "", ["DoD"])) {
|
|
378
|
-
section = "DoD";
|
|
379
|
-
sectionLevel = level;
|
|
380
|
-
}
|
|
381
|
-
else if (matchesTaskSectionTitle(heading[2] ?? "", ["Verification", "验收"])) {
|
|
382
|
-
section = "Verification";
|
|
383
|
-
sectionLevel = level;
|
|
384
|
-
}
|
|
385
|
-
else if (section && level <= sectionLevel) {
|
|
386
|
-
section = undefined;
|
|
387
|
-
}
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
398
|
+
for (let index = 0; index < lines.length; index++) {
|
|
399
|
+
const section = sectionOf[index];
|
|
390
400
|
if (!section)
|
|
391
401
|
continue;
|
|
402
|
+
const line = lines[index] ?? "";
|
|
392
403
|
if (section === "DoD" && line.trim())
|
|
393
404
|
dodHasContent = true;
|
|
394
405
|
const checkbox = /^\s*[-*]\s+\[([ xX])\]\s*(.+?)\s*$/.exec(line);
|
|
@@ -409,23 +420,11 @@ export function uncheckedTaskAcceptanceItems(content) {
|
|
|
409
420
|
* step's `→ dod:N` refs (spec 037, D4 — `/tasks doctor`'s drift checks).
|
|
410
421
|
*/
|
|
411
422
|
export function countTaskDodItems(content) {
|
|
412
|
-
|
|
413
|
-
|
|
423
|
+
const lines = content.split("\n");
|
|
424
|
+
const sectionOf = classifyTaskSectionLines(lines, [{ label: "DoD", names: ["DoD"] }]);
|
|
414
425
|
let count = 0;
|
|
415
|
-
for (
|
|
416
|
-
|
|
417
|
-
if (heading) {
|
|
418
|
-
const level = heading[1]?.length ?? 7;
|
|
419
|
-
if (matchesTaskSectionTitle(heading[2] ?? "", ["DoD"])) {
|
|
420
|
-
inDod = true;
|
|
421
|
-
sectionLevel = level;
|
|
422
|
-
}
|
|
423
|
-
else if (inDod && level <= sectionLevel) {
|
|
424
|
-
inDod = false;
|
|
425
|
-
}
|
|
426
|
-
continue;
|
|
427
|
-
}
|
|
428
|
-
if (inDod && /^\s*[-*]\s+\[[ xX]\]/.test(line))
|
|
426
|
+
for (let index = 0; index < lines.length; index++) {
|
|
427
|
+
if (sectionOf[index] === "DoD" && /^\s*[-*]\s+\[[ xX]\]/.test(lines[index] ?? ""))
|
|
429
428
|
count++;
|
|
430
429
|
}
|
|
431
430
|
return count;
|
|
@@ -583,28 +582,12 @@ export function appendCurrentCycleNote(content, note) {
|
|
|
583
582
|
throw new Error("Current Cycle note must not be empty.");
|
|
584
583
|
}
|
|
585
584
|
const lines = content.split("\n");
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
for (let index = 0; index < lines.length; index++) {
|
|
589
|
-
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
590
|
-
if (!match || !matchesTaskSectionTitle(match[2] ?? "", ["Current Cycle", "当前周期"]))
|
|
591
|
-
continue;
|
|
592
|
-
sectionStart = index;
|
|
593
|
-
sectionLevel = match[1]?.length ?? 0;
|
|
594
|
-
break;
|
|
595
|
-
}
|
|
596
|
-
if (sectionStart === -1) {
|
|
585
|
+
const bounds = findTaskSectionBounds(lines, CURRENT_CYCLE_SECTION_NAMES);
|
|
586
|
+
if (!bounds) {
|
|
597
587
|
throw new Error('Task body has no "Current Cycle" section; normalize the task skeleton first.');
|
|
598
588
|
}
|
|
599
|
-
let insertAt =
|
|
600
|
-
|
|
601
|
-
const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
602
|
-
if (match && (match[1]?.length ?? 7) <= sectionLevel) {
|
|
603
|
-
insertAt = index;
|
|
604
|
-
break;
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
while (insertAt > sectionStart + 1 && (lines[insertAt - 1] ?? "").trim() === "") {
|
|
589
|
+
let insertAt = bounds.end;
|
|
590
|
+
while (insertAt > bounds.headingIndex + 1 && (lines[insertAt - 1] ?? "").trim() === "") {
|
|
608
591
|
insertAt--;
|
|
609
592
|
}
|
|
610
593
|
lines.splice(insertAt, 0, `- ${trimmedNote}`);
|
|
@@ -619,31 +602,17 @@ export function appendCurrentCycleNote(content, note) {
|
|
|
619
602
|
*/
|
|
620
603
|
export function upsertCurrentCycleCompletionEvidence(content, evidenceLines) {
|
|
621
604
|
const lines = content.split("\n");
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
for (let index = 0; index < lines.length; index++) {
|
|
625
|
-
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
626
|
-
if (!match || !matchesTaskSectionTitle(match[2] ?? "", ["Current Cycle", "当前周期"]))
|
|
627
|
-
continue;
|
|
628
|
-
currentStart = index;
|
|
629
|
-
currentLevel = match[1]?.length ?? 0;
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
if (currentStart === -1 || currentLevel >= 6) {
|
|
605
|
+
const currentBounds = findTaskSectionBounds(lines, CURRENT_CYCLE_SECTION_NAMES);
|
|
606
|
+
if (!currentBounds || currentBounds.level >= 6) {
|
|
633
607
|
// Legacy/non-standard one-shot tasks were historically completable without the
|
|
634
608
|
// canonical skeleton. Keep that compatibility, but upsert one bounded top-level
|
|
635
609
|
// block instead of returning to the old append-only behavior.
|
|
636
610
|
const stripped = stripLegacyCompletionEvidence(content).content.replace(/\n+$/, "");
|
|
637
611
|
return `${stripped}\n\n## Completion Evidence\n\n${evidenceLines.join("\n")}\n`;
|
|
638
612
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
if (match && (match[1]?.length ?? 7) <= currentLevel) {
|
|
643
|
-
currentEnd = index;
|
|
644
|
-
break;
|
|
645
|
-
}
|
|
646
|
-
}
|
|
613
|
+
const currentStart = currentBounds.headingIndex;
|
|
614
|
+
const currentLevel = currentBounds.level;
|
|
615
|
+
let currentEnd = currentBounds.end;
|
|
647
616
|
const evidenceLevel = currentLevel + 1;
|
|
648
617
|
let evidenceStart = -1;
|
|
649
618
|
let evidenceEnd = -1;
|
|
@@ -789,7 +758,7 @@ export function startTaskCycle(content, cycleId, archivePrevious = true) {
|
|
|
789
758
|
if (!match)
|
|
790
759
|
continue;
|
|
791
760
|
const level = match[1]?.length ?? 0;
|
|
792
|
-
if (matchesTaskSectionTitle(match[2] ?? "",
|
|
761
|
+
if (matchesTaskSectionTitle(match[2] ?? "", CURRENT_CYCLE_SECTION_NAMES)) {
|
|
793
762
|
currentStart = index;
|
|
794
763
|
currentLevel = level;
|
|
795
764
|
}
|
|
@@ -853,29 +822,11 @@ export function startTaskCycle(content, cycleId, archivePrevious = true) {
|
|
|
853
822
|
*/
|
|
854
823
|
function resetTaskAcceptanceCheckboxes(content) {
|
|
855
824
|
const lines = content.split("\n");
|
|
856
|
-
|
|
857
|
-
let sectionLevel = 0;
|
|
825
|
+
const sectionOf = classifyTaskSectionLines(lines, DOD_VERIFICATION_SECTIONS);
|
|
858
826
|
for (let index = 0; index < lines.length; index++) {
|
|
859
|
-
|
|
860
|
-
const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
|
|
861
|
-
if (heading) {
|
|
862
|
-
const level = heading[1]?.length ?? 7;
|
|
863
|
-
if (matchesTaskSectionTitle(heading[2] ?? "", ["DoD"])) {
|
|
864
|
-
section = "DoD";
|
|
865
|
-
sectionLevel = level;
|
|
866
|
-
}
|
|
867
|
-
else if (matchesTaskSectionTitle(heading[2] ?? "", ["Verification", "验收"])) {
|
|
868
|
-
section = "Verification";
|
|
869
|
-
sectionLevel = level;
|
|
870
|
-
}
|
|
871
|
-
else if (section && level <= sectionLevel) {
|
|
872
|
-
section = undefined;
|
|
873
|
-
}
|
|
874
|
-
continue;
|
|
875
|
-
}
|
|
876
|
-
if (!section)
|
|
827
|
+
if (!sectionOf[index])
|
|
877
828
|
continue;
|
|
878
|
-
const checkbox = /^(\s*[-*]\s+)\[[xX]\](\s*.*)$/.exec(
|
|
829
|
+
const checkbox = /^(\s*[-*]\s+)\[[xX]\](\s*.*)$/.exec(lines[index] ?? "");
|
|
879
830
|
if (checkbox)
|
|
880
831
|
lines[index] = `${checkbox[1]}[ ]${checkbox[2]}`;
|
|
881
832
|
}
|
|
@@ -889,27 +840,10 @@ function resetTaskAcceptanceCheckboxes(content) {
|
|
|
889
840
|
*/
|
|
890
841
|
function resetPlanStepCheckboxes(content) {
|
|
891
842
|
const lines = content.split("\n");
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
for (let index = 0; index < lines.length; index++) {
|
|
895
|
-
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
896
|
-
if (!match || !matchesTaskSectionTitle(match[2] ?? "", PLAN_SECTION_NAMES))
|
|
897
|
-
continue;
|
|
898
|
-
sectionStart = index;
|
|
899
|
-
sectionLevel = match[1]?.length ?? 0;
|
|
900
|
-
break;
|
|
901
|
-
}
|
|
902
|
-
if (sectionStart === -1)
|
|
843
|
+
const bounds = findTaskSectionBounds(lines, PLAN_SECTION_NAMES);
|
|
844
|
+
if (!bounds)
|
|
903
845
|
return content;
|
|
904
|
-
let
|
|
905
|
-
for (let index = sectionStart + 1; index < lines.length; index++) {
|
|
906
|
-
const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
907
|
-
if (match && (match[1]?.length ?? 7) <= sectionLevel) {
|
|
908
|
-
sectionEnd = index;
|
|
909
|
-
break;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
for (let index = sectionStart + 1; index < sectionEnd; index++) {
|
|
846
|
+
for (let index = bounds.headingIndex + 1; index < bounds.end; index++) {
|
|
913
847
|
const checkbox = /^(\s*[-*]\s+)\[[xX!]\](\s*.*)$/.exec(lines[index] ?? "");
|
|
914
848
|
if (checkbox)
|
|
915
849
|
lines[index] = `${checkbox[1]}[ ]${checkbox[2]}`;
|
|
@@ -927,7 +861,7 @@ function extractLatestNote(content) {
|
|
|
927
861
|
if (heading) {
|
|
928
862
|
if (inSection && (heading[1]?.length ?? 7) <= sectionLevel)
|
|
929
863
|
break;
|
|
930
|
-
if (!inSection && matchesTaskSectionTitle(heading[2] ?? "",
|
|
864
|
+
if (!inSection && matchesTaskSectionTitle(heading[2] ?? "", CURRENT_CYCLE_SECTION_NAMES)) {
|
|
931
865
|
inSection = true;
|
|
932
866
|
sectionLevel = heading[1]?.length ?? 0;
|
|
933
867
|
}
|
package/dist/tools/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ConfigDiagnostic } from "../shared/config-diagnostic.js";
|
|
2
2
|
export type WebSearchProvider = "brave" | "tavily" | "jina" | "searxng" | "duckduckgo";
|
|
3
3
|
export interface PipiclawWebSearchConfig {
|
|
4
4
|
provider: WebSearchProvider;
|
package/dist/tools/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
1
|
import { join } from "node:path";
|
|
3
2
|
import { APP_HOME_DIR } from "../paths.js";
|
|
4
|
-
import {
|
|
3
|
+
import { loadJsonConfig, pushConfigWarning } from "../shared/config-diagnostic.js";
|
|
4
|
+
import { clampInteger } from "../shared/numeric.js";
|
|
5
5
|
import { isRecord } from "../shared/type-guards.js";
|
|
6
6
|
const WEB_SEARCH_PROVIDERS = ["brave", "tavily", "jina", "searxng", "duckduckgo"];
|
|
7
7
|
export const DEFAULT_TOOLS_CONFIG = {
|
|
@@ -40,19 +40,6 @@ export const DEFAULT_TOOLS_CONFIG = {
|
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
|
-
function clampInteger(value, fallback, minimum, maximum) {
|
|
44
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
45
|
-
return fallback;
|
|
46
|
-
}
|
|
47
|
-
const normalized = Math.floor(value);
|
|
48
|
-
if (normalized < minimum) {
|
|
49
|
-
return fallback;
|
|
50
|
-
}
|
|
51
|
-
if (maximum !== undefined && normalized > maximum) {
|
|
52
|
-
return fallback;
|
|
53
|
-
}
|
|
54
|
-
return normalized;
|
|
55
|
-
}
|
|
56
43
|
function asTrimmedString(value, fallback = "") {
|
|
57
44
|
return typeof value === "string" ? value.trim() : fallback;
|
|
58
45
|
}
|
|
@@ -67,12 +54,7 @@ function asOptionalProxy(value) {
|
|
|
67
54
|
return trimmed.length > 0 ? trimmed : null;
|
|
68
55
|
}
|
|
69
56
|
function pushInvalidValueDiagnostic(diagnostics, configPath, field, message) {
|
|
70
|
-
diagnostics
|
|
71
|
-
source: "tools",
|
|
72
|
-
path: configPath,
|
|
73
|
-
severity: "warning",
|
|
74
|
-
message: `${field}: ${message}`,
|
|
75
|
-
});
|
|
57
|
+
pushConfigWarning(diagnostics, "tools", configPath, field, message);
|
|
76
58
|
}
|
|
77
59
|
function mergeToolsConfig(source, configPath, diagnostics) {
|
|
78
60
|
if (!isRecord(source)) {
|
|
@@ -172,31 +154,12 @@ export function getToolsConfigPath(appHomeDir = APP_HOME_DIR) {
|
|
|
172
154
|
return join(appHomeDir, "tools.json");
|
|
173
155
|
}
|
|
174
156
|
export function loadToolsConfigWithDiagnostics(appHomeDir = APP_HOME_DIR) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const diagnostics = [];
|
|
182
|
-
return {
|
|
183
|
-
config: mergeToolsConfig(raw, configPath, diagnostics),
|
|
184
|
-
diagnostics,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
return {
|
|
189
|
-
config: DEFAULT_TOOLS_CONFIG,
|
|
190
|
-
diagnostics: [
|
|
191
|
-
{
|
|
192
|
-
source: "tools",
|
|
193
|
-
path: configPath,
|
|
194
|
-
severity: "error",
|
|
195
|
-
message: errorMessage(error),
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
};
|
|
199
|
-
}
|
|
157
|
+
return loadJsonConfig({
|
|
158
|
+
source: "tools",
|
|
159
|
+
path: getToolsConfigPath(appHomeDir),
|
|
160
|
+
defaults: DEFAULT_TOOLS_CONFIG,
|
|
161
|
+
merge: mergeToolsConfig,
|
|
162
|
+
});
|
|
200
163
|
}
|
|
201
164
|
export function loadToolsConfig(appHomeDir = APP_HOME_DIR) {
|
|
202
165
|
return loadToolsConfigWithDiagnostics(appHomeDir).config;
|
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Compile a shell-style glob pattern into a
|
|
2
|
+
* Compile a shell-style glob pattern into a matcher for POSIX-relative file paths.
|
|
3
3
|
*
|
|
4
4
|
* Semantics follow the convention the model already knows from `find`/`fd`/Claude Code's own glob
|
|
5
5
|
* tool: a pattern with no `/` matches the *basename* at any depth (so `*.ts` searches the whole
|
|
6
6
|
* tree, not just its top level); `**` matches any number of path segments, including zero, when it
|
|
7
|
-
* sits between (or at the start/end of) path separators; `{a,b}` is brace-expanded into
|
|
8
|
-
*
|
|
7
|
+
* sits between (or at the start/end of) path separators; `{a,b}` is brace-expanded into
|
|
8
|
+
* alternatives. Matching is always case-sensitive and always against `/`-joined relative paths —
|
|
9
9
|
* callers never see platform separators.
|
|
10
|
+
*
|
|
11
|
+
* ## Why this is not a regular expression
|
|
12
|
+
*
|
|
13
|
+
* The obvious implementation compiles the whole pattern into one `RegExp` — and that regex is a
|
|
14
|
+
* denial-of-service primitive, because the pattern is a model-supplied argument and the matcher
|
|
15
|
+
* runs once per walked file on the event loop. Nested unbounded quantifiers backtrack
|
|
16
|
+
* exponentially on a *near* miss: `**/` repeated ten times took ~2s per path, `{*,*}` repeated
|
|
17
|
+
* five times ~145ms and rising by ~17x per group, and `*a*a*a*a*a*a*a*azzz` — nineteen
|
|
18
|
+
* characters, no `**`, no braces — took **32 seconds** against a sixty-character name. Folding
|
|
19
|
+
* `**/` or capping the pattern length only removes particular spellings; the blow-up belongs to
|
|
20
|
+
* the whole class of "several stars separated by literals", which no length bound can exclude.
|
|
21
|
+
*
|
|
22
|
+
* So the pattern is matched structurally instead: braces expand to a bounded set of variants,
|
|
23
|
+
* each variant is split into path segments, and both the segment sequence and each segment's
|
|
24
|
+
* characters are matched by the classic single-backtrack-point wildcard algorithm. That is
|
|
25
|
+
* O(n·m) in the worst case with no nested quantifiers, so every shape above matches in
|
|
26
|
+
* microseconds and no pattern can stall the walk.
|
|
10
27
|
*/
|
|
11
|
-
export
|
|
28
|
+
export interface GlobMatcher {
|
|
29
|
+
/** True when `path` — a `/`-joined path relative to the walk root — matches the pattern. */
|
|
30
|
+
test(path: string): boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function compileGlobPattern(pattern: string): GlobMatcher;
|