@oyasmi/pipiclaw 0.9.2-beta.4 → 0.9.2

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.
Files changed (76) hide show
  1. package/dist/agent/channel-runner.d.ts +32 -1
  2. package/dist/agent/channel-runner.js +112 -12
  3. package/dist/agent/context-budget.d.ts +9 -1
  4. package/dist/agent/context-budget.js +11 -5
  5. package/dist/agent/job-manager.d.ts +2 -0
  6. package/dist/agent/job-manager.js +1 -0
  7. package/dist/agent/session-events.js +2 -22
  8. package/dist/agent/types.d.ts +2 -1
  9. package/dist/channel/channel-context.d.ts +4 -0
  10. package/dist/channel/channel-event.d.ts +39 -0
  11. package/dist/channel/channel-event.js +11 -1
  12. package/dist/channel/project-scope-store.js +6 -11
  13. package/dist/channel/store.d.ts +7 -0
  14. package/dist/commands/catalog.d.ts +1 -1
  15. package/dist/memory/bootstrap.js +3 -5
  16. package/dist/memory/candidates.js +2 -4
  17. package/dist/memory/files.d.ts +0 -1
  18. package/dist/memory/files.js +6 -9
  19. package/dist/memory/maintenance-state.js +4 -0
  20. package/dist/runtime/bootstrap.d.ts +12 -6
  21. package/dist/runtime/bootstrap.js +144 -75
  22. package/dist/runtime/delivery.js +1 -0
  23. package/dist/runtime/dingtalk.d.ts +59 -3
  24. package/dist/runtime/dingtalk.js +192 -83
  25. package/dist/runtime/inbound-media.d.ts +60 -0
  26. package/dist/runtime/inbound-media.js +95 -0
  27. package/dist/runtime/task-driver.d.ts +7 -0
  28. package/dist/runtime/task-driver.js +23 -44
  29. package/dist/runtime/task-migration.d.ts +11 -0
  30. package/dist/runtime/task-migration.js +11 -0
  31. package/dist/security/command-guard.js +1 -3
  32. package/dist/security/config.d.ts +1 -1
  33. package/dist/security/config.js +8 -32
  34. package/dist/security/path-guard.js +1 -6
  35. package/dist/security/project-scope.js +1 -3
  36. package/dist/settings.d.ts +2 -2
  37. package/dist/settings.js +13 -20
  38. package/dist/shared/atomic-file.d.ts +2 -3
  39. package/dist/shared/atomic-file.js +8 -9
  40. package/dist/shared/config-diagnostic.d.ts +21 -0
  41. package/dist/shared/config-diagnostic.js +32 -0
  42. package/dist/shared/numeric.d.ts +7 -0
  43. package/dist/shared/numeric.js +19 -0
  44. package/dist/shared/text-utils.d.ts +10 -0
  45. package/dist/shared/text-utils.js +16 -0
  46. package/dist/shared/types.d.ts +23 -0
  47. package/dist/shared/types.js +12 -0
  48. package/dist/shared/with-timeout.d.ts +3 -0
  49. package/dist/shared/with-timeout.js +8 -0
  50. package/dist/subagents/discovery.d.ts +7 -7
  51. package/dist/subagents/discovery.js +27 -59
  52. package/dist/subagents/runs.d.ts +6 -0
  53. package/dist/subagents/runs.js +11 -0
  54. package/dist/subagents/tool.js +195 -128
  55. package/dist/subagents/workspace-lease.js +1 -3
  56. package/dist/tasks/control.d.ts +2 -0
  57. package/dist/tasks/control.js +2 -0
  58. package/dist/tasks/ledger.d.ts +0 -9
  59. package/dist/tasks/ledger.js +92 -158
  60. package/dist/tools/config.d.ts +1 -1
  61. package/dist/tools/config.js +9 -46
  62. package/dist/tools/skill.js +1 -3
  63. package/dist/tools/truncate.js +24 -28
  64. package/dist/tui/app.js +1 -1
  65. package/dist/web/config.js +3 -15
  66. package/examples/sub-agents/builder.md +1 -1
  67. package/examples/sub-agents/documenter.md +1 -1
  68. package/examples/sub-agents/explorer.md +4 -4
  69. package/examples/sub-agents/git-committer.md +4 -4
  70. package/examples/sub-agents/log-sifter.md +3 -3
  71. package/examples/sub-agents/planner.md +1 -1
  72. package/examples/sub-agents/reviewer.md +1 -1
  73. package/examples/sub-agents/worker.md +1 -1
  74. package/package.json +3 -2
  75. package/dist/agent/index.d.ts +0 -2
  76. package/dist/agent/index.js +0 -1
