@kynver-app/runtime 0.1.90 → 0.1.92

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 (65) hide show
  1. package/dist/box-identity.d.ts +19 -0
  2. package/dist/box-resource-snapshot-shared.d.ts +2 -0
  3. package/dist/cleanup-active-worktrees.d.ts +1 -1
  4. package/dist/cleanup-dependency-scan.d.ts +1 -0
  5. package/dist/cleanup-dir-size.d.ts +2 -1
  6. package/dist/cleanup-execute.d.ts +2 -4
  7. package/dist/cleanup-guards.d.ts +5 -0
  8. package/dist/cleanup-harness-path-validate.d.ts +5 -0
  9. package/dist/cleanup-index-status.d.ts +9 -0
  10. package/dist/cleanup-path-ownership.d.ts +9 -0
  11. package/dist/cleanup-privileged-remove.d.ts +13 -0
  12. package/dist/cleanup-progress.d.ts +2 -0
  13. package/dist/cleanup-remove-path.d.ts +17 -0
  14. package/dist/cleanup-retention-config.d.ts +4 -0
  15. package/dist/cleanup-run-liveness.d.ts +6 -2
  16. package/dist/cleanup-run-terminal-cache.d.ts +6 -0
  17. package/dist/cleanup-summary.d.ts +29 -0
  18. package/dist/cleanup-types.d.ts +9 -1
  19. package/dist/cleanup-worktree-index.d.ts +3 -2
  20. package/dist/cli.js +3620 -1698
  21. package/dist/cli.js.map +4 -4
  22. package/dist/completion-ack.d.ts +8 -0
  23. package/dist/completion-response.d.ts +1 -1
  24. package/dist/config.d.ts +6 -0
  25. package/dist/daemon-box-identity.d.ts +16 -0
  26. package/dist/db-credential-env-paths.d.ts +13 -0
  27. package/dist/db-credential-resolver.d.ts +2 -1
  28. package/dist/default-repo-cli.d.ts +20 -0
  29. package/dist/dispatch-claim-release.d.ts +17 -0
  30. package/dist/dispatch-lane-normalization.d.ts +14 -0
  31. package/dist/dispatch.d.ts +4 -1
  32. package/dist/doctor/doctor.types.d.ts +2 -0
  33. package/dist/doctor/runtime-takeover-cli.d.ts +1 -1
  34. package/dist/doctor/runtime-takeover-scheduler.d.ts +3 -1
  35. package/dist/harness-worktree-build-guard.d.ts +12 -0
  36. package/dist/heartbeat-final-result.d.ts +5 -0
  37. package/dist/heartbeat.d.ts +3 -1
  38. package/dist/index.d.ts +7 -1
  39. package/dist/index.js +3513 -1406
  40. package/dist/index.js.map +4 -4
  41. package/dist/landing-contract-pr-classify.d.ts +4 -0
  42. package/dist/memory-cost-package-version-guard-enforce.d.ts +10 -0
  43. package/dist/memory-cost-package-version-guard.d.ts +49 -0
  44. package/dist/orchestration-enforcement/config.d.ts +5 -0
  45. package/dist/orchestration-enforcement/evaluator.d.ts +6 -0
  46. package/dist/orchestration-enforcement/idempotency.d.ts +8 -0
  47. package/dist/orchestration-enforcement/index.d.ts +4 -0
  48. package/dist/orchestration-enforcement/types.d.ts +24 -0
  49. package/dist/prompt.d.ts +2 -0
  50. package/dist/repo-search.d.ts +40 -0
  51. package/dist/resource-gate.d.ts +5 -0
  52. package/dist/run-worker-index.d.ts +10 -0
  53. package/dist/runner-identity.d.ts +2 -0
  54. package/dist/shell-command-outcome.d.ts +1 -1
  55. package/dist/status.d.ts +13 -0
  56. package/dist/supervisor.d.ts +3 -1
  57. package/dist/validate.d.ts +10 -0
  58. package/dist/worker-cap-source.d.ts +29 -0
  59. package/dist/worker-final-result-embed.d.ts +1 -0
  60. package/dist/worker-ops.d.ts +22 -1
  61. package/dist/worker-persona-catalog.d.ts +24 -0
  62. package/dist/worker-persona-catalog.js +138 -0
  63. package/dist/worker-persona-catalog.js.map +7 -0
  64. package/dist/workspace-runtime-config.d.ts +2 -0
  65. package/package.json +1 -1
