@mrclrchtr/supi-consulting 0.0.0-stage → 8.0.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.
Files changed (78) hide show
  1. package/CLAUDE.md +23 -0
  2. package/CONTEXT.md +53 -0
  3. package/README.md +104 -2
  4. package/docs/adr/0001-use-an-isolated-antigravity-home.md +5 -0
  5. package/node_modules/@mrclrchtr/supi-core/README.md +137 -0
  6. package/node_modules/@mrclrchtr/supi-core/package.json +77 -0
  7. package/node_modules/@mrclrchtr/supi-core/src/api.ts +42 -0
  8. package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +342 -0
  9. package/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +363 -0
  10. package/node_modules/@mrclrchtr/supi-core/src/config.ts +17 -0
  11. package/node_modules/@mrclrchtr/supi-core/src/context/context-provider-registry.ts +36 -0
  12. package/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +31 -0
  13. package/node_modules/@mrclrchtr/supi-core/src/context.ts +8 -0
  14. package/node_modules/@mrclrchtr/supi-core/src/debug-identity.ts +11 -0
  15. package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +313 -0
  16. package/node_modules/@mrclrchtr/supi-core/src/debug-timing.ts +120 -0
  17. package/node_modules/@mrclrchtr/supi-core/src/debug.ts +14 -0
  18. package/node_modules/@mrclrchtr/supi-core/src/evidence-badge.ts +41 -0
  19. package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +64 -0
  20. package/node_modules/@mrclrchtr/supi-core/src/index.ts +38 -0
  21. package/node_modules/@mrclrchtr/supi-core/src/llm.ts +356 -0
  22. package/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +134 -0
  23. package/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +44 -0
  24. package/node_modules/@mrclrchtr/supi-core/src/path.ts +2 -0
  25. package/node_modules/@mrclrchtr/supi-core/src/project-roots.ts +170 -0
  26. package/node_modules/@mrclrchtr/supi-core/src/project.ts +15 -0
  27. package/node_modules/@mrclrchtr/supi-core/src/prompt-surface.ts +4 -0
  28. package/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +93 -0
  29. package/node_modules/@mrclrchtr/supi-core/src/report.ts +121 -0
  30. package/node_modules/@mrclrchtr/supi-core/src/session-capabilities.ts +242 -0
  31. package/node_modules/@mrclrchtr/supi-core/src/session-capability-profiles.ts +240 -0
  32. package/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +71 -0
  33. package/node_modules/@mrclrchtr/supi-core/src/session.ts +47 -0
  34. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +105 -0
  35. package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +454 -0
  36. package/node_modules/@mrclrchtr/supi-core/src/settings.ts +36 -0
  37. package/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +11 -0
  38. package/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +68 -0
  39. package/node_modules/@mrclrchtr/supi-core/src/terminal.ts +60 -0
  40. package/node_modules/@mrclrchtr/supi-core/src/tui.ts +141 -0
  41. package/package.json +78 -4
  42. package/scripts/live-probe.ts +139 -0
  43. package/src/agents/antigravity/activity.ts +22 -0
  44. package/src/agents/antigravity/adapter.ts +196 -0
  45. package/src/agents/antigravity/availability.ts +231 -0
  46. package/src/agents/antigravity/isolated-home.ts +346 -0
  47. package/src/agents/antigravity/models.ts +15 -0
  48. package/src/agents/antigravity/process/environment.ts +33 -0
  49. package/src/agents/antigravity/process/event-values.ts +273 -0
  50. package/src/agents/antigravity/process/events.ts +366 -0
  51. package/src/agents/antigravity/process/hooks.ts +219 -0
  52. package/src/agents/antigravity/process/ndjson.ts +120 -0
  53. package/src/agents/antigravity/process/protocol.ts +69 -0
  54. package/src/agents/antigravity/process/runner.ts +147 -0
  55. package/src/agents/antigravity/process/subprocess.ts +278 -0
  56. package/src/agents/antigravity/process/usage.ts +50 -0
  57. package/src/agents/antigravity/structured-output.ts +58 -0
  58. package/src/agents/antigravity/types.ts +17 -0
  59. package/src/agents/errors.ts +27 -0
  60. package/src/agents/types.ts +43 -0
  61. package/src/catalogue.ts +17 -0
  62. package/src/config.ts +26 -0
  63. package/src/conversation/handles.ts +187 -0
  64. package/src/evidence-hash.ts +6 -0
  65. package/src/extension.ts +26 -0
  66. package/src/footer-constants.ts +5 -0
  67. package/src/footer.ts +25 -0
  68. package/src/runtime.ts +244 -0
  69. package/src/settings.ts +38 -0
  70. package/src/tool/consulting_run/evidence.ts +169 -0
  71. package/src/tool/consulting_run/execute.ts +201 -0
  72. package/src/tool/consulting_run/guidance.ts +3 -0
  73. package/src/tool/consulting_run/input.ts +117 -0
  74. package/src/tool/consulting_run/register.ts +36 -0
  75. package/src/tool/consulting_run/render.ts +261 -0
  76. package/src/tool/consulting_run/result.ts +185 -0
  77. package/src/tool/consulting_run/spec.ts +20 -0
  78. package/src/types.ts +104 -0
