@andares/pi-toolkits 0.12.4 → 0.14.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/CHANGELOG.md +43 -0
- package/README.md +134 -17
- package/README.zh-CN.md +115 -16
- package/package.json +24 -11
- package/src/features/ask/index.ts +6 -0
- package/src/features/init/apply.ts +32 -12
- package/src/features/init/audit-uat.test.ts +103 -0
- package/src/features/init/audit.ts +148 -0
- package/src/features/init/detect.ts +4 -0
- package/src/features/init/index.ts +47 -2
- package/src/features/init/plan.ts +11 -0
- package/src/features/init/refresh.test.ts +208 -0
- package/src/features/init/refresh.ts +255 -0
- package/src/features/init/spec.ts +20 -0
- package/src/features/init/templates/agents-skeleton.md +2 -0
- package/src/features/init/templates/uat-readme.md +53 -0
- package/src/features/init/templates/workflow-block.md +21 -0
- package/src/features/init/templates.test.ts +3 -1
- package/src/features/init/templates.ts +2 -0
- package/src/features/init/types.ts +12 -1
- package/src/features/permission/index.ts +32 -0
- package/src/features/permission/policy.test.ts +10 -0
- package/src/features/permission/units.test.ts +157 -0
- package/src/features/permission/units.ts +317 -15
- package/src/features/plan/assets/index-C1YLIi4I.js +1 -0
- package/src/features/plan/assets/index-DMEpYC3V.css +1 -0
- package/src/features/plan/assets/index.html +14 -0
- package/src/features/plan/assets.test.ts +64 -0
- package/src/features/plan/blocks.test.ts +77 -0
- package/src/features/plan/blocks.ts +153 -0
- package/src/features/plan/diff.test.ts +144 -0
- package/src/features/plan/diff.ts +193 -0
- package/src/features/plan/feedback.test.ts +233 -0
- package/src/features/plan/feedback.ts +182 -0
- package/src/features/plan/index.test.ts +385 -0
- package/src/features/plan/index.ts +433 -0
- package/src/features/plan/prompt.test.ts +91 -0
- package/src/features/plan/prompt.ts +110 -0
- package/src/features/plan/render.test.ts +94 -0
- package/src/features/plan/render.ts +131 -0
- package/src/features/plan/server.test.ts +374 -0
- package/src/features/plan/server.ts +272 -0
- package/src/features/plan/store.test.ts +145 -0
- package/src/features/plan/store.ts +244 -0
- package/src/features/review/index.ts +54 -28
- package/src/features/review/review.test.ts +46 -1
- package/src/features/uat/assets/index-D-W9zj0w.css +1 -0
- package/src/features/uat/assets/index-DCBQCsli.js +1 -0
- package/src/features/uat/assets/index.html +14 -0
- package/src/features/uat/constants.ts +23 -0
- package/src/features/uat/index.test.ts +404 -0
- package/src/features/uat/index.ts +329 -0
- package/src/features/uat/item-tool.ts +280 -0
- package/src/features/uat/ledger.test.ts +249 -0
- package/src/features/uat/ledger.ts +504 -0
- package/src/features/uat/prompt.ts +78 -0
- package/src/features/uat/record-tool.ts +167 -0
- package/src/features/uat/records.test.ts +145 -0
- package/src/features/uat/records.ts +268 -0
- package/src/features/uat/server.ts +181 -0
- package/src/features/uat/state.test.ts +41 -0
- package/src/features/uat/state.ts +67 -0
- package/src/features/whats-new/changelog.ts +104 -0
- package/src/features/whats-new/constants.ts +35 -0
- package/src/features/whats-new/index.ts +146 -0
- package/src/features/whats-new/notice.ts +68 -0
- package/src/features/whats-new/paths.ts +29 -0
- package/src/features/whats-new/store.ts +114 -0
- package/src/features/whats-new/version.ts +43 -0
- package/src/features/whats-new/whats-new.test.ts +460 -0
- package/src/index.ts +13 -1
- package/src/lib/ask-control.ts +25 -0
- package/src/lib/opener.test.ts +72 -0
- package/src/lib/opener.ts +121 -0
- package/src/lib/permission-control.ts +39 -0
- package/src/lib/startup.test.ts +1 -1
- package/src/lib/web-review.ts +341 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* whats-new feature — persisted "which version has the operator seen" state.
|
|
3
|
+
*
|
|
4
|
+
* State lives in `<agent-dir>/pi-toolkits-whats-new.json` (agent-dir from
|
|
5
|
+
* getAgentDir(), same convention as the other feature stores):
|
|
6
|
+
*
|
|
7
|
+
* { "lastSeenVersion": "0.13.0" }
|
|
8
|
+
*
|
|
9
|
+
* `lastSeenVersion` is the highest version whose notes were already handled —
|
|
10
|
+
* shown, or recorded silently because this is a fresh install. A missing field
|
|
11
|
+
* means a fresh install: there is no previous version to report from.
|
|
12
|
+
*
|
|
13
|
+
* Robustness: a missing file means defaults, a corrupted file falls back to
|
|
14
|
+
* defaults with one warning, writes are atomic (tmp + rename) and never throw.
|
|
15
|
+
* A failed write only means the notice may appear once more; it must never
|
|
16
|
+
* block a session.
|
|
17
|
+
*/
|
|
18
|
+
import {
|
|
19
|
+
existsSync,
|
|
20
|
+
mkdirSync,
|
|
21
|
+
readFileSync,
|
|
22
|
+
renameSync,
|
|
23
|
+
writeFileSync,
|
|
24
|
+
} from "node:fs";
|
|
25
|
+
import { dirname, join } from "node:path";
|
|
26
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
27
|
+
import { WHATS_NEW_FILE } from "./constants.js";
|
|
28
|
+
import { parseVersion } from "./version.js";
|
|
29
|
+
|
|
30
|
+
export interface WhatsNewState {
|
|
31
|
+
/** Highest version already handled; absent on a fresh install. */
|
|
32
|
+
lastSeenVersion?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_STATE: WhatsNewState = {};
|
|
36
|
+
|
|
37
|
+
/** Coerce an unknown JSON blob into state (defaults for gaps). */
|
|
38
|
+
export function normalizeState(input: unknown): WhatsNewState {
|
|
39
|
+
const state: WhatsNewState = { ...DEFAULT_STATE };
|
|
40
|
+
if (!input || typeof input !== "object") return state;
|
|
41
|
+
const raw = input as Partial<WhatsNewState>;
|
|
42
|
+
if (
|
|
43
|
+
typeof raw.lastSeenVersion === "string" &&
|
|
44
|
+
parseVersion(raw.lastSeenVersion) !== undefined
|
|
45
|
+
) {
|
|
46
|
+
state.lastSeenVersion = raw.lastSeenVersion;
|
|
47
|
+
}
|
|
48
|
+
return state;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export class WhatsNewStore {
|
|
52
|
+
private state: WhatsNewState = { ...DEFAULT_STATE };
|
|
53
|
+
private readonly file: string;
|
|
54
|
+
private loaded = false;
|
|
55
|
+
|
|
56
|
+
constructor(file: string = join(getAgentDir(), WHATS_NEW_FILE)) {
|
|
57
|
+
this.file = file;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Path of the JSON file. */
|
|
61
|
+
get path(): string {
|
|
62
|
+
return this.file;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private ensureLoaded(): void {
|
|
66
|
+
if (this.loaded) return;
|
|
67
|
+
this.loaded = true;
|
|
68
|
+
try {
|
|
69
|
+
if (!existsSync(this.file)) return;
|
|
70
|
+
const parsed: unknown = JSON.parse(readFileSync(this.file, "utf8"));
|
|
71
|
+
this.state = normalizeState(parsed);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
// pi-lens-ignore: no-console-except-error,console-statement, — deliberate degradation log
|
|
74
|
+
console.warn(
|
|
75
|
+
"[pi-toolkits/whats-new] Failed to load state, using defaults:",
|
|
76
|
+
error instanceof Error ? error.message : String(error),
|
|
77
|
+
);
|
|
78
|
+
this.state = { ...DEFAULT_STATE };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Current state (a copy). */
|
|
83
|
+
get(): WhatsNewState {
|
|
84
|
+
this.ensureLoaded();
|
|
85
|
+
return { ...this.state };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Remember that `version` was handled. */
|
|
89
|
+
markSeen(version: string): void {
|
|
90
|
+
this.ensureLoaded();
|
|
91
|
+
if (parseVersion(version) === undefined) return;
|
|
92
|
+
this.state.lastSeenVersion = version;
|
|
93
|
+
this.save();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Atomically persist (tmp + rename). Never throws. */
|
|
97
|
+
private save(): void {
|
|
98
|
+
try {
|
|
99
|
+
const dir = dirname(this.file);
|
|
100
|
+
if (!existsSync(dir)) {
|
|
101
|
+
mkdirSync(dir, { recursive: true });
|
|
102
|
+
}
|
|
103
|
+
const tmp = `${this.file}.tmp`;
|
|
104
|
+
writeFileSync(tmp, `${JSON.stringify(this.state, null, 2)}\n`, "utf8");
|
|
105
|
+
renameSync(tmp, this.file);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// pi-lens-ignore: no-console-except-error,console-statement, — deliberate degradation log
|
|
108
|
+
console.warn(
|
|
109
|
+
"[pi-toolkits/whats-new] Failed to save state:",
|
|
110
|
+
error instanceof Error ? error.message : String(error),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* whats-new feature — strict `X.Y.Z` versions.
|
|
3
|
+
*
|
|
4
|
+
* Package versions in this repo are always plain `X.Y.Z` (the release script
|
|
5
|
+
* rejects anything else), so prerelease/build metadata is deliberately not
|
|
6
|
+
* parsed. An unparseable version yields `undefined`, and callers treat that as
|
|
7
|
+
* "do not announce" instead of guessing an ordering — a wrong comparison would
|
|
8
|
+
* replay notes the operator already saw.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface VersionParts {
|
|
12
|
+
major: number;
|
|
13
|
+
minor: number;
|
|
14
|
+
patch: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const VERSION_RE = /^v?(\d+)\.(\d+)\.(\d+)$/;
|
|
18
|
+
|
|
19
|
+
/** Parse `X.Y.Z` (an optional leading `v` is tolerated). */
|
|
20
|
+
export function parseVersion(value: string): VersionParts | undefined {
|
|
21
|
+
const match = VERSION_RE.exec(value.trim());
|
|
22
|
+
if (!match) return undefined;
|
|
23
|
+
return {
|
|
24
|
+
major: Number(match[1]),
|
|
25
|
+
minor: Number(match[2]),
|
|
26
|
+
patch: Number(match[3]),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Numeric ordering: negative when `a < b`, positive when `a > b`, 0 when equal
|
|
32
|
+
* or when either side is unparseable (never announce on an unknown ordering).
|
|
33
|
+
*/
|
|
34
|
+
export function compareVersions(a: string, b: string): number {
|
|
35
|
+
const left = parseVersion(a);
|
|
36
|
+
const right = parseVersion(b);
|
|
37
|
+
if (!left || !right) return 0;
|
|
38
|
+
return (
|
|
39
|
+
left.major - right.major ||
|
|
40
|
+
left.minor - right.minor ||
|
|
41
|
+
left.patch - right.patch
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* whats-new feature — parser, version ordering, store and startup tests.
|
|
3
|
+
*
|
|
4
|
+
* Everything is deterministic: temp directories for state and fixtures, an
|
|
5
|
+
* injected version, and a fake `pi` that records entries instead of rendering
|
|
6
|
+
* them. The startup cases encode the product rule exactly — the notice fires on
|
|
7
|
+
* the first TUI start after an upgrade and never again for that version.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
existsSync,
|
|
11
|
+
mkdirSync,
|
|
12
|
+
mkdtempSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
rmSync,
|
|
15
|
+
writeFileSync,
|
|
16
|
+
} from "node:fs";
|
|
17
|
+
import { tmpdir } from "node:os";
|
|
18
|
+
import { join } from "node:path";
|
|
19
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
20
|
+
import type {
|
|
21
|
+
ExtensionAPI,
|
|
22
|
+
ExtensionContext,
|
|
23
|
+
SessionStartEvent,
|
|
24
|
+
} from "@earendil-works/pi-coding-agent";
|
|
25
|
+
import {
|
|
26
|
+
parseChangelog,
|
|
27
|
+
readPackageVersion,
|
|
28
|
+
releasesForUpgrade,
|
|
29
|
+
sortReleasesDescending,
|
|
30
|
+
} from "./changelog.js";
|
|
31
|
+
import { registerWhatsNew, type WhatsNewOptions } from "./index.js";
|
|
32
|
+
import {
|
|
33
|
+
buildUpgradeNotice,
|
|
34
|
+
renderReleaseSections,
|
|
35
|
+
} from "./notice.js";
|
|
36
|
+
import { WhatsNewStore, normalizeState } from "./store.js";
|
|
37
|
+
import { compareVersions, parseVersion } from "./version.js";
|
|
38
|
+
|
|
39
|
+
const CHANGELOG = `# Changelog
|
|
40
|
+
|
|
41
|
+
Intro prose that is not part of any release.
|
|
42
|
+
|
|
43
|
+
## Unreleased
|
|
44
|
+
|
|
45
|
+
- work in progress
|
|
46
|
+
|
|
47
|
+
## 0.13.1 — 2026-11-13
|
|
48
|
+
|
|
49
|
+
- fix one
|
|
50
|
+
- fix two
|
|
51
|
+
- nested detail is not a notice line
|
|
52
|
+
- fix three
|
|
53
|
+
- fix four
|
|
54
|
+
- fix five
|
|
55
|
+
- fix six
|
|
56
|
+
- fix seven
|
|
57
|
+
|
|
58
|
+
## 0.13.0 — 2026-11-12
|
|
59
|
+
|
|
60
|
+
- plan feature
|
|
61
|
+
|
|
62
|
+
## 0.12.0 — 2026-11-06
|
|
63
|
+
|
|
64
|
+
- old feature
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const dirs: string[] = [];
|
|
68
|
+
|
|
69
|
+
function tempDir(): string {
|
|
70
|
+
const dir = mkdtempSync(join(tmpdir(), "pi-whats-new-"));
|
|
71
|
+
dirs.push(dir);
|
|
72
|
+
return dir;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
afterEach(() => {
|
|
76
|
+
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
interface Fixture {
|
|
80
|
+
storeFile: string;
|
|
81
|
+
changelogFile: string;
|
|
82
|
+
packageFile: string;
|
|
83
|
+
dir: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function fixture(options: { version?: string; changelog?: string } = {}): Fixture {
|
|
87
|
+
const dir = tempDir();
|
|
88
|
+
const changelogFile = join(dir, "CHANGELOG.md");
|
|
89
|
+
const packageFile = join(dir, "package.json");
|
|
90
|
+
writeFileSync(changelogFile, options.changelog ?? CHANGELOG, "utf8");
|
|
91
|
+
writeFileSync(packageFile, JSON.stringify({ version: options.version ?? "0.13.1" }), "utf8");
|
|
92
|
+
return { dir, storeFile: join(dir, "state", "whats-new.json"), changelogFile, packageFile };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function readState(file: string): { lastSeenVersion?: string } {
|
|
96
|
+
return JSON.parse(readFileSync(file, "utf8")) as { lastSeenVersion?: string };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface Harness {
|
|
100
|
+
start(reason: SessionStartEvent["reason"], ctx: ExtensionContext): void;
|
|
101
|
+
entries: Array<{ type: string; data: unknown }>;
|
|
102
|
+
commands: string[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function harness(options: WhatsNewOptions): Harness {
|
|
106
|
+
const entries: Harness["entries"] = [];
|
|
107
|
+
const commands: string[] = [];
|
|
108
|
+
let startHandler: ((event: SessionStartEvent, ctx: ExtensionContext) => void) | undefined;
|
|
109
|
+
|
|
110
|
+
const pi = {
|
|
111
|
+
on(event: string, handler: (event: SessionStartEvent, ctx: ExtensionContext) => void) {
|
|
112
|
+
if (event === "session_start") startHandler = handler;
|
|
113
|
+
},
|
|
114
|
+
registerEntryRenderer() {},
|
|
115
|
+
appendEntry(type: string, data: unknown) {
|
|
116
|
+
entries.push({ type, data });
|
|
117
|
+
},
|
|
118
|
+
registerCommand(name: string) {
|
|
119
|
+
commands.push(name);
|
|
120
|
+
},
|
|
121
|
+
} as unknown as ExtensionAPI;
|
|
122
|
+
|
|
123
|
+
registerWhatsNew(pi, options);
|
|
124
|
+
if (!startHandler) throw new Error("whats-new did not register");
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
entries,
|
|
128
|
+
commands,
|
|
129
|
+
start: (reason, ctx) => startHandler?.({ type: "session_start", reason }, ctx),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface CtxOptions {
|
|
134
|
+
mode?: ExtensionContext["mode"];
|
|
135
|
+
sessionId?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function makeCtx(options: CtxOptions = {}): {
|
|
139
|
+
ctx: ExtensionContext;
|
|
140
|
+
notes: Array<{ message: string; kind?: string }>;
|
|
141
|
+
} {
|
|
142
|
+
const notes: Array<{ message: string; kind?: string }> = [];
|
|
143
|
+
const ctx = {
|
|
144
|
+
mode: options.mode ?? "tui",
|
|
145
|
+
hasUI: true,
|
|
146
|
+
cwd: "/tmp/project",
|
|
147
|
+
ui: {
|
|
148
|
+
notify: (message: string, kind?: string) => notes.push({ message, kind }),
|
|
149
|
+
},
|
|
150
|
+
sessionManager: { getSessionId: () => options.sessionId ?? "session-1" },
|
|
151
|
+
} as unknown as ExtensionContext;
|
|
152
|
+
return { ctx, notes };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
describe("versions", () => {
|
|
156
|
+
it("orders numerically, not lexically", () => {
|
|
157
|
+
expect(compareVersions("0.9.0", "0.10.0")).toBeLessThan(0);
|
|
158
|
+
expect(compareVersions("0.13.0", "0.13.1")).toBeLessThan(0);
|
|
159
|
+
expect(compareVersions("1.0.0", "0.99.99")).toBeGreaterThan(0);
|
|
160
|
+
expect(compareVersions("0.13.1", "0.13.1")).toBe(0);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("treats unparseable versions as unknown (zero) and never as an upgrade", () => {
|
|
164
|
+
expect(parseVersion("0.13.1")).toEqual({ major: 0, minor: 13, patch: 1 });
|
|
165
|
+
expect(parseVersion("v1.2.3")).toEqual({ major: 1, minor: 2, patch: 3 });
|
|
166
|
+
expect(parseVersion("0.13")).toBeUndefined();
|
|
167
|
+
expect(parseVersion("next")).toBeUndefined();
|
|
168
|
+
expect(compareVersions("next", "0.13.0")).toBe(0);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("changelog parsing", () => {
|
|
173
|
+
it("reads one section per version and only top-level bullets", () => {
|
|
174
|
+
const releases = parseChangelog(CHANGELOG);
|
|
175
|
+
expect(releases.map((release) => release.version)).toEqual([
|
|
176
|
+
"0.13.1",
|
|
177
|
+
"0.13.0",
|
|
178
|
+
"0.12.0",
|
|
179
|
+
]);
|
|
180
|
+
const latest = releases[0];
|
|
181
|
+
expect(latest.notes).toHaveLength(7);
|
|
182
|
+
expect(latest.notes).not.toContain("nested detail is not a notice line");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("ignores Unreleased and text before the first version heading", () => {
|
|
186
|
+
const releases = parseChangelog(CHANGELOG);
|
|
187
|
+
expect(releases.some((release) => release.version === "Unreleased")).toBe(false);
|
|
188
|
+
expect(releases.flatMap((release) => release.notes)).not.toContain(
|
|
189
|
+
"work in progress",
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("accepts bracketed and dated headings", () => {
|
|
194
|
+
const releases = parseChangelog("## [0.2.0] - 2026-01-02\n\n- note\n");
|
|
195
|
+
expect(releases).toEqual([{ version: "0.2.0", notes: ["note"] }]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("keeps empty sections so the version still shows up", () => {
|
|
199
|
+
expect(parseChangelog("## 0.2.0\n\n## 0.3.0\n- note\n")).toEqual([
|
|
200
|
+
{ version: "0.2.0", notes: [] },
|
|
201
|
+
{ version: "0.3.0", notes: ["note"] },
|
|
202
|
+
]);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("filters an upgrade range: from is exclusive, to inclusive, newest first", () => {
|
|
206
|
+
const releases = parseChangelog(CHANGELOG);
|
|
207
|
+
expect(releasesForUpgrade(releases, "0.12.0", "0.13.1").map((r) => r.version)).toEqual([
|
|
208
|
+
"0.13.1",
|
|
209
|
+
"0.13.0",
|
|
210
|
+
]);
|
|
211
|
+
expect(releasesForUpgrade(releases, "0.13.1", "0.13.1")).toEqual([]);
|
|
212
|
+
expect(releasesForUpgrade(releases, "0.13.1", "0.12.0")).toEqual([]);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("sorts releases newest first", () => {
|
|
216
|
+
expect(sortReleasesDescending(parseChangelog(CHANGELOG))[0].version).toBe("0.13.1");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("reads the version from a package manifest and rejects junk", () => {
|
|
220
|
+
const dir = tempDir();
|
|
221
|
+
const file = join(dir, "package.json");
|
|
222
|
+
writeFileSync(file, JSON.stringify({ version: "0.13.1" }));
|
|
223
|
+
expect(readPackageVersion(file)).toBe("0.13.1");
|
|
224
|
+
writeFileSync(file, JSON.stringify({ version: "not-a-version" }));
|
|
225
|
+
expect(readPackageVersion(file)).toBeUndefined();
|
|
226
|
+
writeFileSync(file, "{ broken");
|
|
227
|
+
expect(readPackageVersion(file)).toBeUndefined();
|
|
228
|
+
expect(readPackageVersion(join(dir, "missing.json"))).toBeUndefined();
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe("notice text", () => {
|
|
233
|
+
it("caps notes per version and points at the changelog", () => {
|
|
234
|
+
const releases = parseChangelog(CHANGELOG);
|
|
235
|
+
const lines = renderReleaseSections(releasesForUpgrade(releases, "0.12.0", "0.13.1"), {
|
|
236
|
+
maxNotesPerVersion: 3,
|
|
237
|
+
});
|
|
238
|
+
expect(lines).toContain("0.13.1");
|
|
239
|
+
expect(lines.filter((line) => line.startsWith(" - fix"))).toHaveLength(3);
|
|
240
|
+
expect(lines).toContain(" - (+4 more in CHANGELOG.md)");
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("caps versions and points at the changelog", () => {
|
|
244
|
+
const releases = ["0.3.0", "0.2.0", "0.1.0"].map((version) => ({
|
|
245
|
+
version,
|
|
246
|
+
notes: ["note"],
|
|
247
|
+
}));
|
|
248
|
+
const lines = renderReleaseSections(releases, { maxVersions: 1 });
|
|
249
|
+
expect(lines).toContain("(+2 older versions — see CHANGELOG.md)");
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("builds the upgrade title from the two versions", () => {
|
|
253
|
+
const notice = buildUpgradeNotice("0.12.0", "0.13.1", []);
|
|
254
|
+
expect(notice.title).toBe("pi-toolkits updated 0.12.0 → 0.13.1");
|
|
255
|
+
expect(notice.lines).toContain("No release notes are bundled for this version.");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe("state store", () => {
|
|
261
|
+
it("defaults to no recorded version", () => {
|
|
262
|
+
const file = join(tempDir(), "state.json");
|
|
263
|
+
const store = new WhatsNewStore(file);
|
|
264
|
+
expect(store.get()).toEqual({});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("round-trips lastSeenVersion", () => {
|
|
268
|
+
const file = join(tempDir(), "nested", "state.json");
|
|
269
|
+
const store = new WhatsNewStore(file);
|
|
270
|
+
store.markSeen("0.13.0");
|
|
271
|
+
expect(readState(file)).toEqual({ lastSeenVersion: "0.13.0" });
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("normalizes junk files and ignores invalid versions", () => {
|
|
275
|
+
expect(normalizeState(null)).toEqual({});
|
|
276
|
+
expect(normalizeState({ enabled: false, lastSeenVersion: "nope" })).toEqual({});
|
|
277
|
+
const file = join(tempDir(), "state.json");
|
|
278
|
+
writeFileSync(file, "{ broken");
|
|
279
|
+
const store = new WhatsNewStore(file);
|
|
280
|
+
expect(store.get()).toEqual({});
|
|
281
|
+
store.markSeen("bad-version");
|
|
282
|
+
expect(store.get()).toEqual({});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("never throws when the state path is unusable", () => {
|
|
286
|
+
const dir = tempDir();
|
|
287
|
+
const blocker = join(dir, "blocker");
|
|
288
|
+
writeFileSync(blocker, "not a directory");
|
|
289
|
+
const store = new WhatsNewStore(join(blocker, "state.json"));
|
|
290
|
+
expect(() => store.markSeen("0.13.1")).not.toThrow();
|
|
291
|
+
expect(existsSync(join(blocker, "state.json"))).toBe(false);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
describe("startup notice", () => {
|
|
296
|
+
it("does not claim a global slash command", () => {
|
|
297
|
+
const app = harness(fixture());
|
|
298
|
+
expect(app.commands).toEqual([]);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it("stays silent on a fresh install and records the running version", () => {
|
|
302
|
+
const files = fixture();
|
|
303
|
+
const app = harness({
|
|
304
|
+
storeFile: files.storeFile,
|
|
305
|
+
changelogFile: files.changelogFile,
|
|
306
|
+
packageFile: files.packageFile,
|
|
307
|
+
});
|
|
308
|
+
const { ctx } = makeCtx();
|
|
309
|
+
app.start("startup", ctx);
|
|
310
|
+
expect(app.entries).toHaveLength(0);
|
|
311
|
+
expect(readState(files.storeFile).lastSeenVersion).toBe("0.13.1");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("announces once after an upgrade, with only the new sections", () => {
|
|
315
|
+
const files = fixture();
|
|
316
|
+
mkdirSync(join(files.dir, "state"), { recursive: true });
|
|
317
|
+
writeFileSync(
|
|
318
|
+
files.storeFile,
|
|
319
|
+
JSON.stringify({ lastSeenVersion: "0.12.0" }),
|
|
320
|
+
);
|
|
321
|
+
const app = harness({
|
|
322
|
+
storeFile: files.storeFile,
|
|
323
|
+
changelogFile: files.changelogFile,
|
|
324
|
+
packageFile: files.packageFile,
|
|
325
|
+
});
|
|
326
|
+
const { ctx } = makeCtx();
|
|
327
|
+
app.start("startup", ctx);
|
|
328
|
+
|
|
329
|
+
expect(app.entries).toHaveLength(1);
|
|
330
|
+
const data = app.entries[0].data as { title: string; lines: string[] };
|
|
331
|
+
expect(data.title).toBe("pi-toolkits updated 0.12.0 → 0.13.1");
|
|
332
|
+
expect(data.lines).toContain("0.13.1");
|
|
333
|
+
expect(data.lines).toContain("0.13.0");
|
|
334
|
+
expect(data.lines).not.toContain("0.12.0");
|
|
335
|
+
expect(data.lines).not.toContain(" - old feature");
|
|
336
|
+
expect(readState(files.storeFile).lastSeenVersion).toBe("0.13.1");
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("never announces the same version twice", () => {
|
|
340
|
+
const files = fixture();
|
|
341
|
+
mkdirSync(join(files.dir, "state"), { recursive: true });
|
|
342
|
+
writeFileSync(
|
|
343
|
+
files.storeFile,
|
|
344
|
+
JSON.stringify({ lastSeenVersion: "0.12.0" }),
|
|
345
|
+
);
|
|
346
|
+
const app = harness({
|
|
347
|
+
storeFile: files.storeFile,
|
|
348
|
+
changelogFile: files.changelogFile,
|
|
349
|
+
packageFile: files.packageFile,
|
|
350
|
+
});
|
|
351
|
+
app.start("startup", makeCtx({ sessionId: "first" }).ctx);
|
|
352
|
+
app.start("startup", makeCtx({ sessionId: "second" }).ctx);
|
|
353
|
+
expect(app.entries).toHaveLength(1);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("deduplicates a repeated emission for the same session", () => {
|
|
357
|
+
const files = fixture();
|
|
358
|
+
mkdirSync(join(files.dir, "state"), { recursive: true });
|
|
359
|
+
writeFileSync(
|
|
360
|
+
files.storeFile,
|
|
361
|
+
JSON.stringify({ lastSeenVersion: "0.12.0" }),
|
|
362
|
+
);
|
|
363
|
+
const app = harness({
|
|
364
|
+
storeFile: files.storeFile,
|
|
365
|
+
changelogFile: files.changelogFile,
|
|
366
|
+
packageFile: files.packageFile,
|
|
367
|
+
});
|
|
368
|
+
const { ctx } = makeCtx({ sessionId: "same" });
|
|
369
|
+
app.start("startup", ctx);
|
|
370
|
+
app.start("startup", ctx);
|
|
371
|
+
expect(app.entries).toHaveLength(1);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("ignores every reason except a process startup", () => {
|
|
375
|
+
const files = fixture();
|
|
376
|
+
mkdirSync(join(files.dir, "state"), { recursive: true });
|
|
377
|
+
writeFileSync(
|
|
378
|
+
files.storeFile,
|
|
379
|
+
JSON.stringify({ lastSeenVersion: "0.12.0" }),
|
|
380
|
+
);
|
|
381
|
+
const app = harness({
|
|
382
|
+
storeFile: files.storeFile,
|
|
383
|
+
changelogFile: files.changelogFile,
|
|
384
|
+
packageFile: files.packageFile,
|
|
385
|
+
});
|
|
386
|
+
for (const reason of ["reload", "new", "resume", "fork"] as const) {
|
|
387
|
+
app.start(reason, makeCtx({ sessionId: reason }).ctx);
|
|
388
|
+
}
|
|
389
|
+
expect(app.entries).toHaveLength(0);
|
|
390
|
+
expect(readState(files.storeFile).lastSeenVersion).toBe("0.12.0");
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("stays silent outside the interactive TUI and does not consume the notice", () => {
|
|
394
|
+
const files = fixture();
|
|
395
|
+
mkdirSync(join(files.dir, "state"), { recursive: true });
|
|
396
|
+
writeFileSync(
|
|
397
|
+
files.storeFile,
|
|
398
|
+
JSON.stringify({ lastSeenVersion: "0.12.0" }),
|
|
399
|
+
);
|
|
400
|
+
const app = harness({
|
|
401
|
+
storeFile: files.storeFile,
|
|
402
|
+
changelogFile: files.changelogFile,
|
|
403
|
+
packageFile: files.packageFile,
|
|
404
|
+
});
|
|
405
|
+
for (const mode of ["print", "json", "rpc"] as const) {
|
|
406
|
+
app.start("startup", makeCtx({ mode, sessionId: mode }).ctx);
|
|
407
|
+
}
|
|
408
|
+
expect(app.entries).toHaveLength(0);
|
|
409
|
+
expect(readState(files.storeFile).lastSeenVersion).toBe("0.12.0");
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
it("does not announce a downgrade and keeps the recorded version", () => {
|
|
414
|
+
const files = fixture({ version: "0.12.0" });
|
|
415
|
+
mkdirSync(join(files.dir, "state"), { recursive: true });
|
|
416
|
+
writeFileSync(
|
|
417
|
+
files.storeFile,
|
|
418
|
+
JSON.stringify({ lastSeenVersion: "0.13.1" }),
|
|
419
|
+
);
|
|
420
|
+
const app = harness({
|
|
421
|
+
storeFile: files.storeFile,
|
|
422
|
+
changelogFile: files.changelogFile,
|
|
423
|
+
packageFile: files.packageFile,
|
|
424
|
+
});
|
|
425
|
+
app.start("startup", makeCtx().ctx);
|
|
426
|
+
expect(app.entries).toHaveLength(0);
|
|
427
|
+
expect(readState(files.storeFile).lastSeenVersion).toBe("0.13.1");
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it("still reports the upgrade when the changelog has no section for it", () => {
|
|
431
|
+
const files = fixture({ version: "0.14.0" });
|
|
432
|
+
mkdirSync(join(files.dir, "state"), { recursive: true });
|
|
433
|
+
writeFileSync(
|
|
434
|
+
files.storeFile,
|
|
435
|
+
JSON.stringify({ lastSeenVersion: "0.13.1" }),
|
|
436
|
+
);
|
|
437
|
+
const app = harness({
|
|
438
|
+
storeFile: files.storeFile,
|
|
439
|
+
changelogFile: files.changelogFile,
|
|
440
|
+
packageFile: files.packageFile,
|
|
441
|
+
});
|
|
442
|
+
app.start("startup", makeCtx().ctx);
|
|
443
|
+
const data = app.entries[0].data as { lines: string[] };
|
|
444
|
+
expect(data.lines).toContain("No release notes are bundled for this version.");
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("uses an explicit version without reading package.json", () => {
|
|
448
|
+
const files = fixture();
|
|
449
|
+
const app = harness({
|
|
450
|
+
storeFile: files.storeFile,
|
|
451
|
+
changelogFile: files.changelogFile,
|
|
452
|
+
packageFile: join(files.dir, "missing.json"),
|
|
453
|
+
version: "0.13.0",
|
|
454
|
+
});
|
|
455
|
+
app.start("startup", makeCtx().ctx);
|
|
456
|
+
expect(app.entries).toHaveLength(0);
|
|
457
|
+
expect(readState(files.storeFile).lastSeenVersion).toBe("0.13.0");
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
|
package/src/index.ts
CHANGED
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
* - ask — read-only Q&A mode (/ask)
|
|
9
9
|
* - favorites — model favorites (ctrl+A/ctrl+J in /model, favorites-only cycling)
|
|
10
10
|
* - stash — prompt stash (ctrl+alt+y swap / double-press stash-and-clear)
|
|
11
|
-
* - review — third-party code review with a configured review model (third-review)
|
|
11
|
+
* - review — third-party code review with a configured review model (/ask-review, alias /third-review)
|
|
12
12
|
* - compact — dedicated compact model for /compact + auto-compact summaries
|
|
13
13
|
* - autostart — replay project-declared slash commands at session start (/add-dir persistence)
|
|
14
14
|
* - permission — session-scoped boundary permission checks (/ask-perm)
|
|
15
15
|
* - init — agent memory framework install / adoption (/ask-init)
|
|
16
|
+
* - uat — acceptance ledger and browser page (/ask-uat, record_change)
|
|
16
17
|
* - quit-guard — quit watchdog: force-exit when pi's shutdown hangs (/quit-guard)
|
|
18
|
+
* - whats-new — automatic release notes on the first start after an upgrade
|
|
17
19
|
*
|
|
18
20
|
* `ask` and `permission` are independent gates on one bus: each answers its own
|
|
19
21
|
* question and the strictest answer wins, so they compose rather than replace
|
|
@@ -28,9 +30,12 @@ import { registerCompact } from "./features/compact/index.js";
|
|
|
28
30
|
import { registerFavorites } from "./features/favorites/index.js";
|
|
29
31
|
import { registerInit } from "./features/init/index.js";
|
|
30
32
|
import { registerPermission } from "./features/permission/index.js";
|
|
33
|
+
import { registerPlan } from "./features/plan/index.js";
|
|
31
34
|
import { registerQuitGuard } from "./features/quit-guard/index.js";
|
|
32
35
|
import { registerReview } from "./features/review/index.js";
|
|
33
36
|
import { registerStash } from "./features/stash/index.js";
|
|
37
|
+
import { registerUat } from "./features/uat/index.js";
|
|
38
|
+
import { registerWhatsNew } from "./features/whats-new/index.js";
|
|
34
39
|
|
|
35
40
|
export default function piToolkits(pi: ExtensionAPI): void {
|
|
36
41
|
// One rolling audit sink for every gate. Creation is lazy and side-effect
|
|
@@ -42,6 +47,9 @@ export default function piToolkits(pi: ExtensionAPI): void {
|
|
|
42
47
|
// Permission registers its session_start reset before autostart, so a
|
|
43
48
|
// project-declared `/ask-perm ...` runs against a freshly reset mode.
|
|
44
49
|
registerPermission(pi, gates, { audit });
|
|
50
|
+
// Plan mode drives the permission control that `registerPermission` just
|
|
51
|
+
// published (it turns checks on while planning and restores them after).
|
|
52
|
+
registerPlan(pi, gates);
|
|
45
53
|
registerAutostart(pi);
|
|
46
54
|
registerCompact(pi);
|
|
47
55
|
registerFavorites(pi);
|
|
@@ -49,6 +57,10 @@ export default function piToolkits(pi: ExtensionAPI): void {
|
|
|
49
57
|
registerQuitGuard(pi);
|
|
50
58
|
registerReview(pi);
|
|
51
59
|
registerStash(pi);
|
|
60
|
+
// UAT registers after plan so its `before_agent_start` re-assertion runs last
|
|
61
|
+
// and can add `record_change` to whatever tool set plan installed.
|
|
62
|
+
registerUat(pi);
|
|
63
|
+
registerWhatsNew(pi);
|
|
52
64
|
|
|
53
65
|
gates.install(pi);
|
|
54
66
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ask control — lets `/ask-plan` leave consult mode before opening its broader
|
|
3
|
+
* planning phase.
|
|
4
|
+
*
|
|
5
|
+
* `/ask` owns its state and its tool-set snapshot, so another feature must not
|
|
6
|
+
* imitate the exit by manipulating tools itself. This small handle is the same
|
|
7
|
+
* registry pattern as `permission-control.ts`: the owner publishes enter/exit
|
|
8
|
+
* semantics, the caller only asks for a transition.
|
|
9
|
+
*/
|
|
10
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
|
|
12
|
+
export interface AskControl {
|
|
13
|
+
isActive(): boolean;
|
|
14
|
+
exit(ctx: ExtensionContext): void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let current: AskControl | undefined;
|
|
18
|
+
|
|
19
|
+
export function setAskControl(control: AskControl | undefined): void {
|
|
20
|
+
current = control;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getAskControl(): AskControl | undefined {
|
|
24
|
+
return current;
|
|
25
|
+
}
|