@andares/pi-toolkits 0.12.0 → 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 CHANGED
@@ -401,7 +401,7 @@ repository root stays readable: `AGENTS.md`, `specs/`, `design/`, `docs/`,
401
401
  | `/ask-init check` | audit the installed framework (read-only; writes only a runtime report under `.agents/framework/reports/`) |
402
402
  | `/ask-init roots` | sync the directories added with `pi-add-dir` into the framework state |
403
403
  | `/ask-init --yes` | skip the confirmation panel |
404
- | `/ask-init --lang zh\|en` | language for generated prose (default: detected from the project's own docs) |
404
+ | `/ask-init --lang zh\|en` | rendering language for framework-generated files (per run; default: detected from the project's own docs) |
405
405
 
406
406
  **What the mechanical half guarantees**:
407
407
 
@@ -447,7 +447,8 @@ root entry must stay a **scope card** (≤30 lines: what lives there, its comman
447
447
  which main-repo memory file describes it) — never a second copy of the rules.
448
448
 
449
449
  The framework contract shipped into a project is English (it is read by models and
450
- published); text written *into* a project follows that project's language.
450
+ published); framework-generated files are rendered in that project's language. The
451
+ package never directs the model which language to write or reply in.
451
452
 
452
453
  > **After the run**, `/reload` so the new `AGENTS.md` enters the prompt. The
453
454
  > framework version lives in `.agents/framework/state.toml`; a project whose state
package/README.zh-CN.md CHANGED
@@ -399,7 +399,7 @@ run = [
399
399
  | `/ask-init check` | 审计已装的框架(只读;只在 `.agents/framework/reports/` 留下运行期报告) |
400
400
  | `/ask-init roots` | 把 `pi-add-dir` 添加的目录同步进框架状态 |
401
401
  | `/ask-init --yes` | 跳过确认面板 |
402
- | `/ask-init --lang zh\|en` | 生成正文的语言(默认按项目自身文档判定) |
402
+ | `/ask-init --lang zh\|en` | 框架生成文件的渲染语言(单次生效;默认按项目自身文档判定) |
403
403
 
404
404
  **机械那一半保证什么**:
405
405
 
@@ -432,7 +432,8 @@ run = [
432
432
  全文注入每次请求,所以根里的入口只能是 **scope card**(≤30 行:这里放什么、它的命令、
433
433
  去主仓哪个记忆文件读),绝不能是规则的第二份副本。
434
434
 
435
- 装进项目的框架契约用英文(给模型读、也随 npm 发布);写进项目的正文跟随项目语言。
435
+ 装进项目的框架契约用英文(给模型读、也随 npm 发布);框架生成的文件按项目语言渲染。
436
+ 本包不会指示模型用哪种语言写文件或回复。
436
437
 
437
438
  > **跑完记得 `/reload`**,让新的 `AGENTS.md` 进入提示词。框架版本记在
438
439
  > `.agents/framework/state.toml`;若项目的状态版本比当前工具新,则拒绝迁移。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andares/pi-toolkits",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Integrated toolkit extension for pi — ask mode (read-only Q&A), session-scoped permission checks, model favorites, prompt stash, third-party code review, session autostart, a dedicated compaction model, and an agent memory framework (/ask-init)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
2
2
  import { createHash } from "node:crypto";
3
3
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { join } from "node:path";
5
- import { applyPlan, rewriteText, stateToToml } from "./apply.js";
5
+ import { applyPlan, rewriteText, scrubRetiredFields, stateToToml } from "./apply.js";
6
6
  import { parseState } from "./detect.js";
7
7
  import { detect } from "./detect.js";
8
8
  import { buildPlan } from "./plan.js";
@@ -96,7 +96,10 @@ describe("applyPlan", () => {
96
96
  const state = parseState(readFileSync(join(root, ".agents/framework/state.toml"), "utf8"));
97
97
  expect(state.version).toBe(1);
98
98
  expect(state.migrations.length).toBeGreaterThan(0);
99
- expect(state.lang).toBe("zh");
99
+ // The rendering language is computed per run and never persisted.
100
+ expect(readFileSync(join(root, ".agents/framework/state.toml"), "utf8")).not.toMatch(
101
+ /^\s*lang\s*=/m,
102
+ );
100
103
  expect(applied.planPath).toMatch(/^\.agents\/framework\/plans\/plan-.*\.json$/);
101
104
  const order = JSON.parse(readFileSync(join(root, applied.planPath ?? ""), "utf8")) as {
102
105
  tasks: Array<{ id: string }>;
@@ -113,6 +116,35 @@ describe("applyPlan", () => {
113
116
  }
114
117
  });
115
118
 
119
+ describe("retired-field cleanup", () => {
120
+ it("scrubs old plan artifacts during a mutating run", () => {
121
+ const old = `${JSON.stringify(
122
+ {
123
+ framework: "agent-framework",
124
+ mode: "adopt",
125
+ language: "zh",
126
+ tasks: [{ id: "survey", detail: "Read.\nLanguage for everything you write: zh." }],
127
+ },
128
+ null,
129
+ 2,
130
+ )}\n`;
131
+ const root = project({ ...LEGACY, ".agents/framework/plans/plan-old.json": old });
132
+ try {
133
+ const applied = applyPlan(planFor(root), {
134
+ now: new Date("2026-10-26T10:00:00+08:00"),
135
+ });
136
+ expect(applied.summary.some((line) => line.includes("removed obsolete fields"))).toBe(true);
137
+ const scrubbed = JSON.parse(
138
+ readFileSync(join(root, ".agents/framework/plans/plan-old.json"), "utf8"),
139
+ ) as { language?: unknown; tasks: Array<{ detail: string }> };
140
+ expect("language" in scrubbed).toBe(false);
141
+ expect(scrubbed.tasks[0].detail).toBe("Read.");
142
+ } finally {
143
+ remove(root);
144
+ }
145
+ });
146
+ });
147
+
116
148
  it("is safe to run twice", () => {
117
149
  const root = project(LEGACY);
118
150
  try {
@@ -170,7 +202,6 @@ describe("applyPlan", () => {
170
202
  updated: "2026-01-02T00:00:00+08:00",
171
203
  profile: "core" as const,
172
204
  modules: ["design"],
173
- lang: "zh" as const,
174
205
  roots: [
175
206
  {
176
207
  label: "api",
@@ -262,3 +293,128 @@ it("does not corrupt non-UTF-8 files during reference rewriting", () => {
262
293
  remove(root);
263
294
  }
264
295
  });
296
+
297
+ describe("scrubRetiredFields", () => {
298
+ const STATE = [
299
+ "version = 1",
300
+ 'tool = "0.11.0"',
301
+ 'created = "2026-01-01T00:00:00+08:00"',
302
+ 'updated = "2026-01-01T00:00:00+08:00"',
303
+ 'profile = "core"',
304
+ "modules = []",
305
+ 'lang = "zh"',
306
+ "",
307
+ "[[managed]]",
308
+ 'path = ".agents/memory/README.md"',
309
+ 'sha256 = "abc"',
310
+ 'template = "memory-readme"',
311
+ "",
312
+ ].join("\n");
313
+
314
+ function artifact(withLanguage: boolean, retiredDetail = false): string {
315
+ const detail = retiredDetail
316
+ ? "Read the project.\nLanguage for everything you write: en."
317
+ : "Read the project.";
318
+ return `${JSON.stringify(
319
+ {
320
+ framework: "agent-framework",
321
+ mode: "adopt",
322
+ ...(withLanguage ? { language: "en" } : {}),
323
+ tasks: [{ id: "survey", kind: "survey", detail, acceptance: [] }],
324
+ },
325
+ null,
326
+ 2,
327
+ )}\n`;
328
+ }
329
+
330
+ it("removes the retired state line and plan key, idempotently", () => {
331
+ const root = project({
332
+ ".agents/framework/state.toml": STATE,
333
+ ".agents/framework/plans/plan-a.json": artifact(true, true),
334
+ ".agents/framework/plans/plan-b.json": artifact(false),
335
+ });
336
+ try {
337
+ const first = scrubRetiredFields(root);
338
+ expect(first).toEqual({ stateScrubbed: true, plansScrubbed: 1 });
339
+ expect(readFileSync(join(root, ".agents/framework/state.toml"), "utf8")).not.toMatch(/^\s*lang\s*=/m);
340
+ // Everything except the retired line survives untouched.
341
+ expect(readFileSync(join(root, ".agents/framework/state.toml"), "utf8")).toContain('template = "memory-readme"');
342
+ const a = JSON.parse(readFileSync(join(root, ".agents/framework/plans/plan-a.json"), "utf8")) as {
343
+ tasks: Array<{ detail: string }>;
344
+ };
345
+ expect("language" in a).toBe(false);
346
+ expect((a as { mode?: string }).mode).toBe("adopt");
347
+ expect(a.tasks[0].detail).toBe("Read the project.");
348
+
349
+ const second = scrubRetiredFields(root);
350
+ expect(second).toEqual({ stateScrubbed: false, plansScrubbed: 0 });
351
+ } finally {
352
+ remove(root);
353
+ }
354
+ });
355
+
356
+ it("is a no-op on a clean or missing install", () => {
357
+ const clean = project({
358
+ ".agents/framework/state.toml": STATE.replace('lang = "zh"\n', ""),
359
+ ".agents/framework/plans/plan-c.json": artifact(false),
360
+ });
361
+ try {
362
+ expect(scrubRetiredFields(clean)).toEqual({ stateScrubbed: false, plansScrubbed: 0 });
363
+ } finally {
364
+ remove(clean);
365
+ }
366
+ const empty = project({ "README.md": "# demo\n" });
367
+ try {
368
+ expect(scrubRetiredFields(empty)).toEqual({ stateScrubbed: false, plansScrubbed: 0 });
369
+ } finally {
370
+ remove(empty);
371
+ }
372
+ });
373
+
374
+ it("leaves malformed plan artifacts untouched", () => {
375
+ const root = project({
376
+ ".agents/framework/state.toml": STATE,
377
+ ".agents/framework/plans/broken.json": "{ not json",
378
+ });
379
+ try {
380
+ expect(scrubRetiredFields(root)).toEqual({ stateScrubbed: true, plansScrubbed: 0 });
381
+ expect(readFileSync(join(root, ".agents/framework/plans/broken.json"), "utf8")).toBe("{ not json");
382
+ } finally {
383
+ remove(root);
384
+ }
385
+ });
386
+
387
+ it("changes nothing under --dry-run", () => {
388
+ const root = project({
389
+ ".agents/framework/state.toml": STATE,
390
+ ".agents/framework/plans/plan-a.json": artifact(true, true),
391
+ });
392
+ try {
393
+ const before = readFileSync(join(root, ".agents/framework/state.toml"), "utf8");
394
+ const beforePlan = readFileSync(join(root, ".agents/framework/plans/plan-a.json"), "utf8");
395
+ expect(scrubRetiredFields(root, { dryRun: true })).toEqual({
396
+ stateScrubbed: true,
397
+ plansScrubbed: 1,
398
+ });
399
+ expect(readFileSync(join(root, ".agents/framework/state.toml"), "utf8")).toBe(before);
400
+ expect(readFileSync(join(root, ".agents/framework/plans/plan-a.json"), "utf8")).toBe(beforePlan);
401
+ } finally {
402
+ remove(root);
403
+ }
404
+ });
405
+
406
+ it("only filters the top-level region, never a table key with the same name", () => {
407
+ const withTableKey = `${STATE}\n[[roots]]\nlabel = "api"\nlang = "zh"\n`;
408
+ const root = project({ ".agents/framework/state.toml": withTableKey });
409
+ try {
410
+ scrubRetiredFields(root);
411
+ const text = readFileSync(join(root, ".agents/framework/state.toml"), "utf8");
412
+ // The top-level line is gone; the root entry keeps its own key.
413
+ expect(text.split("\n").filter((line) => line === 'lang = "zh"')).toHaveLength(1);
414
+ expect(text).toContain("[[roots]]");
415
+ expect(text).toContain('label = "api"');
416
+ } finally {
417
+ remove(root);
418
+ }
419
+ });
420
+ });
@@ -35,6 +35,7 @@ import {
35
35
  IMPLEMENTATIONS_DIR,
36
36
  MEMORY_DIR,
37
37
  PLAN_FILE,
38
+ PLANS_DIR,
38
39
  REPORTS_DIR,
39
40
  SIGNPOST_FILE,
40
41
  SPECS_DIR,
@@ -374,7 +375,6 @@ export function stateToToml(state: FrameworkState): string {
374
375
  updated: state.updated,
375
376
  profile: state.profile,
376
377
  modules: state.modules,
377
- lang: state.lang,
378
378
  budgets: state.budgets
379
379
  ? compact({
380
380
  agents_md_soft_chars: state.budgets.agentsMdSoftChars,
@@ -618,6 +618,7 @@ export function applyPlan(plan: Plan, options: ApplyOptions = {}): ApplyResult {
618
618
  ? writeCoverageFile(plan, plan.artifacts.coverage)
619
619
  : undefined;
620
620
  const planPath = !ctx.dryRun && plan.artifacts.plan ? writeWorkOrder(plan, ctx) : undefined;
621
+ const scrubbedPlans = planPath ? scrubPlanArtifacts(join(plan.root, PLANS_DIR), false) : 0;
621
622
 
622
623
  const summary: string[] = [];
623
624
  if (ctx.snapshot) summary.push(`snapshot: ${ctx.snapshot.dir} (${ctx.snapshot.files} files)`);
@@ -628,6 +629,7 @@ export function applyPlan(plan: Plan, options: ApplyOptions = {}): ApplyResult {
628
629
  if (ctx.created.length > 0) summary.push(`created ${ctx.created.length} files`);
629
630
  if (coverageWritten) summary.push(`coverage worklist: ${coverageWritten}`);
630
631
  if (planPath) summary.push(`work order: ${planPath}`);
632
+ if (scrubbedPlans > 0) summary.push(`removed obsolete fields from ${scrubbedPlans} plan artifact(s)`);
631
633
  if (ctx.skipped.length > 0) summary.push(`skipped ${ctx.skipped.length} (see report)`);
632
634
 
633
635
  return {
@@ -666,6 +668,102 @@ function writeWorkOrder(plan: Plan, ctx: ApplyContext): string | undefined {
666
668
  return plan.artifacts.plan;
667
669
  }
668
670
 
671
+ /**
672
+ * Remove retired language directives from every plan artifact in a directory.
673
+ * Covers the top-level `language` key and the retired survey-task line that old
674
+ * runs serialized into `tasks[].detail`. Local-only run artefacts; unreadable
675
+ * files are left untouched. Returns how many files were (or would be) rewritten.
676
+ */
677
+ const RETIRED_DETAIL_LINES = [
678
+ "Language for everything you write: en.",
679
+ "Language for everything you write: zh.",
680
+ ];
681
+
682
+ function scrubPlanArtifacts(dir: string, dryRun: boolean): number {
683
+ if (!existsSync(dir)) return 0;
684
+ let scrubbed = 0;
685
+ for (const name of readdirSync(dir).sort()) {
686
+ if (!name.endsWith(".json")) continue;
687
+ const file = join(dir, name);
688
+ try {
689
+ const value = JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown> | null;
690
+ if (value === null || typeof value !== "object" || Array.isArray(value)) continue;
691
+ let changed = false;
692
+ if ("language" in value) {
693
+ delete value.language;
694
+ changed = true;
695
+ }
696
+ if (Array.isArray(value.tasks)) {
697
+ for (const task of value.tasks) {
698
+ if (task === null || typeof task !== "object") continue;
699
+ const record = task as Record<string, unknown>;
700
+ if (typeof record.detail !== "string") continue;
701
+ const kept = record.detail
702
+ .split("\n")
703
+ .filter((line) => !RETIRED_DETAIL_LINES.includes(line))
704
+ .join("\n");
705
+ if (kept === record.detail) continue;
706
+ record.detail = kept;
707
+ changed = true;
708
+ }
709
+ }
710
+ if (!changed) continue;
711
+ scrubbed += 1;
712
+ if (!dryRun) writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`, "utf8");
713
+ } catch {
714
+ // Not ours to fix: malformed artifacts stay as they are.
715
+ }
716
+ }
717
+ return scrubbed;
718
+ }
719
+
720
+ /**
721
+ * A retired `lang` key, in the shapes TOML accepts. Only the top-level region of
722
+ * the state file is filtered: an identically named key inside a table belongs to
723
+ * that table, not to us.
724
+ */
725
+ const RETIRED_STATE_LINE = /^\s*lang\s*=\s*["'](?:zh|en)["']\s*(?:#.*)?$/;
726
+
727
+ function scrubStateLang(raw: string): string {
728
+ const lines = raw.split("\n");
729
+ const firstTable = lines.findIndex((line) => /^\s*\[/.test(line));
730
+ const limit = firstTable === -1 ? lines.length : firstTable;
731
+ return lines.filter((line, index) => index >= limit || !RETIRED_STATE_LINE.test(line)).join("\n");
732
+ }
733
+
734
+ export interface ScrubOptions {
735
+ /** Report what would change without touching the files. */
736
+ readonly dryRun?: boolean;
737
+ }
738
+
739
+ export interface ScrubResult {
740
+ /** state.toml lost (in a dry run: would lose) the retired key. */
741
+ readonly stateScrubbed: boolean;
742
+ /** Plan artifacts that were (in a dry run: would be) rewritten. */
743
+ readonly plansScrubbed: number;
744
+ }
745
+
746
+ /**
747
+ * Maintenance entry: remove retired language fields from an installed
748
+ * framework (the `lang` line in state.toml, the `language` key and the retired
749
+ * survey line in plan artifacts). Idempotent — a second call reports nothing to
750
+ * do. Files outside the three retired shapes are not rewritten.
751
+ */
752
+ export function scrubRetiredFields(root: string, options: ScrubOptions = {}): ScrubResult {
753
+ const dryRun = options.dryRun === true;
754
+ const stateFile = join(root, STATE_FILE);
755
+ let stateScrubbed = false;
756
+ if (existsSync(stateFile)) {
757
+ const raw = readFileSync(stateFile, "utf8");
758
+ const kept = scrubStateLang(raw);
759
+ if (kept !== raw) {
760
+ stateScrubbed = true;
761
+ if (!dryRun) writeFileSync(stateFile, kept, "utf8");
762
+ }
763
+ }
764
+ return { stateScrubbed, plansScrubbed: scrubPlanArtifacts(join(root, PLANS_DIR), dryRun) };
765
+ }
766
+
669
767
  /** Write state, refreshing the hashes of files this framework manages. */
670
768
  function writeState(root: string, state: FrameworkState): string {
671
769
  const managedPaths = [CONTRACT_FILE, SIGNPOST_FILE, STATE_GITIGNORE];
@@ -192,7 +192,7 @@ describe("detect", () => {
192
192
  it("parses a deliberately partial state file", () => {
193
193
  const state = parseState('version = 1\nroots = []\n');
194
194
  expect(state.version).toBe(1);
195
- expect(state.lang).toBe("en");
195
+ expect(Object.keys(state)).not.toContain("lang");
196
196
  expect(state.profile).toBe("core");
197
197
  });
198
198
  });
@@ -220,7 +220,6 @@ describe("review regressions", () => {
220
220
  updated: "2026-01-01T00:00:00+08:00",
221
221
  profile: "core",
222
222
  modules: [],
223
- lang: "en",
224
223
  budgets: {
225
224
  agentsMdSoftChars: 9000,
226
225
  agentsMdHardChars: 16000,
@@ -389,7 +389,6 @@ export function parseState(raw: string): FrameworkState {
389
389
  const updated = String(data.updated ?? created);
390
390
  const profile = data.profile === "full" ? "full" : "core";
391
391
  const modules = Array.isArray(data.modules) ? data.modules.map(String) : [];
392
- const lang = data.lang === "zh" ? "zh" : "en";
393
392
  const budgets = data.budgets as Record<string, unknown> | undefined;
394
393
  const roots = Array.isArray(data.roots)
395
394
  ? (data.roots as Array<Record<string, unknown>>).map((entry) => ({
@@ -429,7 +428,6 @@ export function parseState(raw: string): FrameworkState {
429
428
  updated,
430
429
  profile,
431
430
  modules,
432
- lang,
433
431
  budgets: budgets
434
432
  ? {
435
433
  agentsMdSoftChars: numberOrUndefined(
@@ -798,7 +796,7 @@ export function detect(root: string, options: DetectOptions = {}): Facts {
798
796
  modulesPresent: readModulesPresent(root, memory),
799
797
  refs: scanRefs(root),
800
798
  project: detectProject(root),
801
- language: options.lang ?? state?.lang ?? detectLanguage(root),
799
+ language: options.lang ?? detectLanguage(root),
802
800
  roots: mergeRoots(root, state?.roots ?? [], options.addedRoots ?? []),
803
801
  warnings: contextWarnings(context, state, stateError),
804
802
  };
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { buildWorkOrder, serializeWorkOrder } from "./dispatch.js";
3
+ import { buildPlan } from "./plan.js";
4
+ import { detect } from "./detect.js";
5
+ import { project } from "./test-helpers.js";
6
+
7
+ const NOW = new Date("2026-10-26T10:00:00Z");
8
+
9
+ function planFor(files: Record<string, string>) {
10
+ return buildPlan(detect(project(files)), { toolVersion: "test", now: NOW });
11
+ }
12
+
13
+ describe("buildWorkOrder", () => {
14
+ it("contains no language directive at all", () => {
15
+ const order = buildWorkOrder({ plan: planFor({ "README.md": "# demo\n" }) });
16
+ // The work order must not tell the model which language to write or reply in —
17
+ // it works that out from the project's own docs. Rendering language for the
18
+ // framework's own files is computed in code and never appears here.
19
+ expect(order).not.toMatch(/prose language/i);
20
+ expect(order).not.toMatch(/\blanguage\b/i);
21
+ expect(order).not.toMatch(/\b(English|Chinese)\b/);
22
+ expect(order).toContain("Repository:");
23
+ expect(order).toContain("Plan (machine-readable):");
24
+ });
25
+
26
+ it("keeps the project language out of the survey task detail", () => {
27
+ const plan = planFor({ "README.md": "# 演示\n\n本项目只做演示,说明保持中文。\n" });
28
+ expect(plan.language).toBe("zh");
29
+ const order = buildWorkOrder({ plan });
30
+ expect(order).not.toMatch(/\blanguage\b/i);
31
+ const survey = plan.tasks.find((task) => task.id === "survey");
32
+ expect(survey?.detail).not.toMatch(/\blanguage\b/i);
33
+ });
34
+
35
+ it("persists no language field in the serialized work order", () => {
36
+ const plan = planFor({ "README.md": "# demo\n" });
37
+ const raw = serializeWorkOrder(plan);
38
+ expect(raw).not.toMatch(/\blanguage\b/i);
39
+ const parsed = JSON.parse(raw) as Record<string, unknown>;
40
+ expect("language" in parsed).toBe(false);
41
+ });
42
+ });
@@ -26,7 +26,6 @@ const MODE_LABEL: Record<Plan["mode"], string> = {
26
26
 
27
27
  export function buildWorkOrder(input: WorkOrderInput): string {
28
28
  const { plan, applied } = input;
29
- const language = plan.language === "zh" ? "Chinese" : "English";
30
29
 
31
30
  const done: string[] = [];
32
31
  if (applied) {
@@ -65,7 +64,6 @@ export function buildWorkOrder(input: WorkOrderInput): string {
65
64
  `AGENT FRAMEWORK v${plan.frameworkVersion} — ${MODE_LABEL[plan.mode]}`,
66
65
  "",
67
66
  `Repository: ${plan.root}`,
68
- `Prose language for anything you write: ${language}.`,
69
67
  `Plan (machine-readable): ${input.planPath ?? plan.artifacts.plan ?? "(see the plan task)"}`,
70
68
  "",
71
69
  "The deterministic half has already run. Do not repeat it, and do not move, rename or scaffold directories yourself unless a task says so.",
@@ -112,7 +110,6 @@ export function serializeWorkOrder(plan: Plan, applied?: ApplyResult): string {
112
110
  version: plan.frameworkVersion,
113
111
  mode: plan.mode,
114
112
  root: plan.root,
115
- language: plan.language,
116
113
  createdAt: plan.createdAt,
117
114
  tool: plan.toolVersion,
118
115
  artifacts: plan.artifacts,
@@ -83,6 +83,7 @@ describe("parseInitArgs", () => {
83
83
  expect(parseInitArgs("").sub).toBe("run");
84
84
  expect(parseInitArgs("check").sub).toBe("check");
85
85
  expect(parseInitArgs("roots").sub).toBe("roots");
86
+ expect(parseInitArgs("scrub").sub).toBe("scrub");
86
87
  expect(parseInitArgs("plan --deep").sub).toBe("plan");
87
88
  });
88
89
 
@@ -328,4 +329,44 @@ describe("review regressions", () => {
328
329
  remove(root);
329
330
  }
330
331
  });
332
+
333
+ it("scrubs retired language fields, once, and honours --dry-run", async () => {
334
+ const state = [
335
+ "version = 1",
336
+ 'tool = "0.11.0"',
337
+ 'created = "2026-01-01T00:00:00+08:00"',
338
+ 'updated = "2026-01-01T00:00:00+08:00"',
339
+ 'profile = "core"',
340
+ "modules = []",
341
+ 'lang = "zh"',
342
+ "",
343
+ ].join("\n");
344
+ const plan = `${JSON.stringify({ framework: "agent-framework", language: "zh", tasks: [] }, null, 2)}\n`;
345
+ const root = project({
346
+ ".agents/framework/state.toml": state,
347
+ ".agents/framework/plans/plan-old.json": plan,
348
+ });
349
+ try {
350
+ const dry = harness(root);
351
+ registerInit(dry.pi, { now: NOW, toolVersion: "test" });
352
+ await dry.run("scrub --dry-run");
353
+ expect(dry.messages.at(-1)?.message).toMatch(/would clean/);
354
+ expect(readFileSync(join(root, ".agents/framework/state.toml"), "utf8")).toBe(state);
355
+ expect(readFileSync(join(root, ".agents/framework/plans/plan-old.json"), "utf8")).toBe(plan);
356
+
357
+ const h = harness(root);
358
+ registerInit(h.pi, { now: NOW, toolVersion: "test" });
359
+ await h.run("scrub");
360
+ expect(h.messages.at(-1)?.message).toMatch(/cleaned/);
361
+ expect(readFileSync(join(root, ".agents/framework/state.toml"), "utf8")).not.toMatch(/^\s*lang\s*=/m);
362
+ expect(readFileSync(join(root, ".agents/framework/plans/plan-old.json"), "utf8")).not.toMatch(/"language"/);
363
+
364
+ const again = harness(root);
365
+ registerInit(again.pi, { now: NOW, toolVersion: "test" });
366
+ await again.run("scrub");
367
+ expect(again.messages.at(-1)?.message).toMatch(/nothing to scrub/);
368
+ } finally {
369
+ remove(root);
370
+ }
371
+ });
331
372
  });
@@ -31,7 +31,7 @@ import type {
31
31
  } from "@earendil-works/pi-coding-agent";
32
32
  import { Text } from "@earendil-works/pi-tui";
33
33
  import { stateToToml } from "./apply.js";
34
- import { applyPlan } from "./apply.js";
34
+ import { applyPlan, scrubRetiredFields } from "./apply.js";
35
35
  import { audit, countFindings, renderFindings } from "./audit.js";
36
36
  import { detect } from "./detect.js";
37
37
  import { buildWorkOrder } from "./dispatch.js";
@@ -60,7 +60,7 @@ export interface InitOptions {
60
60
  }
61
61
 
62
62
  export interface ParsedInitArgs {
63
- readonly sub: "run" | "plan" | "check" | "roots" | "help";
63
+ readonly sub: "run" | "plan" | "check" | "roots" | "scrub" | "help";
64
64
  readonly dryRun: boolean;
65
65
  readonly deep: boolean;
66
66
  readonly yes: boolean;
@@ -74,9 +74,9 @@ const USAGE = [
74
74
  "/ask-init plan [--deep] show the plan only (writes nothing)",
75
75
  "/ask-init check audit the installed framework (read-only)",
76
76
  "/ask-init roots sync pi-add-dir roots into the framework state",
77
- "/ask-init --dry-run same as plan",
77
+ "/ask-init --dry-run report only, write nothing (same as plan)",
78
78
  "/ask-init --yes skip the confirmation panel",
79
- "/ask-init --lang zh|en language for generated prose",
79
+ "/ask-init --lang zh|en rendering language for framework-generated files",
80
80
  ].join("\n");
81
81
 
82
82
  export function parseInitArgs(input: string): ParsedInitArgs {
@@ -89,7 +89,7 @@ export function parseInitArgs(input: string): ParsedInitArgs {
89
89
  const unknown: string[] = [];
90
90
  for (let index = 0; index < tokens.length; index += 1) {
91
91
  const token = tokens[index];
92
- if (token === "plan" || token === "check" || token === "roots" || token === "help") {
92
+ if (token === "plan" || token === "check" || token === "roots" || token === "scrub" || token === "help") {
93
93
  sub = token;
94
94
  continue;
95
95
  }
@@ -231,7 +231,7 @@ function planText(plan: Plan): string {
231
231
  const lines = [
232
232
  `/ask-init — ${plan.mode}`,
233
233
  `root: ${plan.root}`,
234
- `framework: v${plan.frameworkVersion} · language: ${plan.language}`,
234
+ `framework: v${plan.frameworkVersion}`,
235
235
  "",
236
236
  "## plan",
237
237
  ...plan.summary.map((line) => `- ${line}`),
@@ -443,6 +443,27 @@ function createRunHandler(
443
443
  return;
444
444
  }
445
445
 
446
+ // Hidden maintenance subcommand (not in USAGE): removes retired fields
447
+ // from an installed framework. Documented in AGENTS.md only; obeys
448
+ // `--dry-run` because that flag promises "nothing is written".
449
+ if (parsed.sub === "scrub") {
450
+ const result = scrubRetiredFields(root, { dryRun: parsed.dryRun });
451
+ const parts: string[] = [];
452
+ if (result.stateScrubbed) parts.push(".agents/framework/state.toml");
453
+ if (result.plansScrubbed > 0) {
454
+ parts.push(`${result.plansScrubbed} plan artifact(s)`);
455
+ }
456
+ const verb = parsed.dryRun ? "would clean" : "cleaned";
457
+ const suffix = parsed.dryRun ? " — nothing was written." : "";
458
+ ctx.ui.notify(
459
+ parts.length > 0
460
+ ? `ask-init scrub: ${verb} ${parts.join(" · ")}${suffix}`
461
+ : "ask-init scrub: nothing to scrub — state and plan artifacts are already clean.",
462
+ "info",
463
+ );
464
+ return;
465
+ }
466
+
446
467
  const toolVersion = options.toolVersion ?? packageVersion();
447
468
  const now = options.now ?? new Date();
448
469
  const addedRoots = options.addedRoots ?? addedRootsFromBranch(ctx);
@@ -558,11 +579,11 @@ export function registerInit(pi0: ExtensionAPI, options: InitOptions = {}): void
558
579
  { value: "plan", label: "plan", description: "show the plan only (writes nothing)" },
559
580
  { value: "check", label: "check", description: "audit the installed framework" },
560
581
  { value: "roots", label: "roots", description: "sync pi-add-dir roots into state" },
561
- { value: "--dry-run", label: "--dry-run", description: "same as plan" },
582
+ { value: "--dry-run", label: "--dry-run", description: "report only, write nothing" },
562
583
  { value: "--deep", label: "--deep", description: "allow structural rewrites" },
563
584
  { value: "--yes", label: "--yes", description: "skip the confirmation panel" },
564
- { value: "--lang zh", label: "--lang zh", description: "Chinese prose" },
565
- { value: "--lang en", label: "--lang en", description: "English prose" },
585
+ { value: "--lang zh", label: "--lang zh", description: "render framework text in Chinese" },
586
+ { value: "--lang en", label: "--lang en", description: "render framework text in English" },
566
587
  ].filter((item) => item.value.startsWith(prefix)),
567
588
  handler: createRunHandler(pi, options, runtime),
568
589
  });
@@ -216,7 +216,6 @@ function buildState(
216
216
  updated: iso(now),
217
217
  profile: "core",
218
218
  modules: [...new Set(modules)],
219
- lang: facts.language,
220
219
  budgets: previous?.budgets,
221
220
  roots: facts.roots.length > 0 ? facts.roots : (previous?.roots ?? []),
222
221
  managed: previous?.managed ?? [],
@@ -249,7 +248,6 @@ function surveyTask(facts: Facts): Task {
249
248
  "Read the project and record only evidence; anything you cannot verify is `TBD`.",
250
249
  `Read: ${read.join(", ") || "(no manifests found — walk the tree)"}`,
251
250
  `Also: directory tree (depth 2-3, skip build dirs), \`git log --oneline -20\`, README.`,
252
- `Language for everything you write: ${facts.language}.`,
253
251
  ].join("\n"),
254
252
  acceptance: [
255
253
  "every command in AGENTS.md was read from a manifest/CI/script, not guessed",
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * init feature — markdown fragments shared by the plan, the scaffold and the
3
- * work order. Kept language-aware: the framework's own text is English, but
4
- * anything written into a project follows that project's language.
3
+ * work order. Language-aware only for the framework's own rendered text — never
4
+ * a directive to the model about which language to use.
5
5
  */
6
6
  import {
7
7
  MEMORY_DIR,
@@ -308,9 +308,11 @@ export type AuditCode = (typeof AUDIT_CODES)[keyof typeof AUDIT_CODES];
308
308
  /* -------------------------------------------------------------------------- */
309
309
 
310
310
  /**
311
- * Framework-owned text (contract, plan headers, audit codes) ships in English:
312
- * it is read by models and published on npm. Text *written into a project*
313
- * follows that project's language (`zh` when its docs are mostly CJK).
311
+ * Rendering language for framework-generated files (skeleton, seeds, index
312
+ * tables). This is our own output choice, never a directive to the model:
313
+ * nothing in this package tells the model which language to write or reply in —
314
+ * the model judges that itself from the project's own docs. The value is
315
+ * computed per run and is never persisted to state or plan artifacts.
314
316
  */
315
317
  export type ProjectLanguage = "zh" | "en";
316
318
 
@@ -60,7 +60,6 @@ export interface FrameworkState {
60
60
  updated: string;
61
61
  profile: "core" | "full";
62
62
  modules: string[];
63
- lang: ProjectLanguage;
64
63
  budgets?: {
65
64
  agentsMdSoftChars?: number;
66
65
  agentsMdHardChars?: number;