@event4u/agent-config 8.4.0 → 8.4.1
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/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
- package/dist/discovery/deprecation-report.md +1 -1
- package/dist/discovery/discovery-manifest.json +1 -1
- package/dist/discovery/discovery-manifest.json.sha256 +1 -1
- package/dist/discovery/discovery-manifest.summary.md +1 -1
- package/dist/discovery/orphan-report.md +1 -1
- package/dist/discovery/packs.json +1 -1
- package/dist/discovery/trust-report.md +1 -1
- package/dist/discovery/workspaces.json +1 -1
- package/dist/mcp/registry-manifest.json +1 -1
- package/package.json +4 -1
- package/src/agent-src/README.md +64 -0
- package/src/agent-src/scripts/archive_completed_roadmaps.ts +497 -0
- package/src/agent-src/scripts/scan-seeder-violations.php +145 -0
- package/src/agent-src/scripts/update_roadmap_progress.ts +1087 -0
- package/src/agent-src/templates/AGENTS.md +34 -0
- package/src/agent-src/templates/scripts/README.md +195 -0
- package/src/agent-src/templates/scripts/check_memory.ts +662 -0
- package/src/agent-src/templates/scripts/check_memory_proposal.ts +370 -0
- package/src/agent-src/templates/scripts/historical-bug-patterns.example.yml +84 -0
- package/src/agent-src/templates/scripts/implement_ticket/__main__.ts +27 -0
- package/src/agent-src/templates/scripts/memory_hash.ts +355 -0
- package/src/agent-src/templates/scripts/memory_lookup.ts +1089 -0
- package/src/agent-src/templates/scripts/memory_report.ts +868 -0
- package/src/agent-src/templates/scripts/memory_signal.ts +444 -0
- package/src/agent-src/templates/scripts/memory_status.ts +215 -0
- package/src/agent-src/templates/scripts/ownership-map.example.yml +87 -0
- package/src/agent-src/templates/scripts/pr-risk-config.example.yml +76 -0
- package/src/agent-src/templates/scripts/pr_review_routing.ts +544 -0
- package/src/agent-src/templates/scripts/pr_risk_review.ts +0 -0
- package/src/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
- package/src/agent-src/templates/scripts/telemetry/boundary.ts +164 -0
- package/src/agent-src/templates/scripts/telemetry/engagement.ts +479 -0
- package/src/agent-src/templates/scripts/telemetry/report_renderer.ts +394 -0
- package/src/agent-src/templates/scripts/telemetry/settings.ts +210 -0
- package/src/agent-src/templates/scripts/telemetry_record.ts +276 -0
- package/src/agent-src/templates/scripts/telemetry_report.ts +211 -0
- package/src/agent-src/templates/scripts/telemetry_status.ts +333 -0
- package/src/agent-src/templates/scripts/tier_usage_report.ts +619 -0
- package/src/agent-src/templates/scripts/work_engine/__main__.ts +14 -0
- package/src/agent-src/templates/scripts/work_engine/_lib/agent_settings.ts +1261 -0
- package/src/agent-src/templates/scripts/work_engine/_lib/user_global_paths.ts +329 -0
- package/src/agent-src/templates/scripts/work_engine/cli.ts +206 -0
- package/src/agent-src/templates/scripts/work_engine/cli_args.ts +249 -0
- package/src/agent-src/templates/scripts/work_engine/delivery_state.ts +225 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/analyze.ts +125 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/implement.ts +189 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/index.ts +94 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/memory.ts +193 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/plan.ts +267 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/refine.ts +518 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/report.ts +379 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/test.ts +268 -0
- package/src/agent-src/templates/scripts/work_engine/directives/backend/verify.ts +258 -0
- package/src/agent-src/templates/scripts/work_engine/directives/index.ts +32 -0
- package/src/agent-src/templates/scripts/work_engine/directives/mixed/contract.ts +243 -0
- package/src/agent-src/templates/scripts/work_engine/directives/mixed/index.ts +108 -0
- package/src/agent-src/templates/scripts/work_engine/directives/mixed/stitch.ts +259 -0
- package/src/agent-src/templates/scripts/work_engine/directives/mixed/ui.ts +216 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/_passthrough.ts +40 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/app_spec.ts +241 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/apply.ts +216 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/audit.ts +506 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/design.ts +325 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/index.ts +102 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +462 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/review.ts +474 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui/scaffold.ts +352 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/_skipped.ts +33 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/apply.ts +213 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/index.ts +111 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/refine.ts +126 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/report.ts +112 -0
- package/src/agent-src/templates/scripts/work_engine/directives/ui_trivial/test.ts +164 -0
- package/src/agent-src/templates/scripts/work_engine/dispatcher.ts +515 -0
- package/src/agent-src/templates/scripts/work_engine/emitters.ts +119 -0
- package/src/agent-src/templates/scripts/work_engine/errors.ts +24 -0
- package/src/agent-src/templates/scripts/work_engine/hook_bootstrap.ts +104 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.ts +189 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.ts +41 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.ts +89 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/decision_gate.ts +193 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.ts +304 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/directive_set_guard.ts +110 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/halt_surface_audit.ts +118 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/index.ts +17 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.ts +161 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/state_shape_validation.ts +45 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/builtin/trace.ts +134 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/context.ts +94 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/events.ts +58 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/exceptions.ts +85 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/index.ts +27 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/registry.ts +66 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/runner.ts +90 -0
- package/src/agent-src/templates/scripts/work_engine/hooks/settings.ts +260 -0
- package/src/agent-src/templates/scripts/work_engine/input_builders.ts +260 -0
- package/src/agent-src/templates/scripts/work_engine/intent/classify.ts +466 -0
- package/src/agent-src/templates/scripts/work_engine/migration/v0_to_v1.ts +531 -0
- package/src/agent-src/templates/scripts/work_engine/orchestration.ts +366 -0
- package/src/agent-src/templates/scripts/work_engine/persona_policy.ts +97 -0
- package/src/agent-src/templates/scripts/work_engine/resolvers/diff.ts +135 -0
- package/src/agent-src/templates/scripts/work_engine/resolvers/file.ts +175 -0
- package/src/agent-src/templates/scripts/work_engine/resolvers/prompt.ts +115 -0
- package/src/agent-src/templates/scripts/work_engine/scoring/confidence.ts +415 -0
- package/src/agent-src/templates/scripts/work_engine/scoring/decision_engine.ts +466 -0
- package/src/agent-src/templates/scripts/work_engine/scoring/decision_trace.ts +298 -0
- package/src/agent-src/templates/scripts/work_engine/scoring/memory_visibility.ts +444 -0
- package/src/agent-src/templates/scripts/work_engine/stack/detect.ts +252 -0
- package/src/agent-src/templates/scripts/work_engine/stack/runner.ts +745 -0
- package/src/agent-src/templates/scripts/work_engine/state.ts +1151 -0
- package/src/agent-src/templates/scripts/work_engine/state_io.ts +413 -0
- package/src/install/atomic.ts +111 -0
- package/src/install/conflict.ts +226 -0
- package/src/install/detect.ts +280 -0
- package/src/install/paths.ts +90 -0
- package/src/install/plan.ts +205 -0
- package/src/install/preflight.ts +210 -0
- package/src/install/selectedTools.ts +52 -0
- package/src/install/toolDetection.ts +120 -0
- package/src/install/txlog.ts +161 -0
- package/src/install/types.ts +175 -0
- package/src/install/wizard-plan.ts +216 -0
- package/src/scripts/prepack-check.mjs +108 -5
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conflict resolution — Phase A5 (simplified, three modes).
|
|
3
|
+
*
|
|
4
|
+
* Three decisions only, replacing the legacy `prompt → write / skip /
|
|
5
|
+
* abort` triple from `scripts/install.py:_resolve_file_conflict`:
|
|
6
|
+
*
|
|
7
|
+
* - `write` — target either does not exist OR policy authorises overwrite.
|
|
8
|
+
* - `skip` — target exists, known path, not forced: leave it alone.
|
|
9
|
+
* - `surface` — foreign collision: defer to the wizard's conflict screen
|
|
10
|
+
* (Phase B3). Headless callers translate `surface` to `skip`
|
|
11
|
+
* unless `policy.force` is true.
|
|
12
|
+
*
|
|
13
|
+
* JSON-aware deep-merge stays: callers that detect a `.json` target with
|
|
14
|
+
* matching `knownPointers` route through {@link mergeJsonContent} instead
|
|
15
|
+
* of byte-equality.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { existsSync } from 'node:fs';
|
|
19
|
+
|
|
20
|
+
import { sha256File } from './plan.js';
|
|
21
|
+
import type {
|
|
22
|
+
ConflictEntry,
|
|
23
|
+
ConflictPolicy,
|
|
24
|
+
ConflictResolution,
|
|
25
|
+
FileEntry,
|
|
26
|
+
InstallPlan,
|
|
27
|
+
} from './types.js';
|
|
28
|
+
|
|
29
|
+
/** Outcome of {@link resolveFileConflict}. */
|
|
30
|
+
export type ConflictOutcome = 'write' | 'skip' | 'surface';
|
|
31
|
+
|
|
32
|
+
/** Inputs the resolver needs — purely the target + the active policy. */
|
|
33
|
+
export interface ResolveInputs {
|
|
34
|
+
/** Absolute path of the target on disk. */
|
|
35
|
+
readonly targetPath: string;
|
|
36
|
+
/** True when the byte-comparison says the target matches the plan. */
|
|
37
|
+
readonly idempotent: boolean;
|
|
38
|
+
/** True when the target already exists on disk. */
|
|
39
|
+
readonly exists: boolean;
|
|
40
|
+
/** Active install policy. */
|
|
41
|
+
readonly policy: ConflictPolicy;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Decide what to do with a single planned target.
|
|
46
|
+
*
|
|
47
|
+
* Decision matrix (mirrors the Python legacy with the 3-option prompt
|
|
48
|
+
* collapsed into `surface`):
|
|
49
|
+
*
|
|
50
|
+
* | Exists? | Idempotent? | Known? | Force? | → Outcome |
|
|
51
|
+
* |---------|-------------|--------|--------|------------|
|
|
52
|
+
* | no | — | — | — | `write` |
|
|
53
|
+
* | yes | yes | — | — | `skip` |
|
|
54
|
+
* | yes | no | yes | no | `skip` |
|
|
55
|
+
* | yes | no | yes | yes | `write` |
|
|
56
|
+
* | yes | no | no | yes | `write` |
|
|
57
|
+
* | yes | no | no | no | `surface` |
|
|
58
|
+
*
|
|
59
|
+
* Headless callers (B1 CLI) collapse `surface` to `skip` automatically
|
|
60
|
+
* because there is no UI to defer to; the apply layer records the entry
|
|
61
|
+
* under {@link ApplyResult.conflicts} so the wizard can pick it up next.
|
|
62
|
+
*/
|
|
63
|
+
export function resolveFileConflict(inputs: ResolveInputs): ConflictOutcome {
|
|
64
|
+
const { targetPath, idempotent, exists, policy } = inputs;
|
|
65
|
+
if (!exists) return 'write';
|
|
66
|
+
if (idempotent) return 'skip';
|
|
67
|
+
|
|
68
|
+
const isKnown = policy.knownPaths.has(targetPath);
|
|
69
|
+
if (isKnown) {
|
|
70
|
+
return policy.force ? 'write' : 'skip';
|
|
71
|
+
}
|
|
72
|
+
if (policy.force) return 'write';
|
|
73
|
+
return 'surface';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** JSON value the deep-merge accepts. */
|
|
77
|
+
export type JsonValue = null | boolean | number | string | JsonArray | JsonObject;
|
|
78
|
+
export interface JsonObject {
|
|
79
|
+
readonly [key: string]: JsonValue;
|
|
80
|
+
}
|
|
81
|
+
export type JsonArray = ReadonlyArray<JsonValue>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Recursive object merge — overlay wins, nested dicts merged, arrays replaced.
|
|
85
|
+
*
|
|
86
|
+
* Mirrors `scripts/install.py:deep_merge`. Arrays do **not** concatenate;
|
|
87
|
+
* Claude / Cursor / Cline hook configs rely on whole-array replacement to
|
|
88
|
+
* stay idempotent across re-runs.
|
|
89
|
+
*
|
|
90
|
+
* Returns a fresh object — both inputs remain untouched.
|
|
91
|
+
*/
|
|
92
|
+
export function deepMerge(base: JsonObject, overlay: JsonObject): JsonObject {
|
|
93
|
+
const out: Record<string, JsonValue> = { ...base };
|
|
94
|
+
for (const [key, value] of Object.entries(overlay)) {
|
|
95
|
+
const prev = out[key];
|
|
96
|
+
if (isPlainObject(prev) && isPlainObject(value)) {
|
|
97
|
+
out[key] = deepMerge(prev, value);
|
|
98
|
+
} else {
|
|
99
|
+
out[key] = cloneValue(value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Merge `overlay` into `existing` and return the canonical 4-space JSON.
|
|
107
|
+
*
|
|
108
|
+
* Format matches `write_json_file` in the Python installer (4-space indent,
|
|
109
|
+
* trailing newline, no ASCII-escape) so the apply layer can compare bytes
|
|
110
|
+
* to detect idempotent merges and skip the write.
|
|
111
|
+
*/
|
|
112
|
+
export function mergeJsonContent(existing: JsonObject, overlay: JsonObject): string {
|
|
113
|
+
const merged = deepMerge(existing, overlay);
|
|
114
|
+
return `${JSON.stringify(merged, null, 4)}\n`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Parse JSON bytes leniently — invalid / non-object payloads collapse to `{}`.
|
|
119
|
+
*
|
|
120
|
+
* Matches `read_json_file` in the legacy script: corrupt JSON is treated
|
|
121
|
+
* as an empty doc rather than a hard failure, so the merge step always
|
|
122
|
+
* produces a well-formed output even when an upstream tool wrote a
|
|
123
|
+
* truncated config.
|
|
124
|
+
*/
|
|
125
|
+
export function parseJsonLenient(content: string): JsonObject {
|
|
126
|
+
try {
|
|
127
|
+
const parsed = JSON.parse(content) as unknown;
|
|
128
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
129
|
+
return parsed as JsonObject;
|
|
130
|
+
}
|
|
131
|
+
} catch {
|
|
132
|
+
/* fall through — treat as empty */
|
|
133
|
+
}
|
|
134
|
+
return {};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Heuristic for routing a {@link FileEntry} through JSON merge. */
|
|
138
|
+
export function isJsonTarget(entry: FileEntry): boolean {
|
|
139
|
+
return entry.kind === 'deployed' && entry.path.endsWith('.json');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Threshold at which the wizard switches the conflict screen from
|
|
144
|
+
* single-pick to batch-resolution mode (council Finding #19).
|
|
145
|
+
*
|
|
146
|
+
* Below the threshold the user picks a resolution per row; at or above
|
|
147
|
+
* it the screen renders a summary table + global CTAs to dodge the
|
|
148
|
+
* 50-click stale-tree problem.
|
|
149
|
+
*/
|
|
150
|
+
export const CONFLICT_BATCH_THRESHOLD = 5;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Walk an {@link InstallPlan} and return one {@link ConflictEntry} per
|
|
154
|
+
* planned target the policy would `surface` to the UI.
|
|
155
|
+
*
|
|
156
|
+
* Pure-ish — reads from the filesystem only to compute idempotency
|
|
157
|
+
* (`existsSync` + `sha256File`). Skips bridges (`sha256 === null`) since
|
|
158
|
+
* bridge writers own a separate idempotency model. Skips entries whose
|
|
159
|
+
* `path` is in `policy.knownPaths`, and skips entries that are
|
|
160
|
+
* byte-equal to the planned content. Returns an empty array when
|
|
161
|
+
* `policy.force` is true — overwrite mode silences the screen.
|
|
162
|
+
*/
|
|
163
|
+
export function computeConflicts(plan: InstallPlan): readonly ConflictEntry[] {
|
|
164
|
+
if (plan.policy.force) return [];
|
|
165
|
+
const out: ConflictEntry[] = [];
|
|
166
|
+
for (const entries of Object.values(plan.filesByTool)) {
|
|
167
|
+
for (const entry of entries) {
|
|
168
|
+
if (entry.kind === 'bridge') continue;
|
|
169
|
+
if (entry.sha256 === null) continue;
|
|
170
|
+
if (!existsSync(entry.path)) continue;
|
|
171
|
+
if (plan.policy.knownPaths.has(entry.path)) continue;
|
|
172
|
+
const onDisk = sha256File(entry.path);
|
|
173
|
+
if (onDisk === entry.sha256) continue;
|
|
174
|
+
out.push({
|
|
175
|
+
path: entry.path,
|
|
176
|
+
kind: entry.kind,
|
|
177
|
+
plannedSha256: entry.sha256,
|
|
178
|
+
existingSha256: onDisk,
|
|
179
|
+
mergeable: isJsonTarget(entry),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Expand a batch choice into a per-path {@link ConflictResolution} map.
|
|
188
|
+
*
|
|
189
|
+
* The wizard sends either `resolutions` directly (single-pick mode) or
|
|
190
|
+
* a `batchChoice` (≥ 5 conflicts) that the server fans out across every
|
|
191
|
+
* surfaced entry. `merge-json` maps non-JSON entries to `skip` since
|
|
192
|
+
* deep-merge is JSON-only — the council picked skip over overwrite so a
|
|
193
|
+
* single non-JSON file in a batch never silently overwrites.
|
|
194
|
+
*/
|
|
195
|
+
export function expandBatchChoice(
|
|
196
|
+
conflicts: ReadonlyArray<ConflictEntry>,
|
|
197
|
+
choice: 'skip-all' | 'overwrite-all' | 'merge-json',
|
|
198
|
+
): Record<string, ConflictResolution> {
|
|
199
|
+
const out: Record<string, ConflictResolution> = {};
|
|
200
|
+
for (const c of conflicts) {
|
|
201
|
+
if (choice === 'skip-all') {
|
|
202
|
+
out[c.path] = 'skip';
|
|
203
|
+
} else if (choice === 'overwrite-all') {
|
|
204
|
+
out[c.path] = 'overwrite';
|
|
205
|
+
} else {
|
|
206
|
+
out[c.path] = c.mergeable ? 'merge' : 'skip';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function isPlainObject(v: unknown): v is JsonObject {
|
|
213
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function cloneValue(v: JsonValue): JsonValue {
|
|
217
|
+
if (Array.isArray(v)) {
|
|
218
|
+
return v.map(cloneValue);
|
|
219
|
+
}
|
|
220
|
+
if (isPlainObject(v)) {
|
|
221
|
+
const out: Record<string, JsonValue> = {};
|
|
222
|
+
for (const [k, val] of Object.entries(v)) out[k] = cloneValue(val);
|
|
223
|
+
return out;
|
|
224
|
+
}
|
|
225
|
+
return v;
|
|
226
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detection layer — Phase A2 port of `scripts/install.py:detect_*`.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions only: read once, return a plan. No side effects in
|
|
5
|
+
* the detection itself — atomic writes and conflict resolution happen
|
|
6
|
+
* in later phases against the data this module returns.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors:
|
|
9
|
+
* - `SCOPE_DETECT_MANIFESTS` → {@link SCOPE_DETECT_MANIFESTS}
|
|
10
|
+
* - `SCOPE_DETECT_AI_DIRS` → {@link SCOPE_DETECT_AI_DIRS}
|
|
11
|
+
* - `SCOPE_DETECT_AI_FILES` → {@link SCOPE_DETECT_AI_FILES}
|
|
12
|
+
* - `detect_scope(cwd)` → {@link detectScope}
|
|
13
|
+
* - `detect_package_root(project_root)` → {@link detectPackageRoot}
|
|
14
|
+
* - `detect_package_type(...)` → {@link detectPackageType}
|
|
15
|
+
*
|
|
16
|
+
* v4 addition (no Python counterpart): {@link discoverPacks} walks the
|
|
17
|
+
* monorepo `packages/` tree to enumerate available packs.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
21
|
+
import { homedir } from 'node:os';
|
|
22
|
+
import { join, resolve } from 'node:path';
|
|
23
|
+
|
|
24
|
+
import type { InstallTarget } from './types.js';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Settings-file name used as the strongest project-scope signal.
|
|
28
|
+
*
|
|
29
|
+
* Matches `SETTINGS_FILE` in `scripts/install.py`. Presence in `cwd`
|
|
30
|
+
* short-circuits scope detection to `'project'` without consulting
|
|
31
|
+
* the manifest / AI-tool lists.
|
|
32
|
+
*/
|
|
33
|
+
export const SETTINGS_FILE = '.agent-settings.yml';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Manifest files that, when present, count as a project-shape signal.
|
|
37
|
+
*
|
|
38
|
+
* Listed in the order they are most commonly canonical; detection
|
|
39
|
+
* short-circuits on the first hit. `.git/` is intentionally absent —
|
|
40
|
+
* monorepos, dotfile-git repos, and non-Git workspaces all break it
|
|
41
|
+
* (ADR-007 D2).
|
|
42
|
+
*/
|
|
43
|
+
export const SCOPE_DETECT_MANIFESTS: readonly string[] = [
|
|
44
|
+
'package.json',
|
|
45
|
+
'composer.json',
|
|
46
|
+
'pyproject.toml',
|
|
47
|
+
'Cargo.toml',
|
|
48
|
+
'go.mod',
|
|
49
|
+
'Gemfile',
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** Project-local AI-tool config directories that count as a presence signal. */
|
|
53
|
+
export const SCOPE_DETECT_AI_DIRS: readonly string[] = [
|
|
54
|
+
'.claude',
|
|
55
|
+
'.cursor',
|
|
56
|
+
'.windsurf',
|
|
57
|
+
'.augment',
|
|
58
|
+
'.clinerules',
|
|
59
|
+
'.copilot',
|
|
60
|
+
'.gemini',
|
|
61
|
+
'.codex',
|
|
62
|
+
'.aider',
|
|
63
|
+
'.continue',
|
|
64
|
+
'.roo',
|
|
65
|
+
'.kilocode',
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
/** Project-local AI-tool config files that count as a presence signal. */
|
|
69
|
+
export const SCOPE_DETECT_AI_FILES: readonly string[] = [
|
|
70
|
+
'CLAUDE.md',
|
|
71
|
+
'AGENTS.md',
|
|
72
|
+
'GEMINI.md',
|
|
73
|
+
'.windsurfrules',
|
|
74
|
+
'.aider.conf.yml',
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Scope detection outcome.
|
|
79
|
+
*
|
|
80
|
+
* - `project` — install into `cwd` (existing `.agent-settings.yml`).
|
|
81
|
+
* - `prompt` — caller MUST resolve the ambiguity (manifest + AI marker).
|
|
82
|
+
* - `global` — install to user-scope paths (default).
|
|
83
|
+
*/
|
|
84
|
+
export type Scope = 'project' | 'prompt' | 'global';
|
|
85
|
+
|
|
86
|
+
/** Reason string carried alongside a {@link Scope} for UI / log surfaces. */
|
|
87
|
+
export interface ScopeDecision {
|
|
88
|
+
readonly scope: Scope;
|
|
89
|
+
readonly reason: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Multi-signal scope detection (ADR-007 D2 / Phase 1.3).
|
|
94
|
+
*
|
|
95
|
+
* 1:1 port of `scripts/install.py:detect_scope`. Pure — no side effects.
|
|
96
|
+
*/
|
|
97
|
+
export function detectScope(cwd: string): ScopeDecision {
|
|
98
|
+
if (existsSync(join(cwd, SETTINGS_FILE))) {
|
|
99
|
+
return { scope: 'project', reason: `existing ${SETTINGS_FILE}` };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const manifest = SCOPE_DETECT_MANIFESTS.find((m) => existsSync(join(cwd, m)));
|
|
103
|
+
const aiDir = SCOPE_DETECT_AI_DIRS.find((d) => isDir(join(cwd, d)));
|
|
104
|
+
const aiFile = SCOPE_DETECT_AI_FILES.find((f) => existsSync(join(cwd, f)));
|
|
105
|
+
|
|
106
|
+
if (manifest !== undefined && (aiDir !== undefined || aiFile !== undefined)) {
|
|
107
|
+
const marker = aiDir ?? aiFile;
|
|
108
|
+
return {
|
|
109
|
+
scope: 'prompt',
|
|
110
|
+
reason: `manifest (${manifest}) + AI-tool config (${marker ?? ''})`,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return { scope: 'global', reason: 'no project-scope signals' };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Map a {@link Scope} to the {@link InstallTarget} consumed by plan builder.
|
|
119
|
+
*
|
|
120
|
+
* `prompt` is treated as ambiguous — caller resolves via CLI flag or UI.
|
|
121
|
+
* Defaulting `prompt` to `global` here would silently swallow the signal.
|
|
122
|
+
*/
|
|
123
|
+
export function scopeToTarget(scope: Scope): InstallTarget | null {
|
|
124
|
+
if (scope === 'project') return 'project';
|
|
125
|
+
if (scope === 'global') return 'global';
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Project shape inferred from manifest presence. */
|
|
130
|
+
export interface ProjectShape {
|
|
131
|
+
readonly kind: 'composer' | 'npm' | 'cargo' | 'pyproject' | 'go' | 'ruby' | 'unknown';
|
|
132
|
+
readonly root: string;
|
|
133
|
+
readonly manifest: string | null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Detect project shape from manifest markers — pure read of cwd.
|
|
138
|
+
*
|
|
139
|
+
* Manifest-to-kind mapping mirrors {@link SCOPE_DETECT_MANIFESTS}:
|
|
140
|
+
* `package.json` → npm, `composer.json` → composer, etc.
|
|
141
|
+
*/
|
|
142
|
+
export function detectProjectShape(root: string): ProjectShape {
|
|
143
|
+
const manifest = SCOPE_DETECT_MANIFESTS.find((m) => existsSync(join(root, m)));
|
|
144
|
+
if (manifest === undefined) {
|
|
145
|
+
return { kind: 'unknown', root, manifest: null };
|
|
146
|
+
}
|
|
147
|
+
const kind = ({
|
|
148
|
+
'package.json': 'npm',
|
|
149
|
+
'composer.json': 'composer',
|
|
150
|
+
'pyproject.toml': 'pyproject',
|
|
151
|
+
'Cargo.toml': 'cargo',
|
|
152
|
+
'go.mod': 'go',
|
|
153
|
+
Gemfile: 'ruby',
|
|
154
|
+
} as const)[manifest] ?? 'unknown';
|
|
155
|
+
return { kind, root, manifest };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** AI-tool presence flags discovered in a project tree. */
|
|
159
|
+
export interface ToolPresence {
|
|
160
|
+
readonly augment: boolean;
|
|
161
|
+
readonly claude: boolean;
|
|
162
|
+
readonly cursor: boolean;
|
|
163
|
+
readonly cline: boolean;
|
|
164
|
+
readonly windsurf: boolean;
|
|
165
|
+
readonly agentsMd: boolean;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Read AI-tool presence flags from `root`. Pure — no writes. */
|
|
169
|
+
export function detectToolPresence(root: string): ToolPresence {
|
|
170
|
+
return {
|
|
171
|
+
augment: isDir(join(root, '.augment')),
|
|
172
|
+
claude: isDir(join(root, '.claude')),
|
|
173
|
+
cursor: isDir(join(root, '.cursor')),
|
|
174
|
+
cline: isDir(join(root, '.clinerules')),
|
|
175
|
+
windsurf: isDir(join(root, '.windsurf')) || existsSync(join(root, '.windsurfrules')),
|
|
176
|
+
agentsMd: existsSync(join(root, 'AGENTS.md')),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Discover packs under a workspace root (`packages/pack-*` convention).
|
|
182
|
+
*
|
|
183
|
+
* Returns absolute paths to every directory under `<workspace>/packages/`
|
|
184
|
+
* whose name starts with `pack-`. v4-only addition — the legacy Python
|
|
185
|
+
* installer has no equivalent because packs are a v4 concept.
|
|
186
|
+
*/
|
|
187
|
+
export function discoverPacks(workspaceRoot: string): readonly string[] {
|
|
188
|
+
const packagesDir = join(workspaceRoot, 'packages');
|
|
189
|
+
if (!isDir(packagesDir)) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
return readdirSync(packagesDir)
|
|
193
|
+
.filter((name) => name.startsWith('pack-'))
|
|
194
|
+
.map((name) => resolve(packagesDir, name))
|
|
195
|
+
.filter(isDir);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Locate the agent-config package root from a project root.
|
|
200
|
+
*
|
|
201
|
+
* 1:1 port of `scripts/install.py:detect_package_root` — prefers an
|
|
202
|
+
* npm-installed copy under `node_modules/@event4u/agent-config/`,
|
|
203
|
+
* falls back to the project root itself for in-package development
|
|
204
|
+
* (presence of `src/config/profiles/minimal.ini` is the development-mode
|
|
205
|
+
* signal in the Python script; we mirror it).
|
|
206
|
+
*
|
|
207
|
+
* Returns `null` instead of failing — caller decides UX (Python `fail`
|
|
208
|
+
* exits the process; the TS engine surfaces the error to the wizard).
|
|
209
|
+
*/
|
|
210
|
+
export function detectPackageRoot(projectRoot: string): string | null {
|
|
211
|
+
const npmPath = join(projectRoot, 'node_modules', '@event4u', 'agent-config');
|
|
212
|
+
if (isDir(npmPath)) {
|
|
213
|
+
return resolve(npmPath);
|
|
214
|
+
}
|
|
215
|
+
if (existsSync(join(projectRoot, 'src', 'config', 'profiles', 'minimal.ini'))) {
|
|
216
|
+
return projectRoot;
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Classify a package root as `npm` (under node_modules) or `local`. */
|
|
222
|
+
export function detectPackageType(packageRoot: string): 'npm' | 'local' {
|
|
223
|
+
return packageRoot.split(/[\\/]/).includes('node_modules') ? 'npm' : 'local';
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function isDir(path: string): boolean {
|
|
227
|
+
try {
|
|
228
|
+
return statSync(path).isDirectory();
|
|
229
|
+
} catch {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Result of a v3-on-disk probe. road-to-unified-setup § Phase E2.
|
|
236
|
+
*
|
|
237
|
+
* The v4 wizard renders a backup-screen with two CTAs when a v3 install
|
|
238
|
+
* is detected — `path` reports where the legacy tree lives, `version`
|
|
239
|
+
* carries the first non-empty line of `<path>/VERSION` for the operator
|
|
240
|
+
* banner, `backupTarget` is the suggested destination for the rsync /
|
|
241
|
+
* cp copy. `present: false` short-circuits the banner.
|
|
242
|
+
*/
|
|
243
|
+
export interface LegacyV3Detection {
|
|
244
|
+
readonly present: boolean;
|
|
245
|
+
readonly path: string;
|
|
246
|
+
readonly version: string | null;
|
|
247
|
+
readonly backupTarget: string;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Detect a v3.x install at `~/.event4u/agent-config/` (or the override
|
|
252
|
+
* passed in). Returns `present: false` when the directory or the
|
|
253
|
+
* `VERSION` file is missing, or when the recorded major version is not
|
|
254
|
+
* `3.x`. The caller decides what to do with `present: true` — the wire
|
|
255
|
+
* route in `installRoute` exposes the structure 1:1.
|
|
256
|
+
*/
|
|
257
|
+
export function detectLegacyV3(opts: { home?: string } = {}): LegacyV3Detection {
|
|
258
|
+
const home = opts.home ?? homedir();
|
|
259
|
+
const path = join(home, '.event4u', 'agent-config');
|
|
260
|
+
const backupTarget = join(home, '.event4u', 'agent-config.v3.bak');
|
|
261
|
+
if (!isDir(path)) {
|
|
262
|
+
return { present: false, path, version: null, backupTarget };
|
|
263
|
+
}
|
|
264
|
+
const versionFile = join(path, 'VERSION');
|
|
265
|
+
if (!existsSync(versionFile)) {
|
|
266
|
+
return { present: false, path, version: null, backupTarget };
|
|
267
|
+
}
|
|
268
|
+
let raw = '';
|
|
269
|
+
try {
|
|
270
|
+
raw = readFileSync(versionFile, 'utf8').trim();
|
|
271
|
+
} catch {
|
|
272
|
+
return { present: false, path, version: null, backupTarget };
|
|
273
|
+
}
|
|
274
|
+
const firstLine = raw.split('\n', 1)[0]?.trim() ?? '';
|
|
275
|
+
const major = firstLine.split('.')[0]?.trim();
|
|
276
|
+
if (major !== '3') {
|
|
277
|
+
return { present: false, path, version: firstLine || null, backupTarget };
|
|
278
|
+
}
|
|
279
|
+
return { present: true, path, version: firstLine, backupTarget };
|
|
280
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralised path resolution for the unified TS install engine.
|
|
3
|
+
*
|
|
4
|
+
* Council Finding #16: every downstream module reads paths from one
|
|
5
|
+
* place — no inline `os.tmpdir()` or `~/.event4u/...` literals scattered
|
|
6
|
+
* across A2–A6.
|
|
7
|
+
*
|
|
8
|
+
* All helpers accept an optional `home` argument so tests can drive
|
|
9
|
+
* platform behaviour (POSIX vs Windows env-var fallback) without
|
|
10
|
+
* mocking `node:os`. Production callers omit it and `os.homedir()` is
|
|
11
|
+
* consulted lazily.
|
|
12
|
+
*
|
|
13
|
+
* Platform notes:
|
|
14
|
+
* - POSIX: `os.homedir()` reads `$HOME`.
|
|
15
|
+
* - Windows: `os.homedir()` reads `$USERPROFILE`, then `$HOMEDRIVE+$HOMEPATH`.
|
|
16
|
+
*
|
|
17
|
+
* The install root and log path live under a fixed `.event4u/agent-config/`
|
|
18
|
+
* sub-tree so both platforms land on the same logical location.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { homedir, tmpdir } from 'node:os';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Sub-tree under the user's home where v4 installs land.
|
|
26
|
+
*
|
|
27
|
+
* Matches the legacy Python installer's target (`~/.event4u/agent-config/`)
|
|
28
|
+
* so v3 and v4 read/write the same physical tree and v3-detection (Phase E2)
|
|
29
|
+
* can introspect a prior install without a migration step.
|
|
30
|
+
*/
|
|
31
|
+
export const INSTALL_ROOT_SUBPATH = '.event4u/agent-config';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Active transaction log filename written by Phase A4 atomic-writer.
|
|
35
|
+
*
|
|
36
|
+
* Per Phase A4 + council Finding #18: rotation produces sibling files
|
|
37
|
+
* (`install-log.<ISO>.jsonl.gz`); recovery only scans the active log.
|
|
38
|
+
*/
|
|
39
|
+
export const INSTALL_LOG_FILENAME = 'install-log.jsonl';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the home directory.
|
|
43
|
+
*
|
|
44
|
+
* `home` override is accepted so tests can pin platform behaviour
|
|
45
|
+
* without mocking the `node:os` module. Empty / falsy override falls
|
|
46
|
+
* back to `os.homedir()`.
|
|
47
|
+
*/
|
|
48
|
+
function resolveHome(home?: string): string {
|
|
49
|
+
if (home && home.length > 0) {
|
|
50
|
+
return home;
|
|
51
|
+
}
|
|
52
|
+
const fromOs = homedir();
|
|
53
|
+
if (!fromOs) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
'Cannot resolve home directory — both $HOME (POSIX) and $USERPROFILE (Windows) are unset.',
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return fromOs;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Absolute path to the v4 install root: `~/.event4u/agent-config/`.
|
|
63
|
+
*
|
|
64
|
+
* Stable across platforms because the suffix is a POSIX-style join
|
|
65
|
+
* applied via `path.join`, which normalises separators per platform.
|
|
66
|
+
*/
|
|
67
|
+
export function getInstallRoot(home?: string): string {
|
|
68
|
+
return join(resolveHome(home), INSTALL_ROOT_SUBPATH);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Absolute path to the active transaction log:
|
|
73
|
+
* `~/.event4u/agent-config/install-log.jsonl`.
|
|
74
|
+
*
|
|
75
|
+
* Phase A4 writers append here on every successful atomic rename.
|
|
76
|
+
*/
|
|
77
|
+
export function getLogPath(home?: string): string {
|
|
78
|
+
return join(getInstallRoot(home), INSTALL_LOG_FILENAME);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* OS-level temp directory.
|
|
83
|
+
*
|
|
84
|
+
* Wraps `os.tmpdir()` so callers funnel through one symbol — drop-in
|
|
85
|
+
* replacement when a future test harness needs to redirect temp writes
|
|
86
|
+
* to a scratch dir without monkey-patching `node:os`.
|
|
87
|
+
*/
|
|
88
|
+
export function getTempPath(): string {
|
|
89
|
+
return tmpdir();
|
|
90
|
+
}
|