@@ -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] ?? "", ["Current Cycle", "当前周期"]))) {
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
- let sectionStart = -1;
118
- let sectionLevel = 0;
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 = sectionStart + 1; index < sectionEnd; 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] ?? "", ["Current Cycle", "当前周期"])) {
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
- let sectionStart = -1;
212
- let sectionLevel = 0;
213
- for (let index = 0; index < lines.length; index++) {
214
- const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
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
- let section;
370
- let sectionLevel = 0;
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 (const line of content.split("\n")) {
374
- const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
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
- let inDod = false;
413
- let sectionLevel = 0;
423
+ const lines = content.split("\n");
424
+ const sectionOf = classifyTaskSectionLines(lines, [{ label: "DoD", names: ["DoD"] }]);
414
425
  let count = 0;
415
- for (const line of content.split("\n")) {
416
- const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
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
- let sectionStart = -1;
587
- let sectionLevel = 0;
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 = lines.length;
600
- for (let index = sectionStart + 1; index < lines.length; index++) {
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
- let currentStart = -1;
623
- let currentLevel = 0;
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
- let currentEnd = lines.length;
640
- for (let index = currentStart + 1; index < lines.length; index++) {
641
- const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
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] ?? "", ["Current Cycle", "当前周期"])) {
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
- let section;
857
- let sectionLevel = 0;
825
+ const sectionOf = classifyTaskSectionLines(lines, DOD_VERIFICATION_SECTIONS);
858
826
  for (let index = 0; index < lines.length; index++) {
859
- const line = lines[index] ?? "";
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(line);
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
- let sectionStart = -1;
893
- let sectionLevel = 0;
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 sectionEnd = lines.length;
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] ?? "", ["Current Cycle", "当前周期"])) {
864
+ if (!inSection && matchesTaskSectionTitle(heading[2] ?? "", CURRENT_CYCLE_SECTION_NAMES)) {
931
865
  inSection = true;
932
866
  sectionLevel = heading[1]?.length ?? 0;
933
867
  }
@@ -1,4 +1,4 @@
1
- import type { ConfigDiagnostic } from "../shared/config-diagnostic.js";
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;
@@ -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 { errorMessage } from "../shared/text-utils.js";
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.push({
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
- const configPath = getToolsConfigPath(appHomeDir);
176
- if (!existsSync(configPath)) {
177
- return { config: DEFAULT_TOOLS_CONFIG, diagnostics: [] };
178
- }
179
- try {
180
- const raw = JSON.parse(readFileSync(configPath, "utf-8"));
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;
@@ -4,6 +4,7 @@ import { dirname, join } from "node:path";
4
4
  import { Type } from "typebox";
5
5
  import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
6
6
  import { checkPathGuard } from "../security/path-guard-check.js";
7
+ import { isNodeError } from "../shared/fs-utils.js";
7
8
  import { RecoverableToolError } from "../shared/recoverable-error.js";
8
9
  import { resolveSkillPath, scanSkillContent, validateSkillFrontmatter, validateSkillName } from "./skill-security.js";
9
10
  import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
@@ -20,9 +21,6 @@ const skillSchema = Type.Object({
20
21
  }),
21
22
  name: Type.Optional(Type.String({ description: "Exact workspace skill name from the list (required for read)." })),
22
23
  });
23
- function isNodeError(error) {
24
- return error instanceof Error && "code" in error;
25
- }
26
24
  function extractDescription(content) {
27
25
  const match = content.replace(/\r\n/g, "\n").match(/^---\n([\s\S]*?)\n---/);
28
26
  if (!match) {
@@ -31,6 +31,26 @@ export function formatSize(bytes) {
31
31
  return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
32
32
  }
33
33
  }
34
+ /** Line/byte totals shared by both `truncateHead` and `truncateTail`. */
35
+ function measureContent(content) {
36
+ const totalBytes = Buffer.byteLength(content, "utf-8");
37
+ const lines = content.split("\n");
38
+ return { lines, totalLines: lines.length, totalBytes };
39
+ }
40
+ /** The "nothing to truncate" result both directions return when content already fits. */
41
+ function unclippedResult(content, totalLines, totalBytes) {
42
+ return {
43
+ content,
44
+ truncated: false,
45
+ truncatedBy: null,
46
+ totalLines,
47
+ totalBytes,
48
+ outputLines: totalLines,
49
+ outputBytes: totalBytes,
50
+ lastLinePartial: false,
51
+ firstLineExceedsLimit: false,
52
+ };
53
+ }
34
54
  /**
35
55
  * Truncate content from the head (keep first N lines/bytes).
36
56
  * Suitable for file reads where you want to see the beginning.
@@ -41,22 +61,10 @@ export function formatSize(bytes) {
41
61
  export function truncateHead(content, options = {}) {
42
62
  const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
43
63
  const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
44
- const totalBytes = Buffer.byteLength(content, "utf-8");
45
- const lines = content.split("\n");
46
- const totalLines = lines.length;
64
+ const { lines, totalLines, totalBytes } = measureContent(content);
47
65
  // Check if no truncation needed
48
66
  if (totalLines <= maxLines && totalBytes <= maxBytes) {
49
- return {
50
- content,
51
- truncated: false,
52
- truncatedBy: null,
53
- totalLines,
54
- totalBytes,
55
- outputLines: totalLines,
56
- outputBytes: totalBytes,
57
- lastLinePartial: false,
58
- firstLineExceedsLimit: false,
59
- };
67
+ return unclippedResult(content, totalLines, totalBytes);
60
68
  }
61
69
  // Check if first line alone exceeds byte limit
62
70
  const firstLineBytes = Buffer.byteLength(lines[0], "utf-8");
@@ -114,22 +122,10 @@ export function truncateHead(content, options = {}) {
114
122
  export function truncateTail(content, options = {}) {
115
123
  const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
116
124
  const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
117
- const totalBytes = Buffer.byteLength(content, "utf-8");
118
- const lines = content.split("\n");
119
- const totalLines = lines.length;
125
+ const { lines, totalLines, totalBytes } = measureContent(content);
120
126
  // Check if no truncation needed
121
127
  if (totalLines <= maxLines && totalBytes <= maxBytes) {
122
- return {
123
- content,
124
- truncated: false,
125
- truncatedBy: null,
126
- totalLines,
127
- totalBytes,
128
- outputLines: totalLines,
129
- outputBytes: totalBytes,
130
- lastLinePartial: false,
131
- firstLineExceedsLimit: false,
132
- };
128
+ return unclippedResult(content, totalLines, totalBytes);
133
129
  }
134
130
  // Work backwards from the end
135
131
  const outputLinesArr = [];
package/dist/tui/app.js CHANGED
@@ -7,8 +7,8 @@
7
7
  * preparation shares `prepareAppServices` with the DingTalk path.
8
8
  */
9
9
  import { userInfo } from "node:os";
10
- import { createRunner } from "../agent/index.js";
11
10
  import { channelRunningJobLines } from "../agent/job-manager.js";
11
+ import { createRunner } from "../agent/runner-factory.js";
12
12
  import { ensureChannelDir } from "../channel/channel-paths.js";
13
13
  import { ChannelStore } from "../channel/store.js";
14
14
  import { renderBuiltInHelp } from "../commands/catalog.js";
@@ -1,7 +1,8 @@
1
+ import { clampInteger } from "../shared/numeric.js";
1
2
  export function resolveWebSearchRequest(config, query, count) {
2
3
  return {
3
4
  query: query.trim(),
4
- count: clamp(count, config.maxResults, 1, 10),
5
+ count: clampInteger(count, config.maxResults, 1, 10),
5
6
  timeoutMs: config.timeoutMs,
6
7
  };
7
8
  }
@@ -9,7 +10,7 @@ export function resolveWebFetchRequest(config, url, extractMode, maxChars) {
9
10
  return {
10
11
  url: url.trim(),
11
12
  extractMode: extractMode === "text" ? "text" : extractMode === "markdown" ? "markdown" : config.defaultExtractMode,
12
- maxChars: clamp(maxChars, config.maxChars, 100),
13
+ maxChars: clampInteger(maxChars, config.maxChars, 100),
13
14
  timeoutMs: config.timeoutMs,
14
15
  maxImageBytes: config.maxImageBytes,
15
16
  maxResponseBytes: config.maxResponseBytes,
@@ -17,16 +18,3 @@ export function resolveWebFetchRequest(config, url, extractMode, maxChars) {
17
18
  enableJinaFallback: config.enableJinaFallback,
18
19
  };
19
20
  }
20
- function clamp(value, fallback, minimum, maximum) {
21
- if (typeof value !== "number" || !Number.isFinite(value)) {
22
- return fallback;
23
- }
24
- const normalized = Math.floor(value);
25
- if (normalized < minimum) {
26
- return fallback;
27
- }
28
- if (maximum !== undefined && normalized > maximum) {
29
- return fallback;
30
- }
31
- return normalized;
32
- }
@@ -9,7 +9,7 @@ model: sonnet
9
9
  thinkingLevel: medium
10
10
  workload: heavy
11
11
  mutates: write
12
- maxWallTimeSec: 3600
12
+ maxWallTimeSec: 5400
13
13
  ---
14
14
 
15
15
  你是产品实现者。你把已收敛的任务契约转化为最小完整的产品改动、相应测试和可核查的交接信息。
@@ -9,7 +9,7 @@ model: gpt-5.6-luna
9
9
  thinkingLevel: high
10
10
  workload: heavy
11
11
  mutates: write
12
- maxWallTimeSec: 1800
12
+ maxWallTimeSec: 3600
13
13
  ---
14
14
 
15
15
  你是文档负责人。你依据当前实现和已验证的证据编写准确、可执行的文档与变更记录,只留可审查的工作树改动。
@@ -12,10 +12,10 @@ memory: none
12
12
  thinkingLevel: low
13
13
  workload: light
14
14
  mutates: read
15
- maxTurns: 24
16
- maxToolCalls: 64
17
- maxWallTimeSec: 300
18
- bashTimeoutSec: 120
15
+ maxTurns: 32
16
+ maxToolCalls: 96
17
+ maxWallTimeSec: 600
18
+ bashTimeoutSec: 180
19
19
  ---
20
20
 
21
21
  你是代码探索者。你只读调查当前仓库,回答实现在哪里、组件如何连接、某个行为由什么代码产生。
@@ -11,10 +11,10 @@ memory: none
11
11
  thinkingLevel: medium
12
12
  workload: light
13
13
  mutates: write
14
- maxTurns: 24
15
- maxToolCalls: 64
16
- maxWallTimeSec: 600
17
- bashTimeoutSec: 480
14
+ maxTurns: 32
15
+ maxToolCalls: 80
16
+ maxWallTimeSec: 1200
17
+ bashTimeoutSec: 600
18
18
  ---
19
19
 
20
20
  你是 Git 提交整理者。你只处理已经存在的改动:读懂 diff、按授权范围精确暂存、创建清晰的本地 commit 并报告剩余状态。
@@ -12,10 +12,10 @@ memory: none
12
12
  thinkingLevel: low
13
13
  workload: light
14
14
  mutates: read
15
- maxTurns: 24
15
+ maxTurns: 32
16
16
  maxToolCalls: 64
17
- maxWallTimeSec: 300
18
- bashTimeoutSec: 120
17
+ maxWallTimeSec: 900
18
+ bashTimeoutSec: 300
19
19
  ---
20
20
 
21
21
  你是日志筛查者。你在大量原始输出中定位与问题相关的证据,只把足以支撑结论的最小片段带回。