@@ -0,0 +1,19 @@
1
+ import type { KynverUserConfig } from "./config.js";
2
+ export type WorkerPoolBoxKind = "ghost" | "forge";
3
+ export type BoxKindSource = "config" | "env" | "default";
4
+ export interface ResolvedBoxIdentity {
5
+ boxKind: WorkerPoolBoxKind;
6
+ source: BoxKindSource;
7
+ /** True when identity would have been inferred from KYNVER_AGENT_OS_SLUG without an explicit box kind. */
8
+ slugInferenceBlocked: boolean;
9
+ warnings: string[];
10
+ }
11
+ /** Normalize host/box labels to ghost | forge for worker-pool attribution. */
12
+ export declare function normalizeWorkerPoolBoxKind(raw: string | null | undefined): WorkerPoolBoxKind;
13
+ /**
14
+ * Resolve physical box identity for capacity snapshots and daemon policy.
15
+ * Never maps AgentOS workspace slug alone to box kind — Forge installs must set
16
+ * `boxKind` in ~/.kynver/config.json or `KYNVER_BOX_KIND`.
17
+ */
18
+ export declare function resolveBoxIdentity(env?: NodeJS.ProcessEnv, config?: Pick<KynverUserConfig, "boxKind">): ResolvedBoxIdentity;
19
+ export declare function resolveBoxKindFromConfig(config?: Pick<KynverUserConfig, "boxKind">, env?: NodeJS.ProcessEnv): WorkerPoolBoxKind;
@@ -1,2 +1,4 @@
1
+ export { normalizeWorkerPoolBoxKind, resolveBoxIdentity } from "./box-identity.js";
2
+ /** @deprecated Prefer resolveBoxIdentity — kept for callers that only need the kind string. */
1
3
  export declare function resolveBoxKindFromEnv(env?: NodeJS.ProcessEnv): string;
2
4
  export declare function defaultBoxId(boxKind: string, hostLabel?: string | null): string;
@@ -5,7 +5,7 @@ export interface ActiveWorktreeGuardSnapshot {
5
5
  liveRunKeys: Set<string>;
6
6
  }
7
7
  /** Collect worktrees/runs that still have live worker processes (current-run guard). */
8
- export declare function collectActiveWorktreeGuards(harnessRoots: string[]): ActiveWorktreeGuardSnapshot;
8
+ export declare function collectActiveWorktreeGuards(harnessRoots: string[], now?: number): ActiveWorktreeGuardSnapshot;
9
9
  /** True when a worktree path still exists under a live run (belt-and-suspenders). */
10
10
  export declare function isWorktreeOnLiveRun(worktreePath: string, harnessRoot: string, runId: string | undefined, liveRunKeys: Set<string>): boolean;
11
11
  export declare function worktreesDirForRoot(harnessRoot: string): string;
