@wrongstack/core 0.299.0 → 0.300.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.
Files changed (50) hide show
  1. package/dist/coordination/director.d.ts +8 -0
  2. package/dist/coordination/fleet-manager.d.ts +48 -3
  3. package/dist/coordination/ifleet-manager.d.ts +2 -0
  4. package/dist/coordination/index.js +120 -20
  5. package/dist/coordination/multi-agent-coordinator.d.ts +1 -0
  6. package/dist/core/fallback-model.d.ts +48 -0
  7. package/dist/core/index.d.ts +3 -2
  8. package/dist/core/index.js +226 -26
  9. package/dist/core/instruction-template.d.ts +80 -0
  10. package/dist/core/system-prompt-blocks.d.ts +10 -1
  11. package/dist/core/system-prompt-builder.d.ts +35 -1
  12. package/dist/defaults/index.js +238 -99
  13. package/dist/execution/autonomy-brain.d.ts +7 -0
  14. package/dist/execution/council-brain.d.ts +11 -0
  15. package/dist/execution/council-orchestrator.d.ts +23 -4
  16. package/dist/execution/council-prompts.d.ts +12 -1
  17. package/dist/execution/index.js +355 -138
  18. package/dist/fleet-notifier.d.ts +9 -2
  19. package/dist/hooks/index.js +8 -4
  20. package/dist/hq/index.js +18 -4
  21. package/dist/hq/protocol/fleet.d.ts +20 -0
  22. package/dist/hq/protocol.js +10 -0
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1512 -707
  25. package/dist/kernel/events/brain-events.d.ts +9 -0
  26. package/dist/kernel/events/provider-events.d.ts +42 -1
  27. package/dist/models/index.js +1 -1
  28. package/dist/plugin/api.d.ts +6 -0
  29. package/dist/plugin/config.d.ts +55 -0
  30. package/dist/plugin/index.d.ts +1 -1
  31. package/dist/plugin/index.js +134 -21
  32. package/dist/security/index.d.ts +1 -1
  33. package/dist/security/index.js +157 -42
  34. package/dist/security/permission-helpers.d.ts +23 -6
  35. package/dist/security/permission-policy.d.ts +16 -0
  36. package/dist/security/totp.d.ts +14 -0
  37. package/dist/storage/director-state.d.ts +7 -0
  38. package/dist/storage/index.js +33 -8
  39. package/dist/tools/fallback-system-config-view-tool.d.ts +1 -1
  40. package/dist/tools/index.js +388 -102
  41. package/dist/types/council.d.ts +11 -0
  42. package/dist/types/index.d.ts +1 -1
  43. package/dist/types/multi-agent.d.ts +10 -0
  44. package/dist/types/one-shot-llm.d.ts +9 -0
  45. package/dist/types/plugin.d.ts +28 -0
  46. package/dist/worktree/index.js +4 -4
  47. package/instructions/system-lite.md +81 -3
  48. package/instructions/system-pro.md +275 -90
  49. package/instructions/system.md +228 -81
  50. package/package.json +3 -3
@@ -5,8 +5,13 @@ export interface FleetNotifierOptions {
5
5
  projectRoot: string;
6
6
  /** This process's pid, so a WebUI never pings itself. */
7
7
  selfPid?: number | undefined;
8
- /** Injectable POST for tests. Defaults to a timed `fetch`. */
9
- post?: ((url: string) => Promise<void>) | undefined;
8
+ /**
9
+ * Injectable POST for tests. Defaults to a timed `fetch`.
10
+ *
11
+ * The second parameter carries the target's API token (H3). It is optional
12
+ * so an existing `(url) => …` stub stays assignable.
13
+ */
14
+ post?: ((url: string, token?: string | undefined) => Promise<void>) | undefined;
10
15
  }
