vc-extras 0.1.0 → 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 +128 -71
- package/agent-install.mjs +159 -0
- package/agents/tester.md +23 -23
- package/install-extras.mjs +41 -109
- package/install-menu.mjs +22 -43
- package/install-skills.mjs +112 -112
- package/package.json +72 -28
- package/plugin-registry.mjs +73 -0
- package/plugins/config-ui/index.ts +159 -159
- package/plugins/config-ui/lib/arguments.mjs +24 -24
- package/plugins/config-ui/lib/documents.mjs +67 -67
- package/plugins/config-ui/lib/frontmatter.mjs +91 -91
- package/plugins/config-ui/lib/open.mjs +16 -16
- package/plugins/config-ui/lib/ownership.mjs +99 -99
- package/plugins/config-ui/lib/page.mjs +11 -11
- package/plugins/config-ui/lib/patch.mjs +35 -35
- package/plugins/config-ui/lib/paths.mjs +14 -14
- package/plugins/config-ui/lib/plugin-fields.mjs +86 -86
- package/plugins/config-ui/lib/plugin-validation.mjs +28 -28
- package/plugins/config-ui/lib/redaction.mjs +8 -8
- package/plugins/config-ui/lib/registry.mjs +282 -282
- package/plugins/config-ui/lib/secrets.mjs +44 -44
- package/plugins/config-ui/lib/server.mjs +250 -250
- package/plugins/config-ui/lib/sources.mjs +96 -96
- package/plugins/config-ui/lib/state.mjs +156 -156
- package/plugins/config-ui/lib/themes.mjs +113 -113
- package/plugins/config-ui/lib/writer.mjs +690 -690
- package/plugins/config-ui/project-local-owner.ts +106 -106
- package/plugins/config-ui/vc-extras.plugin.json +13 -0
- package/plugins/config-ui/web/app.mjs +997 -997
- package/plugins/config-ui/web/index.html +342 -342
- package/plugins/pi-blackhole/vc-extras.plugin.json +12 -0
- package/plugins/pi-btw/vc-extras.plugin.json +12 -0
- package/plugins/pi-claude-code/vc-extras.plugin.json +12 -0
- package/plugins/pi-fff/vc-extras.plugin.json +12 -0
- package/plugins/pi-jev-auto-mode/vc-extras.plugin.json +12 -0
- package/plugins/pi-mcp-adapter/vc-extras.plugin.json +12 -0
- package/plugins/pi-web-access/vc-extras.plugin.json +12 -0
- package/plugins/vc-ask/claude-hook.mjs +37 -0
- package/plugins/vc-ask/codex-native.mjs +28 -0
- package/plugins/vc-ask/host-channel.mjs +75 -0
- package/plugins/vc-ask/index.ts +57 -0
- package/plugins/vc-ask/native-questions.mjs +33 -0
- package/plugins/vc-ask/package.json +10 -0
- package/plugins/vc-ask/payload.ts +170 -0
- package/plugins/vc-ask/questionnaire/LICENSE.ask-user-question +21 -0
- package/plugins/vc-ask/questionnaire/UPSTREAM.md +104 -0
- package/plugins/vc-ask/questionnaire/answer-channel.ts +135 -0
- package/plugins/vc-ask/questionnaire/config.ts +180 -0
- package/plugins/vc-ask/questionnaire/events.ts +154 -0
- package/plugins/vc-ask/questionnaire/execute.ts +688 -0
- package/plugins/vc-ask/questionnaire/i18n.ts +73 -0
- package/plugins/vc-ask/questionnaire/inline-entry.ts +312 -0
- package/plugins/vc-ask/questionnaire/locales/de.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/en.json +42 -0
- package/plugins/vc-ask/questionnaire/locales/es.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/fr.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/pt-BR.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/pt.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/ru.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/uk.json +43 -0
- package/plugins/vc-ask/questionnaire/locales/zh.json +46 -0
- package/plugins/vc-ask/questionnaire/presentation.ts +11 -0
- package/plugins/vc-ask/questionnaire/question-preview.ts +6 -0
- package/plugins/vc-ask/questionnaire/rpc.ts +221 -0
- package/plugins/vc-ask/questionnaire/session-timeout.ts +67 -0
- package/plugins/vc-ask/questionnaire/state/build-questionnaire.ts +144 -0
- package/plugins/vc-ask/questionnaire/state/external-editor.ts +62 -0
- package/plugins/vc-ask/questionnaire/state/geometry.ts +131 -0
- package/plugins/vc-ask/questionnaire/state/key-router.ts +382 -0
- package/plugins/vc-ask/questionnaire/state/panel-router.ts +32 -0
- package/plugins/vc-ask/questionnaire/state/questionnaire-session.ts +642 -0
- package/plugins/vc-ask/questionnaire/state/row-intent.ts +143 -0
- package/plugins/vc-ask/questionnaire/state/selectors/contract.ts +24 -0
- package/plugins/vc-ask/questionnaire/state/selectors/derivations.ts +40 -0
- package/plugins/vc-ask/questionnaire/state/selectors/focus.ts +17 -0
- package/plugins/vc-ask/questionnaire/state/selectors/projections.ts +99 -0
- package/plugins/vc-ask/questionnaire/state/state-reducer.ts +455 -0
- package/plugins/vc-ask/questionnaire/state/state.ts +90 -0
- package/plugins/vc-ask/questionnaire/state/vertical.ts +158 -0
- package/plugins/vc-ask/questionnaire/timeout.ts +59 -0
- package/plugins/vc-ask/questionnaire/tool/external-answer.ts +103 -0
- package/plugins/vc-ask/questionnaire/tool/format-answer.ts +24 -0
- package/plugins/vc-ask/questionnaire/tool/normalize-params.ts +37 -0
- package/plugins/vc-ask/questionnaire/tool/response-envelope.ts +75 -0
- package/plugins/vc-ask/questionnaire/tool/types.ts +74 -0
- package/plugins/vc-ask/questionnaire/tool/validate-questionnaire.ts +75 -0
- package/plugins/vc-ask/questionnaire/view/card-theme.ts +245 -0
- package/plugins/vc-ask/questionnaire/view/components/inline-input.ts +66 -0
- package/plugins/vc-ask/questionnaire/view/components/multi-select-view.ts +177 -0
- package/plugins/vc-ask/questionnaire/view/components/option-list-view.ts +65 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/markdown-content-cache.ts +101 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-block-renderer.ts +130 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-box-renderer.ts +86 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-layout-decider.ts +204 -0
- package/plugins/vc-ask/questionnaire/view/components/preview/preview-pane.ts +257 -0
- package/plugins/vc-ask/questionnaire/view/components/submit-picker.ts +65 -0
- package/plugins/vc-ask/questionnaire/view/components/tab-bar.ts +57 -0
- package/plugins/vc-ask/questionnaire/view/components/wrapping-select.ts +269 -0
- package/plugins/vc-ask/questionnaire/view/dialog-builder.ts +319 -0
- package/plugins/vc-ask/questionnaire/view/document-theme.ts +53 -0
- package/plugins/vc-ask/questionnaire/view/document-view.ts +306 -0
- package/plugins/vc-ask/questionnaire/view/panel-chrome.ts +133 -0
- package/plugins/vc-ask/questionnaire/view/props-adapter.ts +77 -0
- package/plugins/vc-ask/questionnaire/view/stateful-view.ts +24 -0
- package/plugins/vc-ask/questionnaire/view/tab-components.ts +16 -0
- package/plugins/vc-ask/questionnaire/view/tab-content-strategy.ts +280 -0
- package/plugins/vc-ask/questionnaire/view/vertical-view.ts +218 -0
- package/plugins/vc-ask/user-input-events.ts +34 -0
- package/plugins/vc-ask/vc-extras.plugin.json +18 -0
- package/plugins/vc-footer/agents/claude-code/adapter.mjs +29 -0
- package/plugins/vc-footer/agents/claude-code/cli.mjs +23 -0
- package/plugins/vc-footer/agents/claude-code/renderer.mjs +1 -0
- package/plugins/vc-footer/agents/claude-code/types.d.ts +38 -0
- package/plugins/vc-footer/agents/codex/adapter.mjs +13 -0
- package/plugins/vc-footer/agents/codex/mcp.mjs +45 -0
- package/plugins/vc-footer/agents/codex/native.mjs +19 -0
- package/plugins/vc-footer/agents/codex/renderer.mjs +2 -0
- package/plugins/vc-footer/agents/pi/adapter.mjs +23 -0
- package/plugins/vc-footer/agents/pi/index.js +84 -0
- package/plugins/vc-footer/agents/pi/project-local-owner.mjs +97 -0
- package/plugins/vc-footer/agents/pi/renderer.mjs +5 -0
- package/plugins/vc-footer/core/data.mjs +218 -0
- package/plugins/vc-footer/core/render.mjs +291 -0
- package/plugins/vc-footer/core/types.d.ts +29 -0
- package/plugins/vc-footer/package.json +22 -0
- package/plugins/vc-footer/vc-extras.plugin.json +32 -0
- package/skills/animate/LICENSE +21 -21
- package/skills/animate/RECIPES.md +324 -324
- package/skills/animate/SKILL.md +208 -208
- package/skills/animate/UPSTREAM.md +19 -19
- package/skills/animation-performance/LICENSE +21 -21
- package/skills/animation-performance/SKILL.md +223 -223
- package/skills/animation-performance/UPSTREAM.md +19 -19
- package/skills/answer-me-with-html/SKILL.md +174 -174
- package/skills/answer-me-with-html/scripts/am.mjs +12896 -12896
- package/skills/apple-design/LICENSE +21 -21
- package/skills/apple-design/SKILL.md +291 -291
- package/skills/apple-design/UPSTREAM.md +19 -19
- package/skills/bad-smell/SKILL.md +44 -44
- package/skills/commit/SKILL.md +90 -90
- package/skills/emil-design-eng/LICENSE +21 -21
- package/skills/emil-design-eng/SKILL.md +677 -677
- package/skills/emil-design-eng/UPSTREAM.md +19 -19
- package/skills/find-the-truth/SKILL.md +38 -38
- package/skills/find-the-truth/references/trace-method.md +48 -48
- package/skills/find-the-truth/references/truth-method.md +39 -39
- package/skills/gestures/LICENSE +21 -21
- package/skills/gestures/SKILL.md +107 -107
- package/skills/gestures/UPSTREAM.md +19 -19
- package/skills/humanizer-zh/LICENSE +21 -21
- package/skills/humanizer-zh/SKILL.md +409 -409
- package/skills/humanizer-zh/UPSTREAM.md +7 -7
- package/skills/impeccable/LICENSE +191 -191
- package/skills/impeccable/NOTICE.md +11 -11
- package/skills/impeccable/SKILL.md +89 -89
- package/skills/impeccable/licenses/modern-screenshot-MIT.txt +8 -8
- package/skills/impeccable/licenses/platform-design-skills-MIT.txt +21 -21
- package/skills/impeccable/reference/adapt.md +318 -318
- package/skills/impeccable/reference/adapt.native.md +58 -58
- package/skills/impeccable/reference/android.md +46 -46
- package/skills/impeccable/reference/animate.md +89 -89
- package/skills/impeccable/reference/audit.md +139 -139
- package/skills/impeccable/reference/audit.native.md +139 -139
- package/skills/impeccable/reference/bolder.md +33 -33
- package/skills/impeccable/reference/clarify.md +94 -94
- package/skills/impeccable/reference/colorize.md +86 -86
- package/skills/impeccable/reference/component-review.md +63 -63
- package/skills/impeccable/reference/craft-floor.md +44 -44
- package/skills/impeccable/reference/craft.md +5 -5
- package/skills/impeccable/reference/critique.md +819 -819
- package/skills/impeccable/reference/degraded/asset-producer.md +41 -41
- package/skills/impeccable/reference/degraded/documenter.md +23 -23
- package/skills/impeccable/reference/degraded/finish-reviewer.md +37 -37
- package/skills/impeccable/reference/degraded/manual-edit-applier.md +92 -92
- package/skills/impeccable/reference/delight.md +70 -70
- package/skills/impeccable/reference/distill.md +111 -111
- package/skills/impeccable/reference/doctor.md +54 -54
- package/skills/impeccable/reference/document.md +416 -416
- package/skills/impeccable/reference/extract.md +69 -69
- package/skills/impeccable/reference/generate.md +101 -101
- package/skills/impeccable/reference/harden.md +362 -362
- package/skills/impeccable/reference/hooks.md +114 -114
- package/skills/impeccable/reference/init.md +131 -131
- package/skills/impeccable/reference/ios.md +51 -51
- package/skills/impeccable/reference/layout.md +84 -84
- package/skills/impeccable/reference/live-setup.md +104 -104
- package/skills/impeccable/reference/live.md +327 -327
- package/skills/impeccable/reference/mode-operate.md +21 -21
- package/skills/impeccable/reference/mode-persuade.md +19 -19
- package/skills/impeccable/reference/mode-read.md +21 -21
- package/skills/impeccable/reference/new-work.md +152 -152
- package/skills/impeccable/reference/onboard.md +234 -234
- package/skills/impeccable/reference/operate.md +61 -61
- package/skills/impeccable/reference/optimize.md +257 -257
- package/skills/impeccable/reference/overdrive.md +127 -127
- package/skills/impeccable/reference/polish.md +105 -105
- package/skills/impeccable/reference/quieter.md +99 -99
- package/skills/impeccable/reference/region-map.md +26 -26
- package/skills/impeccable/reference/routing.md +24 -24
- package/skills/impeccable/reference/shape.md +59 -59
- package/skills/impeccable/reference/typeset.md +90 -90
- package/skills/impeccable/reference/visualize.md +47 -47
- package/skills/impeccable/scripts/VERSION +1 -1
- package/skills/impeccable/scripts/command-metadata.json +98 -98
- package/skills/impeccable/scripts/data/font-index-failures.json +120 -120
- package/skills/impeccable/scripts/engine-checksums.txt +9 -9
- package/skills/impeccable/scripts/impeccable +249 -249
- package/skills/impeccable/scripts/impeccable.cmd +278 -278
- package/skills/impeccable/scripts/live-browser-dom.js +320 -320
- package/skills/impeccable/scripts/live-browser-ignores.js +246 -246
- package/skills/impeccable/scripts/live-browser-session.js +183 -183
- package/skills/impeccable/scripts/live-browser.js +13862 -13862
- package/skills/impeccable/scripts/modern-screenshot.umd.js +14 -14
- package/skills/improve-animations/AUDIT.md +115 -115
- package/skills/improve-animations/LICENSE +21 -21
- package/skills/improve-animations/PLAN-TEMPLATE.md +73 -73
- package/skills/improve-animations/SKILL.md +110 -110
- package/skills/improve-animations/UPSTREAM.md +19 -19
- package/skills/pick-ui-library/LICENSE +21 -21
- package/skills/pick-ui-library/SKILL.md +85 -85
- package/skills/pick-ui-library/UPSTREAM.md +19 -19
- package/skills/review-animations/LICENSE +21 -21
- package/skills/review-animations/SKILL.md +120 -120
- package/skills/review-animations/STANDARDS.md +187 -187
- package/skills/review-animations/UPSTREAM.md +19 -19
- package/skills/test/SKILL.md +29 -29
- package/skills/test/references/test-method.md +60 -60
- package/skills/write-doc/SKILL.md +115 -115
- package/skills/write-doc/examples/result-report.md +53 -53
- package/skills/write-doc/examples/task-summary.md +45 -45
- package/skills/write-doc/references/terminology.md +147 -147
- package/specs/ask-host-protocol-v1.md +58 -0
- package/specs/design-demo.md +1102 -1102
- package/specs/frontend-immersive.md +28 -28
- package/specs/plugin-install-v2.md +123 -0
- package/specs/plugin-install.md +38 -0
- package/specs/web-modes/explore.md +31 -31
- package/specs/web-modes/risk.md +15 -15
- package/specs/web-modes/verify.md +16 -16
- package/vc-extras.mjs +46 -62
- package/plugins/essrj/context.ts +0 -47
- package/plugins/essrj/data.ts +0 -190
- package/plugins/essrj/index.ts +0 -139
- package/plugins/essrj/package.json +0 -12
- package/plugins/essrj/project-local-owner.ts +0 -106
- package/plugins/essrj/render.ts +0 -217
- package/plugins/essrj/types.ts +0 -40
- package/plugins.json +0 -38
package/plugins/essrj/data.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import type { EmmaData, GitData, PiPayload } from "./types.ts";
|
|
5
|
-
|
|
6
|
-
const EMPTY_GIT: GitData = {
|
|
7
|
-
branch: "",
|
|
8
|
-
staged: 0,
|
|
9
|
-
unstaged: 0,
|
|
10
|
-
untracked: 0,
|
|
11
|
-
ahead: 0,
|
|
12
|
-
behind: 0,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type CacheRateCacheEntry = {
|
|
16
|
-
mtimeMs: number;
|
|
17
|
-
size: number;
|
|
18
|
-
rate: number | null;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const cacheRateCache = new Map<string, CacheRateCacheEntry>();
|
|
22
|
-
|
|
23
|
-
export function collectCacheHitRate(transcriptPath: string): number | null {
|
|
24
|
-
if (!transcriptPath) return null;
|
|
25
|
-
|
|
26
|
-
let stat;
|
|
27
|
-
try {
|
|
28
|
-
stat = fs.statSync(transcriptPath);
|
|
29
|
-
if (!stat.isFile()) return null;
|
|
30
|
-
} catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const cached = cacheRateCache.get(transcriptPath);
|
|
35
|
-
if (cached && cached.mtimeMs === stat.mtimeMs && cached.size === stat.size) {
|
|
36
|
-
return cached.rate;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
let content: string;
|
|
40
|
-
try {
|
|
41
|
-
content = fs.readFileSync(transcriptPath, "utf8");
|
|
42
|
-
} catch {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let latestRate: number | null = null;
|
|
47
|
-
let hasCacheActivity = false;
|
|
48
|
-
for (const line of content.split(/\r?\n/)) {
|
|
49
|
-
if (!line.trim()) continue;
|
|
50
|
-
try {
|
|
51
|
-
const entry: unknown = JSON.parse(line);
|
|
52
|
-
if (!isRecord(entry) || entry.type !== "message" || !isRecord(entry.message)) continue;
|
|
53
|
-
if (entry.message.role !== "assistant" || !isRecord(entry.message.usage)) continue;
|
|
54
|
-
|
|
55
|
-
const usage = entry.message.usage;
|
|
56
|
-
const input = tokenValue(usage.input);
|
|
57
|
-
const cacheRead = tokenValue(usage.cacheRead);
|
|
58
|
-
const cacheWrite = tokenValue(usage.cacheWrite);
|
|
59
|
-
if (cacheRead > 0 || cacheWrite > 0) hasCacheActivity = true;
|
|
60
|
-
|
|
61
|
-
const total = input + cacheRead + cacheWrite;
|
|
62
|
-
latestRate = total > 0 ? (cacheRead * 100) / total : null;
|
|
63
|
-
} catch {
|
|
64
|
-
// A partial or damaged transcript line must not break the footer.
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const rate = hasCacheActivity ? latestRate : null;
|
|
69
|
-
cacheRateCache.set(transcriptPath, { mtimeMs: stat.mtimeMs, size: stat.size, rate });
|
|
70
|
-
return rate;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function tokenValue(value: unknown): number {
|
|
74
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function collectGit(projectDir: string): GitData {
|
|
78
|
-
if (!projectDir) return { ...EMPTY_GIT };
|
|
79
|
-
try {
|
|
80
|
-
const branch = git(projectDir, ["branch", "--show-current"]).trim();
|
|
81
|
-
let porcelain = "";
|
|
82
|
-
try {
|
|
83
|
-
porcelain = git(projectDir, ["status", "--porcelain"]);
|
|
84
|
-
} catch {
|
|
85
|
-
// A branch is still useful when worktree status is unavailable.
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let ahead = 0;
|
|
89
|
-
let behind = 0;
|
|
90
|
-
try {
|
|
91
|
-
const [aheadText, behindText] = git(projectDir, [
|
|
92
|
-
"rev-list",
|
|
93
|
-
"--left-right",
|
|
94
|
-
"--count",
|
|
95
|
-
"HEAD...@{upstream}",
|
|
96
|
-
]).trim().split(/\s+/);
|
|
97
|
-
ahead = Number.parseInt(aheadText ?? "", 10) || 0;
|
|
98
|
-
behind = Number.parseInt(behindText ?? "", 10) || 0;
|
|
99
|
-
} catch {
|
|
100
|
-
// Repositories without an upstream have no ahead/behind data.
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return { branch, ...parsePorcelain(porcelain), ahead, behind };
|
|
104
|
-
} catch {
|
|
105
|
-
return { ...EMPTY_GIT };
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function git(projectDir: string, args: string[]): string {
|
|
110
|
-
return execFileSync("git", args, {
|
|
111
|
-
cwd: projectDir,
|
|
112
|
-
timeout: 500,
|
|
113
|
-
encoding: "utf8",
|
|
114
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function parsePorcelain(porcelain: string): Pick<GitData, "staged" | "unstaged" | "untracked"> {
|
|
119
|
-
let staged = 0;
|
|
120
|
-
let unstaged = 0;
|
|
121
|
-
let untracked = 0;
|
|
122
|
-
for (const line of porcelain.split("\n")) {
|
|
123
|
-
if (line.length < 2) continue;
|
|
124
|
-
const index = line[0];
|
|
125
|
-
const worktree = line[1];
|
|
126
|
-
if (index === "?" && worktree === "?") {
|
|
127
|
-
untracked++;
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
if (index !== " " && index !== "?") staged++;
|
|
131
|
-
if (worktree !== " " && worktree !== "?") unstaged++;
|
|
132
|
-
}
|
|
133
|
-
return { staged, unstaged, untracked };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// The live event is authoritative. Without it, display only the known legacy
|
|
137
|
-
// on-disk states and never load a project-local workflow module.
|
|
138
|
-
export function collectEmmaData(projectDir: string, stdin: PiPayload): EmmaData | null {
|
|
139
|
-
if (!projectDir) return null;
|
|
140
|
-
const projectEmmaRoot = path.join(projectDir, ".emma");
|
|
141
|
-
const noSession: EmmaData = { sessionId: "", workflowStatus: "ready" };
|
|
142
|
-
const sessionsDir = path.join(projectEmmaRoot, "sessions");
|
|
143
|
-
let sessionId = "";
|
|
144
|
-
try {
|
|
145
|
-
if (!fs.lstatSync(projectEmmaRoot, { throwIfNoEntry: false })?.isDirectory()) return null;
|
|
146
|
-
if (!stdin.session_id || !fs.lstatSync(sessionsDir, { throwIfNoEntry: false })?.isDirectory()) return noSession;
|
|
147
|
-
sessionId = latestPiSessionDirectory(sessionsDir, stdin.session_id);
|
|
148
|
-
if (!sessionId) return noSession;
|
|
149
|
-
const sessionDir = path.join(sessionsDir, sessionId);
|
|
150
|
-
const statusPath = path.join(sessionDir, "status.json");
|
|
151
|
-
const active = fs.lstatSync(statusPath, { throwIfNoEntry: false });
|
|
152
|
-
const statePath = active ? statusPath : path.join(sessionDir, "resume.json");
|
|
153
|
-
const stat = active ?? fs.lstatSync(statePath);
|
|
154
|
-
if (!stat.isFile() || stat.size > 1024 * 1024) throw new Error("Invalid workflow state file");
|
|
155
|
-
const state: unknown = JSON.parse(fs.readFileSync(statePath, "utf8"));
|
|
156
|
-
if (!isRecord(state) || typeof state.status !== "string") throw new Error("Invalid workflow state");
|
|
157
|
-
const { status, planStatus, worktree } = state;
|
|
158
|
-
if (active && ["ready", "completed", "released"].includes(status)) return { sessionId, workflowStatus: status };
|
|
159
|
-
const command = active ? state.command : state.lastCommand;
|
|
160
|
-
if (
|
|
161
|
-
(command !== "shape" && command !== "hunt" && command !== "build") ||
|
|
162
|
-
(!active ? status !== "stashed" : status !== command && status !== "stashed") ||
|
|
163
|
-
![undefined, null, "", "draft", "approved"].includes(planStatus as string | null | undefined) ||
|
|
164
|
-
(command === "shape" && planStatus !== "draft") ||
|
|
165
|
-
(command === "build" && (planStatus !== "approved" || !fs.lstatSync(path.join(sessionDir, "implement.md"), { throwIfNoEntry: false })?.isFile())) ||
|
|
166
|
-
(worktree != null && (!isRecord(worktree) || typeof worktree.path !== "string" || !worktree.path.trim() || typeof worktree.branch !== "string" || !worktree.branch.trim()))
|
|
167
|
-
) throw new Error("Unsupported workflow state");
|
|
168
|
-
return { sessionId, workflowStatus: status };
|
|
169
|
-
} catch { return { sessionId, workflowStatus: "unsupported" }; }
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function latestPiSessionDirectory(sessionsDir: string, piSessionId: string): string {
|
|
173
|
-
const suffix = `_${piSessionId}`;
|
|
174
|
-
return fs
|
|
175
|
-
.readdirSync(sessionsDir, { withFileTypes: true })
|
|
176
|
-
.filter(
|
|
177
|
-
(entry) =>
|
|
178
|
-
entry.isDirectory() &&
|
|
179
|
-
/^\d{14}_/.test(entry.name) &&
|
|
180
|
-
entry.name.endsWith(suffix),
|
|
181
|
-
)
|
|
182
|
-
.map((entry) => entry.name)
|
|
183
|
-
.sort()
|
|
184
|
-
.reverse()[0] ?? "";
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
189
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
190
|
-
}
|
package/plugins/essrj/index.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import { shouldYieldToProject } from "./project-local-owner.ts";
|
|
5
|
-
import { collectSnapshot, renderSnapshot } from "./context.ts";
|
|
6
|
-
import type { EmmaData, FooterSnapshot } from "./types.ts";
|
|
7
|
-
|
|
8
|
-
function workflowProject(cwd: string): string {
|
|
9
|
-
const start = path.resolve(cwd);
|
|
10
|
-
for (let current = start; ; current = path.dirname(current)) {
|
|
11
|
-
if (existsSync(path.join(current, ".emma", "package.json")) || existsSync(path.join(current, ".git"))) return current;
|
|
12
|
-
if (path.dirname(current) === current) return start;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function reportError(stage: string, error: unknown): void {
|
|
17
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
18
|
-
console.error(`vibe-emma ESSRJ ${stage} failed: ${message}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default function essrjExtension(pi: ExtensionAPI): void {
|
|
22
|
-
let snapshot: FooterSnapshot | null = null;
|
|
23
|
-
let footerInstalled = false;
|
|
24
|
-
let startupTimer: ReturnType<typeof setTimeout> | undefined;
|
|
25
|
-
let requestRender = () => {};
|
|
26
|
-
let activeContext: ExtensionContext | null = null;
|
|
27
|
-
|
|
28
|
-
const snapshotFor = (context: ExtensionContext): FooterSnapshot => {
|
|
29
|
-
const request: { cwd: string; piSessionId: string; result?: EmmaData } = {
|
|
30
|
-
cwd: workflowProject(context.cwd), piSessionId: context.sessionManager?.getSessionId() || "",
|
|
31
|
-
};
|
|
32
|
-
pi.events?.emit("emma:status.v1", request);
|
|
33
|
-
return collectSnapshot(context, request.result ?? undefined, request.cwd);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const refresh = (context: ExtensionContext): void => {
|
|
37
|
-
activeContext = context;
|
|
38
|
-
try {
|
|
39
|
-
snapshot = snapshotFor(context);
|
|
40
|
-
requestRender();
|
|
41
|
-
} catch (error) {
|
|
42
|
-
reportError("refresh", error);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const onWorkflowChanged = (event: unknown, context: ExtensionContext): void => {
|
|
47
|
-
if (!event || typeof event !== "object") return;
|
|
48
|
-
const change = event as {
|
|
49
|
-
projectDir?: unknown;
|
|
50
|
-
piSessionId?: unknown;
|
|
51
|
-
sessionId?: unknown;
|
|
52
|
-
stage?: unknown;
|
|
53
|
-
};
|
|
54
|
-
if (typeof change.projectDir !== "string" || path.relative(workflowProject(context.cwd), change.projectDir) || change.piSessionId !== context.sessionManager.getSessionId()) return;
|
|
55
|
-
if (typeof change.sessionId !== "string" || typeof change.stage !== "string") return;
|
|
56
|
-
const validStages = new Set(["ready", "no_session", "shape", "hunt", "build", "stashed", "completed", "released"]);
|
|
57
|
-
if (!validStages.has(change.stage)) return;
|
|
58
|
-
if (snapshot) {
|
|
59
|
-
snapshot.emma = { sessionId: change.sessionId, workflowStatus: change.stage };
|
|
60
|
-
} else snapshot = snapshotFor(context);
|
|
61
|
-
requestRender();
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const installFooter = (context: ExtensionContext): void => {
|
|
65
|
-
if (context.mode !== "tui" || shouldYieldToProject(import.meta.url, "./runtime/essrj/index.ts", context.cwd ?? process.cwd(), context.isProjectTrusted?.() === true)) return;
|
|
66
|
-
activeContext = context;
|
|
67
|
-
snapshot = snapshotFor(context);
|
|
68
|
-
context.ui.setFooter((tui, theme, footerData) => {
|
|
69
|
-
requestRender = () => tui.requestRender();
|
|
70
|
-
const unsubscribe = footerData.onBranchChange(() => refresh(context));
|
|
71
|
-
return {
|
|
72
|
-
dispose() {
|
|
73
|
-
try {
|
|
74
|
-
unsubscribe();
|
|
75
|
-
} catch (error) {
|
|
76
|
-
reportError("dispose", error);
|
|
77
|
-
}
|
|
78
|
-
requestRender = () => {};
|
|
79
|
-
},
|
|
80
|
-
invalidate() {},
|
|
81
|
-
render(width: number): string[] {
|
|
82
|
-
try {
|
|
83
|
-
const output = renderSnapshot(snapshot, width, theme);
|
|
84
|
-
return output
|
|
85
|
-
? output.split("\n")
|
|
86
|
-
: [];
|
|
87
|
-
} catch (error) {
|
|
88
|
-
reportError("render", error);
|
|
89
|
-
return [];
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
footerInstalled = true;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
pi.on("session_start", () => {
|
|
98
|
-
if (startupTimer) clearTimeout(startupTimer);
|
|
99
|
-
startupTimer = undefined;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
pi.on("resources_discover", (_event, context) => {
|
|
103
|
-
if (startupTimer) clearTimeout(startupTimer);
|
|
104
|
-
startupTimer = setTimeout(() => {
|
|
105
|
-
startupTimer = undefined;
|
|
106
|
-
try {
|
|
107
|
-
installFooter(context);
|
|
108
|
-
} catch (error) {
|
|
109
|
-
reportError("install", error);
|
|
110
|
-
}
|
|
111
|
-
}, 0);
|
|
112
|
-
startupTimer.unref?.();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
pi.on("before_agent_start", (_event, context) => refresh(context));
|
|
116
|
-
pi.on("turn_end", (_event, context) => refresh(context));
|
|
117
|
-
pi.on("tool_execution_end", (_event, context) => refresh(context));
|
|
118
|
-
pi.on("model_select", (_event, context) => refresh(context));
|
|
119
|
-
pi.on("thinking_level_select", (_event, context) => refresh(context));
|
|
120
|
-
pi.on("session_info_changed", (_event, context) => refresh(context));
|
|
121
|
-
pi.on("session_compact", (_event, context) => refresh(context));
|
|
122
|
-
pi.events?.on("emma:workflow_changed.v1", (event: unknown) => {
|
|
123
|
-
try {
|
|
124
|
-
if (activeContext) onWorkflowChanged(event, activeContext);
|
|
125
|
-
} catch (error) {
|
|
126
|
-
reportError("workflow-event", error);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
pi.on("session_shutdown", (_event, context) => {
|
|
131
|
-
if (startupTimer) clearTimeout(startupTimer);
|
|
132
|
-
startupTimer = undefined;
|
|
133
|
-
if (context.mode === "tui" && footerInstalled) context.ui.setFooter(undefined);
|
|
134
|
-
snapshot = null;
|
|
135
|
-
activeContext = null;
|
|
136
|
-
footerInstalled = false;
|
|
137
|
-
requestRender = () => {};
|
|
138
|
-
});
|
|
139
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vibe-essrj",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "ESSRJ status footer for Pi and the Emma workflow",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"keywords": ["pi-package"],
|
|
8
|
-
"engines": { "node": ">=22.19.0" },
|
|
9
|
-
"files": ["index.ts", "context.ts", "data.ts", "render.ts", "types.ts", "project-local-owner.ts"],
|
|
10
|
-
"peerDependencies": { "@earendil-works/pi-tui": "*" },
|
|
11
|
-
"pi": { "extensions": ["./index.ts"] }
|
|
12
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { existsSync, lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, isAbsolute, join, matchesGlob, relative, resolve, sep } from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
export function shouldYieldToProject(extensionUrl: string, declaration: string, cwd: string, projectTrusted: boolean): boolean {
|
|
6
|
-
if (projectTrusted !== true) return false;
|
|
7
|
-
const projectRoot = resolve(cwd);
|
|
8
|
-
const emmaRoot = join(projectRoot, ".emma");
|
|
9
|
-
const extensionPath = fileURLToPath(extensionUrl);
|
|
10
|
-
if (isInside(emmaRoot, extensionPath)) return false;
|
|
11
|
-
|
|
12
|
-
const manifestPath = join(emmaRoot, "package.json");
|
|
13
|
-
const settingsPath = join(projectRoot, ".pi", "settings.json");
|
|
14
|
-
if (!isRegularOwnedFile(projectRoot, manifestPath) || !isRegularOwnedFile(projectRoot, settingsPath)) return false;
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
18
|
-
const settings = JSON.parse(readFileSync(settingsPath, "utf8"));
|
|
19
|
-
if (manifest?.name !== "vibe-emma-local" || !Array.isArray(manifest.pi?.extensions) ||
|
|
20
|
-
!manifest.pi.extensions.includes(declaration) || !Array.isArray(settings?.packages)) return false;
|
|
21
|
-
const resource = resolve(emmaRoot, declaration.replace(/^\.\//, ""));
|
|
22
|
-
if (!isRegularOwnedFile(emmaRoot, resource)) return false;
|
|
23
|
-
const settingsRoot = dirname(settingsPath);
|
|
24
|
-
return settings.packages.some((entry: string | { source?: string; extensions?: string[] }) => {
|
|
25
|
-
const source = typeof entry === "string" ? entry : entry?.source;
|
|
26
|
-
if (!source || !packageEntryEnables(entry, declaration, resource)) return false;
|
|
27
|
-
return samePath(resolve(settingsRoot, source.replace(/\\/g, "/")), emmaRoot);
|
|
28
|
-
});
|
|
29
|
-
} catch {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function packageEntryEnables(entry: string | { autoload?: boolean; extensions?: string[] }, declaration: string, resource: string): boolean {
|
|
35
|
-
if (typeof entry === "string") return true;
|
|
36
|
-
if (entry.extensions === undefined) return entry.autoload !== false;
|
|
37
|
-
if (!Array.isArray(entry.extensions) || entry.extensions.length === 0 || entry.extensions.some(value => typeof value !== "string")) return false;
|
|
38
|
-
const relativePath = normalizeExactPath(declaration);
|
|
39
|
-
const absolutePath = toPosix(resource);
|
|
40
|
-
const fileName = basename(relativePath);
|
|
41
|
-
if (entry.autoload === false) {
|
|
42
|
-
// Pi treats an autoload-disabled entry as a delta, applied in order.
|
|
43
|
-
let enabled = false;
|
|
44
|
-
for (const value of entry.extensions) {
|
|
45
|
-
const prefix = value[0];
|
|
46
|
-
const exact = prefix === "+" || prefix === "-";
|
|
47
|
-
const pattern = exact || prefix === "!" ? value.slice(1) : value;
|
|
48
|
-
if (exact ? matchesExact(pattern, relativePath, absolutePath) : matchesPattern(pattern, relativePath, fileName, absolutePath)) {
|
|
49
|
-
enabled = prefix !== "-" && prefix !== "!";
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return enabled;
|
|
53
|
-
}
|
|
54
|
-
const includes = entry.extensions.filter((value) => !/^[!+-]/.test(value));
|
|
55
|
-
const excludes = entry.extensions.filter((value) => value.startsWith("!")).map((value) => value.slice(1));
|
|
56
|
-
const forceIncludes = entry.extensions.filter((value) => value.startsWith("+")).map((value) => value.slice(1));
|
|
57
|
-
const forceExcludes = entry.extensions.filter((value) => value.startsWith("-")).map((value) => value.slice(1));
|
|
58
|
-
let enabled = includes.length === 0 || includes.some((pattern) => matchesPattern(pattern, relativePath, fileName, absolutePath));
|
|
59
|
-
if (excludes.some((pattern) => matchesPattern(pattern, relativePath, fileName, absolutePath))) enabled = false;
|
|
60
|
-
if (forceIncludes.some((pattern) => matchesExact(pattern, relativePath, absolutePath))) enabled = true;
|
|
61
|
-
if (forceExcludes.some((pattern) => matchesExact(pattern, relativePath, absolutePath))) enabled = false;
|
|
62
|
-
return enabled;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function matchesPattern(pattern: string, relativePath: string, fileName: string, absolutePath: string): boolean {
|
|
66
|
-
const normalized = toPosix(pattern);
|
|
67
|
-
return [relativePath, fileName, absolutePath].some((candidate) => matchesGlob(candidate, normalized));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function matchesExact(pattern: string, relativePath: string, absolutePath: string): boolean {
|
|
71
|
-
const normalized = normalizeExactPath(pattern);
|
|
72
|
-
return normalized === relativePath || normalized === absolutePath;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function normalizeExactPath(value: string): string {
|
|
76
|
-
return toPosix(value).replace(/^\.\//, "");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function toPosix(value: string): string {
|
|
80
|
-
return value.replace(/\\/g, "/");
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function isRegularOwnedFile(root: string, file: string): boolean {
|
|
84
|
-
if (!existsSync(file)) return false;
|
|
85
|
-
try {
|
|
86
|
-
if (!lstatSync(file).isFile()) return false;
|
|
87
|
-
const realRoot = realpathSync(root);
|
|
88
|
-
const realFile = realpathSync(file);
|
|
89
|
-
return isInside(realRoot, realFile);
|
|
90
|
-
} catch {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function isInside(root: string, candidate: string): boolean {
|
|
96
|
-
const value = relative(resolve(root), resolve(candidate));
|
|
97
|
-
return value === "" || (!value.startsWith(`..${sep}`) && value !== ".." && !isAbsolute(value));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function samePath(left: string, right: string): boolean {
|
|
101
|
-
const normalize = (value: string) => {
|
|
102
|
-
const resolved = resolve(value).replace(/[\\/]+$/, "");
|
|
103
|
-
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
104
|
-
};
|
|
105
|
-
return normalize(left) === normalize(right);
|
|
106
|
-
}
|
package/plugins/essrj/render.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import type { EmmaData, FooterSnapshot, GitData, PiPayload } from "./types.ts";
|
|
4
|
-
|
|
5
|
-
function fg(r: number, g: number, b: number): string {
|
|
6
|
-
return `\x1b[38;2;${r};${g};${b}m`;
|
|
7
|
-
}
|
|
8
|
-
function dim(): string { return "\x1b[2m"; }
|
|
9
|
-
function reset(): string { return "\x1b[0m"; }
|
|
10
|
-
|
|
11
|
-
export type SemanticColor =
|
|
12
|
-
| "text"
|
|
13
|
-
| "muted"
|
|
14
|
-
| "dim"
|
|
15
|
-
| "accent"
|
|
16
|
-
| "success"
|
|
17
|
-
| "warning"
|
|
18
|
-
| "error";
|
|
19
|
-
|
|
20
|
-
export interface ThemeLike {
|
|
21
|
-
getFgAnsi(color: SemanticColor): string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface Palette {
|
|
25
|
-
white: string;
|
|
26
|
-
whiteDim: string;
|
|
27
|
-
contextInfo: string;
|
|
28
|
-
cyan: string;
|
|
29
|
-
green: string;
|
|
30
|
-
yellow: string;
|
|
31
|
-
red: string;
|
|
32
|
-
magenta: string;
|
|
33
|
-
pink: string;
|
|
34
|
-
pinkDim: string;
|
|
35
|
-
barGreen: string;
|
|
36
|
-
barGreenDim: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const SIGNATURE = {
|
|
40
|
-
dark: {
|
|
41
|
-
magenta: fg(200, 175, 225),
|
|
42
|
-
pink: fg(240, 160, 180),
|
|
43
|
-
pinkDim: fg(156, 104, 117),
|
|
44
|
-
barGreen: fg(170, 230, 170),
|
|
45
|
-
barGreenDim: fg(85, 120, 85),
|
|
46
|
-
},
|
|
47
|
-
light: {
|
|
48
|
-
magenta: fg(142, 36, 170),
|
|
49
|
-
pink: fg(194, 24, 91),
|
|
50
|
-
pinkDim: fg(224, 178, 197),
|
|
51
|
-
barGreen: fg(46, 125, 50),
|
|
52
|
-
barGreenDim: fg(181, 212, 184),
|
|
53
|
-
},
|
|
54
|
-
} as const;
|
|
55
|
-
|
|
56
|
-
function paletteFromTheme(theme: ThemeLike, isLight: boolean): Palette {
|
|
57
|
-
const semantic = (color: SemanticColor): string => theme.getFgAnsi(color);
|
|
58
|
-
const signature = isLight ? SIGNATURE.light : SIGNATURE.dark;
|
|
59
|
-
return {
|
|
60
|
-
white: semantic("text"),
|
|
61
|
-
whiteDim: semantic("muted"),
|
|
62
|
-
contextInfo: semantic("dim"),
|
|
63
|
-
cyan: semantic("accent"),
|
|
64
|
-
green: semantic("success"),
|
|
65
|
-
yellow: semantic("warning"),
|
|
66
|
-
red: semantic("error"),
|
|
67
|
-
magenta: signature.magenta,
|
|
68
|
-
pink: signature.pink,
|
|
69
|
-
pinkDim: signature.pinkDim,
|
|
70
|
-
barGreen: signature.barGreen,
|
|
71
|
-
barGreenDim: signature.barGreenDim,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function ansi256ToRgb(n: number): [number, number, number] {
|
|
76
|
-
if (n < 16) {
|
|
77
|
-
const base: Array<[number, number, number]> = [
|
|
78
|
-
[0, 0, 0], [205, 0, 0], [0, 205, 0], [205, 205, 0],
|
|
79
|
-
[0, 0, 238], [205, 0, 205], [0, 205, 205], [229, 229, 229],
|
|
80
|
-
[127, 127, 127], [255, 0, 0], [0, 255, 0], [255, 255, 0],
|
|
81
|
-
[92, 92, 255], [255, 0, 255], [0, 255, 255], [255, 255, 255],
|
|
82
|
-
];
|
|
83
|
-
return base[n];
|
|
84
|
-
}
|
|
85
|
-
if (n < 232) {
|
|
86
|
-
const i = n - 16;
|
|
87
|
-
const steps = [0, 95, 135, 175, 215, 255];
|
|
88
|
-
return [steps[Math.floor(i / 36)], steps[Math.floor(i / 6) % 6], steps[i % 6]];
|
|
89
|
-
}
|
|
90
|
-
const gray = 8 + (n - 232) * 10;
|
|
91
|
-
return [gray, gray, gray];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function luminance(rgb: [number, number, number]): number {
|
|
95
|
-
const linear = (channel: number): number => {
|
|
96
|
-
const value = channel / 255;
|
|
97
|
-
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
98
|
-
};
|
|
99
|
-
return 0.2126 * linear(rgb[0]) + 0.7152 * linear(rgb[1]) + 0.0722 * linear(rgb[2]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function isLightTheme(theme: ThemeLike): boolean {
|
|
103
|
-
const code = theme.getFgAnsi("text");
|
|
104
|
-
const truecolor = code.match(/38;2;(\d+);(\d+);(\d+)/);
|
|
105
|
-
if (truecolor) {
|
|
106
|
-
return luminance([Number(truecolor[1]), Number(truecolor[2]), Number(truecolor[3])]) < 0.5;
|
|
107
|
-
}
|
|
108
|
-
const indexed = code.match(/38;5;(\d+)/);
|
|
109
|
-
if (indexed) return luminance(ansi256ToRgb(Number(indexed[1]))) < 0.5;
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const SEPARATOR = ` ${dim()}│${reset()} `;
|
|
114
|
-
const ICON = {
|
|
115
|
-
branch: "",
|
|
116
|
-
session: "",
|
|
117
|
-
shape: "",
|
|
118
|
-
hunt: "",
|
|
119
|
-
build: "\u{f13af}",
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
function emmaStage(status: string, C: Palette): { icon: string; label: string; color: string } {
|
|
123
|
-
if (status === "shape") return { icon: ICON.shape, label: "SHAPE", color: C.cyan };
|
|
124
|
-
if (status === "hunt") return { icon: ICON.hunt, label: "HUNT", color: C.red };
|
|
125
|
-
if (status === "build") return { icon: ICON.build, label: "BUILD", color: C.yellow };
|
|
126
|
-
return { icon: "", label: status.toUpperCase(), color: C.magenta };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function renderFooter(snapshot: FooterSnapshot, maxWidth: number, theme: ThemeLike): string {
|
|
130
|
-
const C = paletteFromTheme(theme, isLightTheme(theme));
|
|
131
|
-
const line1 = truncateToWidth(buildLine1(snapshot.stdin, snapshot.extra.git, snapshot.emma, C), maxWidth, "");
|
|
132
|
-
const line2 = truncateToWidth(buildLine2(snapshot.emma, C), maxWidth, "");
|
|
133
|
-
return line1 && line2 ? `${line1}\n${line2}` : line1;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function buildLine1(stdin: PiPayload, git: GitData, emma: EmmaData, C: Palette): string {
|
|
137
|
-
const parts: string[] = [];
|
|
138
|
-
|
|
139
|
-
const projectDir = stdin.workspace.project_dir || stdin.cwd;
|
|
140
|
-
let projectGit = projectDir ? `${C.white}${path.basename(projectDir)}${reset()}` : "";
|
|
141
|
-
if (git.branch) {
|
|
142
|
-
projectGit += `${projectGit ? " " : ""}${C.cyan}${ICON.branch} ${git.branch}${reset()}`;
|
|
143
|
-
const stats: string[] = [];
|
|
144
|
-
if (git.ahead > 0) stats.push(`${C.cyan}⇡${git.ahead}${reset()}`);
|
|
145
|
-
if (git.behind > 0) stats.push(`${C.cyan}⇣${git.behind}${reset()}`);
|
|
146
|
-
if (git.staged > 0) stats.push(`${C.green}+${git.staged}${reset()}`);
|
|
147
|
-
if (git.unstaged > 0) stats.push(`${C.yellow}!${git.unstaged}${reset()}`);
|
|
148
|
-
if (git.untracked > 0) stats.push(`${C.whiteDim}?${git.untracked}${reset()}`);
|
|
149
|
-
if (stats.length > 0) {
|
|
150
|
-
projectGit += `${C.whiteDim} (${reset()}${stats.join(" ")}${C.whiteDim})${reset()}`;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (projectGit) parts.push(projectGit);
|
|
154
|
-
|
|
155
|
-
const usage = calculateContextUsage(stdin.context_window);
|
|
156
|
-
if (usage) {
|
|
157
|
-
const percentColor = usage.percent >= 60 ? C.red : usage.percent >= 40 ? C.yellow : C.green;
|
|
158
|
-
parts.push(
|
|
159
|
-
` ${formatCacheHitRate(stdin.context_window.cache_hit_rate)} ${buildContextBar(usage.percent, C)} ${C.whiteDim}${formatUsageTokens(usage.current)}/${formatTokens(usage.total)}`
|
|
160
|
-
+ ` ${percentColor}${usage.percent}%${reset()}`,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (emma.workflowStatus) {
|
|
165
|
-
const stage = emmaStage(emma.workflowStatus, C);
|
|
166
|
-
parts.push(`${stage.color}${stage.icon ? `${stage.icon} ` : ""}${stage.label}${reset()}`);
|
|
167
|
-
}
|
|
168
|
-
return parts.join(SEPARATOR);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function buildLine2(emma: EmmaData, C: Palette): string {
|
|
172
|
-
if (!emma.sessionId) return "";
|
|
173
|
-
return `${C.contextInfo}${ICON.session} ${C.cyan}${emma.sessionId}${reset()}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function buildContextBar(percent: number, C: Palette, width = 8): string {
|
|
177
|
-
const clamped = Math.min(100, Math.max(0, Math.round(percent)));
|
|
178
|
-
const filled = Math.round((clamped * width) / 100);
|
|
179
|
-
const color = clamped >= 20 ? C.pink : C.barGreen;
|
|
180
|
-
const emptyColor = clamped >= 20 ? C.pinkDim : C.barGreenDim;
|
|
181
|
-
return color + "█".repeat(filled) + dim() + emptyColor + "░".repeat(width - filled) + reset();
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function calculateContextUsage(contextWindow: PiPayload["context_window"]): {
|
|
185
|
-
current: number;
|
|
186
|
-
total: number;
|
|
187
|
-
percent: number;
|
|
188
|
-
} | null {
|
|
189
|
-
const usage = contextWindow.current_usage;
|
|
190
|
-
const current = usage.input_tokens
|
|
191
|
-
+ (usage.cache_creation_input_tokens ?? 0)
|
|
192
|
-
+ (usage.cache_read_input_tokens ?? 0);
|
|
193
|
-
const total = contextWindow.context_window_size || 200000;
|
|
194
|
-
if (current > 0 && total > 0) {
|
|
195
|
-
return { current, total, percent: Math.round((current * 100) / total) };
|
|
196
|
-
}
|
|
197
|
-
if (contextWindow.used_percentage !== null) {
|
|
198
|
-
const percent = Math.round(contextWindow.used_percentage);
|
|
199
|
-
return { current: Math.round((total * percent) / 100), total, percent };
|
|
200
|
-
}
|
|
201
|
-
return { current: 0, total, percent: 0 };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function formatCacheHitRate(rate: number | null): string {
|
|
205
|
-
return rate === null ? "CH -" : `CH ${rate.toFixed(1)}%`;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function formatUsageTokens(value: number): string {
|
|
209
|
-
if (value >= 1000) return (value / 1000).toFixed(value >= 10_000 ? 0 : 1).replace(/\.0$/, "");
|
|
210
|
-
return String(value);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function formatTokens(value: number): string {
|
|
214
|
-
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
|
|
215
|
-
if (value >= 1000) return `${(value / 1000).toFixed(value >= 10_000 ? 0 : 1).replace(/\.0$/, "")}k`;
|
|
216
|
-
return String(value);
|
|
217
|
-
}
|