@@ -0,0 +1,240 @@
1
+ /** Exact names to exclude. Omitted configuration lists mean empty sets. */
2
+ export interface SessionCapabilityProfileDefinition {
3
+ excludedTools?: string[];
4
+ hiddenSkills?: string[];
5
+ }
6
+
7
+ /** Validated exclusion sets. Names need not match the current inventory. */
8
+ export interface SessionCapabilityProfile {
9
+ excludedTools: string[];
10
+ hiddenSkills: string[];
11
+ }
12
+
13
+ /** A profile is available only when validation has no errors. */
14
+ export interface SessionCapabilityProfileValidation {
15
+ profile?: SessionCapabilityProfile;
16
+ errors: string[];
17
+ }
18
+
19
+ function isRecord(value: unknown): value is Record<string, unknown> {
20
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
21
+ const prototype = Object.getPrototypeOf(value);
22
+ return prototype === Object.prototype || prototype === null;
23
+ }
24
+
25
+ function readNames(value: unknown): string[] | undefined {
26
+ if (!Array.isArray(value)) return undefined;
27
+ const names: unknown[] = [...new Set(value)];
28
+ return names.every((name): name is string => typeof name === "string") ? names : undefined;
29
+ }
30
+
31
+ /** Validate and copy a complete definition. Do not check inventory or expand patterns. */
32
+ export function validateSessionCapabilityProfile(
33
+ value: unknown,
34
+ ): SessionCapabilityProfileValidation {
35
+ if (!isRecord(value)) return { errors: ["Profile must be an object."] };
36
+ const excludedTools = Object.hasOwn(value, "excludedTools") ? readNames(value.excludedTools) : [];
37
+ const hiddenSkills = Object.hasOwn(value, "hiddenSkills") ? readNames(value.hiddenSkills) : [];
38
+ const errors = Object.keys(value)
39
+ .filter((key) => key !== "excludedTools" && key !== "hiddenSkills")
40
+ .map((key) => `Unknown profile field: ${key}.`);
41
+ if (!excludedTools) errors.push("excludedTools must be an array of strings.");
42
+ if (!hiddenSkills) errors.push("hiddenSkills must be an array of strings.");
43
+ if (errors.length || !excludedTools || !hiddenSkills) return { errors };
44
+ return { profile: { excludedTools, hiddenSkills }, errors };
45
+ }
46
+
47
+ /** Configuration scope that supplied a profile or default. */
48
+ export type SessionCapabilityProfileScope = "global" | "project";
49
+
50
+ /** Configuration values for the sessionCapabilities section. */
51
+ export interface SessionCapabilityProfilesSection {
52
+ profiles?: Record<string, SessionCapabilityProfileDefinition>;
53
+ defaultProfile?: string | null;
54
+ }
55
+
56
+ /** Session-owned identity and original exclusion sets, independent of configuration. */
57
+ export interface SessionCapabilityProfileSnapshot extends SessionCapabilityProfile {
58
+ id: string;
59
+ source: SessionCapabilityProfileScope;
60
+ }
61
+
62
+ /** A configuration error with a scope and field path for display. */
63
+ export interface SessionCapabilityProfileDiagnostic {
64
+ scope: SessionCapabilityProfileScope;
65
+ path: string;
66
+ message: string;
67
+ }
68
+
69
+ /** A scoped definition, including invalid definitions and hidden global definitions. */
70
+ export interface SessionCapabilityProfileEntry {
71
+ id: string;
72
+ source: SessionCapabilityProfileScope;
73
+ shadowed: boolean;
74
+ profile?: SessionCapabilityProfile;
75
+ errors: SessionCapabilityProfileDiagnostic[];
76
+ }
77
+
78
+ /** Default selection source can differ from the effective profile source. */
79
+ export type SessionCapabilityProfileDefault =
80
+ | { status: "none"; source?: SessionCapabilityProfileScope }
81
+ | {
82
+ status: "resolved";
83
+ source: SessionCapabilityProfileScope;
84
+ id: string;
85
+ profile: SessionCapabilityProfileSnapshot;
86
+ }
87
+ | { status: "invalid"; source: SessionCapabilityProfileScope; id?: string };
88
+
89
+ /** Raw sections, not merged configuration. Callers must check trust before project reads. */
90
+ export interface ResolveSessionCapabilityProfilesOptions {
91
+ global?: unknown;
92
+ project?: unknown;
93
+ projectTrusted: boolean;
94
+ }
95
+
96
+ /** Data for profile rows, scoped actions, and default warnings. No I/O is performed. */
97
+ export interface SessionCapabilityProfilesResolution {
98
+ entries: SessionCapabilityProfileEntry[];
99
+ effectiveProfiles: SessionCapabilityProfileSnapshot[];
100
+ default: SessionCapabilityProfileDefault;
101
+ errors: SessionCapabilityProfileDiagnostic[];
102
+ }
103
+
104
+ /** IDs contain lowercase ASCII words separated by single hyphens. */
105
+ export function isSessionCapabilityProfileId(value: unknown): value is string {
106
+ return typeof value === "string" && /^[a-z]+(?:-[a-z]+)*$/.test(value);
107
+ }
108
+
109
+ /** Validate and copy stored identity and original lists. Invalid metadata has no identity. */
110
+ export function decodeSessionCapabilityProfileSnapshot(
111
+ value: unknown,
112
+ ): SessionCapabilityProfileSnapshot | undefined {
113
+ if (!isRecord(value) || !isSessionCapabilityProfileId(value.id)) return undefined;
114
+ if (value.source !== "global" && value.source !== "project") return undefined;
115
+ const { id, source, ...definition } = value;
116
+ if (!Object.hasOwn(definition, "excludedTools") || !Object.hasOwn(definition, "hiddenSkills"))
117
+ return undefined;
118
+ const result = validateSessionCapabilityProfile(definition);
119
+ return result.profile ? { id, source, ...result.profile } : undefined;
120
+ }
121
+
122
+ function readEntries(
123
+ value: unknown,
124
+ source: SessionCapabilityProfileScope,
125
+ ): SessionCapabilityProfileEntry[] {
126
+ if (!isRecord(value) || !isRecord(value.profiles)) return [];
127
+ return Object.entries(value.profiles).map(([id, definition]) => {
128
+ const result = validateSessionCapabilityProfile(definition);
129
+ if (!isSessionCapabilityProfileId(id))
130
+ result.errors.push("Invalid profile ID: use lowercase words with single hyphens.");
131
+ return {
132
+ id,
133
+ source,
134
+ shadowed: false,
135
+ profile: result.errors.length ? undefined : result.profile,
136
+ errors: result.errors.map((message) => ({ scope: source, path: `profiles.${id}`, message })),
137
+ };
138
+ });
139
+ }
140
+
141
+ type DefaultReference =
142
+ | SessionCapabilityProfileDefault
143
+ | { status: "pending"; source: SessionCapabilityProfileScope; id: string };
144
+
145
+ function readDefault(
146
+ value: unknown,
147
+ source: SessionCapabilityProfileScope,
148
+ errors: SessionCapabilityProfileDiagnostic[],
149
+ ): DefaultReference | undefined {
150
+ if (!isRecord(value) || !Object.hasOwn(value, "defaultProfile")) return undefined;
151
+ if (value.defaultProfile === null) return { status: "none", source };
152
+ if (isSessionCapabilityProfileId(value.defaultProfile)) {
153
+ return { status: "pending", source, id: value.defaultProfile };
154
+ }
155
+ errors.push({
156
+ scope: source,
157
+ path: "defaultProfile",
158
+ message: "defaultProfile must be null or a valid profile ID.",
159
+ });
160
+ return { status: "invalid", source };
161
+ }
162
+
163
+ function resolveDefault(
164
+ selected: DefaultReference | undefined,
165
+ profiles: SessionCapabilityProfileSnapshot[],
166
+ errors: SessionCapabilityProfileDiagnostic[],
167
+ ): SessionCapabilityProfileDefault {
168
+ if (!selected) return { status: "none" };
169
+ if (selected.status !== "pending") return selected;
170
+ const { source, id } = selected;
171
+ const profile = profiles.find((entry) => entry.id === id);
172
+ if (profile) return { status: "resolved", source, id, profile };
173
+ errors.push({
174
+ scope: source,
175
+ path: "defaultProfile",
176
+ message: `Default profile ${id} is missing or invalid. No profile will be applied.`,
177
+ });
178
+ return { status: "invalid", source, id };
179
+ }
180
+
181
+ interface ScopedProfiles {
182
+ entries: SessionCapabilityProfileEntry[];
183
+ errors: SessionCapabilityProfileDiagnostic[];
184
+ default?: DefaultReference;
185
+ }
186
+
187
+ /** Reject malformed sections, but retain known IDs to prevent global fallback. */
188
+ function readSection(value: unknown, scope: SessionCapabilityProfileScope): ScopedProfiles {
189
+ if (value === undefined) return { entries: [], errors: [] };
190
+ if (!isRecord(value)) {
191
+ return {
192
+ entries: [],
193
+ default: { status: "invalid", source: scope },
194
+ errors: [
195
+ { scope, path: "sessionCapabilities", message: "sessionCapabilities must be an object." },
196
+ ],
197
+ };
198
+ }
199
+ const sectionErrors = Object.keys(value)
200
+ .filter((key) => key !== "profiles" && key !== "defaultProfile")
201
+ .map((key) => ({ scope, path: key, message: `Unknown section field: ${key}.` }));
202
+ if (Object.hasOwn(value, "profiles") && !isRecord(value.profiles)) {
203
+ sectionErrors.push({ scope, path: "profiles", message: "profiles must be an object." });
204
+ }
205
+ const entries = readEntries(value, scope);
206
+ const errors = [...sectionErrors, ...entries.flatMap((entry) => entry.errors)];
207
+ const selection = readDefault(value, scope, errors);
208
+ if (sectionErrors.length) {
209
+ for (const entry of entries) {
210
+ entry.profile = undefined;
211
+ entry.errors.push(...sectionErrors);
212
+ }
213
+ return { entries, errors, default: { status: "invalid", source: scope } };
214
+ }
215
+ return { entries, errors, default: selection };
216
+ }
217
+
218
+ /**
219
+ * Resolve whole profiles by ID. Ignore project data unless projectTrusted is true.
220
+ * An absent section is undefined. Malformed sections cannot supply profiles or a default.
221
+ */
222
+ export function resolveSessionCapabilityProfiles(
223
+ options: ResolveSessionCapabilityProfilesOptions,
224
+ ): SessionCapabilityProfilesResolution {
225
+ const global = readSection(options.global, "global");
226
+ const project = readSection(options.projectTrusted ? options.project : undefined, "project");
227
+ const entries = [...global.entries, ...project.entries];
228
+ const errors = [...global.errors, ...project.errors];
229
+ const selected = new Map(entries.map((entry) => [entry.id, entry]));
230
+ for (const entry of entries) entry.shadowed = selected.get(entry.id) !== entry;
231
+ const effectiveProfiles = [...selected.values()].flatMap((entry) =>
232
+ entry.profile ? [{ id: entry.id, source: entry.source, ...entry.profile }] : [],
233
+ );
234
+ return {
235
+ entries,
236
+ effectiveProfiles,
237
+ default: resolveDefault(project.default ?? global.default, effectiveProfiles, errors),
238
+ errors,
239
+ };
240
+ }
@@ -0,0 +1,71 @@
1
+ // Generic session-file tree-walking utilities.
2
+
3
+ import type { FileEntry, SessionEntry } from "@earendil-works/pi-coding-agent";
4
+
5
+ /**
6
+ * Minimal pi API surface needed to track the current session display name reactively.
7
+ * Accept `ExtensionAPI` or any object satisfying this shape.
8
+ */
9
+ export interface SessionNameTrackerHost {
10
+ on(event: string, handler: (...args: unknown[]) => unknown): void;
11
+ getSessionName(): string | undefined;
12
+ }
13
+
14
+ /**
15
+ * Create a reactive session-name tracker that stays consistent across
16
+ * session starts, renames, and shutdowns without polling.
17
+ *
18
+ * Subscribes to `session_start` (initial name), `session_info_changed`
19
+ * (renames via `/name`, `pi.setSessionName()`, or RPC), and
20
+ * `session_shutdown` (reset to `undefined`).
21
+ *
22
+ * @returns a zero-arg getter that always returns the current session name
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const getSessionName = createSessionNameTracker(pi);
27
+ * // …later, during tool execute or spinner rendering:
28
+ * const name = getSessionName();
29
+ * ```
30
+ */
31
+ export function createSessionNameTracker(pi: SessionNameTrackerHost): () => string | undefined {
32
+ let name: string | undefined;
33
+
34
+ pi.on("session_start", () => {
35
+ name = pi.getSessionName();
36
+ });
37
+ pi.on("session_info_changed", (event) => {
38
+ name = (event as { name?: string }).name;
39
+ });
40
+ pi.on("session_shutdown", () => {
41
+ name = undefined;
42
+ });
43
+
44
+ return () => name;
45
+ }
46
+
47
+ /**
48
+ * Resolve the active branch path using PI's append-only tree semantics.
49
+ *
50
+ * The active branch is the path from the **last entry** (current leaf)
51
+ * back to the root via `parentId`. This follows PI's tree structure where
52
+ * entries are append-only and the last entry in the file is always the
53
+ * current leaf of the active branch.
54
+ */
55
+ export function getActiveBranchEntries(entries: FileEntry[]): SessionEntry[] {
56
+ const sessionEntries = entries.filter((e): e is SessionEntry => e.type !== "session");
57
+ const byId = new Map(sessionEntries.map((entry) => [entry.id, entry]));
58
+ const leaf = sessionEntries.at(-1);
59
+ if (!leaf) return [];
60
+
61
+ const path: SessionEntry[] = [];
62
+ const visited = new Set<string>();
63
+ let current: SessionEntry | undefined = leaf;
64
+ while (current) {
65
+ if (visited.has(current.id)) break;
66
+ visited.add(current.id);
67
+ path.unshift(current);
68
+ current = current.parentId ? byId.get(current.parentId) : undefined;
69
+ }
70
+ return path;
71
+ }
@@ -0,0 +1,47 @@
1
+ // supi-core session domain — session utilities and registries.
2
+
3
+ export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
4
+ export type {
5
+ SessionCapabilitySkill,
6
+ SessionCapabilitySkillProvider,
7
+ SessionCapabilityState,
8
+ } from "./session-capabilities.ts";
9
+ export {
10
+ applySessionCapabilityProfile,
11
+ captureSessionCapabilityExclusions,
12
+ clearPendingSessionCapabilityForks,
13
+ createEmptySessionCapabilityState,
14
+ decodeSessionCapabilities,
15
+ findSessionCapabilities,
16
+ getSessionCapabilitySkillProvider,
17
+ isSessionCapabilityProfileModified,
18
+ readPendingSessionCapabilityFork,
19
+ registerSessionCapabilitySkillProvider,
20
+ SESSION_CAPABILITIES_ENTRY,
21
+ sessionCapabilityState,
22
+ setPendingSessionCapabilityFork,
23
+ } from "./session-capabilities.ts";
24
+ export type {
25
+ ResolveSessionCapabilityProfilesOptions,
26
+ SessionCapabilityProfile,
27
+ SessionCapabilityProfileDefault,
28
+ SessionCapabilityProfileDefinition,
29
+ SessionCapabilityProfileDiagnostic,
30
+ SessionCapabilityProfileEntry,
31
+ SessionCapabilityProfileScope,
32
+ SessionCapabilityProfileSnapshot,
33
+ SessionCapabilityProfilesResolution,
34
+ SessionCapabilityProfilesSection,
35
+ SessionCapabilityProfileValidation,
36
+ } from "./session-capability-profiles.ts";
37
+ export {
38
+ decodeSessionCapabilityProfileSnapshot,
39
+ isSessionCapabilityProfileId,
40
+ resolveSessionCapabilityProfiles,
41
+ validateSessionCapabilityProfile,
42
+ } from "./session-capability-profiles.ts";
43
+ export type { SessionNameTrackerHost } from "./session-utils.ts";
44
+ export {
45
+ createSessionNameTracker,
46
+ getActiveBranchEntries,
47
+ } from "./session-utils.ts";
@@ -0,0 +1,105 @@
1
+ // Event-backed settings module registration and collection.
2
+
3
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
4
+ import type { ScopedFieldValue, SettingsAction } from "./settings-schema.ts";
5
+
6
+ export const SUPI_SETTINGS_COLLECT_EVENT = "supi:settings:collect";
7
+
8
+ export type SettingsScope = "project" | "global";
9
+
10
+ /** Scope and PI runtime state supplied for each settings read. */
11
+ export interface SettingsContext {
12
+ scope: SettingsScope;
13
+ cwd: string;
14
+ ctx?: ExtensionContext;
15
+ }
16
+
17
+ /** A resolved, source-aware settings view. */
18
+ export interface SettingsSnapshot {
19
+ rows: ScopedFieldValue[];
20
+ }
21
+
22
+ /** One user action routed to its owning settings module. */
23
+ export interface SettingsActionRequest extends SettingsContext {
24
+ fieldKey: string;
25
+ action: SettingsAction;
26
+ }
27
+
28
+ /** Optional user-facing result from a successful settings action. */
29
+ export interface SettingsApplyResult {
30
+ notice?: {
31
+ message: string;
32
+ level: "info" | "warning" | "error";
33
+ };
34
+ }
35
+
36
+ /**
37
+ * Canonical settings interface consumed by `/supi-settings`.
38
+ *
39
+ * Reads are always asynchronous. Apply resolves only after durable writes and
40
+ * module-owned refresh work complete. Implementations throw on failed writes.
41
+ */
42
+ export interface SettingsModule {
43
+ id: string;
44
+ /** Human-readable section label shown in the UI. */
45
+ label: string;
46
+ /** Optional label that groups this module within its section. */
47
+ subsection?: string;
48
+ read(context: SettingsContext): Promise<SettingsSnapshot>;
49
+ apply(request: SettingsActionRequest): Promise<SettingsApplyResult>;
50
+ }
51
+
52
+ export interface SettingsContributionCollector {
53
+ add(module: SettingsModule): void;
54
+ }
55
+
56
+ export interface SettingsCollectionDiagnostic {
57
+ kind: "warning";
58
+ message: string;
59
+ }
60
+
61
+ export interface SettingsCollectionResult {
62
+ modules: SettingsModule[];
63
+ diagnostics: SettingsCollectionDiagnostic[];
64
+ }
65
+
66
+ export function isSettingsContributionCollector(
67
+ value: unknown,
68
+ ): value is SettingsContributionCollector {
69
+ return (
70
+ typeof value === "object" &&
71
+ value !== null &&
72
+ typeof (value as { add?: unknown }).add === "function"
73
+ );
74
+ }
75
+
76
+ /** Create a collector with last-wins duplicate handling and warning diagnostics. */
77
+ export function createSettingsContributionCollector(): SettingsContributionCollector & {
78
+ result(): SettingsCollectionResult;
79
+ } {
80
+ const modules = new Map<string, SettingsModule>();
81
+ const diagnostics: SettingsCollectionDiagnostic[] = [];
82
+
83
+ return {
84
+ add(module: SettingsModule): void {
85
+ if (modules.has(module.id)) {
86
+ diagnostics.push({
87
+ kind: "warning",
88
+ message: `Duplicate SuPi settings contribution "${module.id}"; using the last contribution.`,
89
+ });
90
+ }
91
+ modules.set(module.id, module);
92
+ },
93
+ result(): SettingsCollectionResult {
94
+ return { modules: Array.from(modules.values()), diagnostics: [...diagnostics] };
95
+ },
96
+ };
97
+ }
98
+
99
+ /** Register one settings module during extension factory setup. */
100
+ export function registerSettings(pi: ExtensionAPI, module: SettingsModule): void {
101
+ const dispose = pi.events.on(SUPI_SETTINGS_COLLECT_EVENT, (collector) => {
102
+ if (isSettingsContributionCollector(collector)) collector.add(module);
103
+ });
104
+ pi.on("session_shutdown", () => dispose());
105
+ }