pi-orchestrator-config 4.2.1 → 4.3.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.
- package/README.md +52 -61
- package/agents/git-expert.md +5 -1
- package/agents/github-expert.md +4 -1
- package/extensions/acpx-provider/runtime-models.ts +18 -6
- package/extensions/cli-provider/agents/claude.ts +3 -2
- package/extensions/cli-provider/agents/cursor.ts +3 -5
- package/extensions/cli-provider/agents/gemini.ts +3 -2
- package/extensions/cli-provider/discover.ts +7 -7
- package/extensions/cli-provider/index.ts +5 -0
- package/extensions/cli-provider/runtime-models.ts +18 -6
- package/extensions/cli-provider/session-reaper.ts +5 -7
- package/extensions/cli-provider/sessions.ts +4 -0
- package/extensions/cli-provider/shared/discover-cache.ts +17 -176
- package/extensions/coms/coms-p2p.ts +1719 -423
- package/extensions/coms/coms-shared.ts +261 -39
- package/extensions/coms/coms-wrapper.ts +100 -62
- package/extensions/coms/index.ts +8 -4
- package/extensions/coms/mixed-turn.ts +26 -0
- package/extensions/coms/probe-socket.ts +42 -0
- package/extensions/coms/themeMap.ts +0 -1
- package/extensions/image-gen/image-gen.ts +19 -1
- package/extensions/orchestrator/async-agents.ts +509 -85
- package/extensions/orchestrator/cron.ts +14 -8
- package/extensions/orchestrator/dreaming.ts +31 -24
- package/extensions/orchestrator/enforcement-helpers.ts +459 -17
- package/extensions/orchestrator/enforcement-rules.ts +5 -4
- package/extensions/orchestrator/enforcement.ts +79 -25
- package/extensions/orchestrator/extended-autocomplete.ts +7 -0
- package/extensions/orchestrator/git-helpers.ts +2 -2
- package/extensions/orchestrator/index.ts +23 -10
- package/extensions/orchestrator/markdown-transformer.ts +313 -0
- package/extensions/orchestrator/memory-embeddings.ts +36 -34
- package/extensions/orchestrator/memory-provenance.ts +29 -25
- package/extensions/orchestrator/memory-scoring.ts +23 -18
- package/extensions/orchestrator/memory-tools.ts +10 -3
- package/extensions/orchestrator/overlay-dashboard.ts +17 -5
- package/extensions/orchestrator/pi-config-review-state.ts +44 -33
- package/extensions/orchestrator/project-settings.ts +220 -21
- package/extensions/orchestrator/review-porcelain.ts +4 -0
- package/extensions/orchestrator/review-ui.ts +11 -5
- package/extensions/orchestrator/rule-placeholders.ts +384 -1
- package/extensions/orchestrator/rules.ts +80 -132
- package/extensions/orchestrator/settings-tui-helpers.ts +380 -0
- package/extensions/orchestrator/settings-tui-submenus.ts +647 -0
- package/extensions/orchestrator/settings-tui.ts +636 -0
- package/extensions/orchestrator/state-jsonl.ts +431 -0
- package/extensions/orchestrator/subagent-tool.ts +105 -50
- package/extensions/orchestrator/sync-limit.ts +23 -0
- package/extensions/orchestrator/task-lifecycle.ts +77 -67
- package/extensions/orchestrator/utils.ts +8 -5
- package/extensions/pidash/pidash.ts +193 -156
- package/extensions/pidiff/pidiff.ts +64 -38
- package/extensions/pidiff/spawn-lock.ts +62 -0
- package/extensions/pitasks/index.ts +430 -0
- package/extensions/pitasks/reminders.ts +37 -0
- package/extensions/pitasks/task-store.ts +467 -0
- package/extensions/pitasks/task-tools.ts +375 -0
- package/extensions/pitasks/task-widget.ts +181 -0
- package/extensions/pitasks/types.ts +38 -0
- package/extensions/providers/acpx-driver.ts +12 -2
- package/extensions/providers/built-in-drivers.ts +6 -6
- package/extensions/providers/claude-driver.ts +1 -1
- package/extensions/providers/cursor-cli-driver.ts +1 -1
- package/extensions/providers/gemini-driver.ts +1 -1
- package/extensions/providers/index.ts +144 -26
- package/extensions/providers/initialized-guard.ts +27 -0
- package/extensions/providers/restore-default-model.ts +596 -0
- package/extensions/providers/session-shutdown.ts +39 -0
- package/extensions/shared/coms-active.ts +23 -0
- package/extensions/shared/create-runtime-provider.ts +2 -0
- package/extensions/shared/daemon-manager.ts +0 -8
- package/extensions/shared/file-logger.ts +132 -25
- package/extensions/shared/logger.ts +50 -0
- package/extensions/shared/models-dev.ts +421 -0
- package/extensions/shared/oneshot.ts +116 -0
- package/extensions/shared/resolve-binary.ts +191 -0
- package/extensions/shared/types.ts +3 -0
- package/package.json +7 -2
- package/prompts/coderabbit-rate-limit.md +2 -0
- package/rules/00-orchestrator-core.md +3 -0
- package/rules/10-agent-routing.md +1 -1
- package/rules/20-code-review-loop.md +38 -16
- package/rules/30-prompt-templates.md +4 -0
- package/rules/35-memory.md +3 -3
- package/rules/40-critical-rules.md +3 -0
- package/rules/55-coms-protocol.md +84 -18
- package/rules/60-task-tracking.md +2 -0
- package/settings-keys.json +481 -20
- package/templates/coms-feature-manager-prompt.md +4 -6
- package/extensions/coms/coms-net-server.ts +0 -1642
- package/extensions/coms/coms-net-wrapper.ts +0 -521
- package/extensions/coms/coms-net.ts +0 -1589
|
@@ -109,6 +109,8 @@ export class OverlayListDashboard<
|
|
|
109
109
|
> implements Component {
|
|
110
110
|
private closed = false;
|
|
111
111
|
private ticker: ReturnType<typeof setInterval>;
|
|
112
|
+
private cachedWidth: number | undefined;
|
|
113
|
+
private cachedLines: string[] | undefined;
|
|
112
114
|
|
|
113
115
|
constructor(
|
|
114
116
|
private tui: TUI,
|
|
@@ -118,7 +120,7 @@ export class OverlayListDashboard<
|
|
|
118
120
|
private selection: OverlaySelection<TId>,
|
|
119
121
|
private done: (value: TId | null) => void,
|
|
120
122
|
) {
|
|
121
|
-
this.ticker = setInterval(() => this.tui.requestRender(), 1000);
|
|
123
|
+
this.ticker = setInterval(() => { this.invalidate(); this.tui.requestRender(); }, 1000);
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
private items(): TItem[] {
|
|
@@ -169,7 +171,8 @@ export class OverlayListDashboard<
|
|
|
169
171
|
this.selection.index =
|
|
170
172
|
(this.selection.index - 1 + items.length) % items.length;
|
|
171
173
|
this.selection.id = items[this.selection.index]?.id;
|
|
172
|
-
this.
|
|
174
|
+
this.invalidate();
|
|
175
|
+
this.tui.requestRender(true);
|
|
173
176
|
}
|
|
174
177
|
return;
|
|
175
178
|
}
|
|
@@ -181,7 +184,8 @@ export class OverlayListDashboard<
|
|
|
181
184
|
if (items.length > 0) {
|
|
182
185
|
this.selection.index = (this.selection.index + 1) % items.length;
|
|
183
186
|
this.selection.id = items[this.selection.index]?.id;
|
|
184
|
-
this.
|
|
187
|
+
this.invalidate();
|
|
188
|
+
this.tui.requestRender(true);
|
|
185
189
|
}
|
|
186
190
|
return;
|
|
187
191
|
}
|
|
@@ -193,12 +197,15 @@ export class OverlayListDashboard<
|
|
|
193
197
|
this.close(null);
|
|
194
198
|
return;
|
|
195
199
|
}
|
|
196
|
-
this.
|
|
200
|
+
this.invalidate();
|
|
201
|
+
this.tui.requestRender(true);
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
205
|
|
|
201
206
|
render(width: number): string[] {
|
|
207
|
+
if (this.cachedLines && this.cachedWidth === width) return this.cachedLines;
|
|
208
|
+
|
|
202
209
|
const theme = this.theme;
|
|
203
210
|
const items = this.items();
|
|
204
211
|
reconcileSelection(this.selection, items);
|
|
@@ -243,6 +250,8 @@ export class OverlayListDashboard<
|
|
|
243
250
|
truncateToWidth(theme.fg("dim", ` ${this.spec.footerHints}`), width),
|
|
244
251
|
);
|
|
245
252
|
|
|
253
|
+
this.cachedLines = lines;
|
|
254
|
+
this.cachedWidth = width;
|
|
246
255
|
return lines;
|
|
247
256
|
}
|
|
248
257
|
|
|
@@ -290,7 +299,10 @@ export class OverlayListDashboard<
|
|
|
290
299
|
return out;
|
|
291
300
|
}
|
|
292
301
|
|
|
293
|
-
invalidate(): void {
|
|
302
|
+
invalidate(): void {
|
|
303
|
+
this.cachedWidth = undefined;
|
|
304
|
+
this.cachedLines = undefined;
|
|
305
|
+
}
|
|
294
306
|
}
|
|
295
307
|
|
|
296
308
|
export class OverlayScrollDetail implements Component {
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Review state machine — tracks code review loop status.
|
|
3
|
-
* State stored in <worktree-root>/.pi/data/pi-config-review-state.
|
|
3
|
+
* State stored in <worktree-root>/.pi/data/pi-config-review-state.jsonl (per-worktree, not shared).
|
|
4
4
|
* Each worktree gets its own state file via resolveWorktreeRoot (--show-toplevel).
|
|
5
5
|
* Used by enforcement to block git commit until all reviewers approve.
|
|
6
|
+
*
|
|
7
|
+
* Persistence: append-only JSONL via JsonlStateStore (issue #724).
|
|
8
|
+
* Each state mutation appends a single JSON line. The latest valid line
|
|
9
|
+
* is the current state. Auto-compaction prevents unbounded growth.
|
|
10
|
+
* On first access, migrates any legacy pi-config-review-state.json automatically.
|
|
6
11
|
*/
|
|
7
12
|
|
|
8
|
-
import {
|
|
13
|
+
import { readFileSync, writeFileSync, unlinkSync } from "node:fs";
|
|
9
14
|
import { join } from "node:path";
|
|
10
15
|
import { getSetting } from "./project-settings.js";
|
|
16
|
+
import { createCachedStore } from "./state-jsonl.js";
|
|
17
|
+
import type { JsonlStateStore } from "./state-jsonl.js";
|
|
11
18
|
import { resolveWorktreeRoot, getProjectDataDir } from "./utils.js";
|
|
12
19
|
|
|
13
20
|
type StateTransitionCallback = (state: ReviewState) => void;
|
|
@@ -23,7 +30,7 @@ export function onStateTransition(cb: StateTransitionCallback): void {
|
|
|
23
30
|
function notifyTransition(state: ReviewState): void {
|
|
24
31
|
if (!onTransitionCb) return;
|
|
25
32
|
try { onTransitionCb({ ...state, reviewers_pending: [...state.reviewers_pending] }); }
|
|
26
|
-
catch
|
|
33
|
+
catch { /* transition callback failed — fire-and-forget, never propagate */ }
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
export interface ReviewState {
|
|
@@ -38,14 +45,16 @@ export interface ReviewState {
|
|
|
38
45
|
tests_passed: boolean;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
const
|
|
48
|
+
const STATE_FILE_JSONL = "pi-config-review-state.jsonl";
|
|
49
|
+
const LEGACY_STATE_FILE = "pi-config-review-state.json";
|
|
42
50
|
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
function getStore(cwd: string): JsonlStateStore<ReviewState> {
|
|
52
|
+
const dataDir = getProjectDataDir(resolveWorktreeRoot(cwd));
|
|
53
|
+
return createCachedStore<ReviewState>(dataDir, STATE_FILE_JSONL, LEGACY_STATE_FILE);
|
|
45
54
|
}
|
|
46
55
|
|
|
47
|
-
function
|
|
48
|
-
getProjectDataDir(resolveWorktreeRoot(cwd));
|
|
56
|
+
export function statePath(cwd: string): string {
|
|
57
|
+
return join(getProjectDataDir(resolveWorktreeRoot(cwd)), STATE_FILE_JSONL);
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
function defaultState(): ReviewState {
|
|
@@ -62,29 +71,35 @@ function defaultState(): ReviewState {
|
|
|
62
71
|
};
|
|
63
72
|
}
|
|
64
73
|
|
|
74
|
+
/** Normalize a raw parsed object into a valid ReviewState with defaults for missing fields. */
|
|
75
|
+
function normalizeRawState(raw: any): ReviewState {
|
|
76
|
+
return {
|
|
77
|
+
status: raw.status ?? "none",
|
|
78
|
+
cycle: typeof raw.cycle === "number" ? raw.cycle : 0,
|
|
79
|
+
reviewers_pending: Array.isArray(raw.reviewers_pending) ? raw.reviewers_pending : [],
|
|
80
|
+
reviewers_total: typeof raw.reviewers_total === "number" ? raw.reviewers_total : 0,
|
|
81
|
+
findings_count: typeof raw.findings_count === "number" ? raw.findings_count : 0,
|
|
82
|
+
last_edit_at: typeof raw.last_edit_at === "string" ? raw.last_edit_at : null,
|
|
83
|
+
last_clean_at: typeof raw.last_clean_at === "string" ? raw.last_clean_at : null,
|
|
84
|
+
edited_during_cycle: raw.edited_during_cycle === true,
|
|
85
|
+
tests_passed: raw.tests_passed === true,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
65
89
|
export function readReviewState(cwd: string): ReviewState {
|
|
66
|
-
const
|
|
67
|
-
|
|
90
|
+
const store = getStore(cwd);
|
|
91
|
+
const raw = store.read();
|
|
92
|
+
if (raw === null) return defaultState();
|
|
68
93
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
cycle: typeof raw.cycle === "number" ? raw.cycle : 0,
|
|
73
|
-
reviewers_pending: Array.isArray(raw.reviewers_pending) ? raw.reviewers_pending : [],
|
|
74
|
-
reviewers_total: typeof raw.reviewers_total === "number" ? raw.reviewers_total : 0,
|
|
75
|
-
findings_count: typeof raw.findings_count === "number" ? raw.findings_count : 0,
|
|
76
|
-
last_edit_at: typeof raw.last_edit_at === "string" ? raw.last_edit_at : null,
|
|
77
|
-
last_clean_at: typeof raw.last_clean_at === "string" ? raw.last_clean_at : null,
|
|
78
|
-
edited_during_cycle: raw.edited_during_cycle === true,
|
|
79
|
-
tests_passed: raw.tests_passed === true,
|
|
80
|
-
};
|
|
81
|
-
} catch (e: any) {
|
|
82
|
-
console.debug("[pi-config-review-state] failed to parse state:", e?.message);
|
|
94
|
+
return normalizeRawState(raw);
|
|
95
|
+
} catch {
|
|
96
|
+
// failed to parse state — return defaults
|
|
83
97
|
return defaultState();
|
|
84
98
|
}
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
function lockPath(cwd: string): string {
|
|
102
|
+
// Lock file sits next to the JSONL state file
|
|
88
103
|
return statePath(cwd) + ".lock";
|
|
89
104
|
}
|
|
90
105
|
|
|
@@ -93,7 +108,7 @@ function acquireLock(cwd: string): boolean {
|
|
|
93
108
|
const maxRetries = 100;
|
|
94
109
|
for (let i = 0; i < maxRetries; i++) {
|
|
95
110
|
try {
|
|
96
|
-
|
|
111
|
+
getProjectDataDir(resolveWorktreeRoot(cwd));
|
|
97
112
|
writeFileSync(lock, String(process.pid), { flag: "wx" });
|
|
98
113
|
return true;
|
|
99
114
|
} catch {
|
|
@@ -126,15 +141,11 @@ function releaseLock(cwd: string): void {
|
|
|
126
141
|
}
|
|
127
142
|
|
|
128
143
|
function writeState(cwd: string, state: ReviewState): void {
|
|
129
|
-
const p = statePath(cwd);
|
|
130
144
|
try {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
renameSync(tmp, p);
|
|
136
|
-
} catch (e: any) {
|
|
137
|
-
console.debug("[pi-config-review-state] write failed:", e?.message);
|
|
145
|
+
const store = getStore(cwd);
|
|
146
|
+
store.write(state);
|
|
147
|
+
} catch {
|
|
148
|
+
// write failed — non-fatal, state file may be stale
|
|
138
149
|
}
|
|
139
150
|
}
|
|
140
151
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Project-level settings — loads .pi/pi-config-settings.json with env var fallback.
|
|
2
|
+
* Project-level settings — loads .pi/pi-config-settings.jsonc (or .json) with env var fallback.
|
|
3
3
|
*
|
|
4
4
|
* Resolution order:
|
|
5
|
-
* 1. Project .pi/pi-config-settings.json (wins if set)
|
|
6
|
-
* 2. Global ~/.pi/pi-config-settings.json (fallback for all projects)
|
|
5
|
+
* 1. Project .pi/pi-config-settings.jsonc or .json (wins if set, .jsonc preferred)
|
|
6
|
+
* 2. Global ~/.pi/pi-config-settings.jsonc or .json (fallback for all projects)
|
|
7
7
|
* 3. Env var (PI_COMMIT_TRAILER, PI_USE_WORKTREES, PI_DREAM_INTERVAL_HOURS, PI_DCO,
|
|
8
8
|
* ACPX_AGENTS, CLI_AGENTS, PI_PIDASH_ENABLE, PI_PIDIFF_ENABLE, PI_PIDASH_PORT, PI_IMAGE_MODEL,
|
|
9
|
-
* PI_INTERNAL_OPERATIONS_PROVIDER, PI_INTERNAL_OPERATIONS_MODEL, PI_REVIEW_LOOP_MAX_CYCLES
|
|
9
|
+
* PI_INTERNAL_OPERATIONS_PROVIDER, PI_INTERNAL_OPERATIONS_MODEL, PI_REVIEW_LOOP_MAX_CYCLES,
|
|
10
|
+
* PI_ENFORCEMENT_ALLOWED_COMMANDS, VERTEX_CLAUDE_1M, PI_SIDECAR_LOG_LEVEL,
|
|
11
|
+
* PI_COMS_MAX_HOPS, PI_COMS_TIMEOUT_MS, PI_COMS_DIR)
|
|
10
12
|
* 4. Default (dream_interval_hours defaults to 3; acpx_agents/cli_agents to []; pidash_enable/pidiff_enable to true; pidash_port to 19190;
|
|
11
13
|
* review_loop_max_cycles to 3)
|
|
12
14
|
*
|
|
@@ -20,6 +22,7 @@ import { existsSync, statSync, readFileSync } from "node:fs";
|
|
|
20
22
|
import { dirname, join } from "node:path";
|
|
21
23
|
import { fileURLToPath } from "node:url";
|
|
22
24
|
import { homedir } from "node:os";
|
|
25
|
+
import stripJsonComments from "strip-json-comments";
|
|
23
26
|
import { resolveRepoRoot } from "./utils.js";
|
|
24
27
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
25
28
|
|
|
@@ -39,6 +42,12 @@ interface ProjectSettings {
|
|
|
39
42
|
pidash_enable?: boolean;
|
|
40
43
|
pidiff_enable?: boolean;
|
|
41
44
|
pidash_port?: number;
|
|
45
|
+
task_auto_clear_enabled?: boolean;
|
|
46
|
+
task_auto_clear_minutes?: number;
|
|
47
|
+
task_reminder_enabled?: boolean;
|
|
48
|
+
task_reminder_interval_minutes?: number;
|
|
49
|
+
task_stale_in_progress_enabled?: boolean;
|
|
50
|
+
task_stale_in_progress_minutes?: number;
|
|
42
51
|
image_model?: string;
|
|
43
52
|
/** Provider for detached LLM async children when parent is acpx (must-async / dream). */
|
|
44
53
|
internal_operations_provider?: string;
|
|
@@ -52,10 +61,43 @@ interface ProjectSettings {
|
|
|
52
61
|
agent_model?: string;
|
|
53
62
|
/** Per-agent provider/model overrides. null = use parent model (skip global agent_provider/agent_model). */
|
|
54
63
|
agent_overrides?: Record<string, { provider?: string | null; model?: string | null }>;
|
|
64
|
+
/** Enable 1M context window variants for Vertex Claude models. */
|
|
65
|
+
vertex_claude_1m?: boolean;
|
|
66
|
+
/** Log level for pi-sidecar (debug, info, warn, error). */
|
|
67
|
+
sidecar_log_level?: string;
|
|
68
|
+
/** Colon-separated command allowlist for enforcement. Empty = allow all. */
|
|
69
|
+
enforcement_allowed_commands?: string;
|
|
70
|
+
/** Enforcement: max sleep seconds allowed in loop context. */
|
|
71
|
+
enforcement_loop_sleep_threshold_s?: number;
|
|
72
|
+
/** Enforcement: max sleep seconds allowed standalone. */
|
|
73
|
+
enforcement_sleep_threshold_s?: number;
|
|
74
|
+
/** Subagent: max sync agent duration in seconds. */
|
|
75
|
+
sync_agent_max_seconds?: number;
|
|
76
|
+
/** Subagent: async poller interval in ms. */
|
|
77
|
+
async_poll_interval_ms?: number;
|
|
78
|
+
/** Subagent: async phantom timeout in ms. */
|
|
79
|
+
async_phantom_timeout_ms?: number;
|
|
80
|
+
/** Max hops for P2P coms message relay. */
|
|
81
|
+
coms_max_hops?: number;
|
|
82
|
+
/** P2P coms message response timeout in ms. */
|
|
83
|
+
coms_timeout_ms?: number;
|
|
84
|
+
/** P2P coms data directory. Empty = ~/.pi/coms. */
|
|
85
|
+
coms_dir?: string;
|
|
86
|
+
/** Coms task heartbeat interval in ms. */
|
|
87
|
+
coms_task_heartbeat_ms?: number;
|
|
88
|
+
/** Coms: entry grace period in ms. */
|
|
89
|
+
coms_entry_grace_period_ms?: number;
|
|
90
|
+
/** Coms: probe timeout in ms. */
|
|
91
|
+
coms_probe_timeout_ms?: number;
|
|
92
|
+
/** Pidiff: stale lock timeout in ms. */
|
|
93
|
+
pidiff_stale_lock_timeout_ms?: number;
|
|
94
|
+
/** Pidiff: daemon startup timeout in seconds. */
|
|
95
|
+
pidiff_daemon_startup_timeout_s?: number;
|
|
55
96
|
}
|
|
56
97
|
|
|
57
98
|
/** Key definition from settings-keys.json — single source of truth for env names + defaults. */
|
|
58
|
-
interface SettingsKeyDef {
|
|
99
|
+
export interface SettingsKeyDef {
|
|
100
|
+
description: string;
|
|
59
101
|
type: string;
|
|
60
102
|
env?: string;
|
|
61
103
|
default: unknown;
|
|
@@ -65,9 +107,18 @@ interface SettingsKeyDef {
|
|
|
65
107
|
per_key_resolution?: boolean;
|
|
66
108
|
}
|
|
67
109
|
|
|
68
|
-
const
|
|
110
|
+
const SETTINGS_FILENAMES = ["pi-config-settings.jsonc", "pi-config-settings.json"];
|
|
69
111
|
|
|
70
|
-
|
|
112
|
+
/** Find the first existing settings file in a directory (.jsonc preferred over .json). */
|
|
113
|
+
export function findSettingsFile(dir: string): string | null {
|
|
114
|
+
for (const name of SETTINGS_FILENAMES) {
|
|
115
|
+
const p = join(dir, name);
|
|
116
|
+
if (existsSync(p)) return p;
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const SETTINGS_KEYS: Record<string, SettingsKeyDef> = JSON.parse(
|
|
71
122
|
readFileSync(join(dirname(fileURLToPath(import.meta.url)), "..", "..", "settings-keys.json"), "utf-8"),
|
|
72
123
|
);
|
|
73
124
|
|
|
@@ -86,6 +137,12 @@ const PROJECT_SETTINGS_KEYS: (keyof ProjectSettings)[] = [
|
|
|
86
137
|
"pidash_enable",
|
|
87
138
|
"pidiff_enable",
|
|
88
139
|
"pidash_port",
|
|
140
|
+
"task_auto_clear_enabled",
|
|
141
|
+
"task_auto_clear_minutes",
|
|
142
|
+
"task_reminder_enabled",
|
|
143
|
+
"task_reminder_interval_minutes",
|
|
144
|
+
"task_stale_in_progress_enabled",
|
|
145
|
+
"task_stale_in_progress_minutes",
|
|
89
146
|
"image_model",
|
|
90
147
|
"internal_operations_provider",
|
|
91
148
|
"internal_operations_model",
|
|
@@ -93,6 +150,22 @@ const PROJECT_SETTINGS_KEYS: (keyof ProjectSettings)[] = [
|
|
|
93
150
|
"agent_provider",
|
|
94
151
|
"agent_model",
|
|
95
152
|
"agent_overrides",
|
|
153
|
+
"vertex_claude_1m",
|
|
154
|
+
"sidecar_log_level",
|
|
155
|
+
"enforcement_allowed_commands",
|
|
156
|
+
"enforcement_loop_sleep_threshold_s",
|
|
157
|
+
"enforcement_sleep_threshold_s",
|
|
158
|
+
"sync_agent_max_seconds",
|
|
159
|
+
"async_poll_interval_ms",
|
|
160
|
+
"async_phantom_timeout_ms",
|
|
161
|
+
"coms_max_hops",
|
|
162
|
+
"coms_timeout_ms",
|
|
163
|
+
"coms_dir",
|
|
164
|
+
"coms_task_heartbeat_ms",
|
|
165
|
+
"coms_entry_grace_period_ms",
|
|
166
|
+
"coms_probe_timeout_ms",
|
|
167
|
+
"pidiff_stale_lock_timeout_ms",
|
|
168
|
+
"pidiff_daemon_startup_timeout_s",
|
|
96
169
|
];
|
|
97
170
|
for (const key of PROJECT_SETTINGS_KEYS) {
|
|
98
171
|
if (!(key in SETTINGS_KEYS)) {
|
|
@@ -100,14 +173,15 @@ for (const key of PROJECT_SETTINGS_KEYS) {
|
|
|
100
173
|
}
|
|
101
174
|
}
|
|
102
175
|
|
|
103
|
-
function getSettingsPath(cwd: string): string {
|
|
104
|
-
|
|
176
|
+
export function getSettingsPath(cwd: string): string {
|
|
177
|
+
const piDir = join(resolveRepoRoot(cwd), ".pi");
|
|
178
|
+
return findSettingsFile(piDir) ?? join(piDir, SETTINGS_FILENAMES[0]);
|
|
105
179
|
}
|
|
106
180
|
|
|
107
|
-
function parseSettingsFile(filePath: string): ProjectSettings {
|
|
181
|
+
export function parseSettingsFile(filePath: string): ProjectSettings {
|
|
108
182
|
if (!existsSync(filePath)) return {};
|
|
109
183
|
try {
|
|
110
|
-
const raw = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
184
|
+
const raw = JSON.parse(stripJsonComments(readFileSync(filePath, "utf-8")));
|
|
111
185
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return {};
|
|
112
186
|
const result: ProjectSettings = {};
|
|
113
187
|
if (typeof raw.commit_trailer === "boolean" || typeof raw.commit_trailer === "string") result.commit_trailer = raw.commit_trailer;
|
|
@@ -160,13 +234,56 @@ function parseSettingsFile(filePath: string): ProjectSettings {
|
|
|
160
234
|
if (typeof val === "object" && val !== null && !Array.isArray(val)) {
|
|
161
235
|
const v = val as { provider?: unknown; model?: unknown };
|
|
162
236
|
const entry: { provider?: string | null; model?: string | null } = {};
|
|
163
|
-
if (v.provider === null
|
|
164
|
-
if (
|
|
237
|
+
if (v.provider === null) entry.provider = null;
|
|
238
|
+
else if (typeof v.provider === "string") entry.provider = v.provider.trim() || undefined;
|
|
239
|
+
if (v.model === null) entry.model = null;
|
|
240
|
+
else if (typeof v.model === "string") entry.model = v.model.trim() || undefined;
|
|
165
241
|
if (entry.provider !== undefined || entry.model !== undefined) overrides[name] = entry;
|
|
166
242
|
}
|
|
167
243
|
}
|
|
168
244
|
if (Object.keys(overrides).length > 0) result.agent_overrides = overrides;
|
|
169
245
|
}
|
|
246
|
+
|
|
247
|
+
// Data-driven parsing for remaining settings — derive from settings-keys.json types
|
|
248
|
+
const SPECIAL_CASE_KEYS = new Set<string>([
|
|
249
|
+
"commit_trailer", "allow_push_to_protected_branches", "use_worktrees",
|
|
250
|
+
"dream_interval_hours", "dco", "comment_signature", "review_loop_enforcement",
|
|
251
|
+
"orchestrator_edit_write_block", "pidash_enable", "pidiff_enable", "pidash_port",
|
|
252
|
+
"image_model", "internal_operations_provider", "internal_operations_model",
|
|
253
|
+
"review_loop_max_cycles", "acpx_agents", "cli_agents", "agent_provider",
|
|
254
|
+
"agent_model", "agent_overrides",
|
|
255
|
+
]);
|
|
256
|
+
for (const [k, def] of Object.entries(SETTINGS_KEYS)) {
|
|
257
|
+
if (SPECIAL_CASE_KEYS.has(k) || k in result) continue;
|
|
258
|
+
if (!(k in raw)) continue;
|
|
259
|
+
const val = raw[k];
|
|
260
|
+
switch (def.type) {
|
|
261
|
+
case "bool":
|
|
262
|
+
if (typeof val === "boolean") (result as any)[k] = val;
|
|
263
|
+
break;
|
|
264
|
+
case "string":
|
|
265
|
+
if (typeof val === "string") (result as any)[k] = val.trim();
|
|
266
|
+
break;
|
|
267
|
+
case "int": {
|
|
268
|
+
if (typeof val === "number" && Number.isInteger(val)) {
|
|
269
|
+
const min = def.min ?? 0;
|
|
270
|
+
const max = def.max ?? Number.MAX_SAFE_INTEGER;
|
|
271
|
+
if (val >= min && val <= max) (result as any)[k] = val;
|
|
272
|
+
}
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
case "port": {
|
|
276
|
+
const min = def.min ?? 0;
|
|
277
|
+
if (typeof val === "number" && Number.isInteger(val) && val >= min && val <= 65535) {
|
|
278
|
+
(result as any)[k] = val;
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
case "number":
|
|
283
|
+
if (typeof val === "number" && Number.isFinite(val)) (result as any)[k] = val;
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
170
287
|
return result;
|
|
171
288
|
} catch (e: any) {
|
|
172
289
|
console.debug(`[project-settings] failed to parse ${filePath}:`, e?.message?.slice(0, 100));
|
|
@@ -174,7 +291,7 @@ function parseSettingsFile(filePath: string): ProjectSettings {
|
|
|
174
291
|
}
|
|
175
292
|
}
|
|
176
293
|
|
|
177
|
-
function loadProjectSettings(cwd: string): ProjectSettings {
|
|
294
|
+
export function loadProjectSettings(cwd: string): ProjectSettings {
|
|
178
295
|
return parseSettingsFile(getSettingsPath(cwd));
|
|
179
296
|
}
|
|
180
297
|
|
|
@@ -187,16 +304,20 @@ export function setGlobalSettingsPath(path: string | null): void {
|
|
|
187
304
|
clearSettingsCache();
|
|
188
305
|
}
|
|
189
306
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return
|
|
307
|
+
/** Resolved global settings file path (honors test override). */
|
|
308
|
+
export function getGlobalSettingsPath(): string {
|
|
309
|
+
return globalSettingsPathOverride ?? findSettingsFile(join(homedir(), ".pi")) ?? join(homedir(), ".pi", SETTINGS_FILENAMES[0]);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function loadGlobalSettings(): ProjectSettings {
|
|
313
|
+
return parseSettingsFile(getGlobalSettingsPath());
|
|
193
314
|
}
|
|
194
315
|
|
|
195
316
|
function projectSettingsFileHasKey(cwd: string, key: string): boolean {
|
|
196
317
|
const filePath = getSettingsPath(cwd);
|
|
197
318
|
if (!existsSync(filePath)) return false;
|
|
198
319
|
try {
|
|
199
|
-
const raw = JSON.parse(readFileSync(filePath, "utf-8"));
|
|
320
|
+
const raw = JSON.parse(stripJsonComments(readFileSync(filePath, "utf-8")));
|
|
200
321
|
return typeof raw === "object" && raw !== null && !Array.isArray(raw) && key in raw;
|
|
201
322
|
} catch (e: any) {
|
|
202
323
|
console.debug(`[project-settings] failed to check key in ${filePath}:`, e?.message?.slice(0, 100));
|
|
@@ -302,7 +423,7 @@ function getSettings(cwd: string): ProjectSettings {
|
|
|
302
423
|
cachedMtime = existsSync(settingsPath) ? statSync(settingsPath).mtimeMs : 0;
|
|
303
424
|
} catch { cachedMtime = 0; }
|
|
304
425
|
try {
|
|
305
|
-
const globalPath =
|
|
426
|
+
const globalPath = getGlobalSettingsPath();
|
|
306
427
|
cachedGlobalMtime = existsSync(globalPath) ? statSync(globalPath).mtimeMs : 0;
|
|
307
428
|
} catch { cachedGlobalMtime = 0; }
|
|
308
429
|
lastMtimeCheck = now;
|
|
@@ -312,7 +433,7 @@ function getSettings(cwd: string): ProjectSettings {
|
|
|
312
433
|
if (now - lastMtimeCheck < MTIME_CHECK_INTERVAL_MS) return cachedSettings;
|
|
313
434
|
lastMtimeCheck = now;
|
|
314
435
|
const settingsPath = getSettingsPath(cwd);
|
|
315
|
-
const globalPath =
|
|
436
|
+
const globalPath = getGlobalSettingsPath();
|
|
316
437
|
let mtime = 0;
|
|
317
438
|
let globalMtime = 0;
|
|
318
439
|
try { if (existsSync(settingsPath)) mtime = statSync(settingsPath).mtimeMs; } catch {}
|
|
@@ -346,6 +467,12 @@ export function getSetting(cwd: string, key: "cli_agents"): string[];
|
|
|
346
467
|
export function getSetting(cwd: string, key: "pidash_enable"): boolean;
|
|
347
468
|
export function getSetting(cwd: string, key: "pidiff_enable"): boolean;
|
|
348
469
|
export function getSetting(cwd: string, key: "pidash_port"): number;
|
|
470
|
+
export function getSetting(cwd: string, key: "task_auto_clear_enabled"): boolean;
|
|
471
|
+
export function getSetting(cwd: string, key: "task_auto_clear_minutes"): number;
|
|
472
|
+
export function getSetting(cwd: string, key: "task_reminder_enabled"): boolean;
|
|
473
|
+
export function getSetting(cwd: string, key: "task_reminder_interval_minutes"): number;
|
|
474
|
+
export function getSetting(cwd: string, key: "task_stale_in_progress_enabled"): boolean;
|
|
475
|
+
export function getSetting(cwd: string, key: "task_stale_in_progress_minutes"): number;
|
|
349
476
|
export function getSetting(cwd: string, key: "image_model"): string;
|
|
350
477
|
export function getSetting(cwd: string, key: "internal_operations_provider"): string;
|
|
351
478
|
export function getSetting(cwd: string, key: "internal_operations_model"): string;
|
|
@@ -353,6 +480,22 @@ export function getSetting(cwd: string, key: "review_loop_max_cycles"): number;
|
|
|
353
480
|
export function getSetting(cwd: string, key: "agent_provider"): string;
|
|
354
481
|
export function getSetting(cwd: string, key: "agent_model"): string;
|
|
355
482
|
export function getSetting(cwd: string, key: "agent_overrides"): Record<string, { provider?: string | null; model?: string | null }>;
|
|
483
|
+
export function getSetting(cwd: string, key: "vertex_claude_1m"): boolean;
|
|
484
|
+
export function getSetting(cwd: string, key: "sidecar_log_level"): string;
|
|
485
|
+
export function getSetting(cwd: string, key: "enforcement_allowed_commands"): string;
|
|
486
|
+
export function getSetting(cwd: string, key: "enforcement_loop_sleep_threshold_s"): number;
|
|
487
|
+
export function getSetting(cwd: string, key: "enforcement_sleep_threshold_s"): number;
|
|
488
|
+
export function getSetting(cwd: string, key: "sync_agent_max_seconds"): number;
|
|
489
|
+
export function getSetting(cwd: string, key: "async_poll_interval_ms"): number;
|
|
490
|
+
export function getSetting(cwd: string, key: "async_phantom_timeout_ms"): number;
|
|
491
|
+
export function getSetting(cwd: string, key: "coms_max_hops"): number;
|
|
492
|
+
export function getSetting(cwd: string, key: "coms_timeout_ms"): number;
|
|
493
|
+
export function getSetting(cwd: string, key: "coms_dir"): string;
|
|
494
|
+
export function getSetting(cwd: string, key: "coms_task_heartbeat_ms"): number;
|
|
495
|
+
export function getSetting(cwd: string, key: "coms_entry_grace_period_ms"): number;
|
|
496
|
+
export function getSetting(cwd: string, key: "coms_probe_timeout_ms"): number;
|
|
497
|
+
export function getSetting(cwd: string, key: "pidiff_stale_lock_timeout_ms"): number;
|
|
498
|
+
export function getSetting(cwd: string, key: "pidiff_daemon_startup_timeout_s"): number;
|
|
356
499
|
export function getSetting(cwd: string, key: string): boolean | string | number | string[] | Record<string, { provider?: string | null; model?: string | null }> {
|
|
357
500
|
const settings = getSettings(cwd);
|
|
358
501
|
const def = SETTINGS_KEYS[key];
|
|
@@ -442,6 +585,39 @@ export function getSetting(cwd: string, key: string): boolean | string | number
|
|
|
442
585
|
}
|
|
443
586
|
return def.default as boolean;
|
|
444
587
|
}
|
|
588
|
+
case "int": {
|
|
589
|
+
if (merged !== undefined) return merged as number;
|
|
590
|
+
if (def.env) {
|
|
591
|
+
const val = process.env[def.env];
|
|
592
|
+
if (val !== undefined && val !== "") {
|
|
593
|
+
const trimmed = val.trim();
|
|
594
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
595
|
+
const n = Number(trimmed);
|
|
596
|
+
const min = def.min ?? 0;
|
|
597
|
+
const max = def.max ?? Number.MAX_SAFE_INTEGER;
|
|
598
|
+
if (n >= min && n <= max) return n;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return def.default as number;
|
|
603
|
+
}
|
|
604
|
+
case "port": {
|
|
605
|
+
if (merged !== undefined) {
|
|
606
|
+
const n = merged as number;
|
|
607
|
+
if (Number.isInteger(n) && n >= 0 && n <= 65535) return n;
|
|
608
|
+
}
|
|
609
|
+
if (def.env) {
|
|
610
|
+
const val = process.env[def.env];
|
|
611
|
+
if (val !== undefined && val !== "") {
|
|
612
|
+
const trimmed = val.trim();
|
|
613
|
+
if (/^\d+$/.test(trimmed)) {
|
|
614
|
+
const n = Number(trimmed);
|
|
615
|
+
if (n >= 0 && n <= 65535) return n;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
return def.default as number;
|
|
620
|
+
}
|
|
445
621
|
case "number": {
|
|
446
622
|
if (merged !== undefined) return merged as number;
|
|
447
623
|
if (def.env) {
|
|
@@ -451,7 +627,8 @@ export function getSetting(cwd: string, key: string): boolean | string | number
|
|
|
451
627
|
return def.default as number;
|
|
452
628
|
}
|
|
453
629
|
case "string": {
|
|
454
|
-
|
|
630
|
+
// Preserve empty strings — some settings use empty as meaningful ("allow all", "use default dir")
|
|
631
|
+
if (merged !== undefined) return merged as string;
|
|
455
632
|
if (def.env) {
|
|
456
633
|
const env = process.env[def.env];
|
|
457
634
|
if (env !== undefined && env !== "") return env.trim();
|
|
@@ -471,5 +648,27 @@ export function registerProjectSettings(pi: ExtensionAPI): void {
|
|
|
471
648
|
|
|
472
649
|
pi.on("session_start", (_event, ctx) => {
|
|
473
650
|
clearSettingsCache();
|
|
651
|
+
|
|
652
|
+
// Inject settings into process.env for standalone packages that can't call getSetting
|
|
653
|
+
const cwd = ctx.cwd;
|
|
654
|
+
const vertexClaude1m = getSetting(cwd, "vertex_claude_1m");
|
|
655
|
+
if (vertexClaude1m) process.env.VERTEX_CLAUDE_1M = "true";
|
|
656
|
+
else delete process.env.VERTEX_CLAUDE_1M;
|
|
657
|
+
|
|
658
|
+
const sidecarLogLevel = getSetting(cwd, "sidecar_log_level");
|
|
659
|
+
if (sidecarLogLevel) process.env.PI_SIDECAR_LOG_LEVEL = sidecarLogLevel;
|
|
660
|
+
else delete process.env.PI_SIDECAR_LOG_LEVEL;
|
|
661
|
+
|
|
662
|
+
const acpxAgents = getSetting(cwd, "acpx_agents");
|
|
663
|
+
if (acpxAgents.length > 0) process.env.ACPX_AGENTS = acpxAgents.join(",");
|
|
664
|
+
else delete process.env.ACPX_AGENTS;
|
|
665
|
+
|
|
666
|
+
const cliAgents = getSetting(cwd, "cli_agents");
|
|
667
|
+
if (cliAgents.length > 0) process.env.CLI_AGENTS = cliAgents.join(",");
|
|
668
|
+
else delete process.env.CLI_AGENTS;
|
|
669
|
+
|
|
670
|
+
const imageModel = getSetting(cwd, "image_model");
|
|
671
|
+
if (imageModel) process.env.PI_IMAGE_MODEL = imageModel;
|
|
672
|
+
else delete process.env.PI_IMAGE_MODEL;
|
|
474
673
|
});
|
|
475
674
|
}
|
|
@@ -12,7 +12,9 @@ import { onStateTransition, readReviewState, markNeedsReview, resetReviewState,
|
|
|
12
12
|
import { ICON_REVIEW_CLEAN, ICON_REVIEW_NEEDED, ICON_REVIEW_PROGRESS, ICON_REVIEW_FINDINGS } from "./icons.js";
|
|
13
13
|
import { getSetting } from "./project-settings.js";
|
|
14
14
|
import { setSlot, clearSlot } from "./status-bar.js";
|
|
15
|
-
import { runGit } from "./git-helpers.js";
|
|
15
|
+
import { runGit, getCurrentBranch } from "./git-helpers.js";
|
|
16
|
+
import { isBumpVersionBranch, getCachedBranch } from "./enforcement.js";
|
|
17
|
+
import { normalizePorcelain } from "./review-porcelain.js";
|
|
16
18
|
|
|
17
19
|
interface ReviewStatusData {
|
|
18
20
|
status: ReviewState["status"];
|
|
@@ -34,6 +36,8 @@ function stateKey(s: { status: string; cycle: number; findings_count: number; te
|
|
|
34
36
|
return `${s.status}:${s.cycle}:${s.findings_count}:${s.tests_passed}:${s.reviewers_pending.length}`;
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
export { normalizePorcelain } from "./review-porcelain.js";
|
|
40
|
+
|
|
37
41
|
export function registerReviewUI(pi: ExtensionAPI): void {
|
|
38
42
|
// Register the entry renderer for "review-status" custom type
|
|
39
43
|
pi.registerEntryRenderer<ReviewStatusData>("review-status", (entry, { expanded }, theme) => {
|
|
@@ -147,9 +151,9 @@ export function registerReviewUI(pi: ExtensionAPI): void {
|
|
|
147
151
|
pi.on("session_start", (_event, ctx) => {
|
|
148
152
|
lastCtx = ctx;
|
|
149
153
|
// Initialize git snapshot for dirty detection
|
|
150
|
-
lastGitSnapshot = runGit(["status", "--porcelain"], ctx.cwd).stdout;
|
|
154
|
+
lastGitSnapshot = normalizePorcelain(runGit(["status", "--porcelain"], ctx.cwd).stdout);
|
|
151
155
|
// If tree is already dirty on session start, ensure review state reflects it
|
|
152
|
-
if (lastGitSnapshot && getSetting(ctx.cwd, "review_loop_enforcement")) {
|
|
156
|
+
if (lastGitSnapshot && getSetting(ctx.cwd, "review_loop_enforcement") && !isBumpVersionBranch(getCurrentBranch(ctx.cwd))) {
|
|
153
157
|
const state = readReviewState(ctx.cwd);
|
|
154
158
|
if (state.status === "none" || state.status === "clean") {
|
|
155
159
|
try { markNeedsReview(ctx.cwd); } catch (e: any) { console.debug("[review-ui] markNeedsReview failed:", e?.message); }
|
|
@@ -164,7 +168,7 @@ export function registerReviewUI(pi: ExtensionAPI): void {
|
|
|
164
168
|
});
|
|
165
169
|
pi.on("agent_end", (_event, ctx) => { lastCtx = ctx; });
|
|
166
170
|
|
|
167
|
-
// Poll pi-config-review-state.
|
|
171
|
+
// Poll pi-config-review-state.jsonl for cross-process updates (subagents write state too)
|
|
168
172
|
const reviewPoller = setInterval(() => {
|
|
169
173
|
if (!lastCtx) return;
|
|
170
174
|
// Access a ctx property to detect stale/disposed context (throws if invalidated)
|
|
@@ -188,8 +192,10 @@ export function registerReviewUI(pi: ExtensionAPI): void {
|
|
|
188
192
|
try { void lastCtx.ui.theme; } catch { lastCtx = null; return; }
|
|
189
193
|
try {
|
|
190
194
|
if (!getSetting(lastCtx.cwd, "review_loop_enforcement")) return;
|
|
195
|
+
// Skip on version bump branches (release workflow only)
|
|
196
|
+
if (isBumpVersionBranch(getCachedBranch(lastCtx.cwd))) return;
|
|
191
197
|
const result = runGit(["status", "--porcelain"], lastCtx.cwd);
|
|
192
|
-
const snapshot = result.stdout;
|
|
198
|
+
const snapshot = normalizePorcelain(result.stdout);
|
|
193
199
|
if (snapshot === lastGitSnapshot) return;
|
|
194
200
|
lastGitSnapshot = snapshot;
|
|
195
201
|
if (snapshot) {
|