@@ -4,6 +4,7 @@ export interface ScanDependencyCacheOptions {
4
4
  harnessRoot: string;
5
5
  worktreesDir: string;
6
6
  nodeModulesAgeMs: number;
7
+ includeOrphans?: boolean;
7
8
  runIdFilter?: string;
8
9
  index: Map<string, IndexedWorktree>;
9
10
  now: number;
@@ -1,4 +1,5 @@
1
1
  /**
2
- * Best-effort directory size. Returns null when entry cap is exceeded (huge trees).
2
+ * Best-effort directory size. Prefers `du -sb` (fast on large `node_modules`);
3
+ * falls back to a capped walk. Returns null when entry cap is exceeded.
3
4
  */
4
5
  export declare function directorySizeBytes(root: string, maxEntries?: number): number | null;
@@ -1,9 +1,7 @@
1
- import type { CleanupAction, CleanupCandidate, CleanupSkipReason } from "./cleanup-types.js";
1
+ import type { CleanupAction, CleanupCandidate } from "./cleanup-types.js";
2
+ export { isHarnessBuildCachePath, isHarnessNextCachePath, isHarnessNodeModulesPath } from "./cleanup-harness-path-validate.js";
2
3
  export declare function removeNodeModules(candidate: CleanupCandidate, execute: boolean): CleanupAction;
3
4
  export declare function removeNextCache(candidate: CleanupCandidate, execute: boolean): CleanupAction;
4
5
  export declare function removeBuildCache(candidate: CleanupCandidate, execute: boolean): CleanupAction;
5
6
  export declare function removeRunDirectory(candidate: CleanupCandidate, execute: boolean): CleanupAction;
6
7
  export declare function removeWorktree(candidate: CleanupCandidate, execute: boolean): CleanupAction;
7
- export declare function isHarnessNodeModulesPath(targetPath: string, harnessRoot: string, worktreesDir: string): CleanupSkipReason | null;
8
- export declare function isHarnessNextCachePath(targetPath: string, harnessRoot: string, worktreesDir: string): CleanupSkipReason | null;
9
- export declare function isHarnessBuildCachePath(targetPath: string, harnessRoot: string, worktreesDir: string): CleanupSkipReason | null;
@@ -1,7 +1,11 @@
1
1
  import type { CleanupSkipReason, WorktreeRemovalGuardHook } from "./cleanup-types.js";
2
2
  import type { IndexedWorktree } from "./cleanup-worktree-index.js";
3
+ import type { CleanupRunLivenessContext } from "./cleanup-run-liveness.js";
4
+ import type { GitAncestry } from "./git.js";
3
5
  import type { RawHarnessWorkerStatus } from "./status.js";
4
6
  export { materialWorktreeChanges } from "./cleanup-guards-helpers.js";
7
+ /** True when git ancestry shows the worker branch is fully landed on the run base. */
8
+ export declare function isLandedGitAncestry(ancestry: GitAncestry | null | undefined): boolean;
5
9
  /** Blocks whole-worktree removal when commits are not landed or tree is dirty. */
6
10
  export declare function isPrOrUnmergedWork(status: RawHarnessWorkerStatus): boolean;
7
11
  export interface WorktreeGuardInput {
@@ -19,6 +23,7 @@ export interface WorktreeGuardInput {
19
23
  */
20
24
  orphanSafety?: CleanupSkipReason | null;
21
25
  worktreeRemovalGuard?: WorktreeRemovalGuardHook;
26
+ liveness?: CleanupRunLivenessContext;
22
27
  }
23
28
  export type WorktreeGuardSkip = CleanupSkipReason | {
24
29
  reason: CleanupSkipReason;
@@ -0,0 +1,5 @@
1
+ import type { CleanupSkipReason } from "./cleanup-types.js";
2
+ export declare function isHarnessNodeModulesPath(targetPath: string, harnessRoot: string, worktreesDir: string): CleanupSkipReason | null;
3
+ export declare function isHarnessNextCachePath(targetPath: string, harnessRoot: string, worktreesDir: string): CleanupSkipReason | null;
4
+ export declare function isHarnessBuildCachePath(targetPath: string, harnessRoot: string, worktreesDir: string): CleanupSkipReason | null;
5
+ export declare function isHarnessGeneratedCachePath(targetPath: string, harnessRoot: string, worktreesDir: string): boolean;
@@ -0,0 +1,9 @@
1
+ import { type RawHarnessWorkerStatus } from "./status.js";
2
+ import type { IndexedWorktree } from "./cleanup-worktree-index.js";
3
+ /** Lazily compute worker status — avoids git/stream work for every indexed worker up front. */
4
+ export declare function indexedWorktreeStatus(entry: IndexedWorktree): RawHarnessWorkerStatus;
5
+ /**
6
+ * Porcelain-only dirty probe for dependency-cache guards. Skips ancestry/stream
7
+ * work that whole-worktree removal needs but `node_modules` GC does not.
8
+ */
9
+ export declare function indexedWorktreeHasMaterialChanges(entry: IndexedWorktree): boolean;
@@ -0,0 +1,9 @@
1
+ export interface PathOwnershipInfo {
2
+ uid: number;
3
+ gid: number;
4
+ /** True when the entry is not owned by the current process user/group. */
5
+ foreign: boolean;
6
+ }
7
+ export declare function readPathOwnership(targetPath: string): PathOwnershipInfo | null;
8
+ /** Shallow scan for foreign-owned entries (dependency caches are usually uniform). */
9
+ export declare function pathHasForeignOwnedEntry(targetPath: string, maxEntries?: number): boolean;
@@ -0,0 +1,13 @@
1
+ export type PrivilegedCleanupMode = "off" | "auto" | "force";
2
+ export declare function resolvePrivilegedCleanupMode(): PrivilegedCleanupMode;
3
+ export interface PrivilegedReclaimResult {
4
+ ok: boolean;
5
+ method?: "chown_then_rm" | "sudo_rm";
6
+ error?: string;
7
+ }
8
+ /**
9
+ * Reclaim a harness generated cache directory that is not owned by the daemon user.
10
+ * Only operates on validated `worktrees/<run>/<worker>/{node_modules,.next,...}` paths.
11
+ */
12
+ export declare function tryPrivilegedReclaimHarnessCache(targetPath: string, harnessRoot: string, worktreesDir: string): PrivilegedReclaimResult;
13
+ export declare const HARNESS_ROOT_OWNED_CACHE_RUNBOOK = "Root-owned harness caches require operator reclaim: configure passwordless sudo for chown/rm under ~/.kynver/harness/worktrees, or run `node scripts/reclaim-harness-root-owned-cache.mjs --execute` as the harness owner with sudo available. See docs/runbooks/harness-root-owned-cache-reclaim.md.";
@@ -0,0 +1,2 @@
1
+ /** stderr progress lines so broad cleanup scans do not appear hung before JSON output. */
2
+ export declare function emitCleanupProgress(phase: string, detail?: string): void;
@@ -0,0 +1,17 @@
1
+ import { rmSync } from "node:fs";
2
+ import type { CleanupCandidate, CleanupSkipReason } from "./cleanup-types.js";
3
+ import { pathHasForeignOwnedEntry } from "./cleanup-path-ownership.js";
4
+ export interface RemoveHarnessPathOutcome {
5
+ executed: boolean;
6
+ skipped: boolean;
7
+ skipReason?: CleanupSkipReason;
8
+ error?: string;
9
+ bytes?: number;
10
+ privilegedReclaim?: boolean;
11
+ }
12
+ interface RemoveHarnessGeneratedPathDeps {
13
+ removePath?: typeof rmSync;
14
+ hasForeignOwnedEntry?: typeof pathHasForeignOwnedEntry;
15
+ }
16
+ export declare function removeHarnessGeneratedPath(candidate: CleanupCandidate, execute: boolean, deps?: RemoveHarnessGeneratedPathDeps): RemoveHarnessPathOutcome;
17
+ export {};
@@ -11,6 +11,10 @@ export interface ResolvedHarnessRetention {
11
11
  includeOrphans: boolean;
12
12
  runIdFilter?: string;
13
13
  accountBytes: boolean;
14
+ /** Cap filesystem walk depth per run dir in `harnessStorageSnapshot` (0 = counts only). */
15
+ storagePerRunEntryCap: number | null;
16
+ /** Per-candidate walk cap when `du` is unavailable (default 2k). */
17
+ byteAccountingEntryCap: number;
14
18
  diskPressure?: boolean;
15
19
  diskGate?: DispatchNextDiskGateShape;
16
20
  }
@@ -1,13 +1,17 @@
1
1
  import type { IndexedWorktree } from "./cleanup-worktree-index.js";
2
+ import type { CleanupRunTerminalCache } from "./cleanup-run-terminal-cache.js";
3
+ export interface CleanupRunLivenessContext {
4
+ runTerminalCache: CleanupRunTerminalCache;
5
+ }
2
6
  /** True when the worker process is still live or marked running in worker.json. */
3
7
  export declare function isWorkerProcessLive(indexed: IndexedWorktree): boolean;
4
8
  /**
5
9
  * Run record still marked active but every worker is finished — safe to treat as
6
10
  * terminal for GC after `finalizeStaleRuns()` (or when deriveTerminalRunStatus is set).
7
11
  */
8
- export declare function isRunStaleActive(indexed: IndexedWorktree): boolean;
12
+ export declare function isRunStaleActive(indexed: IndexedWorktree, ctx?: CleanupRunLivenessContext): boolean;
9
13
  /**
10
14
  * Whether the harness run still has unfinished work that should block whole-worktree removal.
11
15
  * Does not block per-worker `node_modules` when only this worker is finished.
12
16
  */
13
- export declare function runBlocksWorktreeRemoval(indexed: IndexedWorktree): boolean;
17
+ export declare function runBlocksWorktreeRemoval(indexed: IndexedWorktree, ctx?: CleanupRunLivenessContext): boolean;
@@ -0,0 +1,6 @@
1
+ import type { HarnessRunRecord } from "./run-store.js";
2
+ /** Per-sweep memo so worktree guards do not re-derive terminal status for every worker in a run. */
3
+ export declare class CleanupRunTerminalCache {
4
+ private readonly cache;
5
+ derive(run: HarnessRunRecord): string | null;
6
+ }
@@ -0,0 +1,29 @@
1
+ import type { CleanupActionKind, HarnessCleanupSummary, HarnessStorageSnapshotShape } from "./cleanup-types.js";
2
+ export interface CleanupCompactSummary {
3
+ harnessRoot: string;
4
+ scanRoots: string[];
5
+ dryRun: boolean;
6
+ execute: boolean;
7
+ scannedAt: string;
8
+ finalizedRuns: number;
9
+ actionCount: number;
10
+ actionKinds: Partial<Record<CleanupActionKind, number>>;
11
+ totals: HarnessCleanupSummary["totals"];
12
+ storage?: HarnessStorageSnapshotShape;
13
+ preservedLivePaths?: HarnessCleanupSummary["preservedLivePaths"];
14
+ removedRunDirectories?: number;
15
+ sampleActions: Array<{
16
+ kind: CleanupActionKind;
17
+ path: string;
18
+ skipReason?: string;
19
+ bytes?: number | null;
20
+ runId?: string;
21
+ worker?: string;
22
+ }>;
23
+ sampleSkips: HarnessCleanupSummary["skips"];
24
+ }
25
+ /** Operator-facing rollup — bounded samples, no per-path megabyte JSON dumps. */
26
+ export declare function buildCleanupCompactSummary(summary: HarnessCleanupSummary, options?: {
27
+ maxSampleActions?: number;
28
+ maxSampleSkips?: number;
29
+ }): CleanupCompactSummary;
@@ -1,5 +1,7 @@
1
1
  export type CleanupActionKind = "remove_node_modules" | "remove_next_cache" | "remove_build_cache" | "remove_worktree" | "remove_run_directory";
2
2
  export type CleanupSkipReason = "dry_run" | "below_age_threshold" | "active_worker" | "dirty_worktree" | "landing_blocked" | "pr_or_unmerged_commits" | "completion_blocked" | "run_still_active" | "path_outside_harness" | "worktrees_disabled" | "orphan_without_flag" | "missing_worktree" | "remove_failed"
3
+ /** Generated cache owned by another user (often root); daemon cannot unlink without privileged reclaim. */
4
+ | "foreign_owner"
3
5
  /** Harness `runs/` metadata must never be removed by worktree GC. */
4
6
  | "run_metadata_protected"
5
7
  /** AgentOS / operator lifecycle overlay blocked removal (see `detail`). */
@@ -77,6 +79,8 @@ export interface HarnessCleanupSummary {
77
79
  }>;
78
80
  /** Empty harness worktree run directories removed after worker worktrees were reclaimed. */
79
81
  removedRunDirectories?: number;
82
+ /** Bounded operator rollup (always attached; use `kynver cleanup --compact` to emit alone). */
83
+ compactSummary?: import("./cleanup-summary.js").CleanupCompactSummary;
80
84
  }
81
85
  export interface WorktreeRemovalGuardInput {
82
86
  worktreePath: string;
@@ -96,8 +100,12 @@ export interface HarnessCleanupOptions {
96
100
  execute?: boolean;
97
101
  /** When true (default), call `finalizeStaleRuns()` before scanning. */
98
102
  finalizeStaleRuns?: boolean;
99
- /** When true (default), estimate candidate bytes in dry-run summaries. */
103
+ /** When true, estimate candidate bytes for guard-passing removals only. CLI defaults false. */
100
104
  accountBytes?: boolean;
105
+ /** Per-run entry cap for storage snapshot byte totals (`0` = counts only). */
106
+ storagePerRunEntryCap?: number | null;
107
+ /** Per-candidate filesystem walk cap when `du` is unavailable. */
108
+ byteAccountingEntryCap?: number;
101
109
  /** Minimum age before removing generated `node_modules` (default 6h). */
102
110
  nodeModulesAgeMs?: number;
103
111
  /** When 0 or unset, worktree removal is disabled. */
@@ -1,5 +1,5 @@
1
1
  import { type HarnessRunRecord } from "./run-store.js";
2
- import { type HarnessWorkerRecord, type RawHarnessWorkerStatus } from "./status.js";
2
+ import type { HarnessWorkerRecord, RawHarnessWorkerStatus } from "./status.js";
3
3
  export interface IndexedWorktree {
4
4
  harnessRoot?: string;
5
5
  worktreePath: string;
@@ -7,7 +7,8 @@ export interface IndexedWorktree {
7
7
  workerName: string;
8
8
  run: HarnessRunRecord;
9
9
  worker: HarnessWorkerRecord;
10
- status: RawHarnessWorkerStatus;
10
+ /** Populated lazily via `indexedWorktreeStatus()` during guard evaluation. */
11
+ status?: RawHarnessWorkerStatus;
11
12
  }
12
13
  export declare function buildWorktreeIndex(): Map<string, IndexedWorktree>;
13
14
  export declare function buildWorktreeIndexAt(harnessRoot: string): Map<string, IndexedWorktree>;