@mrclrchtr/supi-web 4.7.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -6
- package/src/api.ts +0 -2
- package/src/fetch.ts +23 -16
- package/src/tool/tool-specs.ts +9 -1
- package/node_modules/@mrclrchtr/supi-core/README.md +0 -120
- package/node_modules/@mrclrchtr/supi-core/package.json +0 -75
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +0 -42
- package/node_modules/@mrclrchtr/supi-core/src/config/config.ts +0 -221
- package/node_modules/@mrclrchtr/supi-core/src/config/prompt-surface.ts +0 -357
- package/node_modules/@mrclrchtr/supi-core/src/config.ts +0 -11
- package/node_modules/@mrclrchtr/supi-core/src/context/context-messages.ts +0 -119
- package/node_modules/@mrclrchtr/supi-core/src/context/context-provider-registry.ts +0 -36
- package/node_modules/@mrclrchtr/supi-core/src/context/context-tag.ts +0 -31
- package/node_modules/@mrclrchtr/supi-core/src/context.ts +0 -16
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +0 -287
- package/node_modules/@mrclrchtr/supi-core/src/evidence-badge.ts +0 -41
- package/node_modules/@mrclrchtr/supi-core/src/footer-registry.ts +0 -57
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +0 -36
- package/node_modules/@mrclrchtr/supi-core/src/llm.ts +0 -201
- package/node_modules/@mrclrchtr/supi-core/src/model-selection.ts +0 -134
- package/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +0 -44
- package/node_modules/@mrclrchtr/supi-core/src/path.ts +0 -2
- package/node_modules/@mrclrchtr/supi-core/src/progress-widget.ts +0 -189
- package/node_modules/@mrclrchtr/supi-core/src/project-roots.ts +0 -170
- package/node_modules/@mrclrchtr/supi-core/src/project.ts +0 -15
- package/node_modules/@mrclrchtr/supi-core/src/prompt-surface.ts +0 -4
- package/node_modules/@mrclrchtr/supi-core/src/registry-utils.ts +0 -93
- package/node_modules/@mrclrchtr/supi-core/src/report.ts +0 -121
- package/node_modules/@mrclrchtr/supi-core/src/session-utils.ts +0 -71
- package/node_modules/@mrclrchtr/supi-core/src/session.ts +0 -8
- package/node_modules/@mrclrchtr/supi-core/src/settings/scoped-settings-list.ts +0 -373
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-action-menu.ts +0 -102
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-command.ts +0 -15
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-registry.ts +0 -76
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-schema.ts +0 -487
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-submenus.ts +0 -141
- package/node_modules/@mrclrchtr/supi-core/src/settings/settings-ui.ts +0 -118
- package/node_modules/@mrclrchtr/supi-core/src/settings-ui.ts +0 -3
- package/node_modules/@mrclrchtr/supi-core/src/settings.ts +0 -33
- package/node_modules/@mrclrchtr/supi-core/src/spinner-frames.ts +0 -11
- package/node_modules/@mrclrchtr/supi-core/src/status-spinner.ts +0 -68
- package/node_modules/@mrclrchtr/supi-core/src/terminal.ts +0 -60
- package/node_modules/@mrclrchtr/supi-core/src/tool-framework.ts +0 -192
- package/src/index.ts +0 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-web",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "Public web pages to Markdown, plus focused Context7 docs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,12 +35,8 @@
|
|
|
35
35
|
"jsdom": "^30.0.0",
|
|
36
36
|
"@mozilla/readability": "^0.6.0",
|
|
37
37
|
"turndown": "^7.2.0",
|
|
38
|
-
"turndown-plugin-gfm": "^1.0.2"
|
|
39
|
-
"@mrclrchtr/supi-core": "4.7.0"
|
|
38
|
+
"turndown-plugin-gfm": "^1.0.2"
|
|
40
39
|
},
|
|
41
|
-
"bundledDependencies": [
|
|
42
|
-
"@mrclrchtr/supi-core"
|
|
43
|
-
],
|
|
44
40
|
"peerDependencies": {
|
|
45
41
|
"@earendil-works/pi-ai": "*",
|
|
46
42
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/api.ts
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
export type { Context7RequestOptions } from "./context7-client.ts";
|
|
6
6
|
export { htmlToMarkdown, wrapAsCodeBlock } from "./convert.ts";
|
|
7
|
-
export { default as docsExtension } from "./docs.ts";
|
|
8
7
|
export {
|
|
9
8
|
FetchError,
|
|
10
9
|
type FetchOptions,
|
|
@@ -21,4 +20,3 @@ export {
|
|
|
21
20
|
type WebFetchMdInput,
|
|
22
21
|
type WebToolName,
|
|
23
22
|
} from "./tool/tool-specs.ts";
|
|
24
|
-
export { default } from "./web.ts";
|
package/src/fetch.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
const USER_AGENT = "Mozilla/5.0 (compatible; supi-web/1.0; +https://github.com/mrclrchtr/supi)";
|
|
7
7
|
const ACCEPT_SIBLING = "text/markdown,text/plain;q=0.9,*/*;q=0.1";
|
|
8
8
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
9
|
+
/** Largest timeout accepted by {@link AbortSignal.timeout}. */
|
|
10
|
+
export const FETCH_TIMEOUT_MAX_MS = 4_294_967_295;
|
|
9
11
|
const SNIFF_BYTES = 8192;
|
|
10
12
|
|
|
11
13
|
/** Validated URL result. */
|
|
@@ -24,6 +26,7 @@ export interface FetchResult {
|
|
|
24
26
|
|
|
25
27
|
/** Fetch options. */
|
|
26
28
|
export interface FetchOptions {
|
|
29
|
+
/** Integer timeout from 0 through 4,294,967,295 milliseconds. */
|
|
27
30
|
timeoutMs?: number;
|
|
28
31
|
signal?: AbortSignal;
|
|
29
32
|
}
|
|
@@ -38,12 +41,17 @@ export function isValidHttpUrl(url: string): boolean {
|
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Fetch a URL with full content negotiation and sniffing.
|
|
46
|
+
*
|
|
47
|
+
* Parent cancellation keeps its reason. Request timeouts throw {@link FetchError}.
|
|
48
|
+
*/
|
|
42
49
|
export async function fetchWithNegotiation(
|
|
43
50
|
url: string,
|
|
44
51
|
options: FetchOptions = {},
|
|
45
52
|
): Promise<FetchResult> {
|
|
46
53
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
54
|
+
validateTimeoutMs(timeoutMs);
|
|
47
55
|
const { signal } = options;
|
|
48
56
|
|
|
49
57
|
// 1. Try HEAD negotiation for Markdown
|
|
@@ -297,31 +305,30 @@ export class FetchError extends Error {
|
|
|
297
305
|
}
|
|
298
306
|
}
|
|
299
307
|
|
|
308
|
+
function validateTimeoutMs(timeoutMs: number): void {
|
|
309
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > FETCH_TIMEOUT_MAX_MS) {
|
|
310
|
+
throw new FetchError(
|
|
311
|
+
`Fetch timeout must be an integer from 0 through ${FETCH_TIMEOUT_MAX_MS}ms`,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
300
316
|
async function timedFetch(
|
|
301
317
|
url: string,
|
|
302
318
|
init: RequestInit,
|
|
303
319
|
timeoutMs: number,
|
|
304
320
|
signal?: AbortSignal,
|
|
305
321
|
): Promise<Response> {
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
const abortFromParent = () => controller.abort();
|
|
309
|
-
if (signal?.aborted) abortFromParent();
|
|
310
|
-
else signal?.addEventListener("abort", abortFromParent, { once: true });
|
|
311
|
-
|
|
312
|
-
const timer = setTimeout(() => {
|
|
313
|
-
timedOut = true;
|
|
314
|
-
controller.abort();
|
|
315
|
-
}, timeoutMs);
|
|
322
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
323
|
+
const fetchSignal = signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal;
|
|
316
324
|
|
|
317
325
|
try {
|
|
318
|
-
return await fetch(url, { ...init, signal:
|
|
326
|
+
return await fetch(url, { ...init, signal: fetchSignal });
|
|
319
327
|
} catch (err) {
|
|
320
|
-
if (
|
|
328
|
+
if (timeoutSignal.aborted && fetchSignal.reason === timeoutSignal.reason) {
|
|
329
|
+
throw new FetchError(`Fetch timed out after ${timeoutMs}ms`, { cause: err });
|
|
330
|
+
}
|
|
321
331
|
throw err;
|
|
322
|
-
} finally {
|
|
323
|
-
clearTimeout(timer);
|
|
324
|
-
signal?.removeEventListener("abort", abortFromParent);
|
|
325
332
|
}
|
|
326
333
|
}
|
|
327
334
|
|
package/src/tool/tool-specs.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
2
|
import { type Static, type TSchema, Type } from "typebox";
|
|
3
|
+
import { FETCH_TIMEOUT_MAX_MS } from "../fetch.ts";
|
|
3
4
|
import { MODEL_OUTPUT_LIMIT_DESCRIPTION } from "./output.ts";
|
|
4
5
|
|
|
5
6
|
export const WEB_FETCH_MD_TOOL_NAME = "web_fetch_md";
|
|
@@ -27,7 +28,14 @@ const WebFetchMdParameters = Type.Object(
|
|
|
27
28
|
url: Type.String({ description: "Public http(s) URL" }),
|
|
28
29
|
output_mode: Type.Optional(OutputModeEnum),
|
|
29
30
|
abs_links: Type.Optional(Type.Boolean({ description: "Absolute links/images", default: true })),
|
|
30
|
-
timeout_ms: Type.Optional(
|
|
31
|
+
timeout_ms: Type.Optional(
|
|
32
|
+
Type.Integer({
|
|
33
|
+
description: "Fetch timeout (ms)",
|
|
34
|
+
default: 30_000,
|
|
35
|
+
minimum: 0,
|
|
36
|
+
maximum: FETCH_TIMEOUT_MAX_MS,
|
|
37
|
+
}),
|
|
38
|
+
),
|
|
31
39
|
},
|
|
32
40
|
{ additionalProperties: false },
|
|
33
41
|
);
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<a href="https://github.com/mrclrchtr/supi/tree/main/packages/supi-core">
|
|
3
|
-
<img src="https://raw.githubusercontent.com/mrclrchtr/supi/main/packages/supi-core/assets/social-preview.png" alt="SuPi Core" width="100%">
|
|
4
|
-
</a>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
|
-
# @mrclrchtr/supi-core
|
|
8
|
-
|
|
9
|
-
Shared infrastructure for SuPi extensions.
|
|
10
|
-
|
|
11
|
-
This is a **pure library** — it does not register any pi commands or tools. The `/supi-settings` command is now available through `@mrclrchtr/supi-settings`.
|
|
12
|
-
|
|
13
|
-
## Install
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
pnpm add @mrclrchtr/supi-core
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Package surfaces
|
|
20
|
-
|
|
21
|
-
- `@mrclrchtr/supi-core/api` — reusable helpers for other packages and extensions
|
|
22
|
-
- `@mrclrchtr/supi-core/report` — shared text/report rendering helpers for TUI and plain-text summaries
|
|
23
|
-
|
|
24
|
-
## What you get from the API
|
|
25
|
-
|
|
26
|
-
### Config helpers
|
|
27
|
-
|
|
28
|
-
- `loadSupiConfig()` — merged config with resolution order `defaults <- global <- project`
|
|
29
|
-
- `loadSupiConfigForScope()` — load one scope at a time for settings UIs
|
|
30
|
-
- `writeSupiConfig()` — persist values
|
|
31
|
-
- `removeSupiConfigKey()` — remove a key or override
|
|
32
|
-
|
|
33
|
-
Config file locations:
|
|
34
|
-
|
|
35
|
-
- global: `~/.pi/agent/supi/config.json`
|
|
36
|
-
- project: `.pi/supi/config.json`
|
|
37
|
-
|
|
38
|
-
### Settings helpers
|
|
39
|
-
|
|
40
|
-
- `registerDeclarativeSettings(pi, options)` — contribute a config-backed declarative settings section with source-aware scoped persistence
|
|
41
|
-
- `registerSettingsCommand(pi)` — register `/supi-settings` (used by `@mrclrchtr/supi-settings`)
|
|
42
|
-
- `openSettingsOverlay(pi, ctx)` — open the shared settings UI directly
|
|
43
|
-
- `createInputSubmenu()` — helper for simple text-entry submenus
|
|
44
|
-
- `createModelPickerSubmenu()` — helper for scoped model selection submenus, with optional host-owned choices and `disabled` control
|
|
45
|
-
|
|
46
|
-
The built-in settings UI supports:
|
|
47
|
-
|
|
48
|
-
- project/global scope toggle
|
|
49
|
-
- source badges for project, global, and default values
|
|
50
|
-
- Inherit/Reset actions that delete scoped config keys
|
|
51
|
-
- grouped extension sections
|
|
52
|
-
- searchable setting lists
|
|
53
|
-
|
|
54
|
-
### Context helpers
|
|
55
|
-
|
|
56
|
-
- `wrapExtensionContext()` — wrap injected text in SuPi's `<extension-context>` tag
|
|
57
|
-
- `findLastUserMessageIndex()`
|
|
58
|
-
- `getContextToken()`
|
|
59
|
-
- `getPromptContent()`
|
|
60
|
-
- `pruneAndReorderContextMessages()`
|
|
61
|
-
- `restorePromptContent()`
|
|
62
|
-
|
|
63
|
-
### Shared registries
|
|
64
|
-
|
|
65
|
-
- context-provider registry for `/supi-context`
|
|
66
|
-
- debug-event registry for producers that want shared debug capture
|
|
67
|
-
- settings registry used by `/supi-settings`
|
|
68
|
-
|
|
69
|
-
### Project and session helpers
|
|
70
|
-
|
|
71
|
-
- project-root detection and directory walking helpers such as `findProjectRoot()` and `walkProject()`
|
|
72
|
-
- active-branch session helper: `getActiveBranchEntries()`
|
|
73
|
-
- terminal helpers such as `formatTitle()`, `signalWaiting()`, and `signalDone()`
|
|
74
|
-
|
|
75
|
-
### Report helpers
|
|
76
|
-
|
|
77
|
-
- `clampReportWidth()` — enforce a minimum readable report width
|
|
78
|
-
- `formatReportTitle()` / `formatSectionHeader()` — shared themed headers
|
|
79
|
-
- `formatDimLine()` / `formatKeyValueLine()` — common summary rows
|
|
80
|
-
- `formatOverflowHint()` — consistent preview-overflow hints
|
|
81
|
-
- `wrapReportText()` — ANSI-aware wrapped report blocks with optional indentation
|
|
82
|
-
|
|
83
|
-
## Example
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
87
|
-
import { loadSupiConfig, registerDeclarativeSettings, wrapExtensionContext } from "@mrclrchtr/supi-core/api";
|
|
88
|
-
|
|
89
|
-
export default function myExtension(pi: ExtensionAPI) {
|
|
90
|
-
const defaults = { enabled: true };
|
|
91
|
-
const config = loadSupiConfig("my-extension", process.cwd(), defaults);
|
|
92
|
-
|
|
93
|
-
registerDeclarativeSettings(pi, {
|
|
94
|
-
id: "my-extension",
|
|
95
|
-
label: "My Extension",
|
|
96
|
-
section: "my-extension",
|
|
97
|
-
defaults,
|
|
98
|
-
fields: [
|
|
99
|
-
{
|
|
100
|
-
kind: "boolean" as const,
|
|
101
|
-
key: "enabled",
|
|
102
|
-
label: "Enabled",
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const message = wrapExtensionContext("my-extension", "hello", {
|
|
108
|
-
enabled: config.enabled,
|
|
109
|
-
});
|
|
110
|
-
void message;
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Source
|
|
115
|
-
|
|
116
|
-
- `src/api.ts` — exported library surface
|
|
117
|
-
- `src/config.ts` — shared config loading and writing
|
|
118
|
-
- `src/config-settings.ts` — config-backed settings registration helper
|
|
119
|
-
- `src/settings-ui.ts` — shared settings overlay
|
|
120
|
-
- `src/report.ts` — shared text/report rendering helpers
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mrclrchtr/supi-core",
|
|
3
|
-
"version": "4.7.0",
|
|
4
|
-
"description": "Shared settings, configuration, reporting, and session infrastructure",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/mrclrchtr/supi.git",
|
|
9
|
-
"directory": "packages/supi-core"
|
|
10
|
-
},
|
|
11
|
-
"homepage": "https://github.com/mrclrchtr/supi/tree/main/packages/supi-core#readme",
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/mrclrchtr/supi/issues"
|
|
14
|
-
},
|
|
15
|
-
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [
|
|
19
|
-
"pi",
|
|
20
|
-
"pi-coding-agent",
|
|
21
|
-
"supi",
|
|
22
|
-
"extension-utils",
|
|
23
|
-
"settings",
|
|
24
|
-
"configuration"
|
|
25
|
-
],
|
|
26
|
-
"type": "module",
|
|
27
|
-
"files": [
|
|
28
|
-
"src/**/*.ts",
|
|
29
|
-
"!__tests__"
|
|
30
|
-
],
|
|
31
|
-
"peerDependencies": {
|
|
32
|
-
"@earendil-works/pi-ai": "*",
|
|
33
|
-
"@earendil-works/pi-coding-agent": "*",
|
|
34
|
-
"@earendil-works/pi-tui": "*",
|
|
35
|
-
"typebox": "*"
|
|
36
|
-
},
|
|
37
|
-
"peerDependenciesMeta": {
|
|
38
|
-
"@earendil-works/pi-ai": {
|
|
39
|
-
"optional": true
|
|
40
|
-
},
|
|
41
|
-
"@earendil-works/pi-coding-agent": {
|
|
42
|
-
"optional": true
|
|
43
|
-
},
|
|
44
|
-
"@earendil-works/pi-tui": {
|
|
45
|
-
"optional": true
|
|
46
|
-
},
|
|
47
|
-
"typebox": {
|
|
48
|
-
"optional": true
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
"main": "src/api.ts",
|
|
52
|
-
"exports": {
|
|
53
|
-
"./api": "./src/api.ts",
|
|
54
|
-
"./config": "./src/config.ts",
|
|
55
|
-
"./context": "./src/context.ts",
|
|
56
|
-
"./debug": "./src/debug-registry.ts",
|
|
57
|
-
"./evidence-badge": "./src/evidence-badge.ts",
|
|
58
|
-
"./footer-registry": "./src/footer-registry.ts",
|
|
59
|
-
"./llm": "./src/llm.ts",
|
|
60
|
-
"./model-selection": "./src/model-selection.ts",
|
|
61
|
-
"./package.json": "./package.json",
|
|
62
|
-
"./path": "./src/path.ts",
|
|
63
|
-
"./report": "./src/report.ts",
|
|
64
|
-
"./progress-widget": "./src/progress-widget.ts",
|
|
65
|
-
"./project": "./src/project.ts",
|
|
66
|
-
"./session": "./src/session.ts",
|
|
67
|
-
"./settings": "./src/settings.ts",
|
|
68
|
-
"./settings-ui": "./src/settings-ui.ts",
|
|
69
|
-
"./spinner-frames": "./src/spinner-frames.ts",
|
|
70
|
-
"./status-spinner": "./src/status-spinner.ts",
|
|
71
|
-
"./terminal": "./src/terminal.ts",
|
|
72
|
-
"./tool-framework": "./src/tool-framework.ts",
|
|
73
|
-
"./prompt-surface": "./src/prompt-surface.ts"
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// supi-core — shared infrastructure for SuPi extensions.
|
|
2
|
-
// Provides XML context tag wrapping, unified config system, context-message utilities,
|
|
3
|
-
// settings registry for supi-wide TUI settings, and a shared tool-spec/registration framework.
|
|
4
|
-
//
|
|
5
|
-
// Convenience barrel — re-exports all domain entry points.
|
|
6
|
-
// For lighter imports, use one of the domain subpaths directly
|
|
7
|
-
// (e.g. @mrclrchtr/supi-core/config, @mrclrchtr/supi-core/context).
|
|
8
|
-
|
|
9
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
10
|
-
export * from "./config.ts";
|
|
11
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
12
|
-
export * from "./context.ts";
|
|
13
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
14
|
-
export * from "./debug-registry.ts";
|
|
15
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
16
|
-
export * from "./evidence-badge.ts";
|
|
17
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
18
|
-
export * from "./footer-registry.ts";
|
|
19
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
20
|
-
export * from "./llm.ts";
|
|
21
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
22
|
-
export * from "./model-selection.ts";
|
|
23
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
24
|
-
export * from "./path.ts";
|
|
25
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
26
|
-
export * from "./project.ts";
|
|
27
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
28
|
-
export * from "./report.ts";
|
|
29
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
30
|
-
export * from "./session.ts";
|
|
31
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
32
|
-
export * from "./settings.ts";
|
|
33
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
34
|
-
export * from "./settings-ui.ts";
|
|
35
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
36
|
-
export * from "./spinner-frames.ts";
|
|
37
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
38
|
-
export * from "./status-spinner.ts";
|
|
39
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
40
|
-
export * from "./terminal.ts";
|
|
41
|
-
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
42
|
-
export * from "./tool-framework.ts";
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// Shared config system for SuPi extensions.
|
|
2
|
-
//
|
|
3
|
-
// Global config: ~/.pi/agent/supi/config.json
|
|
4
|
-
// Project config: .pi/supi/config.json (relative to cwd)
|
|
5
|
-
// Resolution: hardcoded defaults ← global ← project
|
|
6
|
-
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import * as os from "node:os";
|
|
9
|
-
import * as path from "node:path";
|
|
10
|
-
import { CONFIG_DIR_NAME } from "@earendil-works/pi-coding-agent";
|
|
11
|
-
|
|
12
|
-
const GLOBAL_CONFIG_DIR = `${CONFIG_DIR_NAME}/agent/supi`;
|
|
13
|
-
const PROJECT_CONFIG_DIR = `${CONFIG_DIR_NAME}/supi`;
|
|
14
|
-
const CONFIG_FILE = "config.json";
|
|
15
|
-
|
|
16
|
-
function getGlobalConfigPath(homeDir?: string): string {
|
|
17
|
-
return path.join(homeDir ?? os.homedir(), GLOBAL_CONFIG_DIR, CONFIG_FILE);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getProjectConfigPath(cwd: string): string {
|
|
21
|
-
return path.join(cwd, PROJECT_CONFIG_DIR, CONFIG_FILE);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Return the SuPi config file path for one scope. */
|
|
25
|
-
export function getSupiConfigPath(
|
|
26
|
-
scope: "global" | "project",
|
|
27
|
-
cwd: string,
|
|
28
|
-
options?: SupiConfigOptions,
|
|
29
|
-
): string {
|
|
30
|
-
return scope === "global" ? getGlobalConfigPath(options?.homeDir) : getProjectConfigPath(cwd);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function readJsonFile(filePath: string): Record<string, unknown> | null {
|
|
34
|
-
let content: string;
|
|
35
|
-
try {
|
|
36
|
-
content = fs.readFileSync(filePath, "utf-8");
|
|
37
|
-
} catch {
|
|
38
|
-
// ENOENT or permission error — silent, file may not exist
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let parsed: unknown;
|
|
43
|
-
try {
|
|
44
|
-
parsed = JSON.parse(content);
|
|
45
|
-
} catch {
|
|
46
|
-
// biome-ignore lint/suspicious/noConsole: deliberate config parse warning
|
|
47
|
-
console.warn(`[supi-core] Failed to parse config file, ignoring: ${filePath}`);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
52
|
-
return parsed as Record<string, unknown>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// biome-ignore lint/suspicious/noConsole: deliberate config parse warning
|
|
56
|
-
console.warn(`[supi-core] Config file root is not an object, ignoring: ${filePath}`);
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function shallowMerge<T>(base: T, ...overrides: Array<Record<string, unknown> | null>): T {
|
|
61
|
-
let result = { ...base };
|
|
62
|
-
for (const override of overrides) {
|
|
63
|
-
if (!override) continue;
|
|
64
|
-
result = { ...result, ...override };
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface SupiConfigOptions {
|
|
70
|
-
homeDir?: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Load and merge config for a given extension section.
|
|
75
|
-
*
|
|
76
|
-
* Resolution order: defaults ← global ← project
|
|
77
|
-
*/
|
|
78
|
-
export function loadSupiConfig<T>(
|
|
79
|
-
section: string,
|
|
80
|
-
cwd: string,
|
|
81
|
-
defaults: T,
|
|
82
|
-
options?: SupiConfigOptions,
|
|
83
|
-
): T {
|
|
84
|
-
const globalConfig = readJsonFile(getGlobalConfigPath(options?.homeDir));
|
|
85
|
-
const projectConfig = readJsonFile(getProjectConfigPath(cwd));
|
|
86
|
-
|
|
87
|
-
const globalSection = extractSection(globalConfig, section);
|
|
88
|
-
const projectSection = extractSection(projectConfig, section);
|
|
89
|
-
|
|
90
|
-
return shallowMerge(defaults, globalSection, projectSection);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Load config for a single scope only.
|
|
95
|
-
*
|
|
96
|
-
* Resolution order: defaults ← selected scope
|
|
97
|
-
*
|
|
98
|
-
* This is useful for settings UIs that need to show the raw values stored in
|
|
99
|
-
* one scope, rather than the effective merged config.
|
|
100
|
-
*/
|
|
101
|
-
export function loadSupiConfigForScope<T>(
|
|
102
|
-
section: string,
|
|
103
|
-
cwd: string,
|
|
104
|
-
defaults: T,
|
|
105
|
-
options: { scope: "global" | "project" } & SupiConfigOptions,
|
|
106
|
-
): T {
|
|
107
|
-
const config = readJsonFile(getSupiConfigPath(options.scope, cwd, { homeDir: options.homeDir }));
|
|
108
|
-
|
|
109
|
-
const scopedSection = extractSection(config, section);
|
|
110
|
-
return shallowMerge(defaults, scopedSection);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Load the raw object for one config section and one scope. */
|
|
114
|
-
export function loadSupiConfigSectionForScope(
|
|
115
|
-
section: string,
|
|
116
|
-
cwd: string,
|
|
117
|
-
options: { scope: "global" | "project" } & SupiConfigOptions,
|
|
118
|
-
): Record<string, unknown> | null {
|
|
119
|
-
const config = readJsonFile(getSupiConfigPath(options.scope, cwd, { homeDir: options.homeDir }));
|
|
120
|
-
return extractSection(config, section);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export interface SupiConfigLocation {
|
|
124
|
-
section: string;
|
|
125
|
-
scope: "global" | "project";
|
|
126
|
-
cwd: string;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Write config values for a given extension section.
|
|
131
|
-
*/
|
|
132
|
-
export function writeSupiConfig(
|
|
133
|
-
loc: SupiConfigLocation,
|
|
134
|
-
value: Record<string, unknown>,
|
|
135
|
-
options?: SupiConfigOptions,
|
|
136
|
-
): void {
|
|
137
|
-
const configPath = getSupiConfigPath(loc.scope, loc.cwd, options);
|
|
138
|
-
|
|
139
|
-
const dir = path.dirname(configPath);
|
|
140
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
141
|
-
|
|
142
|
-
const existing = readJsonFile(configPath) ?? {};
|
|
143
|
-
existing[loc.section] = {
|
|
144
|
-
...((existing[loc.section] as Record<string, unknown>) ?? {}),
|
|
145
|
-
...value,
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
fs.writeFileSync(configPath, `${JSON.stringify(existing, null, 2)}\n`, "utf-8");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Remove a key from a config section.
|
|
153
|
-
* Used by `interval default` to remove the project override.
|
|
154
|
-
*/
|
|
155
|
-
export function removeSupiConfigKey(
|
|
156
|
-
loc: SupiConfigLocation,
|
|
157
|
-
key: string,
|
|
158
|
-
options?: SupiConfigOptions,
|
|
159
|
-
): void {
|
|
160
|
-
const configPath = getSupiConfigPath(loc.scope, loc.cwd, options);
|
|
161
|
-
|
|
162
|
-
const existing = readJsonFile(configPath);
|
|
163
|
-
if (!existing) return;
|
|
164
|
-
|
|
165
|
-
const sectionData = existing[loc.section] as Record<string, unknown> | undefined;
|
|
166
|
-
if (!sectionData) return;
|
|
167
|
-
|
|
168
|
-
delete sectionData[key];
|
|
169
|
-
|
|
170
|
-
if (Object.keys(sectionData).length === 0) {
|
|
171
|
-
delete existing[loc.section];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const dir = path.dirname(configPath);
|
|
175
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
176
|
-
|
|
177
|
-
const content = Object.keys(existing).length > 0 ? `${JSON.stringify(existing, null, 2)}\n` : "";
|
|
178
|
-
|
|
179
|
-
if (content) {
|
|
180
|
-
// Directory guaranteed to exist since we just read from it
|
|
181
|
-
fs.writeFileSync(configPath, content, "utf-8");
|
|
182
|
-
} else {
|
|
183
|
-
try {
|
|
184
|
-
fs.unlinkSync(configPath);
|
|
185
|
-
} catch {
|
|
186
|
-
// File may not exist
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function extractSection(
|
|
192
|
-
config: Record<string, unknown> | null,
|
|
193
|
-
section: string,
|
|
194
|
-
): Record<string, unknown> | null {
|
|
195
|
-
if (!config) return null;
|
|
196
|
-
const data = config[section];
|
|
197
|
-
if (typeof data === "object" && data !== null && !Array.isArray(data)) {
|
|
198
|
-
return data as Record<string, unknown>;
|
|
199
|
-
}
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Shorthand for {@link loadSupiConfig} that infers the return type from defaults.
|
|
205
|
-
*
|
|
206
|
-
* Reduces boilerplate when a package only needs the merged runtime config.
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* const config = loadSectionConfig("my-ext", cwd, { enabled: true, timeout: 30 });
|
|
211
|
-
* // config is typed as { enabled: boolean; timeout: number }
|
|
212
|
-
* ```
|
|
213
|
-
*/
|
|
214
|
-
export function loadSectionConfig<T extends Record<string, unknown>>(
|
|
215
|
-
section: string,
|
|
216
|
-
cwd: string,
|
|
217
|
-
defaults: T,
|
|
218
|
-
options?: SupiConfigOptions,
|
|
219
|
-
): T {
|
|
220
|
-
return loadSupiConfig(section, cwd, defaults, options);
|
|
221
|
-
}
|