11
16
  export declare class FleetNotifier {
12
17
  private readonly baseDir;
@@ -21,6 +26,8 @@ export declare class FleetNotifier {
21
26
  notify(): void;
22
27
  /** Resolve same-project WebUI ping URLs (cached briefly). Exposed for tests. */
23
28
  endpoints(): Promise<string[]>;
29
+ /** Ping targets with their tokens (cached briefly). */
30
+ private targets;
24
31
  dispose(): void;
25
32
  /** Re-scope notifications after an in-process project switch. */
26
33
  setProjectRoot(projectRoot: string): void;
@@ -776,7 +776,11 @@ function hookMatcherMatches(matcher, toolName) {
776
776
 
777
777
  // src/hooks/runner.ts
778
778
  var DEFAULT_TIMEOUT_MS3 = 5e3;
779
+ var DEFAULT_BACKGROUND_TIMEOUT_MS = 6e4;
779
780
  var MAX_TIMEOUT_MS = 10 * 6e4;
781
+ function hookTimeoutMs(entry) {
782
+ return entry.timeoutMs ?? (entry.background ? DEFAULT_BACKGROUND_TIMEOUT_MS : DEFAULT_TIMEOUT_MS3);
783
+ }
780
784
  function normalizePreToolOutcome(outcome) {
781
785
  if ("action" in outcome) return outcome;
782
786
  if (outcome.decision === "block") {
@@ -961,12 +965,12 @@ var HookRunner = class {
961
965
  result = await this.invokeInProcess(entry, payload, env);
962
966
  } else {
963
967
  result = entry.kind === "shell" ? await runShellHookDetailed(
964
- { command: entry.command, timeoutMs: entry.timeoutMs },
968
+ { command: entry.command, timeoutMs: hookTimeoutMs(entry) },
965
969
  payload,
966
970
  this.opts.logger,
967
971
  { signal: env.signal }
968
972
  ) : await runHttpHookDetailed(
969
- { url: entry.url, headers: entry.headers, timeoutMs: entry.timeoutMs },
973
+ { url: entry.url, headers: entry.headers, timeoutMs: hookTimeoutMs(entry) },
970
974
  payload,
971
975
  this.opts.logger,
972
976
  { signal: env.signal }
@@ -983,12 +987,12 @@ var HookRunner = class {
983
987
  }
984
988
  if (!result.failure) return result.outcome;
985
989
  this.opts.logger?.warn?.(
986
- `${payload.event} hook "${entry.name}" failed (${result.failure.kind}): ${result.failure.message}`
990
+ `${payload.event} ${entry.background ? "background " : ""}hook "${entry.name}" failed (${result.failure.kind}): ${result.failure.message}`
987
991
  );
988
992
  return this.failureOutcome(entry, payload, result.failure);
989
993
  }
990
994
  async invokeInProcess(entry, payload, env) {
991
- const timeoutMs = Math.max(1, Math.min(entry.timeoutMs ?? DEFAULT_TIMEOUT_MS3, MAX_TIMEOUT_MS));
995
+ const timeoutMs = Math.max(1, Math.min(hookTimeoutMs(entry), MAX_TIMEOUT_MS));
992
996
  const controller = new AbortController();
993
997
  let timedOut = false;
994
998
  const onParentAbort = () => controller.abort(env.signal?.reason);
package/dist/hq/index.js CHANGED
@@ -492,6 +492,9 @@ function isHqSubagentSummary(x) {
492
492
  const v = x;
493
493
  return typeof v.subagentId === "string" && typeof v.status === "string" && HQ_FLEET_SUBAGENT_STATUS.has(v.status);
494
494
  }
495
+ function isOptionalFiniteNumber(x) {
496
+ return x === void 0 || typeof x === "number" && Number.isFinite(x);
497
+ }
495
498
  function isHqFleetSnapshotPayload(x) {
496
499
  if (typeof x !== "object" || x === null) return false;
497
500
  const v = x;
@@ -501,6 +504,13 @@ function isHqFleetSnapshotPayload(x) {
501
504
  for (const s of v.subagents) {
502
505
  if (!isHqSubagentSummary(s)) return false;
503
506
  }
507
+ if (!isOptionalFiniteNumber(v.maxConcurrent)) return false;
508
+ if (!isOptionalFiniteNumber(v.maxSpawns)) return false;
509
+ if (!isOptionalFiniteNumber(v.usedSpawns)) return false;
510
+ if (!isOptionalFiniteNumber(v.remainingSpawns)) return false;
511
+ if (!isOptionalFiniteNumber(v.checkpointMaxSpawns)) return false;
512
+ if (v.effectiveSource !== void 0 && typeof v.effectiveSource !== "string") return false;
513
+ if (v.ceilingMismatch !== void 0 && typeof v.ceilingMismatch !== "boolean") return false;
504
514
  return true;
505
515
  }
506
516
  function isHqFleetEventPayload(x) {
@@ -2574,9 +2584,6 @@ function watchHqAuthFile(dataDir, onChange, opts = {}) {
2574
2584
  }
2575
2585
  }
2576
2586
  });
2577
- watcher.on("error", (err) => {
2578
- opts.warn?.(`HQ auth watcher error: ${err.message}`);
2579
- });
2580
2587
  return {
2581
2588
  close: () => {
2582
2589
  closed = true;
@@ -3313,7 +3320,14 @@ function startFleetTelemetryBridge(opts) {
3313
3320
  completedTasks: stats.completed,
3314
3321
  failedTasks: stats.stopped,
3315
3322
  ...stats.totalCostUsd !== void 0 ? { totalCostUsd: stats.totalCostUsd } : {},
3316
- subagents
3323
+ subagents,
3324
+ ...stats.maxConcurrent !== void 0 ? { maxConcurrent: stats.maxConcurrent } : {},
3325
+ ...stats.maxSpawns !== void 0 ? { maxSpawns: stats.maxSpawns } : {},
3326
+ ...stats.usedSpawns !== void 0 ? { usedSpawns: stats.usedSpawns } : {},
3327
+ ...stats.remainingSpawns !== void 0 ? { remainingSpawns: stats.remainingSpawns } : {},
3328
+ ...stats.effectiveSource !== void 0 ? { effectiveSource: stats.effectiveSource } : {},
3329
+ ...stats.checkpointMaxSpawns !== void 0 ? { checkpointMaxSpawns: stats.checkpointMaxSpawns } : {},
3330
+ ...stats.ceilingMismatch ? { ceilingMismatch: true } : {}
3317
3331
  };
3318
3332
  }
3319
3333
  const off = events.on("coordinator.stats", (stats) => {
@@ -7,6 +7,19 @@ export interface HqFleetSnapshotPayload {
7
7
  failedTasks: number;
8
8
  totalCostUsd?: number;
9
9
  subagents: readonly HqSubagentSummary[];
10
+ /** Concurrent-subagent ceiling (maxConcurrent). */
11
+ maxConcurrent?: number | undefined;
12
+ /** Lifetime spawn ceiling (maxSpawns). */
13
+ maxSpawns?: number | undefined;
14
+ /** Cumulative spawns consumed this director run. */
15
+ usedSpawns?: number | undefined;
16
+ /** maxSpawns − usedSpawns (clamped ≥ 0). */
17
+ remainingSpawns?: number | undefined;
18
+ /** Winning config source labels, e.g. "maxConcurrent=profile, maxSpawns=env". */
19
+ effectiveSource?: string | undefined;
20
+ /** Historical checkpoint maxSpawns when it disagreed with the live ceiling. */
21
+ checkpointMaxSpawns?: number | undefined;
22
+ ceilingMismatch?: boolean | undefined;
10
23
  }
11
24
  export interface HqFleetEventPayload {
12
25
  runId: string;
@@ -62,6 +75,13 @@ export interface HqFleetSummary {
62
75
  failedTasks: number;
63
76
  totalCostUsd?: number;
64
77
  lastActivityAt: string;
78
+ maxConcurrent?: number | undefined;
79
+ maxSpawns?: number | undefined;
80
+ usedSpawns?: number | undefined;
81
+ remainingSpawns?: number | undefined;
82
+ effectiveSource?: string | undefined;
83
+ checkpointMaxSpawns?: number | undefined;
84
+ ceilingMismatch?: boolean | undefined;
65
85
  }
66
86
  export interface HqQueuedCommand {
67
87
  commandId: string;
@@ -492,6 +492,9 @@ function isHqSubagentSummary(x) {
492
492
  const v = x;
493
493
  return typeof v.subagentId === "string" && typeof v.status === "string" && HQ_FLEET_SUBAGENT_STATUS.has(v.status);
494
494
  }
495
+ function isOptionalFiniteNumber(x) {
496
+ return x === void 0 || typeof x === "number" && Number.isFinite(x);
497
+ }
495
498
  function isHqFleetSnapshotPayload(x) {
496
499
  if (typeof x !== "object" || x === null) return false;
497
500
  const v = x;
@@ -501,6 +504,13 @@ function isHqFleetSnapshotPayload(x) {
501
504
  for (const s of v.subagents) {
502
505
  if (!isHqSubagentSummary(s)) return false;
503
506
  }
507
+ if (!isOptionalFiniteNumber(v.maxConcurrent)) return false;
508
+ if (!isOptionalFiniteNumber(v.maxSpawns)) return false;
509
+ if (!isOptionalFiniteNumber(v.usedSpawns)) return false;
510
+ if (!isOptionalFiniteNumber(v.remainingSpawns)) return false;
511
+ if (!isOptionalFiniteNumber(v.checkpointMaxSpawns)) return false;
512
+ if (v.effectiveSource !== void 0 && typeof v.effectiveSource !== "string") return false;
513
+ if (v.ceilingMismatch !== void 0 && typeof v.ceilingMismatch !== "boolean") return false;
504
514
  return true;
505
515
  }
506
516
  function isHqFleetEventPayload(x) {
package/dist/index.d.ts CHANGED
@@ -54,6 +54,7 @@ export type { FallbackChain, FallbackChainEntry, ProviderHealth, } from './core/
54
54
  export { FallbackProfileManager } from './core/fallback-profile-manager.js';
55
55
  export { InputBuilder, type InputBuilderEvent, type InputBuilderOptions, } from './core/input-builder.js';
56
56
  export { type InstructionBundle, type InstructionBundlePaths, loadInstructionBundle, mergeInstructionBundle, type SystemInstructionBundle, type SystemInstructionVariant, } from './core/instruction-bundle.js';
57
+ export { type InstructionTemplateContext, renderInstructionLayer, } from './core/instruction-template.js';
57
58
  export { buildMailboxBlock, buildMailboxBtwAwarenessBlock, createMailboxChecker, injectPendingMailboxMessages, type MailboxDeliveryMode, type MailboxLoopOptions, } from './core/mailbox-loop.js';
58
59
  export { evaluateModelCalendar, logicalCalendarTarget, type ModelBlackoutRule, type ModelCalendarDecision, } from './core/model-availability-calendar.js';
59
60
  export { runProviderWithRetry } from './core/provider-runner.js';