@blackbelt-technology/pi-dashboard-sim-plugin 0.0.0-stage → 0.12.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 +19 -2
- package/package.json +86 -4
- package/src/client/FolderSimSection.tsx +37 -0
- package/src/client/GlobsEditor.tsx +36 -0
- package/src/client/ProblemTimeline.tsx +178 -0
- package/src/client/ReviewQueues.tsx +150 -0
- package/src/client/SimGlobalSettings.tsx +77 -0
- package/src/client/SimOverlayClaim.tsx +26 -0
- package/src/client/SimPage.tsx +107 -0
- package/src/client/SimPageView.tsx +181 -0
- package/src/client/chips.tsx +40 -0
- package/src/client/index.tsx +3 -0
- package/src/client/sim-api.ts +106 -0
- package/src/client/useSimData.ts +48 -0
- package/src/i18n.ts +152 -0
- package/src/server/index.ts +27 -0
- package/src/server/observe-worker.mjs +4 -0
- package/src/server/observer.ts +119 -0
- package/src/server/sim-routes.ts +381 -0
- package/src/shared/types.ts +95 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** SIM folder page container: loads data, wires actions, renders SimPageView. */
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import type { OutcomeResult, SimScope } from "../shared/types.js";
|
|
5
|
+
import {
|
|
6
|
+
dismissDraft,
|
|
7
|
+
fetchProjectConfig,
|
|
8
|
+
type LinkBody,
|
|
9
|
+
linkDraft,
|
|
10
|
+
postEvent,
|
|
11
|
+
saveProjectGlobs,
|
|
12
|
+
startObservation,
|
|
13
|
+
} from "./sim-api.js";
|
|
14
|
+
import { type SimTab, SimPageView } from "./SimPageView.js";
|
|
15
|
+
import { useSimDrafts, useSimProblem, useSimProblems } from "./useSimData.js";
|
|
16
|
+
|
|
17
|
+
export function SimPage({ cwd, onBack }: { cwd: string; onBack: () => void }): React.ReactElement {
|
|
18
|
+
const [scope, setScope] = useState<SimScope>("project");
|
|
19
|
+
const [tab, setTab] = useState<SimTab>("problems");
|
|
20
|
+
const [selectedId, setSelectedId] = useState<string>();
|
|
21
|
+
const [actionError, setActionError] = useState<string>();
|
|
22
|
+
const problems = useSimProblems(scope, cwd);
|
|
23
|
+
const problem = useSimProblem(scope, cwd, selectedId);
|
|
24
|
+
const drafts = useSimDrafts(cwd);
|
|
25
|
+
const [globs, setGlobs] = useState<{ custom: string[]; defaults: string[] }>();
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (tab !== "settings") return;
|
|
29
|
+
fetchProjectConfig(cwd).then(
|
|
30
|
+
(c) => setGlobs({ custom: c.harnessGlobs, defaults: c.defaults }),
|
|
31
|
+
(e: unknown) => setActionError(e instanceof Error ? e.message : String(e)),
|
|
32
|
+
);
|
|
33
|
+
}, [tab, cwd]);
|
|
34
|
+
|
|
35
|
+
// Poll while the observer runs.
|
|
36
|
+
const running = problems.data?.observer.running;
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!running) return;
|
|
39
|
+
const id = setInterval(problems.refetch, 2000);
|
|
40
|
+
return () => clearInterval(id);
|
|
41
|
+
}, [running, problems.refetch]);
|
|
42
|
+
|
|
43
|
+
const refresh = useCallback(() => {
|
|
44
|
+
problems.refetch();
|
|
45
|
+
problem.refetch();
|
|
46
|
+
drafts.refetch();
|
|
47
|
+
}, [problems.refetch, problem.refetch, drafts.refetch]);
|
|
48
|
+
|
|
49
|
+
const run = useCallback(
|
|
50
|
+
(fn: () => Promise<unknown>) => {
|
|
51
|
+
setActionError(undefined);
|
|
52
|
+
fn().then(refresh, (e: unknown) => setActionError(e instanceof Error ? e.message : String(e)));
|
|
53
|
+
},
|
|
54
|
+
[refresh],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<SimPageView
|
|
59
|
+
folderName={cwd.split(/[\\/]/).pop() || cwd}
|
|
60
|
+
scope={scope}
|
|
61
|
+
onScope={(s) => {
|
|
62
|
+
setScope(s);
|
|
63
|
+
setSelectedId(undefined);
|
|
64
|
+
if (s === "global" && tab === "settings") setTab("problems");
|
|
65
|
+
}}
|
|
66
|
+
tab={tab}
|
|
67
|
+
onTab={setTab}
|
|
68
|
+
data={problems.data}
|
|
69
|
+
error={actionError ?? problems.error}
|
|
70
|
+
selected={selectedId ? problem.data : undefined}
|
|
71
|
+
onSelect={setSelectedId}
|
|
72
|
+
drafts={drafts.data ?? []}
|
|
73
|
+
projectGlobs={globs}
|
|
74
|
+
onSaveGlobs={(next) =>
|
|
75
|
+
run(async () => {
|
|
76
|
+
await saveProjectGlobs(cwd, next);
|
|
77
|
+
setGlobs((g) => (g ? { ...g, custom: next } : g));
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
onObserve={() => run(startObservation)}
|
|
81
|
+
onBack={onBack}
|
|
82
|
+
timeline={{
|
|
83
|
+
mark: (attempt: string, prediction: number, result: OutcomeResult) =>
|
|
84
|
+
run(() => postEvent(scope, cwd, { type: "manual-outcome", attempt, prediction, result })),
|
|
85
|
+
revert: (attempt) => run(() => postEvent(scope, cwd, { type: "revert", attempt })),
|
|
86
|
+
approve: (attempt) => run(() => postEvent(scope, cwd, { type: "review", attempt, decision: "approve" })),
|
|
87
|
+
merge: (from, into) =>
|
|
88
|
+
run(async () => {
|
|
89
|
+
await postEvent(scope, cwd, { type: "merge", from, into });
|
|
90
|
+
setSelectedId(into);
|
|
91
|
+
}),
|
|
92
|
+
}}
|
|
93
|
+
review={{
|
|
94
|
+
link: async (draft: string, body: LinkBody) => {
|
|
95
|
+
await linkDraft(cwd, draft, body);
|
|
96
|
+
refresh();
|
|
97
|
+
},
|
|
98
|
+
dismiss: (draft) => run(() => dismissDraft(cwd, draft)),
|
|
99
|
+
approve: (attempt) => run(() => postEvent(scope, cwd, { type: "review", attempt, decision: "approve" })),
|
|
100
|
+
open: (id) => {
|
|
101
|
+
setSelectedId(id);
|
|
102
|
+
setTab("problems");
|
|
103
|
+
},
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SIM folder page (presentational): header with observer status, Project /
|
|
3
|
+
* Global toggle, Problems | Review | Settings tabs. All data and actions come
|
|
4
|
+
* in through props, so the live-component mock renders the real view.
|
|
5
|
+
*/
|
|
6
|
+
import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
7
|
+
import { mdiArrowLeft } from "@mdi/js";
|
|
8
|
+
import { Icon } from "@mdi/react";
|
|
9
|
+
import type React from "react";
|
|
10
|
+
import type { SimDraft, SimProblemDetail, SimProblemsResponse, SimScope } from "../shared/types.js";
|
|
11
|
+
import { BUTTON, Chip, HEADING } from "./chips.js";
|
|
12
|
+
import { GlobsEditor } from "./GlobsEditor.js";
|
|
13
|
+
import { ProblemDetailView, type TimelineActions } from "./ProblemTimeline.js";
|
|
14
|
+
import { type ReviewActions, ReviewQueues } from "./ReviewQueues.js";
|
|
15
|
+
import { formatHitRate } from "./sim-api.js";
|
|
16
|
+
|
|
17
|
+
export type SimTab = "problems" | "review" | "settings";
|
|
18
|
+
|
|
19
|
+
export interface SimPageViewProps {
|
|
20
|
+
folderName: string;
|
|
21
|
+
scope: SimScope;
|
|
22
|
+
onScope: (s: SimScope) => void;
|
|
23
|
+
tab: SimTab;
|
|
24
|
+
onTab: (t: SimTab) => void;
|
|
25
|
+
data?: SimProblemsResponse;
|
|
26
|
+
error?: string;
|
|
27
|
+
selected?: SimProblemDetail;
|
|
28
|
+
onSelect: (id: string) => void;
|
|
29
|
+
drafts: SimDraft[];
|
|
30
|
+
projectGlobs?: { custom: string[]; defaults: string[] };
|
|
31
|
+
onSaveGlobs: (globs: string[]) => void;
|
|
32
|
+
onObserve: () => void;
|
|
33
|
+
onBack: () => void;
|
|
34
|
+
timeline: TimelineActions;
|
|
35
|
+
review: ReviewActions;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function Tabs({ tab, onTab, data, drafts, scope }: Pick<SimPageViewProps, "tab" | "onTab" | "data" | "drafts" | "scope">): React.ReactElement {
|
|
39
|
+
const t = useT();
|
|
40
|
+
const reviewCount = drafts.filter((d) => d.scope === scope).length + (data?.withheldQueue.length ?? 0);
|
|
41
|
+
const items: Array<[SimTab, string]> = [
|
|
42
|
+
["problems", t("tabProblems", undefined, "Problems")],
|
|
43
|
+
["review", reviewCount ? t("tabReviewN", { n: reviewCount }, `Review (${reviewCount})`) : t("tabReview", undefined, "Review")],
|
|
44
|
+
...(scope === "project" ? ([["settings", t("tabSettings", undefined, "Settings")]] as Array<[SimTab, string]>) : []),
|
|
45
|
+
];
|
|
46
|
+
return (
|
|
47
|
+
<div role="tablist" className="flex gap-1 border-b border-[var(--border-subtle)] px-4">
|
|
48
|
+
{items.map(([id, label]) => (
|
|
49
|
+
<button
|
|
50
|
+
key={id}
|
|
51
|
+
type="button"
|
|
52
|
+
role="tab"
|
|
53
|
+
aria-selected={tab === id}
|
|
54
|
+
data-testid={`sim-tab-${id}`}
|
|
55
|
+
onClick={() => onTab(id)}
|
|
56
|
+
className={`px-2.5 py-1.5 text-[12px] border-b-2 -mb-px ${tab === id ? "border-[var(--accent-primary)] text-[var(--text-primary)]" : "border-transparent text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"}`}
|
|
57
|
+
>
|
|
58
|
+
{label}
|
|
59
|
+
</button>
|
|
60
|
+
))}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function SimPageView(p: SimPageViewProps): React.ReactElement {
|
|
66
|
+
const t = useT();
|
|
67
|
+
const obs = p.data?.observer;
|
|
68
|
+
return (
|
|
69
|
+
<div className="flex flex-col h-full overflow-y-auto bg-[var(--bg-primary)]" data-testid="sim-page" data-scope={p.scope}>
|
|
70
|
+
<div className="px-4 py-2 border-b border-[var(--border-primary)] bg-[var(--bg-primary)] flex flex-wrap items-center gap-2 sticky top-0 z-10">
|
|
71
|
+
<button type="button" onClick={p.onBack} className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)]" title={t("back", undefined, "Back")} data-testid="sim-back">
|
|
72
|
+
<Icon path={mdiArrowLeft} size={0.7} />
|
|
73
|
+
</button>
|
|
74
|
+
<span className="text-sm font-medium text-[var(--text-primary)] truncate">
|
|
75
|
+
{t("pageTitle", { name: p.folderName }, `${p.folderName} · Self-Improvement Memory`)}
|
|
76
|
+
</span>
|
|
77
|
+
<div role="radiogroup" aria-label={t("scope", undefined, "Scope")} className="ml-auto flex rounded border border-[var(--border-subtle)] overflow-hidden">
|
|
78
|
+
{(["project", "global"] as SimScope[]).map((s) => (
|
|
79
|
+
<button
|
|
80
|
+
key={s}
|
|
81
|
+
type="button"
|
|
82
|
+
role="radio"
|
|
83
|
+
aria-checked={p.scope === s}
|
|
84
|
+
data-testid={`sim-scope-${s}`}
|
|
85
|
+
onClick={() => p.onScope(s)}
|
|
86
|
+
className={`px-2.5 py-1 text-[12px] ${p.scope === s ? "bg-[var(--bg-selected)] text-[var(--text-primary)]" : "text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"}`}
|
|
87
|
+
>
|
|
88
|
+
{s === "project" ? t("scopeProject", undefined, "Project") : t("scopeGlobal", undefined, "Global")}
|
|
89
|
+
</button>
|
|
90
|
+
))}
|
|
91
|
+
</div>
|
|
92
|
+
<button type="button" className={BUTTON} onClick={p.onObserve} disabled={obs?.running} data-testid="sim-observe" title={t("observeTip", undefined, "Read later sessions and update automatic outcomes (local evidence)")}>
|
|
93
|
+
{obs?.running
|
|
94
|
+
? t("observing", { done: obs.progress?.done ?? 0, total: obs.progress?.total ?? 0 }, `Observing… ${obs.progress?.done ?? 0}/${obs.progress?.total ?? 0}`)
|
|
95
|
+
: t("observe", undefined, "Observe now")}
|
|
96
|
+
</button>
|
|
97
|
+
</div>
|
|
98
|
+
<Tabs tab={p.tab} onTab={p.onTab} data={p.data} drafts={p.drafts} scope={p.scope} />
|
|
99
|
+
{p.error && (
|
|
100
|
+
<p role="alert" className="m-4 text-[12px] text-[var(--severity-error-fg)]" data-testid="sim-error">
|
|
101
|
+
{p.error}
|
|
102
|
+
</p>
|
|
103
|
+
)}
|
|
104
|
+
{!p.data && !p.error && <p className="m-4 text-[12px] text-[var(--text-tertiary)]">{t("loading", undefined, "Loading…")}</p>}
|
|
105
|
+
{p.data && p.tab === "problems" && (
|
|
106
|
+
<div className="grid gap-4 p-4 md:grid-cols-[minmax(220px,320px)_1fr]">
|
|
107
|
+
<nav aria-label={t("problems", undefined, "Problems")}>
|
|
108
|
+
<h3 className={HEADING}>{t("problemsHeading", { n: p.data.problems.length }, `Problems (${p.data.problems.length})`)}</h3>
|
|
109
|
+
{p.data.problems.length === 0 && (
|
|
110
|
+
<p className="mt-1 text-[12px] text-[var(--text-tertiary)]" data-testid="sim-empty">
|
|
111
|
+
{t("empty", undefined, "No harness problems recorded in this scope yet. Agents record them with `sim record` after a harness edit.")}
|
|
112
|
+
</p>
|
|
113
|
+
)}
|
|
114
|
+
<ul className="mt-1 grid gap-1">
|
|
115
|
+
{p.data.problems.map((pr) => (
|
|
116
|
+
<li key={pr.id}>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
data-testid="sim-problem-row"
|
|
120
|
+
data-problem-id={pr.id}
|
|
121
|
+
aria-current={p.selected?.id === pr.id}
|
|
122
|
+
onClick={() => p.onSelect(pr.id)}
|
|
123
|
+
className={`w-full text-left rounded border px-2 py-1.5 ${p.selected?.id === pr.id ? "border-[var(--accent-primary)] bg-[var(--bg-selected)]" : "border-[var(--border-subtle)] bg-[var(--bg-secondary)] hover:border-[var(--border-strong)]"}`}
|
|
124
|
+
>
|
|
125
|
+
<span className="block text-[13px] text-[var(--text-primary)] truncate">{pr.withheld ? t("withheldProblem", undefined, "(withheld problem)") : pr.name}</span>
|
|
126
|
+
<span className="mt-0.5 flex flex-wrap items-center gap-1.5 text-[11px] text-[var(--text-tertiary)] tabular-nums">
|
|
127
|
+
<span data-testid="sim-problem-attempts">{t("attemptsN", { n: pr.attempts }, `${pr.attempts} attempts`)}</span>
|
|
128
|
+
{pr.pending > 0 && <Chip>{t("pendingN", { n: pr.pending }, `${pr.pending} pending`)}</Chip>}
|
|
129
|
+
<span>{t("hitRate", { rate: formatHitRate(pr.hitRate) }, `hit rate ${formatHitRate(pr.hitRate)}`)}</span>
|
|
130
|
+
</span>
|
|
131
|
+
</button>
|
|
132
|
+
</li>
|
|
133
|
+
))}
|
|
134
|
+
</ul>
|
|
135
|
+
</nav>
|
|
136
|
+
<div className="min-w-0">
|
|
137
|
+
{p.selected ? (
|
|
138
|
+
<ProblemDetailView problem={p.selected} others={p.data.problems} actions={p.timeline} />
|
|
139
|
+
) : (
|
|
140
|
+
p.data.problems.length > 0 && <p className="text-[12px] text-[var(--text-tertiary)]">{t("selectProblem", undefined, "Select a problem to see its attempts.")}</p>
|
|
141
|
+
)}
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
{p.data && p.tab === "review" && (
|
|
146
|
+
<div className="p-4">
|
|
147
|
+
<ReviewQueues data={p.data} drafts={p.drafts} actions={p.review} />
|
|
148
|
+
</div>
|
|
149
|
+
)}
|
|
150
|
+
{p.tab === "settings" && p.scope === "project" && (
|
|
151
|
+
<div className="p-4 grid gap-3 max-w-2xl" data-testid="sim-settings">
|
|
152
|
+
<h3 className={HEADING}>{t("harnessGlobs", undefined, "Extra harness paths for this project")}</h3>
|
|
153
|
+
<p className="text-[12px] text-[var(--text-secondary)]">
|
|
154
|
+
{t("globsHelp", undefined, "Edits to these paths count as harness edits. A glob needs a literal .pi/ segment or names one file at the repository root. Saved to .pi/sim/config.json (shared with the team).")}
|
|
155
|
+
</p>
|
|
156
|
+
<GlobsEditor globs={p.projectGlobs?.custom ?? []} onChange={p.onSaveGlobs} testId="sim-project-globs" />
|
|
157
|
+
<h3 className={HEADING}>{t("defaultGlobs", undefined, "Always harness")}</h3>
|
|
158
|
+
<ul className="grid gap-0.5">
|
|
159
|
+
{(p.projectGlobs?.defaults ?? []).map((g) => (
|
|
160
|
+
<li key={g}>
|
|
161
|
+
<code className="text-[12px] text-[var(--text-tertiary)]">{g}</code>
|
|
162
|
+
</li>
|
|
163
|
+
))}
|
|
164
|
+
</ul>
|
|
165
|
+
</div>
|
|
166
|
+
)}
|
|
167
|
+
{!!p.data?.unreadable && (
|
|
168
|
+
<p className="px-4 py-1 text-[11px] text-[var(--severity-warning-fg)]" data-testid="sim-unreadable">
|
|
169
|
+
{t("unreadable", { n: p.data.unreadable }, `${p.data.unreadable} record files could not be read and are skipped`)}
|
|
170
|
+
</p>
|
|
171
|
+
)}
|
|
172
|
+
{obs?.lastRun && (
|
|
173
|
+
<p className="mt-auto px-4 py-2 text-[11px] text-[var(--text-tertiary)] border-t border-[var(--border-subtle)]" data-testid="sim-observer-last">
|
|
174
|
+
{obs.lastRun.error
|
|
175
|
+
? t("lastRunFailed", { error: obs.lastRun.error }, `Last observation failed: ${obs.lastRun.error}`)
|
|
176
|
+
: t("lastRun", { at: obs.lastRun.at.slice(0, 16).replace("T", " "), n: obs.lastRun.changed, s: obs.lastRun.sessions }, `Last observation ${obs.lastRun.at.slice(0, 16).replace("T", " ")}: ${obs.lastRun.sessions} sessions, ${obs.lastRun.changed} outcomes changed`)}
|
|
177
|
+
</p>
|
|
178
|
+
)}
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Small token-only chips shared by the SIM views. */
|
|
2
|
+
import type React from "react";
|
|
3
|
+
|
|
4
|
+
export type ChipTone = "neutral" | "success" | "warning" | "error" | "info";
|
|
5
|
+
|
|
6
|
+
const TONE: Record<ChipTone, string> = {
|
|
7
|
+
neutral: "bg-[var(--severity-neutral-bg)] text-[var(--severity-neutral-fg)] border-[var(--severity-neutral-border)]",
|
|
8
|
+
success: "bg-[var(--severity-success-bg)] text-[var(--severity-success-fg)] border-[var(--severity-success-border)]",
|
|
9
|
+
warning: "bg-[var(--severity-warning-bg)] text-[var(--severity-warning-fg)] border-[var(--severity-warning-border)]",
|
|
10
|
+
error: "bg-[var(--severity-error-bg)] text-[var(--severity-error-fg)] border-[var(--severity-error-border)]",
|
|
11
|
+
info: "bg-[var(--severity-info-bg)] text-[var(--severity-info-fg)] border-[var(--severity-info-border)]",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function Chip({ tone = "neutral", children, testId, title }: { tone?: ChipTone; children: React.ReactNode; testId?: string; title?: string }): React.ReactElement {
|
|
15
|
+
return (
|
|
16
|
+
<span
|
|
17
|
+
data-testid={testId}
|
|
18
|
+
title={title}
|
|
19
|
+
className={`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[11px] leading-4 whitespace-nowrap ${TONE[tone]}`}
|
|
20
|
+
>
|
|
21
|
+
{children}
|
|
22
|
+
</span>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function resultTone(result: string): ChipTone {
|
|
27
|
+
if (result === "fixed") return "success";
|
|
28
|
+
if (result === "reduced") return "info";
|
|
29
|
+
if (result === "missed") return "error";
|
|
30
|
+
if (result === "inconclusive") return "warning";
|
|
31
|
+
return "neutral";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const BUTTON =
|
|
35
|
+
"text-[12px] px-2.5 py-1 rounded border border-[var(--border-subtle)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:border-[var(--border-strong)] disabled:opacity-40";
|
|
36
|
+
export const BUTTON_PRIMARY =
|
|
37
|
+
"text-[12px] px-2.5 py-1 rounded border border-[var(--accent-primary)] text-[var(--accent-text)] bg-[var(--accent-soft)] hover:border-[var(--accent-primary-strong)] disabled:opacity-40";
|
|
38
|
+
export const INPUT =
|
|
39
|
+
"text-[12px] bg-[var(--bg-primary)] border border-[var(--border-subtle)] rounded px-2 py-1 text-[var(--text-primary)] focus:outline-none focus:border-[var(--accent-primary)]";
|
|
40
|
+
export const HEADING = "text-[11px] uppercase tracking-wide text-[var(--text-tertiary)] font-semibold";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin REST client for `/api/sim/*` (same-origin relative URLs; plain JSON
|
|
3
|
+
* bodies, `{ error }` on refusal). See change: add-self-improvement-memory.
|
|
4
|
+
*/
|
|
5
|
+
import { folderRouteHref } from "@blackbelt-technology/dashboard-plugin-runtime/sdk";
|
|
6
|
+
import type {
|
|
7
|
+
OutcomeResult,
|
|
8
|
+
SimDraft,
|
|
9
|
+
SimGlobalConfig,
|
|
10
|
+
SimProblemDetail,
|
|
11
|
+
SimProblemsResponse,
|
|
12
|
+
SimProjectConfig,
|
|
13
|
+
SimScope,
|
|
14
|
+
} from "../shared/types.js";
|
|
15
|
+
|
|
16
|
+
export const simPageUrl = (cwd: string): string => folderRouteHref(cwd, "/sim");
|
|
17
|
+
|
|
18
|
+
async function parse<T>(res: Response): Promise<T> {
|
|
19
|
+
if (res.status === 204) return undefined as T;
|
|
20
|
+
const type = res.headers.get("content-type") ?? "";
|
|
21
|
+
if (!type.includes("application/json")) throw new Error(`unexpected response (${res.status})`);
|
|
22
|
+
const json = (await res.json()) as T & { error?: string };
|
|
23
|
+
if (!res.ok) throw new Error(json.error ?? `request failed (${res.status})`);
|
|
24
|
+
return json;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const q = (scope: SimScope, cwd?: string): string =>
|
|
28
|
+
`scope=${scope}${cwd ? `&cwd=${encodeURIComponent(cwd)}` : ""}`;
|
|
29
|
+
|
|
30
|
+
const send = (url: string, method: string, body?: unknown) =>
|
|
31
|
+
fetch(url, {
|
|
32
|
+
method,
|
|
33
|
+
...(body === undefined ? {} : { headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) }),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export async function fetchProblems(scope: SimScope, cwd: string, signal?: AbortSignal): Promise<SimProblemsResponse> {
|
|
37
|
+
return parse(await fetch(`/api/sim/problems?${q(scope, cwd)}`, { signal }));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function fetchProblem(scope: SimScope, cwd: string, id: string, signal?: AbortSignal): Promise<SimProblemDetail> {
|
|
41
|
+
const r = await parse<{ problem: SimProblemDetail }>(await fetch(`/api/sim/problems/${encodeURIComponent(id)}?${q(scope, cwd)}`, { signal }));
|
|
42
|
+
return r.problem;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function fetchDrafts(cwd: string, signal?: AbortSignal): Promise<SimDraft[]> {
|
|
46
|
+
const r = await parse<{ drafts: SimDraft[] }>(await fetch(`/api/sim/unlinked?cwd=${encodeURIComponent(cwd)}`, { signal }));
|
|
47
|
+
return r.drafts;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type EventInput =
|
|
51
|
+
| { type: "manual-outcome"; attempt: string; prediction: number; result: OutcomeResult }
|
|
52
|
+
| { type: "revert"; attempt: string }
|
|
53
|
+
| { type: "review"; attempt: string; decision: "approve" }
|
|
54
|
+
| { type: "merge"; from: string; into: string };
|
|
55
|
+
|
|
56
|
+
export async function postEvent(scope: SimScope, cwd: string, event: EventInput): Promise<void> {
|
|
57
|
+
await parse(await send(`/api/sim/events?${q(scope, cwd)}`, "POST", event));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LinkBody {
|
|
61
|
+
problem: { name?: string; id?: string; description?: string };
|
|
62
|
+
rationale: string;
|
|
63
|
+
what?: string;
|
|
64
|
+
predicted: Array<{ kind: "signature" | "oracle"; value: string }>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function linkDraft(cwd: string, id: string, body: LinkBody): Promise<void> {
|
|
68
|
+
await parse(await send(`/api/sim/unlinked/${encodeURIComponent(id)}/link?cwd=${encodeURIComponent(cwd)}`, "POST", body));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function dismissDraft(cwd: string, id: string): Promise<void> {
|
|
72
|
+
await parse(await send(`/api/sim/unlinked/${encodeURIComponent(id)}?cwd=${encodeURIComponent(cwd)}`, "DELETE"));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function startObservation(): Promise<void> {
|
|
76
|
+
const res = await send("/api/sim/observe", "POST", {});
|
|
77
|
+
if (res.status === 409) return; // already running
|
|
78
|
+
await parse(res);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function fetchProjectConfig(cwd: string): Promise<SimProjectConfig> {
|
|
82
|
+
return (await parse<{ config: SimProjectConfig }>(await fetch(`/api/sim/config?${q("project", cwd)}`))).config;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function saveProjectGlobs(cwd: string, harnessGlobs: string[]): Promise<void> {
|
|
86
|
+
await parse(await send(`/api/sim/config?${q("project", cwd)}`, "PUT", { harnessGlobs }));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export async function fetchGlobalConfig(): Promise<SimGlobalConfig> {
|
|
90
|
+
return (await parse<{ config: SimGlobalConfig }>(await fetch("/api/sim/config?scope=global"))).config;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function saveGlobalConfig(patch: Partial<Omit<SimGlobalConfig, "invalid">>): Promise<void> {
|
|
94
|
+
await parse(await send("/api/sim/config?scope=global", "PUT", patch));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** "50%" / "n/a" (hit rate excludes pending, inconclusive, reverted and backfilled). */
|
|
98
|
+
export function formatHitRate(hitRate: number | null): string {
|
|
99
|
+
return hitRate === null ? "n/a" : `${Math.round(hitRate * 100)}%`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `err:bash:enoent` → signature; anything else → oracle command. */
|
|
103
|
+
export function parsePredictionSpec(spec: string): { kind: "signature" | "oracle"; value: string } {
|
|
104
|
+
const s = spec.trim();
|
|
105
|
+
return s.startsWith("err:") ? { kind: "signature", value: s } : { kind: "oracle", value: s.replace(/^oracle:\s*/, "") };
|
|
106
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Data hooks for the SIM page and sidebar row. */
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import type { SimDraft, SimProblemDetail, SimProblemsResponse, SimScope } from "../shared/types.js";
|
|
4
|
+
import { fetchDrafts, fetchProblem, fetchProblems } from "./sim-api.js";
|
|
5
|
+
|
|
6
|
+
interface Loadable<T> {
|
|
7
|
+
data: T | undefined;
|
|
8
|
+
error: string | undefined;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
refetch: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function useLoad<T>(load: (signal: AbortSignal) => Promise<T>, deps: unknown[], enabled = true): Loadable<T> {
|
|
14
|
+
const [data, setData] = useState<T>();
|
|
15
|
+
const [error, setError] = useState<string>();
|
|
16
|
+
const [loading, setLoading] = useState(enabled);
|
|
17
|
+
const [tick, setTick] = useState(0);
|
|
18
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: deps are the caller's inputs.
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!enabled) return;
|
|
21
|
+
const ac = new AbortController();
|
|
22
|
+
setLoading(true);
|
|
23
|
+
load(ac.signal).then(
|
|
24
|
+
(d) => {
|
|
25
|
+
if (ac.signal.aborted) return;
|
|
26
|
+
setData(d);
|
|
27
|
+
setError(undefined);
|
|
28
|
+
setLoading(false);
|
|
29
|
+
},
|
|
30
|
+
(e: unknown) => {
|
|
31
|
+
if (ac.signal.aborted) return;
|
|
32
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
33
|
+
setLoading(false);
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
return () => ac.abort();
|
|
37
|
+
}, [...deps, tick, enabled]);
|
|
38
|
+
const refetch = useCallback(() => setTick((n) => n + 1), []);
|
|
39
|
+
return { data, error, loading, refetch };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const useSimProblems = (scope: SimScope, cwd: string): Loadable<SimProblemsResponse> =>
|
|
43
|
+
useLoad((s) => fetchProblems(scope, cwd, s), [scope, cwd], !!cwd);
|
|
44
|
+
|
|
45
|
+
export const useSimProblem = (scope: SimScope, cwd: string, id: string | undefined): Loadable<SimProblemDetail> =>
|
|
46
|
+
useLoad((s) => fetchProblem(scope, cwd, id as string, s), [scope, cwd, id], !!cwd && !!id);
|
|
47
|
+
|
|
48
|
+
export const useSimDrafts = (cwd: string): Loadable<SimDraft[]> => useLoad((s) => fetchDrafts(cwd, s), [cwd], !!cwd);
|
package/src/i18n.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SIM plugin i18n catalog — UNPREFIXED leaf keys, merged under `plugin.sim.*`.
|
|
3
|
+
* English lives at the call sites (`t(key, vars, fallback)`); zh-CN and hu
|
|
4
|
+
* keep identical key sets. {var} placeholders are interpolated by `t`.
|
|
5
|
+
* See change: add-self-improvement-memory.
|
|
6
|
+
*/
|
|
7
|
+
export const catalog = {
|
|
8
|
+
"zh-CN": {
|
|
9
|
+
add: "添加",
|
|
10
|
+
addGlob: "添加 glob",
|
|
11
|
+
approve: "批准",
|
|
12
|
+
attemptsN: "{n} 次尝试",
|
|
13
|
+
autoObserve: "每小时观察结果",
|
|
14
|
+
autoWas: "(本地证据:{result})",
|
|
15
|
+
back: "返回",
|
|
16
|
+
budget: "每个范围的投递预算(字节)",
|
|
17
|
+
cancel: "取消",
|
|
18
|
+
chooseProblem: "选择一个问题…",
|
|
19
|
+
countsTip: "出现该失败的会话:之前 → 之后",
|
|
20
|
+
defaultGlobs: "始终视为 harness",
|
|
21
|
+
detailCounts: "{n} 次尝试 · 命中率 {rate}",
|
|
22
|
+
dismiss: "忽略",
|
|
23
|
+
empty: "此范围内尚未记录 harness 问题。代理在编辑 harness 后用 `sim record` 记录。",
|
|
24
|
+
globalGlobs: "全局 harness 路径(相对于代理目录)",
|
|
25
|
+
globsHelp: "对这些路径的编辑视为 harness 编辑。glob 需要包含字面的 .pi/ 段,或指向仓库根目录下的单个文件。保存到 .pi/sim/config.json(团队共享)。",
|
|
26
|
+
harnessGlobs: "此项目的额外 harness 路径",
|
|
27
|
+
hitRate: "命中率 {rate}",
|
|
28
|
+
invalidFolderPath: "无效的文件夹路径。",
|
|
29
|
+
lastRun: "上次观察 {at}:{s} 个会话,{n} 个结果变化",
|
|
30
|
+
lastRunFailed: "上次观察失败:{error}",
|
|
31
|
+
link: "关联…",
|
|
32
|
+
linkSubmit: "记录尝试",
|
|
33
|
+
loading: "加载中…",
|
|
34
|
+
markOutcome: "标记结果",
|
|
35
|
+
merge: "合并",
|
|
36
|
+
mergeInto: "合并到",
|
|
37
|
+
noUnlinked: "每次 harness 编辑都有记录。",
|
|
38
|
+
noWithheld: "没有被扣留的内容。",
|
|
39
|
+
observe: "立即观察",
|
|
40
|
+
observeTip: "读取之后的会话并更新自动结果(本地证据)",
|
|
41
|
+
observing: "观察中… {done}/{total}",
|
|
42
|
+
openSim: "打开自我改进记忆",
|
|
43
|
+
pageTitle: "{name} · 自我改进记忆",
|
|
44
|
+
pendingHeading: "等待证据({n})",
|
|
45
|
+
pendingN: "{n} 个待定",
|
|
46
|
+
predictField: "预测,每行一个(err:<tool>:<class> 或 oracle 命令)",
|
|
47
|
+
problemField: "问题(已有名称或新名称)",
|
|
48
|
+
problems: "问题",
|
|
49
|
+
problemsHeading: "问题({n})",
|
|
50
|
+
rationaleField: "此编辑针对的根本原因",
|
|
51
|
+
remove: "移除",
|
|
52
|
+
revert: "标记为已撤销",
|
|
53
|
+
rootCause: "根本原因:",
|
|
54
|
+
save: "保存",
|
|
55
|
+
saved: "已保存",
|
|
56
|
+
scope: "范围",
|
|
57
|
+
scopeGlobal: "全局",
|
|
58
|
+
scopeProject: "项目",
|
|
59
|
+
selectProblem: "选择一个问题以查看其尝试。",
|
|
60
|
+
slotCounts: "{p} 个问题 · {m} 个待定 · {k} 个未关联",
|
|
61
|
+
slotLabel: "Harness 记忆",
|
|
62
|
+
sourceLocal: "{source} · 本地证据",
|
|
63
|
+
sourceManual: "手动",
|
|
64
|
+
sourceNone: "尚无证据",
|
|
65
|
+
tabProblems: "问题",
|
|
66
|
+
tabReview: "审核",
|
|
67
|
+
tabReviewN: "审核({n})",
|
|
68
|
+
tabSettings: "设置",
|
|
69
|
+
trustUser: "由用户关联",
|
|
70
|
+
trustWeb: "来自网络",
|
|
71
|
+
trustWebApproved: "来自网络 · 已批准",
|
|
72
|
+
unlinkedHeading: "未关联的 harness 编辑({n})",
|
|
73
|
+
unreadable: "{n} 个记录文件无法读取,已跳过",
|
|
74
|
+
webTools: "网络工具(在这些工具之后的记录需审核后才投递),逗号分隔",
|
|
75
|
+
windowN: "观察窗口(之前 / 之后的会话数)",
|
|
76
|
+
withheldHeading: "对代理扣留({n})",
|
|
77
|
+
withheldProblem: "(被扣留的问题)",
|
|
78
|
+
withheldReason: "已扣留:{reason}",
|
|
79
|
+
},
|
|
80
|
+
hu: {
|
|
81
|
+
add: "Hozzáadás",
|
|
82
|
+
addGlob: "Glob hozzáadása",
|
|
83
|
+
approve: "Jóváhagyás",
|
|
84
|
+
attemptsN: "{n} kísérlet",
|
|
85
|
+
autoObserve: "Kimenetek óránkénti megfigyelése",
|
|
86
|
+
autoWas: "(helyi bizonyíték: {result})",
|
|
87
|
+
back: "Vissza",
|
|
88
|
+
budget: "Kézbesítési keret hatókörönként (bájt)",
|
|
89
|
+
cancel: "Mégse",
|
|
90
|
+
chooseProblem: "Válassz problémát…",
|
|
91
|
+
countsTip: "a hibát tartalmazó munkamenetek: előtte → utána",
|
|
92
|
+
defaultGlobs: "Mindig harness",
|
|
93
|
+
detailCounts: "{n} kísérlet · találati arány {rate}",
|
|
94
|
+
dismiss: "Elvetés",
|
|
95
|
+
empty: "Ebben a hatókörben még nincs rögzített harness-probléma. Az ügynökök harness-szerkesztés után a `sim record` hívással rögzítik.",
|
|
96
|
+
globalGlobs: "Globális harness-útvonalak (az ügynökkönyvtárhoz képest)",
|
|
97
|
+
globsHelp: "Az ezekre az útvonalakra eső szerkesztések harness-szerkesztésnek számítanak. A globnak tartalmaznia kell egy szó szerinti .pi/ szakaszt, vagy egyetlen fájlt kell megneveznie a tároló gyökerében. Mentés helye: .pi/sim/config.json (a csapattal közös).",
|
|
98
|
+
harnessGlobs: "A projekt további harness-útvonalai",
|
|
99
|
+
hitRate: "találati arány {rate}",
|
|
100
|
+
invalidFolderPath: "Érvénytelen mappaútvonal.",
|
|
101
|
+
lastRun: "Utolsó megfigyelés {at}: {s} munkamenet, {n} kimenet változott",
|
|
102
|
+
lastRunFailed: "Az utolsó megfigyelés sikertelen: {error}",
|
|
103
|
+
link: "Összekapcsolás…",
|
|
104
|
+
linkSubmit: "Kísérlet rögzítése",
|
|
105
|
+
loading: "Betöltés…",
|
|
106
|
+
markOutcome: "Kimenet jelölése",
|
|
107
|
+
merge: "Összevonás",
|
|
108
|
+
mergeInto: "Összevonás ebbe",
|
|
109
|
+
noUnlinked: "Minden harness-szerkesztéshez van rekord.",
|
|
110
|
+
noWithheld: "Nincs visszatartott elem.",
|
|
111
|
+
observe: "Megfigyelés most",
|
|
112
|
+
observeTip: "A későbbi munkamenetek beolvasása és az automatikus kimenetek frissítése (helyi bizonyíték)",
|
|
113
|
+
observing: "Megfigyelés… {done}/{total}",
|
|
114
|
+
openSim: "Önfejlesztő memória megnyitása",
|
|
115
|
+
pageTitle: "{name} · Önfejlesztő memória",
|
|
116
|
+
pendingHeading: "Bizonyítékra vár ({n})",
|
|
117
|
+
pendingN: "{n} függőben",
|
|
118
|
+
predictField: "Előrejelzések, soronként egy (err:<tool>:<class> vagy oracle parancs)",
|
|
119
|
+
problemField: "Probléma (meglévő vagy új név)",
|
|
120
|
+
problems: "Problémák",
|
|
121
|
+
problemsHeading: "Problémák ({n})",
|
|
122
|
+
rationaleField: "A szerkesztéssel kezelt kiváltó ok",
|
|
123
|
+
remove: "Eltávolítás",
|
|
124
|
+
revert: "Visszavontnak jelöl",
|
|
125
|
+
rootCause: "Kiváltó ok:",
|
|
126
|
+
save: "Mentés",
|
|
127
|
+
saved: "Mentve",
|
|
128
|
+
scope: "Hatókör",
|
|
129
|
+
scopeGlobal: "Globális",
|
|
130
|
+
scopeProject: "Projekt",
|
|
131
|
+
selectProblem: "Válassz problémát a kísérletei megtekintéséhez.",
|
|
132
|
+
slotCounts: "{p} probléma · {m} függőben · {k} összekapcsolatlan",
|
|
133
|
+
slotLabel: "Harness-memória",
|
|
134
|
+
sourceLocal: "{source} · helyi bizonyíték",
|
|
135
|
+
sourceManual: "kézi",
|
|
136
|
+
sourceNone: "még nincs bizonyíték",
|
|
137
|
+
tabProblems: "Problémák",
|
|
138
|
+
tabReview: "Áttekintés",
|
|
139
|
+
tabReviewN: "Áttekintés ({n})",
|
|
140
|
+
tabSettings: "Beállítások",
|
|
141
|
+
trustUser: "felhasználó kapcsolta",
|
|
142
|
+
trustWeb: "webes eredetű",
|
|
143
|
+
trustWebApproved: "webes eredetű · jóváhagyva",
|
|
144
|
+
unlinkedHeading: "Összekapcsolatlan harness-szerkesztések ({n})",
|
|
145
|
+
unreadable: "{n} rekordfájl nem olvasható, kihagyva",
|
|
146
|
+
webTools: "Webes eszközök (az ezek után készült rekordok jóváhagyásig visszatartva), vesszővel elválasztva",
|
|
147
|
+
windowN: "Megfigyelési ablak (munkamenetek előtte / utána)",
|
|
148
|
+
withheldHeading: "Ügynököktől visszatartva ({n})",
|
|
149
|
+
withheldProblem: "(visszatartott probléma)",
|
|
150
|
+
withheldReason: "visszatartva: {reason}",
|
|
151
|
+
},
|
|
152
|
+
} as const;
|