@rol1n/pi-kit 0.0.0-stage → 0.1.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/README.md +73 -2
- package/ask-u-questions/README.md +26 -0
- package/ask-u-questions/dialog-ui.ts +80 -0
- package/ask-u-questions/index.ts +92 -0
- package/ask-u-questions/multi-choice.ts +258 -0
- package/ask-u-questions/single-choice.ts +180 -0
- package/ask-u-questions/tool-renderers.ts +67 -0
- package/ask-u-questions/types.ts +192 -0
- package/continue-signal/README.md +20 -0
- package/continue-signal/index.ts +69 -0
- package/custom-providers/README.md +20 -0
- package/custom-providers/asr/handlers/dashscope.ts +154 -0
- package/custom-providers/asr/index.ts +37 -0
- package/custom-providers/asr/models.ts +18 -0
- package/custom-providers/asr/types.ts +20 -0
- package/custom-providers/chat/index.ts +33 -0
- package/custom-providers/chat/magpie.ts +258 -0
- package/custom-providers/chat/models.ts +111 -0
- package/custom-providers/classifier/index.ts +6 -0
- package/custom-providers/classifier/models.ts +1 -0
- package/custom-providers/image/handlers/dashscope.ts +240 -0
- package/custom-providers/image/handlers/openrouter.ts +185 -0
- package/custom-providers/image/index.ts +96 -0
- package/custom-providers/image/models.ts +71 -0
- package/custom-providers/image/types.ts +22 -0
- package/custom-providers/index.ts +64 -0
- package/custom-providers/types.ts +17 -0
- package/image-generate/README.md +25 -0
- package/image-generate/files.ts +49 -0
- package/image-generate/index.ts +220 -0
- package/image-generate/model-selector.ts +150 -0
- package/memory-log/README.md +54 -0
- package/memory-log/agent/consolidator/prompt.ts +47 -0
- package/memory-log/agent/consolidator/tools.ts +160 -0
- package/memory-log/agent/cost.ts +32 -0
- package/memory-log/agent/index.ts +42 -0
- package/memory-log/agent/observer/prompt.ts +73 -0
- package/memory-log/agent/observer/tool.ts +73 -0
- package/memory-log/commands/compact.ts +35 -0
- package/memory-log/commands/consolidate.ts +47 -0
- package/memory-log/commands/status.ts +50 -0
- package/memory-log/config.ts +253 -0
- package/memory-log/debug-log.ts +76 -0
- package/memory-log/hooks/compaction-hook.ts +161 -0
- package/memory-log/hooks/compaction-trigger.ts +160 -0
- package/memory-log/hooks/consolidator-trigger.ts +143 -0
- package/memory-log/hooks/observer-trigger.ts +176 -0
- package/memory-log/ids.ts +78 -0
- package/memory-log/index.ts +149 -0
- package/memory-log/ledger/fold.ts +77 -0
- package/memory-log/ledger/index.ts +7 -0
- package/memory-log/ledger/pool.ts +38 -0
- package/memory-log/ledger/progress.ts +181 -0
- package/memory-log/ledger/projection.ts +115 -0
- package/memory-log/ledger/render.ts +38 -0
- package/memory-log/ledger/serialize.ts +161 -0
- package/memory-log/ledger/types.ts +201 -0
- package/memory-log/memory/index-render.ts +45 -0
- package/memory-log/memory/paths.ts +120 -0
- package/memory-log/memory/session.ts +64 -0
- package/memory-log/runtime.ts +127 -0
- package/memory-log/spawn/launch.ts +133 -0
- package/memory-log/spawn/runs.ts +83 -0
- package/memory-log/tokens.ts +66 -0
- package/memory-log/ui/status-controller.ts +225 -0
- package/memory-log/ui/timeline.ts +103 -0
- package/model-vision/README.md +22 -0
- package/multi-harness/README.md +63 -0
- package/multi-harness/adapters.mjs +72 -0
- package/multi-harness/harness-done.mjs +14 -0
- package/multi-harness/index.ts +375 -0
- package/multi-harness/ipc.mjs +37 -0
- package/multi-harness/opencode-plugin.mjs +99 -0
- package/multi-harness/process-runner.mjs +115 -0
- package/multi-harness/turn-hook.mjs +29 -0
- package/multi-harness/worker-bridge.ts +52 -0
- package/oai-subquota/README.md +22 -0
- package/oai-subquota/index.ts +286 -0
- package/oai-subquota/snapshot.ts +293 -0
- package/oai-subquota/ui.ts +183 -0
- package/package.json +92 -4
- package/prompt-snipaste/README.md +27 -0
- package/prompt-snipaste/index.ts +143 -0
- package/prompt-snipaste/menu.ts +159 -0
- package/prompt-snipaste/prompts/ask-questions.md +8 -0
- package/prompt-snipaste/prompts/delegate-exploration.md +7 -0
- package/prompt-snipaste/prompts/diagnose-report.md +7 -0
- package/prompt-snipaste/prompts/frontend-tech-preset.md +18 -0
- package/prompt-snipaste/prompts/orchestrator-mode.md +7 -0
- package/prompt-snipaste/prompts/session-kickoff.md +7 -0
- package/prompt-snipaste/prompts/verify-not-assume.md +7 -0
- package/prompt-snipaste/renderers.ts +87 -0
- package/prompt-snipaste/snippets.ts +206 -0
- package/prompt-snipaste/types.ts +18 -0
- package/screenshot/README.md +14 -0
- package/srp-theme/README.md +18 -0
- package/srp-theme/footer.ts +193 -0
- package/srp-theme/index.ts +172 -0
- package/srp-theme/tps-meter.ts +441 -0
- package/subagent/README.md +35 -0
- package/subagent/bridge.ts +171 -0
- package/subagent/index.ts +590 -0
- package/subagent/mux.ts +621 -0
- package/subagent/session.ts +166 -0
- package/subagent/ui.ts +100 -0
- package/tui-asr/README.md +21 -0
- package/tui-asr/dictation.ts +272 -0
- package/tui-asr/index.ts +181 -0
- package/tui-asr/input.ts +87 -0
- package/tui-asr/model-selector.ts +163 -0
- package/tui-asr/status.ts +79 -0
- package/web-reach/README.md +19 -0
- package/web-reach/html.ts +83 -0
- package/web-reach/index.ts +82 -0
- package/web-reach/page.ts +214 -0
- package/web-reach/rsc.ts +161 -0
- package/web-reach/search.ts +85 -0
- package/web-reach/transport.ts +35 -0
- package/windows-wheel-fix/README.md +12 -0
- package/windows-wheel-fix/index.ts +44 -0
package/tui-asr/index.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tui-asr — Terminal streaming ASR voice dictation extension for Pi.
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* 1. Streaming ASR: Real-time recognition using Aliyun DashScope Paraformer WebSocket.
|
|
6
|
+
* 2. Visual metering: Animated braille volume level waveform (● ⣀⣄ listening…).
|
|
7
|
+
* 3. Native Pi auth: Resolves keys from `/login dashscope` (auth.json) or DASHSCOPE_API_KEY.
|
|
8
|
+
* 4. Model selector: Native Pi-style searchable TUI selector dialog (/asr model).
|
|
9
|
+
* 5. Input injection: Directly inserts text into active editor or clipboard.
|
|
10
|
+
*
|
|
11
|
+
* Keybindings:
|
|
12
|
+
* - Alt+M: Start / Stop voice dictation
|
|
13
|
+
* - Alt+N: Cancel current dictation
|
|
14
|
+
*
|
|
15
|
+
* Commands:
|
|
16
|
+
* - /asr: Toggle voice dictation
|
|
17
|
+
* - /asr model [name]: Interactive searchable model selector
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
21
|
+
import type { AutocompleteItem } from "@earendil-works/pi-tui";
|
|
22
|
+
import { ALL_ASR_MODELS, createDictationController, ensureCustomProviders, resolveProviderApiKey, type AsrModelDefinition } from "./dictation.ts";
|
|
23
|
+
import { SearchableAsrModelSelectorComponent } from "./model-selector.ts";
|
|
24
|
+
|
|
25
|
+
/** Default startup ASR model ID */
|
|
26
|
+
const DEFAULT_ASR_MODEL = "paraformer-realtime-v2";
|
|
27
|
+
|
|
28
|
+
/** Default shortcuts */
|
|
29
|
+
const TOGGLE_SHORTCUTS = ["alt+m"];
|
|
30
|
+
const CANCEL_SHORTCUTS = ["alt+n"];
|
|
31
|
+
|
|
32
|
+
export default function (pi: ExtensionAPI) {
|
|
33
|
+
ensureCustomProviders(pi);
|
|
34
|
+
let activeModel = DEFAULT_ASR_MODEL;
|
|
35
|
+
|
|
36
|
+
// TUI state
|
|
37
|
+
let tuiHandle: any = null;
|
|
38
|
+
let removeInputListener: (() => void) | null = null;
|
|
39
|
+
let lastCtx: ExtensionContext | null = null;
|
|
40
|
+
|
|
41
|
+
const dictation = createDictationController(() => activeModel, () => tuiHandle);
|
|
42
|
+
const { startDictation, stopDictation, cancelDictation, toggleDictation, cleanup } = dictation;
|
|
43
|
+
|
|
44
|
+
// Key interception
|
|
45
|
+
const ensureTuiAttached = (ctx: ExtensionContext) => {
|
|
46
|
+
lastCtx = ctx;
|
|
47
|
+
if (ctx.mode === "tui" && !removeInputListener && typeof ctx.ui?.onTerminalInput === "function") {
|
|
48
|
+
removeInputListener = ctx.ui.onTerminalInput((keyData) => {
|
|
49
|
+
const matchesAny = (list: string[]) =>
|
|
50
|
+
list.some((s) => {
|
|
51
|
+
const raw = s.toLowerCase().trim();
|
|
52
|
+
if (raw === "alt+m" && (keyData === "\x1bm" || keyData === "µ")) return true;
|
|
53
|
+
if (raw === "alt+n" && (keyData === "\x1bn" || keyData === "Å")) return true;
|
|
54
|
+
return false;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (matchesAny(TOGGLE_SHORTCUTS)) {
|
|
58
|
+
if (dictation.state === "idle") startDictation(ctx);
|
|
59
|
+
else if (dictation.state === "recording") stopDictation();
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (matchesAny(CANCEL_SHORTCUTS)) {
|
|
64
|
+
if (dictation.state !== "idle") {
|
|
65
|
+
cancelDictation();
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return undefined;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
pi.on("session_start", (_event, ctx) => {
|
|
76
|
+
ensureTuiAttached(ctx);
|
|
77
|
+
if (ctx.mode === "tui") {
|
|
78
|
+
ctx.ui.setWidget("tui-asr-handle", (tui: any) => {
|
|
79
|
+
tuiHandle = tui;
|
|
80
|
+
return {
|
|
81
|
+
render: () => [],
|
|
82
|
+
invalidate: () => {},
|
|
83
|
+
dispose: () => {
|
|
84
|
+
tuiHandle = null;
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Register shortcuts
|
|
92
|
+
pi.registerShortcut("alt+m", {
|
|
93
|
+
description: "Toggle voice dictation (tui-asr)",
|
|
94
|
+
handler: async (ctx) => {
|
|
95
|
+
ensureTuiAttached(ctx);
|
|
96
|
+
await toggleDictation(ctx);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
pi.registerShortcut("alt+n", {
|
|
101
|
+
description: "Cancel voice dictation (tui-asr)",
|
|
102
|
+
handler: async (ctx) => {
|
|
103
|
+
ensureTuiAttached(ctx);
|
|
104
|
+
cancelDictation();
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Register command /asr
|
|
109
|
+
pi.registerCommand("asr", {
|
|
110
|
+
description: "Voice dictation control and model switching (/asr [model])",
|
|
111
|
+
getArgumentCompletions: (prefix: string): AutocompleteItem[] | null => {
|
|
112
|
+
const trimmed = prefix.trimStart();
|
|
113
|
+
if (!trimmed || "model".startsWith(trimmed)) {
|
|
114
|
+
return [{ value: "model", label: "model", description: "Select ASR voice model in TUI" }];
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
},
|
|
118
|
+
handler: async (args, ctx) => {
|
|
119
|
+
ensureTuiAttached(ctx);
|
|
120
|
+
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
121
|
+
const sub = parts[0]?.toLowerCase();
|
|
122
|
+
|
|
123
|
+
if (sub === "model") {
|
|
124
|
+
const modelArg = parts[1]?.toLowerCase();
|
|
125
|
+
if (modelArg) {
|
|
126
|
+
const matched = ALL_ASR_MODELS.find(
|
|
127
|
+
(m) =>
|
|
128
|
+
m.id.toLowerCase() === modelArg ||
|
|
129
|
+
m.name.toLowerCase() === modelArg ||
|
|
130
|
+
m.id.toLowerCase().includes(modelArg),
|
|
131
|
+
);
|
|
132
|
+
if (matched) {
|
|
133
|
+
activeModel = matched.id;
|
|
134
|
+
const isLogged = Boolean(await resolveProviderApiKey(matched.provider, ctx));
|
|
135
|
+
const extra = isLogged ? "" : ` (No key detected: please run /login ${matched.provider})`;
|
|
136
|
+
ctx.ui.notify(`ASR model switched to: ${matched.name} (${matched.id})${extra}`, "info");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Open searchable model selector TUI
|
|
142
|
+
const loginStatusMap = new Map<string, boolean>();
|
|
143
|
+
for (const item of ALL_ASR_MODELS) {
|
|
144
|
+
if (!loginStatusMap.has(item.provider)) {
|
|
145
|
+
const key = await resolveProviderApiKey(item.provider, ctx);
|
|
146
|
+
loginStatusMap.set(item.provider, Boolean(key));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const selected = await ctx.ui.custom<AsrModelDefinition | undefined>((tui, theme, _kb, done) => {
|
|
151
|
+
return new SearchableAsrModelSelectorComponent(
|
|
152
|
+
tui,
|
|
153
|
+
theme,
|
|
154
|
+
ALL_ASR_MODELS,
|
|
155
|
+
activeModel,
|
|
156
|
+
(model) => done(model),
|
|
157
|
+
() => done(undefined),
|
|
158
|
+
(provider) => loginStatusMap.get(provider) ?? false,
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (!selected) return;
|
|
163
|
+
|
|
164
|
+
activeModel = selected.id;
|
|
165
|
+
const isLogged = loginStatusMap.get(selected.provider);
|
|
166
|
+
const extra = isLogged ? "" : ` (No key detected: please run /login ${selected.provider})`;
|
|
167
|
+
ctx.ui.notify(`ASR model switched to: ${selected.name} (${selected.id})${extra}`, "info");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Default action: toggle dictation
|
|
172
|
+
await toggleDictation(ctx);
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
pi.on("session_shutdown", () => {
|
|
177
|
+
if (dictation.state !== "idle") cleanup();
|
|
178
|
+
removeInputListener?.();
|
|
179
|
+
removeInputListener = null;
|
|
180
|
+
});
|
|
181
|
+
}
|
package/tui-asr/input.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { spawn, type ChildProcessByStdio } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
export function copyToClipboard(text: string): boolean {
|
|
5
|
+
try {
|
|
6
|
+
const isWsl =
|
|
7
|
+
process.platform === "linux" &&
|
|
8
|
+
typeof process.env.WSL_DISTRO_NAME === "string";
|
|
9
|
+
|
|
10
|
+
let proc: ChildProcessByStdio<any, any, any>;
|
|
11
|
+
if (isWsl) {
|
|
12
|
+
proc = spawn("clip.exe", [], { stdio: ["pipe", "ignore", "ignore"] });
|
|
13
|
+
} else if (process.platform === "win32") {
|
|
14
|
+
proc = spawn("clip", [], { stdio: ["pipe", "ignore", "ignore"] });
|
|
15
|
+
} else if (process.platform === "darwin") {
|
|
16
|
+
proc = spawn("pbcopy", [], { stdio: ["pipe", "ignore", "ignore"] });
|
|
17
|
+
} else {
|
|
18
|
+
try {
|
|
19
|
+
proc = spawn("wl-copy", [], { stdio: ["pipe", "ignore", "ignore"] });
|
|
20
|
+
} catch {
|
|
21
|
+
proc = spawn("xclip", ["-selection", "clipboard"], { stdio: ["pipe", "ignore", "ignore"] });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
proc.stdin.write(text);
|
|
26
|
+
proc.stdin.end();
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface EditorLike {
|
|
34
|
+
getText(): string;
|
|
35
|
+
setText(text: string): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type Target =
|
|
39
|
+
| { kind: "editor"; editor: EditorLike }
|
|
40
|
+
| { kind: "typable"; component: { handleInput(data: string): void } };
|
|
41
|
+
|
|
42
|
+
const asEditorLike = (value: any): EditorLike | null =>
|
|
43
|
+
value && typeof value.getText === "function" && typeof value.setText === "function" ? value : null;
|
|
44
|
+
|
|
45
|
+
function resolveTarget(tuiHandle: any): Target | null {
|
|
46
|
+
const focused = tuiHandle?.focusedComponent;
|
|
47
|
+
if (!focused) return null;
|
|
48
|
+
const editor = asEditorLike(focused) ?? asEditorLike(focused.editor);
|
|
49
|
+
if (editor) return { kind: "editor", editor };
|
|
50
|
+
if (typeof focused.handleInput === "function") return { kind: "typable", component: focused };
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Insert a final transcript into the focused input, with editor and clipboard fallbacks. */
|
|
55
|
+
export function insertTranscript(ctx: ExtensionContext, tuiHandle: any, text: string): void {
|
|
56
|
+
// 1. Fallback: append to main editor if no TUI handle
|
|
57
|
+
if (!tuiHandle) {
|
|
58
|
+
const current = ctx.ui.getEditorText() ?? "";
|
|
59
|
+
const sep = current && !/\s$/.test(current) ? " " : "";
|
|
60
|
+
ctx.ui.setEditorText(current + sep + text);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 2. Insert into focused editor or typable component
|
|
65
|
+
const target = resolveTarget(tuiHandle);
|
|
66
|
+
if (target?.kind === "editor") {
|
|
67
|
+
const current = target.editor.getText() ?? "";
|
|
68
|
+
const sep = current && !/\s$/.test(current) ? " " : "";
|
|
69
|
+
target.editor.setText(current + sep + text);
|
|
70
|
+
tuiHandle.requestRender?.();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (target?.kind === "typable") {
|
|
75
|
+
target.component.handleInput(text);
|
|
76
|
+
tuiHandle.requestRender?.();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 3. Fallback: copy to clipboard if no input focused
|
|
81
|
+
const copied = copyToClipboard(text);
|
|
82
|
+
if (copied) {
|
|
83
|
+
ctx.ui.notify("Dictated text copied to clipboard (no input focused)", "info");
|
|
84
|
+
} else {
|
|
85
|
+
ctx.ui.notify(`Dictated: ${text}`, "info");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Input, fuzzyFilter, getKeybindings } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { AsrModelDefinition } from "./dictation.ts";
|
|
3
|
+
|
|
4
|
+
export class SearchableAsrModelSelectorComponent {
|
|
5
|
+
private searchInput = new Input();
|
|
6
|
+
private selectedIndex = 0;
|
|
7
|
+
private filteredModels: AsrModelDefinition[] = [];
|
|
8
|
+
private _focused = true;
|
|
9
|
+
private cachedLines?: string[];
|
|
10
|
+
private cachedWidth = -1;
|
|
11
|
+
|
|
12
|
+
get focused() {
|
|
13
|
+
return this._focused;
|
|
14
|
+
}
|
|
15
|
+
set focused(value: boolean) {
|
|
16
|
+
this._focused = value;
|
|
17
|
+
this.searchInput.focused = value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
private tui: any,
|
|
22
|
+
private theme: any,
|
|
23
|
+
private models: AsrModelDefinition[],
|
|
24
|
+
private currentModelId: string,
|
|
25
|
+
private onSelect: (model: AsrModelDefinition) => void,
|
|
26
|
+
private onCancel: () => void,
|
|
27
|
+
private getLoginStatus?: (provider: string) => boolean,
|
|
28
|
+
) {
|
|
29
|
+
this.filteredModels = [...models];
|
|
30
|
+
const curIdx = models.findIndex((m) => m.id === currentModelId);
|
|
31
|
+
this.selectedIndex = curIdx >= 0 ? curIdx : 0;
|
|
32
|
+
this.searchInput.focused = true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private refresh() {
|
|
36
|
+
this.cachedLines = undefined;
|
|
37
|
+
this.tui.requestRender?.();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
filterModels(query: string) {
|
|
41
|
+
const q = query.trim().toLowerCase();
|
|
42
|
+
if (q) {
|
|
43
|
+
this.filteredModels = fuzzyFilter(
|
|
44
|
+
this.models,
|
|
45
|
+
q,
|
|
46
|
+
(m) => `${m.id} ${m.name} ${m.provider} ${m.description}`,
|
|
47
|
+
);
|
|
48
|
+
} else {
|
|
49
|
+
this.filteredModels = [...this.models];
|
|
50
|
+
}
|
|
51
|
+
this.selectedIndex = q ? 0 : Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));
|
|
52
|
+
this.refresh();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
render(width: number): string[] {
|
|
56
|
+
if (this.cachedLines && this.cachedWidth === width) return this.cachedLines;
|
|
57
|
+
|
|
58
|
+
const lines: string[] = [];
|
|
59
|
+
const border = this.theme.fg("accent", "─".repeat(Math.max(10, width)));
|
|
60
|
+
|
|
61
|
+
lines.push(border);
|
|
62
|
+
lines.push("");
|
|
63
|
+
|
|
64
|
+
// Scope & credentials status line (matching Pi native selector screenshot)
|
|
65
|
+
const scopeTitle = `${this.theme.fg("muted", "Scope: ")}${this.theme.fg("accent", "all")}${this.theme.fg("muted", " | dashscope")}`;
|
|
66
|
+
lines.push(` ${scopeTitle}`);
|
|
67
|
+
|
|
68
|
+
if (this.getLoginStatus) {
|
|
69
|
+
const loggedIn = this.getLoginStatus("dashscope");
|
|
70
|
+
const authStatus = loggedIn
|
|
71
|
+
? this.theme.fg("success", "✓ DashScope credentials: ready (via /login dashscope)")
|
|
72
|
+
: this.theme.fg("warning", "! DashScope credentials: not logged in (run /login dashscope)");
|
|
73
|
+
lines.push(` ${authStatus}`);
|
|
74
|
+
}
|
|
75
|
+
lines.push("");
|
|
76
|
+
|
|
77
|
+
// Search input line (> █)
|
|
78
|
+
for (const l of this.searchInput.render(Math.max(1, width - 4))) {
|
|
79
|
+
lines.push(` ${l}`);
|
|
80
|
+
}
|
|
81
|
+
lines.push("");
|
|
82
|
+
|
|
83
|
+
// Model list (<cursor><check><model-id> [<provider>] [badges])
|
|
84
|
+
if (this.filteredModels.length === 0) {
|
|
85
|
+
lines.push(` ${this.theme.fg("warning", "No matching ASR models found")}`);
|
|
86
|
+
} else {
|
|
87
|
+
const maxVisible = 6;
|
|
88
|
+
const total = this.filteredModels.length;
|
|
89
|
+
const startIndex = Math.max(0, Math.min(this.selectedIndex - Math.floor(maxVisible / 2), total - maxVisible));
|
|
90
|
+
const endIndex = Math.min(startIndex + maxVisible, total);
|
|
91
|
+
|
|
92
|
+
for (let i = startIndex; i < endIndex; i++) {
|
|
93
|
+
const item = this.filteredModels[i];
|
|
94
|
+
const isSelected = i === this.selectedIndex;
|
|
95
|
+
const isCurrent = item.id === this.currentModelId;
|
|
96
|
+
|
|
97
|
+
const cursor = isSelected ? this.theme.fg("accent", "→ ") : " ";
|
|
98
|
+
const check = isCurrent ? this.theme.fg("accent", "✓ ") : " ";
|
|
99
|
+
const modelText = isSelected
|
|
100
|
+
? (this.theme.bold ? this.theme.bold(this.theme.fg("accent", item.id)) : this.theme.fg("accent", item.id))
|
|
101
|
+
: this.theme.fg("text", item.id);
|
|
102
|
+
const providerBadge = this.theme.fg("muted", `[${item.provider}]`);
|
|
103
|
+
const currentBadge = isCurrent ? this.theme.fg("muted", " · current") : "";
|
|
104
|
+
|
|
105
|
+
lines.push(` ${cursor}${check}${modelText} ${providerBadge}${currentBadge}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (startIndex > 0 || endIndex < total) {
|
|
109
|
+
lines.push(` ${this.theme.fg("muted", `(${this.selectedIndex + 1}/${total})`)}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
lines.push("");
|
|
113
|
+
|
|
114
|
+
// Selected model detail
|
|
115
|
+
const selected = this.filteredModels[this.selectedIndex];
|
|
116
|
+
if (selected) {
|
|
117
|
+
lines.push(` ${this.theme.fg("muted", "Model Name: ")}${selected.name}`);
|
|
118
|
+
lines.push(` ${this.theme.fg("muted", "Description: ")}${selected.description}`);
|
|
119
|
+
}
|
|
120
|
+
lines.push("");
|
|
121
|
+
|
|
122
|
+
// Keybinding footer hints
|
|
123
|
+
lines.push(this.theme.fg("dim", " Enter to select · Escape/Ctrl+C to cancel · ↑↓ to navigate"));
|
|
124
|
+
lines.push(border);
|
|
125
|
+
|
|
126
|
+
this.cachedLines = lines;
|
|
127
|
+
this.cachedWidth = width;
|
|
128
|
+
return lines;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
invalidate() {
|
|
132
|
+
this.cachedLines = undefined;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
handleInput(keyData: string) {
|
|
136
|
+
const kb = getKeybindings();
|
|
137
|
+
if (kb.matches(keyData, "tui.select.up") || keyData === "k") {
|
|
138
|
+
if (this.filteredModels.length === 0) return;
|
|
139
|
+
this.selectedIndex = this.selectedIndex === 0 ? this.filteredModels.length - 1 : this.selectedIndex - 1;
|
|
140
|
+
this.refresh();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (kb.matches(keyData, "tui.select.down") || keyData === "j") {
|
|
144
|
+
if (this.filteredModels.length === 0) return;
|
|
145
|
+
this.selectedIndex = this.selectedIndex === this.filteredModels.length - 1 ? 0 : this.selectedIndex + 1;
|
|
146
|
+
this.refresh();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (kb.matches(keyData, "tui.select.confirm") || keyData === "\n" || keyData === "\r") {
|
|
150
|
+
const selected = this.filteredModels[this.selectedIndex];
|
|
151
|
+
if (selected) {
|
|
152
|
+
this.onSelect(selected);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (kb.matches(keyData, "tui.select.cancel") || keyData === "\x1b" || keyData === "\x03") {
|
|
157
|
+
this.onCancel();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this.searchInput.handleInput(keyData);
|
|
161
|
+
this.filterModels(this.searchInput.getValue());
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
const BRAILLE_FRAMES = ["⠀", "⣀", "⣄", "⣤", "⣦", "⣶", "⣷", "⣿"];
|
|
4
|
+
const METER_CELLS = 4;
|
|
5
|
+
const METER_TICK_MS = 80;
|
|
6
|
+
|
|
7
|
+
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
8
|
+
const SPINNER_INTERVAL_MS = 80;
|
|
9
|
+
|
|
10
|
+
function rmsToBlock(rms: number): string {
|
|
11
|
+
const norm = Math.min(1, Math.max(0, rms / 8000));
|
|
12
|
+
const idx = Math.min(BRAILLE_FRAMES.length - 1, Math.floor(norm * BRAILLE_FRAMES.length));
|
|
13
|
+
return BRAILLE_FRAMES[idx];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Own animation timers for one dictation controller. */
|
|
17
|
+
export function createStatusDisplay(getActiveContext: () => ExtensionContext | null) {
|
|
18
|
+
// Meter animation
|
|
19
|
+
let meter: number[] = new Array(METER_CELLS).fill(0);
|
|
20
|
+
let currentLevel = 0;
|
|
21
|
+
let meterTimer: NodeJS.Timeout | null = null;
|
|
22
|
+
|
|
23
|
+
// Spinner animation
|
|
24
|
+
let spinnerFrame = 0;
|
|
25
|
+
let spinnerTimer: NodeJS.Timeout | null = null;
|
|
26
|
+
|
|
27
|
+
const setStatus = (msg: string | undefined) => {
|
|
28
|
+
const activeCtx = getActiveContext();
|
|
29
|
+
if (!activeCtx) return;
|
|
30
|
+
activeCtx.ui.setStatus("tui-asr", msg);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const stopSpinner = () => {
|
|
34
|
+
if (spinnerTimer) {
|
|
35
|
+
clearInterval(spinnerTimer);
|
|
36
|
+
spinnerTimer = null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const stopMeter = () => {
|
|
41
|
+
if (meterTimer) {
|
|
42
|
+
clearInterval(meterTimer);
|
|
43
|
+
meterTimer = null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Start braille audio level meter animation */
|
|
48
|
+
const startMeter = () => {
|
|
49
|
+
stopMeter();
|
|
50
|
+
meter = new Array(METER_CELLS).fill(0);
|
|
51
|
+
currentLevel = 0;
|
|
52
|
+
const render = () => {
|
|
53
|
+
const dot = getActiveContext()?.ui.theme.fg("error", "●") ?? "●";
|
|
54
|
+
setStatus(`${dot} ${meter.map(rmsToBlock).join("")} listening…`);
|
|
55
|
+
};
|
|
56
|
+
render();
|
|
57
|
+
meterTimer = setInterval(() => {
|
|
58
|
+
meter.shift();
|
|
59
|
+
meter.push(currentLevel);
|
|
60
|
+
render();
|
|
61
|
+
}, METER_TICK_MS);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Start finalizing spinner */
|
|
65
|
+
const startSpinner = (suffix: string) => {
|
|
66
|
+
stopSpinner();
|
|
67
|
+
spinnerFrame = 0;
|
|
68
|
+
setStatus(`${SPINNER_FRAMES[0]} ${suffix}`);
|
|
69
|
+
spinnerTimer = setInterval(() => {
|
|
70
|
+
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES.length;
|
|
71
|
+
setStatus(`${SPINNER_FRAMES[spinnerFrame]} ${suffix}`);
|
|
72
|
+
}, SPINNER_INTERVAL_MS);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
setStatus, startMeter, stopMeter, startSpinner, stopSpinner,
|
|
77
|
+
setLevel(level: number) { currentLevel = level; },
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# web-reach
|
|
2
|
+
|
|
3
|
+
Keyless web search (`web_search` via Exa MCP) and multi-tier page extraction (`web_fetch` supporting Next.js RSC, semantic HTML-to-Markdown, optional `unpdf` PDF extraction, and Jina Reader fallback).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pi install npm:@rol1n/web-reach
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Also included in `@rol1n/pi-kit`.
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
| Environment variable | Default |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `SRP_WEB_SEARCH_TIMEOUT_MS` | `60000` |
|
|
18
|
+
| `SRP_WEB_FETCH_TIMEOUT_MS` | `20000` |
|
|
19
|
+
| `SRP_WEB_FETCH_MAX_BYTES` | `4194304` (4 MiB) |
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export function extractTitleFromHtml(html: string): string {
|
|
2
|
+
const match = html.match(/<title[^>]*>([^<]+)<\/title>/i);
|
|
3
|
+
return match?.[1]?.trim() ?? "";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function isLikelyJSRendered(html: string): boolean {
|
|
7
|
+
const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
|
|
8
|
+
if (!bodyMatch) return false;
|
|
9
|
+
const textContent = bodyMatch[1]
|
|
10
|
+
.replace(/<script[\s\S]*?<\/script>/gi, "")
|
|
11
|
+
.replace(/<style[\s\S]*?<\/style>/gi, "")
|
|
12
|
+
.replace(/<[^>]+>/g, "")
|
|
13
|
+
.replace(/\s+/g, " ")
|
|
14
|
+
.trim();
|
|
15
|
+
const scriptCount = (html.match(/<script/gi) || []).length;
|
|
16
|
+
return textContent.length < 300 && scriptCount >= 2;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function htmlToMarkdown(html: string): string {
|
|
20
|
+
let s = html.replace(/<(script|style|noscript|svg|canvas|form|nav|footer|header|aside)[\s\S]*?<\/\1>/gi, " ");
|
|
21
|
+
s = s.replace(/<!--[\s\S]*?-->/g, " ");
|
|
22
|
+
|
|
23
|
+
// Headings
|
|
24
|
+
s = s.replace(/<h1[^>]*>([\s\S]*?)<\/h1>/gi, "\n\n# $1\n\n");
|
|
25
|
+
s = s.replace(/<h2[^>]*>([\s\S]*?)<\/h2>/gi, "\n\n## $1\n\n");
|
|
26
|
+
s = s.replace(/<h3[^>]*>([\s\S]*?)<\/h3>/gi, "\n\n### $1\n\n");
|
|
27
|
+
s = s.replace(/<h4[^>]*>([\s\S]*?)<\/h4>/gi, "\n\n#### $1\n\n");
|
|
28
|
+
s = s.replace(/<h5[^>]*>([\s\S]*?)<\/h5>/gi, "\n\n##### $1\n\n");
|
|
29
|
+
s = s.replace(/<h6[^>]*>([\s\S]*?)<\/h6>/gi, "\n\n###### $1\n\n");
|
|
30
|
+
|
|
31
|
+
// Code blocks and inline code
|
|
32
|
+
s = s.replace(/<pre[^>]*><code[^>]*>([\s\S]*?)<\/code><\/pre>/gi, "\n```\n$1\n```\n");
|
|
33
|
+
s = s.replace(/<pre[^>]*>([\s\S]*?)<\/pre>/gi, "\n```\n$1\n```\n");
|
|
34
|
+
s = s.replace(/<code[^>]*>([\s\S]*?)<\/code>/gi, " `$1` ");
|
|
35
|
+
|
|
36
|
+
// Blockquotes and emphasis
|
|
37
|
+
s = s.replace(/<blockquote[^>]*>([\s\S]*?)<\/blockquote>/gi, "\n> $1\n");
|
|
38
|
+
s = s.replace(/<(strong|b)[^>]*>([\s\S]*?)<\/\1>/gi, "**$2**");
|
|
39
|
+
s = s.replace(/<(em|i)[^>]*>([\s\S]*?)<\/\1>/gi, "*$2*");
|
|
40
|
+
|
|
41
|
+
// Links
|
|
42
|
+
s = s.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/gi, (_, href, text) => {
|
|
43
|
+
const t = text.replace(/<[^>]*>/g, "").trim();
|
|
44
|
+
if (!t) return "";
|
|
45
|
+
if (href.startsWith("#") || href.startsWith("javascript:")) return t;
|
|
46
|
+
return `[${t}](${href})`;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Lists
|
|
50
|
+
s = s.replace(/<li[^>]*>([\s\S]*?)<\/li>/gi, "\n- $1");
|
|
51
|
+
s = s.replace(/<\/(ul|ol)>/gi, "\n\n");
|
|
52
|
+
|
|
53
|
+
// Tables
|
|
54
|
+
s = s.replace(/<tr[^>]*>([\s\S]*?)<\/tr>/gi, "\n$1 |");
|
|
55
|
+
s = s.replace(/<t[dh][^>]*>([\s\S]*?)<\/t[dh]>/gi, " | $1");
|
|
56
|
+
s = s.replace(/<\/(table|thead|tbody)>/gi, "\n\n");
|
|
57
|
+
|
|
58
|
+
// Paragraphs and line breaks
|
|
59
|
+
s = s.replace(/<\/(p|div|section|article)>/gi, "\n\n");
|
|
60
|
+
s = s.replace(/<br\s*\/?>/gi, "\n");
|
|
61
|
+
|
|
62
|
+
// Strip remaining tags
|
|
63
|
+
s = s.replace(/<[^>]*>/g, " ");
|
|
64
|
+
|
|
65
|
+
// HTML entity decoding
|
|
66
|
+
s = s
|
|
67
|
+
.replace(/ /g, " ")
|
|
68
|
+
.replace(/&/g, "&")
|
|
69
|
+
.replace(/</g, "<")
|
|
70
|
+
.replace(/>/g, ">")
|
|
71
|
+
.replace(/"/g, '"')
|
|
72
|
+
.replace(/'/g, "'")
|
|
73
|
+
.replace(/…/g, "…")
|
|
74
|
+
.replace(/—/g, "—")
|
|
75
|
+
.replace(/–/g, "–");
|
|
76
|
+
|
|
77
|
+
return s
|
|
78
|
+
.split("\n")
|
|
79
|
+
.map((line) => line.trimEnd())
|
|
80
|
+
.filter((line, i, arr) => !(line === "" && arr[i - 1] === ""))
|
|
81
|
+
.join("\n")
|
|
82
|
+
.trim();
|
|
83
|
+
}
|