@asterxsk/kiln 0.1.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/LICENSE +21 -0
- package/README.md +170 -0
- package/agent/AGENTS.md +67 -0
- package/agent/README.md +5 -0
- package/agent/extensions/AGENTS.md +68 -0
- package/agent/extensions/ask-user/index.ts +418 -0
- package/agent/extensions/ask-user/install.ps1 +23 -0
- package/agent/extensions/ask-user/install.sh +21 -0
- package/agent/extensions/ask-user/package-lock.json +769 -0
- package/agent/extensions/ask-user/package.json +19 -0
- package/agent/extensions/ask-user/prompt.ts +45 -0
- package/agent/extensions/ask-user/tsconfig.json +7 -0
- package/agent/extensions/background-terminals/docs/implementation-guide.md +942 -0
- package/agent/extensions/background-terminals/index.ts +627 -0
- package/agent/extensions/background-terminals/install.ps1 +23 -0
- package/agent/extensions/background-terminals/install.sh +21 -0
- package/agent/extensions/background-terminals/manager.test.ts +735 -0
- package/agent/extensions/background-terminals/output.test.ts +109 -0
- package/agent/extensions/background-terminals/package-lock.json +769 -0
- package/agent/extensions/background-terminals/package.json +17 -0
- package/agent/extensions/background-terminals/prompt.test.ts +125 -0
- package/agent/extensions/background-terminals/ps.test.ts +82 -0
- package/agent/extensions/background-terminals/result-delivery.test.ts +44 -0
- package/agent/extensions/background-terminals/src/domain.ts +87 -0
- package/agent/extensions/background-terminals/src/manager.ts +907 -0
- package/agent/extensions/background-terminals/src/output.ts +84 -0
- package/agent/extensions/background-terminals/src/prompt.ts +142 -0
- package/agent/extensions/background-terminals/src/result-delivery.ts +27 -0
- package/agent/extensions/background-terminals/src/runtime.ts +36 -0
- package/agent/extensions/background-terminals/src/ui/output-view.ts +79 -0
- package/agent/extensions/background-terminals/src/ui/ps.ts +621 -0
- package/agent/extensions/background-terminals/tsconfig.json +7 -0
- package/agent/extensions/destructive/README.md +31 -0
- package/agent/extensions/destructive/index.ts +88 -0
- package/agent/extensions/destructive/install.ps1 +23 -0
- package/agent/extensions/destructive/install.sh +21 -0
- package/agent/extensions/file-search/index.spec.ts +443 -0
- package/agent/extensions/file-search/index.ts +459 -0
- package/agent/extensions/file-search/install.ps1 +23 -0
- package/agent/extensions/file-search/install.sh +21 -0
- package/agent/extensions/file-search/package-lock.json +2253 -0
- package/agent/extensions/file-search/package.json +23 -0
- package/agent/extensions/file-search/src/args.ts +122 -0
- package/agent/extensions/file-search/src/binaries.ts +422 -0
- package/agent/extensions/file-search/src/output.ts +126 -0
- package/agent/extensions/file-search/src/process.ts +146 -0
- package/agent/extensions/file-search/src/prompt.ts +52 -0
- package/agent/extensions/file-search/tsconfig.json +7 -0
- package/agent/extensions/goal/README.md +50 -0
- package/agent/extensions/goal/index.ts +155 -0
- package/agent/extensions/goal/install.ps1 +23 -0
- package/agent/extensions/goal/install.sh +21 -0
- package/agent/extensions/modelconf/PLAN.md +915 -0
- package/agent/extensions/modelconf/README.md +66 -0
- package/agent/extensions/modelconf/index.ts +296 -0
- package/agent/extensions/modelconf/install.ps1 +23 -0
- package/agent/extensions/modelconf/install.sh +21 -0
- package/agent/extensions/modelconf/package-lock.json +1809 -0
- package/agent/extensions/modelconf/package.json +13 -0
- package/agent/extensions/modelconf/src/fuzzy.ts +26 -0
- package/agent/extensions/modelconf/src/glob.ts +13 -0
- package/agent/extensions/modelconf/src/persistence.test.ts +46 -0
- package/agent/extensions/modelconf/src/persistence.ts +164 -0
- package/agent/extensions/modelconf/src/ui/ModelConfView.test.ts +75 -0
- package/agent/extensions/modelconf/src/ui/ModelConfView.ts +1101 -0
- package/agent/extensions/modelconf/tsconfig.json +15 -0
- package/agent/extensions/pi-web-access/CHANGELOG.md +690 -0
- package/agent/extensions/pi-web-access/LICENSE +21 -0
- package/agent/extensions/pi-web-access/README.md +470 -0
- package/agent/extensions/pi-web-access/SECURITY.md +5 -0
- package/agent/extensions/pi-web-access/activity.ts +101 -0
- package/agent/extensions/pi-web-access/auth-fetch.ts +148 -0
- package/agent/extensions/pi-web-access/banner.png +0 -0
- package/agent/extensions/pi-web-access/brightdata-unlocker.ts +272 -0
- package/agent/extensions/pi-web-access/chrome-cookies.ts +669 -0
- package/agent/extensions/pi-web-access/content-find.ts +139 -0
- package/agent/extensions/pi-web-access/credential-source.ts +191 -0
- package/agent/extensions/pi-web-access/data-uri-sanitize.ts +406 -0
- package/agent/extensions/pi-web-access/datalab-pdf-extract.ts +568 -0
- package/agent/extensions/pi-web-access/declared-web-links.ts +173 -0
- package/agent/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +496 -0
- package/agent/extensions/pi-web-access/evidence/contract-probe.mjs +140 -0
- package/agent/extensions/pi-web-access/exa.ts +526 -0
- package/agent/extensions/pi-web-access/extract.ts +1196 -0
- package/agent/extensions/pi-web-access/feature-config.ts +29 -0
- package/agent/extensions/pi-web-access/fetch-params.ts +111 -0
- package/agent/extensions/pi-web-access/gemini-adc.ts +298 -0
- package/agent/extensions/pi-web-access/gemini-api.ts +353 -0
- package/agent/extensions/pi-web-access/gemini-pdf-extract.ts +108 -0
- package/agent/extensions/pi-web-access/gemini-search.ts +21 -0
- package/agent/extensions/pi-web-access/gemini-url-context.ts +128 -0
- package/agent/extensions/pi-web-access/gemini-web-config.ts +101 -0
- package/agent/extensions/pi-web-access/gemini-web.ts +487 -0
- package/agent/extensions/pi-web-access/github-api.ts +197 -0
- package/agent/extensions/pi-web-access/github-extract.ts +746 -0
- package/agent/extensions/pi-web-access/github-issue-pr.ts +700 -0
- package/agent/extensions/pi-web-access/index.ts +1737 -0
- package/agent/extensions/pi-web-access/package-lock.json +5808 -0
- package/agent/extensions/pi-web-access/package.json +64 -0
- package/agent/extensions/pi-web-access/page-query.ts +96 -0
- package/agent/extensions/pi-web-access/pdf-extract.ts +409 -0
- package/agent/extensions/pi-web-access/pi-web-fetch-demo.mp4 +0 -0
- package/agent/extensions/pi-web-access/promise-try.d.ts +7 -0
- package/agent/extensions/pi-web-access/query-rewrite.ts +51 -0
- package/agent/extensions/pi-web-access/render-search-error.ts +170 -0
- package/agent/extensions/pi-web-access/rsc-extract.ts +338 -0
- package/agent/extensions/pi-web-access/search-types.ts +20 -0
- package/agent/extensions/pi-web-access/source-check.ts +282 -0
- package/agent/extensions/pi-web-access/ssrf-protection.ts +526 -0
- package/agent/extensions/pi-web-access/storage.ts +521 -0
- package/agent/extensions/pi-web-access/summary-model-scope.ts +125 -0
- package/agent/extensions/pi-web-access/test/auth-fetch.test.mjs +208 -0
- package/agent/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +840 -0
- package/agent/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +441 -0
- package/agent/extensions/pi-web-access/test/config-path.test.mjs +283 -0
- package/agent/extensions/pi-web-access/test/content-find.test.mjs +25 -0
- package/agent/extensions/pi-web-access/test/credential-source.test.mjs +118 -0
- package/agent/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +210 -0
- package/agent/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +552 -0
- package/agent/extensions/pi-web-access/test/declared-web-links.test.mjs +212 -0
- package/agent/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +40 -0
- package/agent/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +334 -0
- package/agent/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +95 -0
- package/agent/extensions/pi-web-access/test/fetch-modes.test.mjs +53 -0
- package/agent/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +92 -0
- package/agent/extensions/pi-web-access/test/fetch-params.test.mjs +86 -0
- package/agent/extensions/pi-web-access/test/fetch-render-call.test.mjs +34 -0
- package/agent/extensions/pi-web-access/test/fetch-routing.test.mjs +173 -0
- package/agent/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +257 -0
- package/agent/extensions/pi-web-access/test/gemini-api-transport.test.mjs +170 -0
- package/agent/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +133 -0
- package/agent/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +178 -0
- package/agent/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +148 -0
- package/agent/extensions/pi-web-access/test/get-search-content.test.mjs +223 -0
- package/agent/extensions/pi-web-access/test/github-extract.test.mjs +378 -0
- package/agent/extensions/pi-web-access/test/github-issue-pr.test.mjs +565 -0
- package/agent/extensions/pi-web-access/test/inline-content-config.test.mjs +99 -0
- package/agent/extensions/pi-web-access/test/lazy-extract-load.test.mjs +118 -0
- package/agent/extensions/pi-web-access/test/local-video-oversize.test.mjs +52 -0
- package/agent/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +50 -0
- package/agent/extensions/pi-web-access/test/page-query.test.mjs +51 -0
- package/agent/extensions/pi-web-access/test/pdf-config.test.mjs +140 -0
- package/agent/extensions/pi-web-access/test/pdf-extract.test.mjs +500 -0
- package/agent/extensions/pi-web-access/test/proxy-transport.test.mjs +286 -0
- package/agent/extensions/pi-web-access/test/query-rewrite.test.mjs +52 -0
- package/agent/extensions/pi-web-access/test/rsc-fallback.test.mjs +102 -0
- package/agent/extensions/pi-web-access/test/search-error-render.test.mjs +152 -0
- package/agent/extensions/pi-web-access/test/search-providers.test.mjs +274 -0
- package/agent/extensions/pi-web-access/test/source-check.test.mjs +179 -0
- package/agent/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +205 -0
- package/agent/extensions/pi-web-access/test/ssrf-protection.test.mjs +456 -0
- package/agent/extensions/pi-web-access/test/summary-model-scope.test.mjs +106 -0
- package/agent/extensions/pi-web-access/test/tool-registration-config.test.mjs +182 -0
- package/agent/extensions/pi-web-access/test/web-search-answer-render.test.mjs +66 -0
- package/agent/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +64 -0
- package/agent/extensions/pi-web-access/tsconfig.json +11 -0
- package/agent/extensions/pi-web-access/utils.ts +451 -0
- package/agent/extensions/pi-web-access/video-extract.ts +392 -0
- package/agent/extensions/pi-web-access/youtube-extract.ts +328 -0
- package/agent/extensions/shared/activity-status.ts +31 -0
- package/agent/extensions/shared/child-session.test.ts +270 -0
- package/agent/extensions/shared/child-session.ts +148 -0
- package/agent/extensions/shared/context-utilization.test.ts +48 -0
- package/agent/extensions/shared/context-utilization.ts +47 -0
- package/agent/extensions/shared/dashboard-state.ts +99 -0
- package/agent/extensions/shared/install.ps1 +23 -0
- package/agent/extensions/shared/install.sh +21 -0
- package/agent/extensions/shared/tool-call-timeout.test.ts +117 -0
- package/agent/extensions/shared/tool-call-timeout.ts +104 -0
- package/agent/extensions/skillsconf/README.md +74 -0
- package/agent/extensions/skillsconf/index.ts +92 -0
- package/agent/extensions/skillsconf/install.ps1 +23 -0
- package/agent/extensions/skillsconf/install.sh +21 -0
- package/agent/extensions/skillsconf/package-lock.json +1809 -0
- package/agent/extensions/skillsconf/package.json +18 -0
- package/agent/extensions/skillsconf/src/delete-skill.test.ts +64 -0
- package/agent/extensions/skillsconf/src/delete-skill.ts +45 -0
- package/agent/extensions/skillsconf/src/filter.test.ts +80 -0
- package/agent/extensions/skillsconf/src/filter.ts +74 -0
- package/agent/extensions/skillsconf/src/fuzzy.ts +26 -0
- package/agent/extensions/skillsconf/src/persistence.test.ts +72 -0
- package/agent/extensions/skillsconf/src/persistence.ts +169 -0
- package/agent/extensions/skillsconf/src/ui/SkillConfView.test.ts +337 -0
- package/agent/extensions/skillsconf/src/ui/SkillConfView.ts +758 -0
- package/agent/extensions/skillsconf/src/ui/text-input.ts +91 -0
- package/agent/extensions/skillsconf/src/ui/tui-helpers.ts +144 -0
- package/agent/extensions/skillsconf/tsconfig.json +15 -0
- package/agent/extensions/status line/index.ts +282 -0
- package/agent/extensions/status line/install.ps1 +23 -0
- package/agent/extensions/status line/install.sh +21 -0
- package/agent/extensions/subagents/by-the-way.test.ts +29 -0
- package/agent/extensions/subagents/claude.test.ts +119 -0
- package/agent/extensions/subagents/codex.test.ts +102 -0
- package/agent/extensions/subagents/context-usage.test.ts +107 -0
- package/agent/extensions/subagents/docs/design-plan.md +568 -0
- package/agent/extensions/subagents/docs/effect-v4-extension-guide.md +354 -0
- package/agent/extensions/subagents/docs/effect-v4-notes.md +571 -0
- package/agent/extensions/subagents/index.ts +779 -0
- package/agent/extensions/subagents/install.ps1 +23 -0
- package/agent/extensions/subagents/install.sh +21 -0
- package/agent/extensions/subagents/manager.test.ts +276 -0
- package/agent/extensions/subagents/package-lock.json +2244 -0
- package/agent/extensions/subagents/package.json +19 -0
- package/agent/extensions/subagents/result-delivery.test.ts +27 -0
- package/agent/extensions/subagents/src/backend.ts +73 -0
- package/agent/extensions/subagents/src/backends/claude.ts +701 -0
- package/agent/extensions/subagents/src/backends/codex.ts +1060 -0
- package/agent/extensions/subagents/src/backends/pi.ts +575 -0
- package/agent/extensions/subagents/src/backends/stub.ts +300 -0
- package/agent/extensions/subagents/src/by-the-way.ts +21 -0
- package/agent/extensions/subagents/src/domain.ts +253 -0
- package/agent/extensions/subagents/src/format.ts +74 -0
- package/agent/extensions/subagents/src/manager.ts +736 -0
- package/agent/extensions/subagents/src/prompt.ts +92 -0
- package/agent/extensions/subagents/src/result-delivery.ts +20 -0
- package/agent/extensions/subagents/src/runtime.ts +53 -0
- package/agent/extensions/subagents/src/ui/takeover.ts +583 -0
- package/agent/extensions/subagents/src/ui/transcript.ts +201 -0
- package/agent/extensions/subagents/takeover.test.ts +29 -0
- package/agent/extensions/subagents/tsconfig.json +7 -0
- package/agent/extensions/taste/index.ts +443 -0
- package/agent/extensions/taste/install.ps1 +23 -0
- package/agent/extensions/taste/install.sh +21 -0
- package/agent/extensions/todo/AGENTS.md +38 -0
- package/agent/extensions/todo/LICENSE +21 -0
- package/agent/extensions/todo/config.ts +55 -0
- package/agent/extensions/todo/index.ts +151 -0
- package/agent/extensions/todo/install.ps1 +23 -0
- package/agent/extensions/todo/install.sh +21 -0
- package/agent/extensions/todo/locales/de.json +17 -0
- package/agent/extensions/todo/locales/en.json +15 -0
- package/agent/extensions/todo/locales/es.json +17 -0
- package/agent/extensions/todo/locales/fr.json +17 -0
- package/agent/extensions/todo/locales/pt-BR.json +17 -0
- package/agent/extensions/todo/locales/pt.json +17 -0
- package/agent/extensions/todo/locales/ru.json +17 -0
- package/agent/extensions/todo/locales/uk.json +17 -0
- package/agent/extensions/todo/locales/zh.json +17 -0
- package/agent/extensions/todo/package-lock.json +3358 -0
- package/agent/extensions/todo/package.json +67 -0
- package/agent/extensions/todo/state/i18n-bridge.ts +64 -0
- package/agent/extensions/todo/state/invariants.ts +20 -0
- package/agent/extensions/todo/state/replay.ts +38 -0
- package/agent/extensions/todo/state/selectors.ts +107 -0
- package/agent/extensions/todo/state/state-reducer.ts +326 -0
- package/agent/extensions/todo/state/state.ts +18 -0
- package/agent/extensions/todo/state/store.ts +82 -0
- package/agent/extensions/todo/state/task-graph.ts +57 -0
- package/agent/extensions/todo/todo-overlay.ts +200 -0
- package/agent/extensions/todo/todo.ts +155 -0
- package/agent/extensions/todo/tool/response-envelope.ts +109 -0
- package/agent/extensions/todo/tool/types.ts +206 -0
- package/agent/extensions/todo/verify-ref-system.js +0 -0
- package/agent/extensions/todo/view/format.ts +177 -0
- package/agent/extensions/trim-context/README.md +54 -0
- package/agent/extensions/trim-context/index.ts +487 -0
- package/agent/extensions/trim-context/install.ps1 +23 -0
- package/agent/extensions/trim-context/install.sh +21 -0
- package/agent/install.ps1 +527 -0
- package/agent/install.sh +511 -0
- package/agent/keybindings.json +7 -0
- package/bin/kiln.js +359 -0
- package/package.json +21 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transcript rendering for the takeover view: turns a SubagentSnapshot's
|
|
3
|
+
* normalized transcript + live state into plain wrapped lines. Ported from
|
|
4
|
+
* v1, with the session-poking replaced by snapshot reads.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import {
|
|
9
|
+
truncateToWidth,
|
|
10
|
+
visibleWidth,
|
|
11
|
+
wrapTextWithAnsi,
|
|
12
|
+
} from "@earendil-works/pi-tui";
|
|
13
|
+
import type { SubagentSnapshot, TranscriptItem } from "../domain.ts";
|
|
14
|
+
|
|
15
|
+
const ANSI_PATTERN =
|
|
16
|
+
// eslint-disable-next-line no-control-regex
|
|
17
|
+
/[\u001B\u009B][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[a-zA-Z\d]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))/g;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Strip raw ANSI codes, expand tabs, and drop control chars. Terminal-expanded
|
|
21
|
+
* tabs (and stray escapes) make lines wider than the width we declare to the
|
|
22
|
+
* TUI, which desyncs the renderer and smears the overlay.
|
|
23
|
+
*/
|
|
24
|
+
export function sanitizeText(text: string): string {
|
|
25
|
+
return text
|
|
26
|
+
.replace(ANSI_PATTERN, "")
|
|
27
|
+
.replaceAll("\t", " ")
|
|
28
|
+
.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function renderUserText(
|
|
32
|
+
theme: Theme,
|
|
33
|
+
text: string,
|
|
34
|
+
width: number,
|
|
35
|
+
out: string[],
|
|
36
|
+
) {
|
|
37
|
+
const clean = sanitizeText(text).trim();
|
|
38
|
+
if (!clean) return;
|
|
39
|
+
const wrapped = wrapTextWithAnsi(clean, Math.max(10, width - 2));
|
|
40
|
+
for (let i = 0; i < wrapped.length; i++) {
|
|
41
|
+
const prefix = i === 0 ? theme.fg("accent", "> ") : " ";
|
|
42
|
+
out.push(
|
|
43
|
+
truncateToWidth(prefix + theme.fg("userMessageText", wrapped[i]), width),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function renderThinking(
|
|
49
|
+
theme: Theme,
|
|
50
|
+
text: string,
|
|
51
|
+
width: number,
|
|
52
|
+
out: string[],
|
|
53
|
+
) {
|
|
54
|
+
const reasoning = sanitizeText(text).trim();
|
|
55
|
+
if (!reasoning) return;
|
|
56
|
+
const prefix = theme.fg("dim", "~ ");
|
|
57
|
+
// Preserve paragraph breaks so multi-paragraph reasoning doesn't collapse
|
|
58
|
+
// into one wall of text; each paragraph gets its own `~` continuation.
|
|
59
|
+
const wrapped = wrapTextWithAnsi(reasoning, Math.max(10, width - 2));
|
|
60
|
+
for (let i = 0; i < wrapped.length; i++) {
|
|
61
|
+
const line = wrapped[i];
|
|
62
|
+
if (line.trim() === "" && i > 0) {
|
|
63
|
+
out.push("");
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
out.push(
|
|
67
|
+
truncateToWidth(
|
|
68
|
+
(i === 0 ? prefix : " ") + theme.fg("muted", theme.italic(line)),
|
|
69
|
+
width,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function renderAssistantItem(
|
|
76
|
+
theme: Theme,
|
|
77
|
+
item: Extract<TranscriptItem, { kind: "assistant" }>,
|
|
78
|
+
width: number,
|
|
79
|
+
out: string[],
|
|
80
|
+
) {
|
|
81
|
+
// A rendered reasoning block is followed by a blank line so the thinking
|
|
82
|
+
// doesn't run into the answer/tool call that comes next.
|
|
83
|
+
let pendingGap = false;
|
|
84
|
+
for (const part of item.parts) {
|
|
85
|
+
if (part.type === "text") {
|
|
86
|
+
const text = sanitizeText(part.text).trim();
|
|
87
|
+
if (!text) continue;
|
|
88
|
+
if (pendingGap) out.push("");
|
|
89
|
+
out.push(...wrapTextWithAnsi(text, width));
|
|
90
|
+
pendingGap = false;
|
|
91
|
+
} else if (part.type === "thinking") {
|
|
92
|
+
const before = out.length;
|
|
93
|
+
renderThinking(
|
|
94
|
+
theme,
|
|
95
|
+
part.redacted ? "[redacted reasoning]" : part.text,
|
|
96
|
+
width,
|
|
97
|
+
out,
|
|
98
|
+
);
|
|
99
|
+
pendingGap = out.length > before;
|
|
100
|
+
} else if (part.type === "toolCall") {
|
|
101
|
+
if (pendingGap) out.push("");
|
|
102
|
+
const preview = part.argsPreview ? sanitizeText(part.argsPreview) : "";
|
|
103
|
+
const line =
|
|
104
|
+
theme.fg("muted", "→ ") +
|
|
105
|
+
theme.fg("toolTitle", part.name) +
|
|
106
|
+
(preview && preview !== "{}" ? theme.fg("dim", ` ${preview}`) : "");
|
|
107
|
+
out.push(truncateToWidth(line, width));
|
|
108
|
+
pendingGap = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function renderToolResultItem(
|
|
114
|
+
theme: Theme,
|
|
115
|
+
item: Extract<TranscriptItem, { kind: "toolResult" }>,
|
|
116
|
+
width: number,
|
|
117
|
+
out: string[],
|
|
118
|
+
) {
|
|
119
|
+
const firstLine =
|
|
120
|
+
sanitizeText(item.outputPreview ?? "")
|
|
121
|
+
.split("\n")
|
|
122
|
+
.find((line) => line.trim()) ?? "";
|
|
123
|
+
const label = item.isError
|
|
124
|
+
? theme.fg("error", " error: ")
|
|
125
|
+
: theme.fg("dim", " output: ");
|
|
126
|
+
out.push(
|
|
127
|
+
truncateToWidth(label + theme.fg("dim", firstLine || "(no output)"), width),
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Render a subagent's conversation as plain lines, wrapped to `width`. */
|
|
132
|
+
export function buildTranscriptLines(
|
|
133
|
+
snap: SubagentSnapshot,
|
|
134
|
+
width: number,
|
|
135
|
+
theme: Theme,
|
|
136
|
+
): string[] {
|
|
137
|
+
const out: string[] = [];
|
|
138
|
+
|
|
139
|
+
for (const item of snap.transcript) {
|
|
140
|
+
const before = out.length;
|
|
141
|
+
if (item.kind === "user") {
|
|
142
|
+
renderUserText(theme, item.text, width, out);
|
|
143
|
+
} else if (item.kind === "assistant") {
|
|
144
|
+
renderAssistantItem(theme, item, width, out);
|
|
145
|
+
} else {
|
|
146
|
+
renderToolResultItem(theme, item, width, out);
|
|
147
|
+
}
|
|
148
|
+
if (out.length > before) out.push("");
|
|
149
|
+
}
|
|
150
|
+
while (out.length > 0 && out[out.length - 1] === "") out.pop();
|
|
151
|
+
|
|
152
|
+
// Live streaming assistant buffers (cleared when the finalized message lands).
|
|
153
|
+
if (snap.liveAssistant) {
|
|
154
|
+
const { thinking, text } = snap.liveAssistant;
|
|
155
|
+
const before = out.length;
|
|
156
|
+
if (out.length > 0) out.push("");
|
|
157
|
+
if (thinking.trim()) renderThinking(theme, thinking, width, out);
|
|
158
|
+
if (text.trim()) {
|
|
159
|
+
// Separate the streamed answer from the reasoning block above it.
|
|
160
|
+
if (thinking.trim()) out.push("");
|
|
161
|
+
out.push(...wrapTextWithAnsi(sanitizeText(text).trim(), width));
|
|
162
|
+
}
|
|
163
|
+
if (out.length === before + 1) out.pop();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Live tool executions (present until the ToolEnd lands in the transcript).
|
|
167
|
+
for (const tool of snap.liveTools) {
|
|
168
|
+
if (out.length > 0) out.push("");
|
|
169
|
+
const marker = tool.done
|
|
170
|
+
? tool.isError
|
|
171
|
+
? theme.fg("error", "error")
|
|
172
|
+
: theme.fg("success", "done")
|
|
173
|
+
: theme.fg("warning", "running");
|
|
174
|
+
let line = `${theme.fg("toolTitle", tool.name)} · ${marker}`;
|
|
175
|
+
const preview = tool.outputPreview && sanitizeText(tool.outputPreview);
|
|
176
|
+
if (preview) line += theme.fg("dim", ` · ${preview}`);
|
|
177
|
+
out.push(truncateToWidth(line, width));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Queued steering/follow-up messages: show them immediately so Enter
|
|
181
|
+
// visibly acknowledges the user's input instead of appearing to do nothing.
|
|
182
|
+
for (const message of snap.queued) {
|
|
183
|
+
if (out.length > 0) out.push("");
|
|
184
|
+
const prefix = theme.fg("warning", `> [queued ${message.kind}] `);
|
|
185
|
+
const wrapped = wrapTextWithAnsi(
|
|
186
|
+
sanitizeText(message.text),
|
|
187
|
+
Math.max(10, width - visibleWidth(prefix)),
|
|
188
|
+
);
|
|
189
|
+
for (let i = 0; i < wrapped.length; i++) {
|
|
190
|
+
out.push(
|
|
191
|
+
truncateToWidth(
|
|
192
|
+
(i === 0 ? prefix : " ".repeat(visibleWidth(prefix))) +
|
|
193
|
+
theme.fg("muted", wrapped[i]),
|
|
194
|
+
width,
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
reconcileDashboardSelection,
|
|
5
|
+
type DashboardSelection,
|
|
6
|
+
} from "./src/ui/takeover.ts";
|
|
7
|
+
|
|
8
|
+
test("dashboard selection follows its subagent id and falls back by row", () => {
|
|
9
|
+
const selection: DashboardSelection = { id: "sa-7", index: 6 };
|
|
10
|
+
|
|
11
|
+
reconcileDashboardSelection(selection, [
|
|
12
|
+
{ id: "sa-new" },
|
|
13
|
+
...Array.from({ length: 8 }, (_, index) => ({ id: `sa-${index + 1}` })),
|
|
14
|
+
]);
|
|
15
|
+
assert.deepEqual(selection, { id: "sa-7", index: 7 });
|
|
16
|
+
|
|
17
|
+
reconcileDashboardSelection(selection, [
|
|
18
|
+
...Array.from({ length: 6 }, (_, index) => ({ id: `sa-${index + 1}` })),
|
|
19
|
+
{ id: "sa-8" },
|
|
20
|
+
{ id: "sa-9" },
|
|
21
|
+
]);
|
|
22
|
+
assert.deepEqual(selection, { id: "sa-9", index: 7 });
|
|
23
|
+
|
|
24
|
+
reconcileDashboardSelection(selection, [{ id: "sa-1" }, { id: "sa-2" }]);
|
|
25
|
+
assert.deepEqual(selection, { id: "sa-2", index: 1 });
|
|
26
|
+
|
|
27
|
+
reconcileDashboardSelection(selection, []);
|
|
28
|
+
assert.deepEqual(selection, { id: undefined, index: 0 });
|
|
29
|
+
});
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-taste — local "taste" learning, no npx / no network.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors Command Code's Taste but entirely on-disk:
|
|
5
|
+
* - Learns preferences from each completed request via the active local model.
|
|
6
|
+
* - Stores them as markdown at two scopes:
|
|
7
|
+
* Global : ~/.pi/agent/extensions/taste/taste.md (applies to ALL projects)
|
|
8
|
+
* Project: <cwd>/.pi/taste/taste.md (this codebase only)
|
|
9
|
+
* - Feeds high-confidence learnings back into the system prompt each turn.
|
|
10
|
+
*
|
|
11
|
+
* Confidence system: new learning = newConfidence (0.40); a repeat (same
|
|
12
|
+
* category + normalized text) raises confidence by repeatIncrement (0.10),
|
|
13
|
+
* capped at 0.95. Only learnings >= applyThreshold (0.60) are injected.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
17
|
+
import { CONFIG_DIR_NAME } from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import { uuidv7 } from "@earendil-works/pi-ai";
|
|
19
|
+
import * as fs from "node:fs";
|
|
20
|
+
import * as path from "node:path";
|
|
21
|
+
import * as os from "node:os";
|
|
22
|
+
|
|
23
|
+
// ---- Paths -------------------------------------------------------------
|
|
24
|
+
// Global taste lives INSIDE this extension's folder (per user request).
|
|
25
|
+
const EXT_DIR = path.join(os.homedir(), ".pi", "agent", "extensions", "taste");
|
|
26
|
+
const GLOBAL_TASTE = path.join(EXT_DIR, "taste.md");
|
|
27
|
+
const GLOBAL_SETTINGS = path.join(EXT_DIR, "settings.json");
|
|
28
|
+
|
|
29
|
+
const projectTasteFile = (cwd: string) =>
|
|
30
|
+
path.join(cwd, CONFIG_DIR_NAME, "taste", "taste.md");
|
|
31
|
+
const projectSettingsFile = (cwd: string) =>
|
|
32
|
+
path.join(cwd, CONFIG_DIR_NAME, "taste", "settings.json");
|
|
33
|
+
|
|
34
|
+
// ---- Settings ----------------------------------------------------------
|
|
35
|
+
interface Settings {
|
|
36
|
+
learning: boolean;
|
|
37
|
+
applyThreshold: number;
|
|
38
|
+
newConfidence: number;
|
|
39
|
+
repeatIncrement: number;
|
|
40
|
+
minPromptLength: number;
|
|
41
|
+
minIntervalMs: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const DEFAULTS: Settings = {
|
|
45
|
+
learning: true,
|
|
46
|
+
applyThreshold: 0.6,
|
|
47
|
+
newConfidence: 0.4,
|
|
48
|
+
repeatIncrement: 0.1,
|
|
49
|
+
minPromptLength: 20,
|
|
50
|
+
minIntervalMs: 15000,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function loadSettings(file: string): Settings {
|
|
54
|
+
try {
|
|
55
|
+
if (fs.existsSync(file)) {
|
|
56
|
+
return { ...DEFAULTS, ...JSON.parse(fs.readFileSync(file, "utf8")) };
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
/* corrupt settings -> defaults */
|
|
60
|
+
}
|
|
61
|
+
return { ...DEFAULTS };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ---- Taste data model --------------------------------------------------
|
|
65
|
+
interface Item {
|
|
66
|
+
text: string;
|
|
67
|
+
confidence: number;
|
|
68
|
+
}
|
|
69
|
+
type Taste = Map<string, Item[]>;
|
|
70
|
+
|
|
71
|
+
const normalize = (s: string) =>
|
|
72
|
+
s.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
73
|
+
|
|
74
|
+
function parseTaste(text: string): Taste {
|
|
75
|
+
const taste: Taste = new Map();
|
|
76
|
+
let category = "Other";
|
|
77
|
+
for (const line of text.split(/\r?\n/)) {
|
|
78
|
+
const h = line.match(/^#\s+(.+?)\s*$/);
|
|
79
|
+
if (h) {
|
|
80
|
+
category = h[1].trim() || "Other";
|
|
81
|
+
if (!taste.has(category)) taste.set(category, []);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const b = line.match(
|
|
85
|
+
/^-\s+(.*?)\s*\.\s*Confidence:\s*([0-9]+(?:\.[0-9]+)?)\s*$/i,
|
|
86
|
+
);
|
|
87
|
+
if (b) {
|
|
88
|
+
const items = taste.get(category) ?? [];
|
|
89
|
+
items.push({ text: b[1].trim(), confidence: parseFloat(b[2]) });
|
|
90
|
+
taste.set(category, items);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return taste;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function serializeTaste(taste: Taste): string {
|
|
97
|
+
const lines: string[] = [];
|
|
98
|
+
for (const [category, items] of taste) {
|
|
99
|
+
if (items.length === 0) continue;
|
|
100
|
+
lines.push(`# ${category}`);
|
|
101
|
+
for (const it of [...items].sort((a, b) => b.confidence - a.confidence)) {
|
|
102
|
+
lines.push(`- ${it.text}. Confidence: ${it.confidence.toFixed(2)}`);
|
|
103
|
+
}
|
|
104
|
+
lines.push("");
|
|
105
|
+
}
|
|
106
|
+
return lines.join("\n").trimEnd() + "\n";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Merge one learning; returns true if the file should be rewritten. */
|
|
110
|
+
function mergeLearning(
|
|
111
|
+
taste: Taste,
|
|
112
|
+
category: string,
|
|
113
|
+
preference: string,
|
|
114
|
+
s: Settings,
|
|
115
|
+
): boolean {
|
|
116
|
+
const cat = category.trim() || "Other";
|
|
117
|
+
const norm = normalize(preference);
|
|
118
|
+
if (!norm) return false;
|
|
119
|
+
|
|
120
|
+
const items = taste.get(cat) ?? [];
|
|
121
|
+
const existing = items.find((i) => normalize(i.text) === norm);
|
|
122
|
+
if (existing) {
|
|
123
|
+
const before = existing.confidence;
|
|
124
|
+
existing.confidence = Math.min(
|
|
125
|
+
0.95,
|
|
126
|
+
+(existing.confidence + s.repeatIncrement).toFixed(2),
|
|
127
|
+
);
|
|
128
|
+
return existing.confidence !== before;
|
|
129
|
+
}
|
|
130
|
+
items.push({ text: preference.trim(), confidence: s.newConfidence });
|
|
131
|
+
taste.set(cat, items);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function readTaste(file: string): Taste {
|
|
136
|
+
try {
|
|
137
|
+
if (fs.existsSync(file)) return parseTaste(fs.readFileSync(file, "utf8"));
|
|
138
|
+
} catch {
|
|
139
|
+
/* unreadable -> empty */
|
|
140
|
+
}
|
|
141
|
+
return new Map();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function writeTaste(file: string, taste: Taste): void {
|
|
145
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
146
|
+
fs.writeFileSync(file, serializeTaste(taste), "utf8");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function safeDelete(file: string): void {
|
|
150
|
+
try {
|
|
151
|
+
if (fs.existsSync(file)) fs.unlinkSync(file);
|
|
152
|
+
} catch {
|
|
153
|
+
/* ignore */
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---- Apply: build the system-prompt section ----------------------------
|
|
158
|
+
function tasteToLines(taste: Taste, threshold: number): string[] {
|
|
159
|
+
const out: string[] = [];
|
|
160
|
+
for (const [cat, items] of taste) {
|
|
161
|
+
const applied = items.filter((i) => i.confidence >= threshold);
|
|
162
|
+
if (applied.length === 0) continue;
|
|
163
|
+
out.push(`**${cat}**`);
|
|
164
|
+
for (const it of [...applied].sort((a, b) => b.confidence - a.confidence)) {
|
|
165
|
+
out.push(`- ${it.text}. (conf ${it.confidence.toFixed(2)})`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function buildTasteSection(
|
|
172
|
+
gTaste: Taste,
|
|
173
|
+
pTaste: Taste,
|
|
174
|
+
gThresh: number,
|
|
175
|
+
pThresh: number,
|
|
176
|
+
): string {
|
|
177
|
+
const gLines = tasteToLines(gTaste, gThresh);
|
|
178
|
+
const pLines = tasteToLines(pTaste, pThresh);
|
|
179
|
+
if (gLines.length === 0 && pLines.length === 0) return "";
|
|
180
|
+
|
|
181
|
+
const parts = [
|
|
182
|
+
"## Your learned taste (pi-taste)",
|
|
183
|
+
"",
|
|
184
|
+
"Preferences learned from your past requests. Follow them unless the current request clearly overrides.",
|
|
185
|
+
"",
|
|
186
|
+
];
|
|
187
|
+
if (gLines.length) {
|
|
188
|
+
parts.push("### Global preferences (all projects)");
|
|
189
|
+
parts.push(...gLines, "");
|
|
190
|
+
}
|
|
191
|
+
if (pLines.length) {
|
|
192
|
+
parts.push("### This project");
|
|
193
|
+
parts.push(...pLines, "");
|
|
194
|
+
}
|
|
195
|
+
return parts.join("\n").trimEnd();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ---- Learn: extract preferences via the active local model ------------
|
|
199
|
+
interface RawLearning {
|
|
200
|
+
category?: string;
|
|
201
|
+
preference?: string;
|
|
202
|
+
scope?: "global" | "project";
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const EXTRACT_PROMPT = `You are a coding-preference extractor. Given a user's coding request and the assistant's outcome, extract DURABLE preferences about how this user likes to work.
|
|
206
|
+
|
|
207
|
+
Rules:
|
|
208
|
+
- Extract only preferences clearly evidenced by the request or the resulting choices: tooling, libraries, language style, architecture, testing, git/commit style, documentation, or communication/format.
|
|
209
|
+
- Do NOT extract task-specific facts (file names, bug locations, one-off decisions).
|
|
210
|
+
- For each, set scope:
|
|
211
|
+
- "global" if it applies to ANY software project regardless of language/stack (e.g. "prefer pnpm", "write concise commit messages").
|
|
212
|
+
- "project" if it is specific to THIS codebase (its languages, frameworks, conventions, file layout).
|
|
213
|
+
- Choose a short category from: CLI, TypeScript, JavaScript, Python, Rust, Go, Architecture, Testing, Git, Documentation, Style, Tooling, Communication, Other.
|
|
214
|
+
|
|
215
|
+
Return ONLY minified JSON: an array of {"category":string,"preference":string,"scope":"global"|"project"}. No markdown fences, no commentary. If nothing durable, return [].`;
|
|
216
|
+
|
|
217
|
+
function parseLearnings(text: string): RawLearning[] {
|
|
218
|
+
let t = text.trim();
|
|
219
|
+
const fence = t.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
220
|
+
if (fence) t = fence[1].trim();
|
|
221
|
+
try {
|
|
222
|
+
const parsed = JSON.parse(t);
|
|
223
|
+
if (!Array.isArray(parsed)) return [];
|
|
224
|
+
return parsed
|
|
225
|
+
.filter(
|
|
226
|
+
(x) =>
|
|
227
|
+
x &&
|
|
228
|
+
typeof x.preference === "string" &&
|
|
229
|
+
x.preference.trim().length > 0,
|
|
230
|
+
)
|
|
231
|
+
.map((x) => ({
|
|
232
|
+
category: typeof x.category === "string" ? x.category : "Other",
|
|
233
|
+
preference: x.preference,
|
|
234
|
+
scope: x.scope === "global" ? "global" : "project",
|
|
235
|
+
}));
|
|
236
|
+
} catch {
|
|
237
|
+
return [];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function lastAssistantText(ctx: ExtensionContext): string {
|
|
242
|
+
const entries = ctx.sessionManager.getEntries();
|
|
243
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
244
|
+
const e = entries[i];
|
|
245
|
+
if (e.type === "message" && e.message?.role === "assistant") {
|
|
246
|
+
const c = e.message.content;
|
|
247
|
+
if (typeof c === "string") return c;
|
|
248
|
+
if (Array.isArray(c)) {
|
|
249
|
+
return c
|
|
250
|
+
.filter((p: any) => p?.type === "text")
|
|
251
|
+
.map((p: any) => p.text)
|
|
252
|
+
.join("\n");
|
|
253
|
+
}
|
|
254
|
+
return "";
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return "";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async function extractLearnings(
|
|
261
|
+
ctx: ExtensionContext,
|
|
262
|
+
userPrompt: string,
|
|
263
|
+
assistantText: string,
|
|
264
|
+
): Promise<RawLearning[]> {
|
|
265
|
+
if (!ctx.model) return [];
|
|
266
|
+
if (!ctx.modelRegistry.hasConfiguredAuth(ctx.model)) return [];
|
|
267
|
+
|
|
268
|
+
const context = {
|
|
269
|
+
messages: [
|
|
270
|
+
{
|
|
271
|
+
role: "user" as const,
|
|
272
|
+
content: [
|
|
273
|
+
{
|
|
274
|
+
type: "text" as const,
|
|
275
|
+
text:
|
|
276
|
+
EXTRACT_PROMPT +
|
|
277
|
+
`\n\nUSER REQUEST:\n${userPrompt}\n\nASSISTANT OUTCOME:\n${assistantText}`,
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
timestamp: Date.now(),
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
} as any;
|
|
284
|
+
|
|
285
|
+
const res = await ctx.modelRegistry.complete(ctx.model, context, {
|
|
286
|
+
reasoningEffort: "low",
|
|
287
|
+
cacheRetention: "none",
|
|
288
|
+
sessionId: uuidv7(),
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const text = res.content
|
|
292
|
+
.filter((c: any) => c.type === "text")
|
|
293
|
+
.map((c: any) => c.text)
|
|
294
|
+
.join("");
|
|
295
|
+
return parseLearnings(text);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ---- Wiring ------------------------------------------------------------
|
|
299
|
+
export default function (pi: ExtensionAPI) {
|
|
300
|
+
let lastUserPrompt = "";
|
|
301
|
+
let lastLearnAt = 0;
|
|
302
|
+
let pendingLearn: Promise<void> | null = null;
|
|
303
|
+
// True only between a genuine user `input` and that turn's `agent_settled`.
|
|
304
|
+
// Synthetic re-runs (auto-compaction, retries) emit no `input`, so this
|
|
305
|
+
// stays false and we never learn preferences from a system-generated prompt.
|
|
306
|
+
let freshInput = false;
|
|
307
|
+
|
|
308
|
+
// A genuine user submission arms learning. Extension-injected messages
|
|
309
|
+
// (source "extension") are excluded so we don't learn the taste of our own
|
|
310
|
+
// meta-prompts (e.g. review-subagent instructions).
|
|
311
|
+
pi.on("input", (event) => {
|
|
312
|
+
if (event.source !== "extension") freshInput = true;
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
// Apply: inject learned taste before each agent run.
|
|
316
|
+
pi.on("before_agent_start", (event, ctx) => {
|
|
317
|
+
if (freshInput) lastUserPrompt = event.prompt ?? "";
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
const gSettings = loadSettings(GLOBAL_SETTINGS);
|
|
321
|
+
const pSettings = loadSettings(projectSettingsFile(ctx.cwd));
|
|
322
|
+
const gTaste = readTaste(GLOBAL_TASTE);
|
|
323
|
+
const pTaste = readTaste(projectTasteFile(ctx.cwd));
|
|
324
|
+
|
|
325
|
+
const section = buildTasteSection(
|
|
326
|
+
gTaste,
|
|
327
|
+
pTaste,
|
|
328
|
+
gSettings.applyThreshold,
|
|
329
|
+
pSettings.applyThreshold,
|
|
330
|
+
);
|
|
331
|
+
if (!section) return;
|
|
332
|
+
return { systemPrompt: event.systemPrompt + "\n\n" + section };
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Learn: after a request fully settles (no retry/compact/follow-up left).
|
|
336
|
+
pi.on("agent_settled", async (_event, ctx) => {
|
|
337
|
+
const gSettings = loadSettings(GLOBAL_SETTINGS);
|
|
338
|
+
const pSettings = loadSettings(projectSettingsFile(ctx.cwd));
|
|
339
|
+
if (!gSettings.learning && !pSettings.learning) return;
|
|
340
|
+
if (!freshInput) return; // synthetic re-run (e.g. auto-compaction) — skip
|
|
341
|
+
freshInput = false; // this genuine turn is now being consumed
|
|
342
|
+
|
|
343
|
+
const prompt = lastUserPrompt.trim();
|
|
344
|
+
if (!prompt || prompt.length < gSettings.minPromptLength) return;
|
|
345
|
+
if (prompt.startsWith("/taste")) return; // don't learn from our own command
|
|
346
|
+
|
|
347
|
+
// Rate-limit window follows whichever scope is actually learning.
|
|
348
|
+
const interval = gSettings.learning
|
|
349
|
+
? gSettings.minIntervalMs
|
|
350
|
+
: pSettings.minIntervalMs;
|
|
351
|
+
if (Date.now() - lastLearnAt < interval) return;
|
|
352
|
+
|
|
353
|
+
const assistantText = lastAssistantText(ctx);
|
|
354
|
+
if (!assistantText) return;
|
|
355
|
+
|
|
356
|
+
const learnings = await extractLearnings(ctx, prompt, assistantText);
|
|
357
|
+
if (learnings.length === 0) return;
|
|
358
|
+
|
|
359
|
+
// Only consume the cooldown once we actually learned something.
|
|
360
|
+
lastLearnAt = Date.now();
|
|
361
|
+
|
|
362
|
+
const task = (async () => {
|
|
363
|
+
let wrote = false;
|
|
364
|
+
for (const l of learnings) {
|
|
365
|
+
const isGlobal = l.scope === "global";
|
|
366
|
+
const settings = isGlobal ? gSettings : pSettings;
|
|
367
|
+
if (!settings.learning) continue;
|
|
368
|
+
const file = isGlobal ? GLOBAL_TASTE : projectTasteFile(ctx.cwd);
|
|
369
|
+
const taste = readTaste(file);
|
|
370
|
+
if (mergeLearning(taste, l.category ?? "Other", l.preference ?? "", settings)) {
|
|
371
|
+
writeTaste(file, taste);
|
|
372
|
+
wrote = true;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (wrote && ctx.hasUI) {
|
|
376
|
+
ctx.ui.notify(
|
|
377
|
+
`TASTE learned ${learnings.length} preference(s)`,
|
|
378
|
+
"info",
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
})();
|
|
382
|
+
pendingLearn = task;
|
|
383
|
+
await task;
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
// Flush any in-flight learning so it isn't lost on exit.
|
|
387
|
+
pi.on("session_shutdown", async () => {
|
|
388
|
+
if (pendingLearn) {
|
|
389
|
+
try {
|
|
390
|
+
await pendingLearn;
|
|
391
|
+
} catch {
|
|
392
|
+
/* ignore */
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// /taste — view or reset learnings.
|
|
398
|
+
pi.registerCommand("taste", {
|
|
399
|
+
description:
|
|
400
|
+
"Show or reset learned taste. Usage: /taste [reset [global|project]]",
|
|
401
|
+
handler: async (args, ctx) => {
|
|
402
|
+
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
403
|
+
if (parts[0] === "reset") {
|
|
404
|
+
const scope = parts[1];
|
|
405
|
+
if (scope === "global") {
|
|
406
|
+
safeDelete(GLOBAL_TASTE);
|
|
407
|
+
ctx.ui.notify("Cleared global taste.", "info");
|
|
408
|
+
} else if (scope === "project") {
|
|
409
|
+
safeDelete(projectTasteFile(ctx.cwd));
|
|
410
|
+
ctx.ui.notify("Cleared project taste.", "info");
|
|
411
|
+
} else if (!scope) {
|
|
412
|
+
safeDelete(GLOBAL_TASTE);
|
|
413
|
+
safeDelete(projectTasteFile(ctx.cwd));
|
|
414
|
+
ctx.ui.notify("Cleared global + project taste.", "info");
|
|
415
|
+
} else {
|
|
416
|
+
ctx.ui.notify(
|
|
417
|
+
`Unknown scope '${scope}'. Use 'global' or 'project'.`,
|
|
418
|
+
"warning",
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const g = readTaste(GLOBAL_TASTE);
|
|
425
|
+
const p = readTaste(projectTasteFile(ctx.cwd));
|
|
426
|
+
const gSettings = loadSettings(GLOBAL_SETTINGS);
|
|
427
|
+
const pSettings = loadSettings(projectSettingsFile(ctx.cwd));
|
|
428
|
+
const count = (t: Taste) =>
|
|
429
|
+
[...t.values()].reduce((n, a) => n + a.length, 0);
|
|
430
|
+
const applied = (t: Taste, th: number) =>
|
|
431
|
+
[...t.values()].flat().filter((i) => i.confidence >= th).length;
|
|
432
|
+
|
|
433
|
+
ctx.ui.notify(
|
|
434
|
+
[
|
|
435
|
+
`TASTE — global : ${count(g)} prefs (${applied(g, gSettings.applyThreshold)} applied) → ${GLOBAL_TASTE}`,
|
|
436
|
+
`TASTE — project: ${count(p)} prefs (${applied(p, pSettings.applyThreshold)} applied) → ${projectTasteFile(ctx.cwd)}`,
|
|
437
|
+
`Run '/taste reset [global|project]' to clear.`,
|
|
438
|
+
].join("\n"),
|
|
439
|
+
"info",
|
|
440
|
+
);
|
|
441
|
+
},
|
|
442
|
+
});
|
|
443
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env pwsh
|
|
2
|
+
# Per-extension installer — Windows / PowerShell
|
|
3
|
+
# Installs npm dependencies for this extension. No-op if no package.json.
|
|
4
|
+
$ErrorActionPreference = "Stop"
|
|
5
|
+
$extDir = $PSScriptRoot
|
|
6
|
+
if (-not $extDir) { $extDir = Split-Path -Parent $MyInvocation.MyCommand.Path }
|
|
7
|
+
if (-not (Test-Path "$extDir/package.json")) {
|
|
8
|
+
Write-Host " - no package.json — skipping" -ForegroundColor DarkGray
|
|
9
|
+
exit 0
|
|
10
|
+
}
|
|
11
|
+
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
|
|
12
|
+
Write-Host " x npm not found — install Node.js 22+" -ForegroundColor Red
|
|
13
|
+
exit 1
|
|
14
|
+
}
|
|
15
|
+
if (Test-Path "$extDir/package-lock.json") {
|
|
16
|
+
Write-Host " - npm ci" -ForegroundColor DarkGray
|
|
17
|
+
npm --prefix $extDir ci --no-audit --no-fund
|
|
18
|
+
} else {
|
|
19
|
+
Write-Host " - npm install" -ForegroundColor DarkGray
|
|
20
|
+
npm --prefix $extDir install --no-audit --no-fund
|
|
21
|
+
}
|
|
22
|
+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
23
|
+
Write-Host " + done" -ForegroundColor Green
|