universal-dev-standards 6.14.0-beta.11 → 6.14.0-beta.13

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.
Files changed (46) hide show
  1. package/bin/uds.js +8 -1
  2. package/bundled/ai/standards/secret-management-standards.ai.yaml +12 -1
  3. package/bundled/core/secret-management-standards.md +13 -1
  4. package/bundled/hooks/validate-commit-msg.mjs +52 -9
  5. package/bundled/locales/zh-CN/CHANGELOG.md +3 -3
  6. package/bundled/locales/zh-CN/README.md +1 -1
  7. package/bundled/locales/zh-CN/SECURITY.md +1 -1
  8. package/bundled/locales/zh-CN/docs/CHEATSHEET.md +1 -1
  9. package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +4 -3
  10. package/bundled/locales/zh-TW/CHANGELOG.md +3 -3
  11. package/bundled/locales/zh-TW/README.md +1 -1
  12. package/bundled/locales/zh-TW/SECURITY.md +1 -1
  13. package/bundled/locales/zh-TW/core/secret-management-standards.md +12 -4
  14. package/bundled/locales/zh-TW/docs/CHEATSHEET.md +1 -1
  15. package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +4 -3
  16. package/package.json +1 -1
  17. package/src/commands/audit.js +28 -1
  18. package/src/commands/check.js +72 -3
  19. package/src/commands/compile.js +37 -4
  20. package/src/commands/config.js +28 -19
  21. package/src/commands/init.js +59 -28
  22. package/src/commands/release-messages.js +228 -0
  23. package/src/commands/release.js +72 -72
  24. package/src/commands/spec.js +4 -2
  25. package/src/commands/update.js +114 -12
  26. package/src/compilers/claude-code-compiler.js +9 -1
  27. package/src/i18n/messages.js +96 -0
  28. package/src/installers/hooks-installer.js +1 -1
  29. package/src/mcp/server.js +9 -3
  30. package/src/prompts/init.js +17 -17
  31. package/src/reconciler/plan-executor.js +63 -5
  32. package/src/reconciler/recorded-versions.js +49 -0
  33. package/src/uninstallers/hook-uninstaller.js +9 -1
  34. package/src/uninstallers/skills-uninstaller.js +10 -3
  35. package/src/utils/available-standards-report.js +25 -4
  36. package/src/utils/available-standards.js +13 -3
  37. package/src/utils/build-manifest.js +1 -1
  38. package/src/utils/commit-message-judge.js +38 -9
  39. package/src/utils/friction-detector.js +23 -11
  40. package/src/utils/git-hooks.js +106 -4
  41. package/src/utils/integration-generator.js +75 -49
  42. package/src/utils/legacy-hook-migration.js +121 -2
  43. package/src/utils/sdd-header.js +11 -0
  44. package/src/utils/spinner.js +14 -4
  45. package/src/utils/standard-validator.js +3 -2
  46. package/standards-registry.json +10 -8
@@ -51,15 +51,28 @@ function withUncasedLettersAsLowercase(text) {
51
51
  return text.replace(/\p{L}/gu, (ch) => (ch.toLowerCase() === ch.toUpperCase() ? 'a' : ch));
52
52
  }
53
53
 
54
+ /** Compare dotted numeric versions ("1.0.0" < "2.0.0"); a missing or non-numeric part counts as 0. */
55
+ function compareVersions(a, b) {
56
+ const part = (v) => String(v ?? '0').split(/[.-]/).map((n) => Number.parseInt(n, 10) || 0);
57
+ const [x, y] = [part(a), part(b)];
58
+ for (let i = 0; i < Math.max(x.length, y.length); i++) {
59
+ const d = (x[i] ?? 0) - (y[i] ?? 0);
60
+ if (d !== 0) return d < 0 ? -1 : 1;
61
+ }
62
+ return 0;
63
+ }
64
+
54
65
  /**
55
66
  * The commit types the project's installed option files allow. An option file belongs to this standard when
56
67
  * its `meta.parent` is `commit-message`. Installed projects keep option files flat in `.standards/options/`
57
68
  * (`english.ai.yaml`); a checkout of UDS itself nests them (`.standards/options/commit-message/`). Both are read.
58
69
  * @param {string} standardsDir - `<project>/.standards`
59
- * @returns {{ types: string[], source: string }}
70
+ * @param {{ shippedRoot?: string|null }} [opts] - the folder holding the option files this CLI ships (`<root>/ai/options/commit-message/`)
71
+ * @returns {{ types: string[], source: string, stale: Array<{id: string, installed: string, shipped: string}> }}
60
72
  */
61
- export function allowedCommitTypes(standardsDir) {
73
+ export function allowedCommitTypes(standardsDir, { shippedRoot = null } = {}) {
62
74
  const found = new Set();
75
+ const stale = [];
63
76
  const optionsDir = path.join(standardsDir, 'options');
64
77
  for (const dir of [optionsDir, path.join(optionsDir, 'commit-message')]) {
65
78
  let names = [];
@@ -72,7 +85,19 @@ export function allowedCommitTypes(standardsDir) {
72
85
  try {
73
86
  const doc = yaml.load(fs.readFileSync(path.join(dir, name), 'utf-8'));
74
87
  if (doc?.meta?.parent !== 'commit-message') continue;
75
- for (const entry of doc.types || []) {
88
+ // XSPEC-475 R7: an installed option file that is OLDER than the one this CLI ships is judged by the shipped one, and
89
+ // the caller is told. After a CLI upgrade and before `uds update --apply` the installed file still has the old rules
90
+ // (traditional-chinese 1.0.0 listed Chinese types), and judging by it gave the opposite of the current answer without a word.
91
+ let rules = doc;
92
+ const shippedFile = shippedRoot && doc.id ? path.join(shippedRoot, 'ai', 'options', 'commit-message', `${doc.id}.ai.yaml`) : null;
93
+ if (shippedFile && fs.existsSync(shippedFile)) {
94
+ const shipped = yaml.load(fs.readFileSync(shippedFile, 'utf-8'));
95
+ if (compareVersions(doc.meta.version, shipped?.meta?.version) < 0) { // [mutation-anchor:installed-option-older]
96
+ rules = shipped;
97
+ stale.push({ id: doc.id, installed: String(doc.meta.version ?? 'unknown'), shipped: String(shipped.meta.version) });
98
+ }
99
+ }
100
+ for (const entry of rules.types || []) {
76
101
  if (entry && typeof entry.type === 'string') found.add(entry.type);
77
102
  }
78
103
  } catch {
@@ -80,8 +105,8 @@ export function allowedCommitTypes(standardsDir) {
80
105
  }
81
106
  }
82
107
  }
83
- if (found.size === 0) return { types: FALLBACK_TYPES, source: 'the Conventional Commits set, because no commit-message option file is installed' };
84
- return { types: [...found], source: '.standards/options' };
108
+ if (found.size === 0) return { types: FALLBACK_TYPES, source: 'the Conventional Commits set, because no commit-message option file is installed', stale };
109
+ return { types: [...found], source: stale.length > 0 ? ".standards/options, with the CLI's current rules for the option file(s) listed as out of date" : '.standards/options', stale };
85
110
  }
86
111
 
87
112
  /** The `validator` pattern of a rule in the standard, as a RegExp, or null when there is none. */
@@ -99,12 +124,13 @@ function ruleValidator(standardConfig, ruleId) {
99
124
  * @param {Object} standardConfig - the parsed commit-message standard
100
125
  * @param {string} input - the commit message (only the first line is the header)
101
126
  * @param {{ standardsDir: string }} context
102
- * @returns {{ verdict: 'pass' | 'fail', findings: string[], checked: string[], notChecked: string[] }}
127
+ * @returns {{ verdict: 'pass' | 'fail', findings: string[], checked: string[], notChecked: string[], notes: string[] }}
103
128
  */
104
- export function judgeCommitMessage(standardConfig, input, { standardsDir }) {
129
+ export function judgeCommitMessage(standardConfig, input, { standardsDir, shippedRoot = null }) {
105
130
  const findings = [];
106
131
  const checked = [];
107
132
  const notChecked = [];
133
+ const notes = [];
108
134
 
109
135
  const header = String(input).replace(/\r\n/g, '\n').split('\n')[0];
110
136
  const match = HEADER.exec(header);
@@ -114,7 +140,10 @@ export function judgeCommitMessage(standardConfig, input, { standardsDir }) {
114
140
  findings.push('The first line is not in the form <type>(<scope>): <subject> (scope is optional).');
115
141
  } else {
116
142
  const { type, scope, subject } = match.groups;
117
- const { types, source } = allowedCommitTypes(standardsDir);
143
+ const { types, source, stale } = allowedCommitTypes(standardsDir, { shippedRoot });
144
+ for (const o of stale) {
145
+ notes.push(`The installed option file "${o.id}" is version ${o.installed}, older than the ${o.shipped} this CLI ships, so this message was judged by the CLI's current rules. Run \`uds update --apply\` to bring the installed option file up to date.`);
146
+ }
118
147
 
119
148
  checked.push(`type is one of: ${types.join(', ')} (from ${source})`);
120
149
  if (!types.includes(type)) {
@@ -151,5 +180,5 @@ export function judgeCommitMessage(standardConfig, input, { standardsDir }) {
151
180
  notChecked.push('rule imperative-mood (the standard gives no machine-checkable pattern)');
152
181
  notChecked.push('rule no-mixed-changes and the commit language option');
153
182
 
154
- return { verdict: findings.length === 0 ? 'pass' : 'fail', findings, checked, notChecked };
183
+ return { verdict: findings.length === 0 ? 'pass' : 'fail', findings, checked, notChecked, notes };
155
184
  }
@@ -55,18 +55,30 @@ export function detectFrictions(projectPath, manifest) {
55
55
  * @returns {Array}
56
56
  */
57
57
  function detectAvailableStandards(manifest) {
58
- const { offered } = getAvailableStandards(manifest);
59
- if (offered.length === 0) return [];
60
-
58
+ const { offered, recommended } = getAvailableStandards(manifest);
61
59
  const msg = t().availableStandards;
62
- const shown = offered.slice(0, 5).map(s => s.id).join(', ');
63
- return [{
64
- standard: msg.frictionStandard.replace('{count}', offered.length),
65
- type: 'not-installed',
66
- severity: 'LOW',
67
- diff: offered.length > 5 ? `${shown}, …` : shown,
68
- suggestion: msg.frictionSuggestion
69
- }];
60
+ const findings = [];
61
+ if (offered.length > 0) {
62
+ const shown = offered.slice(0, 5).map(s => s.id).join(', ');
63
+ findings.push({
64
+ standard: msg.frictionStandard.replace('{count}', offered.length),
65
+ type: 'not-installed',
66
+ severity: 'LOW',
67
+ diff: offered.length > 5 ? `${shown}, …` : shown,
68
+ suggestion: msg.frictionSuggestion
69
+ });
70
+ }
71
+ // XSPEC-475 R9: the recommended core standards are named, with the command that installs each one.
72
+ if (recommended.length > 0) {
73
+ findings.push({
74
+ standard: msg.frictionRecommended.replace('{count}', recommended.length),
75
+ type: 'not-installed',
76
+ severity: 'LOW',
77
+ diff: recommended.map(s => s.id).join(', '),
78
+ suggestion: recommended.map(s => `uds update --apply --add-standard ${s.id}`).join('; ')
79
+ });
80
+ }
81
+ return findings;
70
82
  }
71
83
 
72
84
  /**
@@ -189,16 +189,34 @@ export function hookRunsUdsCheck(content) {
189
189
  * - Not installed: say what is missing and how to fix it, exit non-zero. It
190
190
  * neither skips the check nor downloads anything.
191
191
  *
192
- * @param {{args?: string, hookFile?: string}} [opts]
192
+ * @param {{args?: string, hookFile?: string, ci?: boolean}} [opts]
193
193
  * args — extra arguments to keep on the check command
194
194
  * (e.g. `--standard checkin-standards`, which older UDS versions wrote).
195
195
  * hookFile — the file the block is written into, named in the "blocked" message so
196
196
  * it points at the file the adopter actually has (default `.husky/pre-commit`;
197
197
  * the native hook passes `.git/hooks/pre-commit`).
198
+ * ci — call `check --ci` (default). A plain `uds check` prints "Some issues detected" and exits 0
199
+ * when a standard file was edited, so a hook that runs it never stops a commit for that
200
+ * (XSPEC-482 R3, found by the beta.12 macOS retest: tampered standard, `git commit` went
201
+ * through). `--ci` is the mode whose exit code says "issues". `ci: false` rebuilds the text
202
+ * UDS 6.14.0-beta.2 to beta.12 wrote, ONLY so that `uds update` can recognise it exactly
203
+ * (legacy-hook-migration.js); nothing writes that text any more.
198
204
  * @returns {string} the block, LF line endings, ending with a newline
199
205
  */
200
- export function buildPreCommitBlock({ args = '', hookFile = '.husky/pre-commit' } = {}) {
201
- const cmd = args ? `${UDS_BIN_NAME} check ${args}` : `${UDS_BIN_NAME} check`;
206
+ export function buildPreCommitBlock({ args = '', hookFile = '.husky/pre-commit', ci = true } = {}) {
207
+ const cmd = args ? `${UDS_BIN_NAME} check ${args}` : `${UDS_BIN_NAME} check${ci ? ' --ci' : ''}`;
208
+ // When the check fails the commit is stopped; say so (the lines above it name the files), otherwise the
209
+ // reader sees a list of warnings and no sign that git refused the commit because of them.
210
+ const afterCheck = (ci && !args)
211
+ ? [
212
+ ' status=$?',
213
+ ' if [ "$status" -ne 0 ]; then',
214
+ ' echo "[UDS] This commit is blocked: the UDS check found the issues listed above." >&2',
215
+ ' echo "[UDS] To put the standard files back, run the UDS CLI with: check --restore" >&2',
216
+ ' fi',
217
+ ' exit $status'
218
+ ]
219
+ : [' exit $?'];
202
220
  return [
203
221
  UDS_HOOK_MARKER,
204
222
  '# Runs the UDS CLI installed in this project (node_modules/.bin) or on PATH.',
@@ -208,7 +226,7 @@ export function buildPreCommitBlock({ args = '', hookFile = '.husky/pre-commit'
208
226
  ' PATH="$PWD/node_modules/.bin:$PATH"',
209
227
  ` if command -v ${UDS_BIN_NAME} >/dev/null 2>&1; then`,
210
228
  ` ${cmd}`,
211
- ' exit $?',
229
+ ...afterCheck,
212
230
  ' fi',
213
231
  ` echo "[UDS] Pre-commit check cannot run: the UDS CLI (${UDS_BIN_NAME}) is not installed." >&2`,
214
232
  ` echo "[UDS] Install it: npm install --save-dev ${UDS_BIN_NAME} (or: npm install -g ${UDS_BIN_NAME})" >&2`,
@@ -220,6 +238,90 @@ export function buildPreCommitBlock({ args = '', hookFile = '.husky/pre-commit'
220
238
  ].join('\n');
221
239
  }
222
240
 
241
+ /**
242
+ * The whole `.git/hooks/pre-commit` file `uds init` writes for a project that has no package.json.
243
+ *
244
+ * Fail-closed (XSPEC-444 R1 class sweep): a linter that is installed and fails blocks the commit; one that is
245
+ * not installed is skipped. The UDS check is the block above, whose exit status stops the commit.
246
+ *
247
+ * @param {{ci?: boolean}} [opts] `ci: false` rebuilds the beta.2 to beta.12 text, for exact recognition only (see buildPreCommitBlock)
248
+ * @returns {string}
249
+ */
250
+ export function buildNativePreCommitHook({ ci = true } = {}) {
251
+ return `#!/bin/sh
252
+ # UDS pre-commit hook
253
+ # Auto-generated by uds init
254
+
255
+ echo "Running UDS pre-commit checks..."
256
+
257
+ # Lint, when the language's linter is installed. A failing linter blocks the commit.
258
+ if [ -f pyproject.toml ] || [ -f requirements.txt ]; then
259
+ if python -m ruff --version >/dev/null 2>&1; then
260
+ python -m ruff check . || exit $?
261
+ fi
262
+ elif [ -f go.mod ]; then
263
+ if command -v go >/dev/null 2>&1; then
264
+ go vet ./... || exit $?
265
+ fi
266
+ elif [ -f Cargo.toml ]; then
267
+ if command -v cargo >/dev/null 2>&1; then
268
+ cargo clippy || exit $?
269
+ fi
270
+ fi
271
+
272
+ ${buildPreCommitBlock({ hookFile: '.git/hooks/pre-commit', ci })}
273
+ echo "Pre-commit checks passed"
274
+ `;
275
+ }
276
+
277
+ /**
278
+ * The `.git/hooks/pre-commit` that every UDS release from the 5.x line to 6.13.1 wrote (checked byte for byte
279
+ * against the file `universal-dev-standards@6.11.0` produces; the template did not change between those
280
+ * releases, `git log -S` on init.js). It runs `uds check 2>/dev/null || true`: the CLI that PATH happens to
281
+ * hold, errors thrown away, always "passed". Kept here as text so `uds update` and `uds uninstall` can tell
282
+ * "UDS wrote exactly this" from "someone edited it". Nothing writes it any more.
283
+ */
284
+ export const LEGACY_NATIVE_HOOK_6_11 = `#!/bin/sh
285
+ # UDS pre-commit hook
286
+ # Auto-generated by uds init
287
+
288
+ echo "Running UDS pre-commit checks..."
289
+
290
+ # Run lint if available
291
+ if [ -f pyproject.toml ] || [ -f requirements.txt ]; then
292
+ python -m ruff check . 2>/dev/null || true
293
+ elif [ -f go.mod ]; then
294
+ go vet ./... 2>/dev/null || true
295
+ elif [ -f Cargo.toml ]; then
296
+ cargo clippy 2>/dev/null || true
297
+ fi
298
+
299
+ # UDS Standard Check
300
+ uds check 2>/dev/null || true
301
+
302
+ echo "Pre-commit checks passed"
303
+ `;
304
+
305
+ /** Line endings made LF, so a hook file saved with CRLF still compares equal to the text above. */
306
+ const lf = (text) => String(text).replace(/\r\n/g, '\n');
307
+
308
+ /**
309
+ * Which hook text, if any, is `content` byte for byte (apart from line endings)?
310
+ * @returns {'legacy-6.11'|'without-ci'|'current'|null}
311
+ * legacy-6.11 — the always-pass hook of 5.x to 6.13.1;
312
+ * without-ci — the beta.2 to beta.12 hook, whose check cannot fail a commit;
313
+ * current — what this CLI writes;
314
+ * null — anything else: not provably UDS's.
315
+ */
316
+ export function classifyNativePreCommitHook(content) {
317
+ if (typeof content !== 'string') return null;
318
+ const text = lf(content);
319
+ if (text === LEGACY_NATIVE_HOOK_6_11) return 'legacy-6.11';
320
+ if (text === buildNativePreCommitHook({ ci: false })) return 'without-ci';
321
+ if (text === buildNativePreCommitHook()) return 'current';
322
+ return null;
323
+ }
324
+
223
325
  /**
224
326
  * Remove the block buildPreCommitBlock() writes — from the marker line through
225
327
  * the end-marker line, inclusive — and nothing else. A block whose end marker is
@@ -2472,11 +2472,17 @@ export function generateIndexDisclosure(format, language = 'en') {
2472
2472
  'follow its contents. Working from this block alone means working without the',
2473
2473
  'standards.'
2474
2474
  ]
2475
- : [
2476
- '**這個區塊是索引,不是標準本文。** 規則並未複製於此。',
2477
- '在依照下方任何一項行動之前,請打開 `.standards/` 底下對應的檔案並遵守其內容。',
2478
- '只憑這個區塊工作,等同於沒有採用標準。'
2479
- ];
2475
+ : language === 'zh-cn'
2476
+ ? [
2477
+ '**这个区块是索引,不是标准本文。** 规则并未复制于此。',
2478
+ '在依照下方任何一项行动之前,请打开 `.standards/` 底下对应的文件并遵守其内容。',
2479
+ '只凭这个区块工作,等同于没有采用标准。'
2480
+ ]
2481
+ : [
2482
+ '**這個區塊是索引,不是標準本文。** 規則並未複製於此。',
2483
+ '在依照下方任何一項行動之前,請打開 `.standards/` 底下對應的檔案並遵守其內容。',
2484
+ '只憑這個區塊工作,等同於沒有採用標準。'
2485
+ ];
2480
2486
 
2481
2487
  if (format === 'markdown') {
2482
2488
  return lines.map((l) => `> ${l}`).join('\n');
@@ -2486,6 +2492,22 @@ export function generateIndexDisclosure(format, language = 'en') {
2486
2492
  return lines.map((l) => l.replace(/\*\*/g, '').replace(/`/g, '')).join('\n');
2487
2493
  }
2488
2494
 
2495
+ /**
2496
+ * Pick the text for a content language: English, Traditional Chinese (also used for 'bilingual', whose second language
2497
+ * is Traditional unless the display language is Simplified), or Simplified Chinese for 'zh-cn'.
2498
+ * XSPEC-482 R13: these functions chose between English and Traditional only, so a Simplified Chinese project got
2499
+ * Traditional sentences in the block `uds init` wrote.
2500
+ * @param {string} language
2501
+ * @param {string} en
2502
+ * @param {string} zhTw
2503
+ * @param {string} zhCn
2504
+ * @returns {string}
2505
+ */
2506
+ function byLanguage(language, en, zhTw, zhCn) {
2507
+ if (language === 'en') return en;
2508
+ return language === 'zh-cn' ? zhCn : zhTw;
2509
+ }
2510
+
2489
2511
  /**
2490
2512
  * Generate minimal standards reference for minimal content mode
2491
2513
  * @param {string[]} installedStandards - List of installed standard file paths
@@ -2537,17 +2559,16 @@ export function generateMinimalStandardsReference(
2537
2559
  const sections = [];
2538
2560
 
2539
2561
  if (format === 'markdown') {
2540
- sections.push(language === 'en'
2541
- ? '## Standards Reference'
2542
- : '## 規範文件參考');
2562
+ sections.push(byLanguage(language, '## Standards Reference', '## 規範文件參考', '## 规范文档参考'));
2543
2563
  sections.push('');
2544
- sections.push(language === 'en'
2545
- ? '**IMPORTANT**: When performing related tasks, you MUST read and follow the standards in `.standards/`:'
2546
- : '**重要**:執行相關任務時,務必讀取並遵循 `.standards/` 目錄下的對應規範:');
2564
+ sections.push(byLanguage(language,
2565
+ '**IMPORTANT**: When performing related tasks, you MUST read and follow the standards in `.standards/`:',
2566
+ '**重要**:執行相關任務時,務必讀取並遵循 `.standards/` 目錄下的對應規範:',
2567
+ '**重要**:执行相关任务时,务必读取并遵循 `.standards/` 目录下的对应规范:'));
2547
2568
  sections.push('');
2548
2569
 
2549
2570
  if (coreStandards.length > 0) {
2550
- sections.push(language === 'en' ? '**Core Standards:**' : '**核心規範:**');
2571
+ sections.push(byLanguage(language, '**Core Standards:**', '**核心規範:**', '**核心规范:**'));
2551
2572
  for (const std of coreStandards) {
2552
2573
  sections.push(`- \`.standards/${std.filename}\``);
2553
2574
  }
@@ -2555,7 +2576,7 @@ export function generateMinimalStandardsReference(
2555
2576
  }
2556
2577
 
2557
2578
  if (optionStandards.length > 0) {
2558
- sections.push(language === 'en' ? '**Options:**' : '**選項:**');
2579
+ sections.push(byLanguage(language, '**Options:**', '**選項:**', '**选项:**'));
2559
2580
  for (const std of optionStandards) {
2560
2581
  sections.push(`- \`.standards/options/${std.filename}\``);
2561
2582
  }
@@ -2565,20 +2586,20 @@ export function generateMinimalStandardsReference(
2565
2586
  // Said out loud rather than dropped quietly. A shorter list and a complete
2566
2587
  // one read the same, and only the manifest knows which this is.
2567
2588
  if (unresolved.length > 0) {
2568
- sections.push(language === 'en'
2569
- ? `> ${unresolved.length} manifest entr${unresolved.length === 1 ? 'y' : 'ies'} could not be matched to an installed file and ${unresolved.length === 1 ? 'is' : 'are'} not listed above: ${unresolved.join(', ')}. Run \`uds update\` — if that does not clear it, the manifest and the registry disagree.`
2570
- : `> 有 ${unresolved.length} 筆 manifest 項目對不到已安裝的檔案,未列於上方:${unresolved.join('、')}。請執行 \`uds update\`;若仍未消失,代表 manifest 與 registry 不一致。`);
2589
+ sections.push(byLanguage(language,
2590
+ `> ${unresolved.length} manifest entr${unresolved.length === 1 ? 'y' : 'ies'} could not be matched to an installed file and ${unresolved.length === 1 ? 'is' : 'are'} not listed above: ${unresolved.join(', ')}. Run \`uds update\` — if that does not clear it, the manifest and the registry disagree.`,
2591
+ `> 有 ${unresolved.length} 筆 manifest 項目對不到已安裝的檔案,未列於上方:${unresolved.join('、')}。請執行 \`uds update\`;若仍未消失,代表 manifest 與 registry 不一致。`,
2592
+ `> 有 ${unresolved.length} 笔 manifest 项目对不到已安装的文件,未列于上方:${unresolved.join('、')}。请执行 \`uds update\`;若仍未消失,代表 manifest 与 registry 不一致。`));
2571
2593
  sections.push('');
2572
2594
  }
2573
2595
  } else {
2574
2596
  // Plaintext format
2575
- sections.push(language === 'en'
2576
- ? '## Standards Reference'
2577
- : '## 規範文件參考');
2597
+ sections.push(byLanguage(language, '## Standards Reference', '## 規範文件參考', '## 规范文档参考'));
2578
2598
  sections.push('');
2579
- sections.push(language === 'en'
2580
- ? 'IMPORTANT: When performing related tasks, read and follow the standards in .standards/:'
2581
- : '重要:執行相關任務時,務必讀取並遵循 .standards/ 目錄下的對應規範:');
2599
+ sections.push(byLanguage(language,
2600
+ 'IMPORTANT: When performing related tasks, read and follow the standards in .standards/:',
2601
+ '重要:執行相關任務時,務必讀取並遵循 .standards/ 目錄下的對應規範:',
2602
+ '重要:执行相关任务时,务必读取并遵循 .standards/ 目录下的对应规范:'));
2582
2603
  sections.push('');
2583
2604
 
2584
2605
  for (const std of coreStandards) {
@@ -2587,7 +2608,7 @@ export function generateMinimalStandardsReference(
2587
2608
 
2588
2609
  if (optionStandards.length > 0) {
2589
2610
  sections.push('');
2590
- sections.push(language === 'en' ? 'Options:' : '選項:');
2611
+ sections.push(byLanguage(language, 'Options:', '選項:', '选项:'));
2591
2612
  for (const std of optionStandards) {
2592
2613
  sections.push(`- .standards/options/${std.filename}`);
2593
2614
  }
@@ -2595,9 +2616,10 @@ export function generateMinimalStandardsReference(
2595
2616
 
2596
2617
  if (unresolved.length > 0) {
2597
2618
  sections.push('');
2598
- sections.push(language === 'en'
2599
- ? `NOTE: ${unresolved.length} manifest entries could not be matched to an installed file and are not listed: ${unresolved.join(', ')}`
2600
- : `注意:有 ${unresolved.length} 筆 manifest 項目對不到已安裝的檔案,未列出:${unresolved.join('、')}`);
2619
+ sections.push(byLanguage(language,
2620
+ `NOTE: ${unresolved.length} manifest entries could not be matched to an installed file and are not listed: ${unresolved.join(', ')}`,
2621
+ `注意:有 ${unresolved.length} 筆 manifest 項目對不到已安裝的檔案,未列出:${unresolved.join('、')}`,
2622
+ `注意:有 ${unresolved.length} 笔 manifest 项目对不到已安装的文件,未列出:${unresolved.join('、')}`));
2601
2623
  }
2602
2624
  sections.push('');
2603
2625
  }
@@ -3045,7 +3067,10 @@ export function generateIntegrationContent(config) {
3045
3067
 
3046
3068
  // Include commit message language directive inside markers so it updates with marker-based updates
3047
3069
  if (outputLanguage) {
3048
- const commitLangSection = generateOutputLanguageDirective(outputLanguage, language);
3070
+ // A Simplified Chinese project that chose bilingual commits gets the Simplified directive, as the commit-standards
3071
+ // section above already does; the Traditional one named "English + 繁體中文" for a project that asked for 简体中文 (XSPEC-482 R13).
3072
+ const directiveLanguage = (outputLanguage === 'bilingual' && language === 'zh-cn') ? 'bilingual-zhcn' : outputLanguage;
3073
+ const commitLangSection = generateOutputLanguageDirective(directiveLanguage, language);
3049
3074
  if (commitLangSection) {
3050
3075
  standardsContent += commitLangSection + '\n\n';
3051
3076
  }
@@ -3332,9 +3357,7 @@ export function generateComplianceInstructions(
3332
3357
  sections.push('');
3333
3358
 
3334
3359
  if (mustFollow.length > 0) {
3335
- sections.push(language === 'en'
3336
- ? '**MUST follow** (always required):'
3337
- : '**MUST follow** (每次都要遵守):');
3360
+ sections.push(byLanguage(language, '**MUST follow** (always required):', '**MUST follow** (每次都要遵守):', '**MUST follow** (每次都要遵守):'));
3338
3361
  sections.push('| Task | Standard | When |');
3339
3362
  sections.push('|------|----------|------|');
3340
3363
  for (const entry of mustFollow) {
@@ -3344,9 +3367,7 @@ export function generateComplianceInstructions(
3344
3367
  }
3345
3368
 
3346
3369
  if (shouldFollow.length > 0) {
3347
- sections.push(language === 'en'
3348
- ? '**SHOULD follow** (when relevant):'
3349
- : '**SHOULD follow** (相關任務時參考):');
3370
+ sections.push(byLanguage(language, '**SHOULD follow** (when relevant):', '**SHOULD follow** (相關任務時參考):', '**SHOULD follow** (相关任务时参考):'));
3350
3371
  sections.push('| Task | Standard | When |');
3351
3372
  sections.push('|------|----------|------|');
3352
3373
  for (const entry of shouldFollow) {
@@ -3363,9 +3384,7 @@ export function generateComplianceInstructions(
3363
3384
  sections.push('');
3364
3385
 
3365
3386
  if (mustFollow.length > 0) {
3366
- sections.push(language === 'en'
3367
- ? 'MUST follow (always required):'
3368
- : 'MUST follow (每次都要遵守):');
3387
+ sections.push(byLanguage(language, 'MUST follow (always required):', 'MUST follow (每次都要遵守):', 'MUST follow (每次都要遵守):'));
3369
3388
  for (const entry of mustFollow) {
3370
3389
  sections.push(`- ${entry.task}: Read ${entry.standard} ${entry.when.toLowerCase()}`);
3371
3390
  }
@@ -3373,9 +3392,7 @@ export function generateComplianceInstructions(
3373
3392
  }
3374
3393
 
3375
3394
  if (shouldFollow.length > 0) {
3376
- sections.push(language === 'en'
3377
- ? 'SHOULD follow (when relevant):'
3378
- : 'SHOULD follow (相關任務時參考):');
3395
+ sections.push(byLanguage(language, 'SHOULD follow (when relevant):', 'SHOULD follow (相關任務時參考):', 'SHOULD follow (相关任务时参考):'));
3379
3396
  for (const entry of shouldFollow) {
3380
3397
  sections.push(`- ${entry.task}: Reference ${entry.standard}`);
3381
3398
  }
@@ -3429,14 +3446,23 @@ export function generateStandardsIndex(installedStandards, format, language = 'z
3429
3446
  ? ['', `${unresolved.length} further manifest entr${unresolved.length === 1 ? 'y has' : 'ies have'} no installed file and ${unresolved.length === 1 ? 'is' : 'are'} not counted above: ${unresolved.join(', ')}. Standards removed upstream stay in a manifest until someone drops them; \`uds update\` does not prune them.`]
3430
3447
  : [])
3431
3448
  ]
3432
- : [
3433
- `本專案採用 UDS 標準共 **${total}** 條(core ${coreCount}、options ${optionCount}),安裝於 \`.standards/\`。`,
3434
- '',
3435
- '權威清單為 `.standards/manifest.json` 的 `standards` 欄位。要知道某標準要求什麼,讀它自己的檔案——並看第一行,已棄用的標準會在那裡寫明。',
3436
- ...(unresolved.length > 0
3437
- ? ['', `另有 ${unresolved.length} 筆 manifest 項目沒有已安裝的檔案,未計入上方數字:${unresolved.join('、')}。上游移除的標準會留在 manifest 裡直到有人拿掉它;\`uds update\` 不會修剪它們。`]
3438
- : [])
3439
- ];
3449
+ : language === 'zh-cn'
3450
+ ? [
3451
+ `本项目采用 UDS 标准共 **${total}** 条(core ${coreCount}、options ${optionCount}),安装于 \`.standards/\`。`,
3452
+ '',
3453
+ '权威清单为 `.standards/manifest.json` 的 `standards` 字段。要知道某标准要求什么,读它自己的文件——并看第一行,已弃用的标准会在那里写明。',
3454
+ ...(unresolved.length > 0
3455
+ ? ['', `另有 ${unresolved.length} 笔 manifest 项目没有已安装的文件,未计入上方数字:${unresolved.join('、')}。上游移除的标准会留在 manifest 里直到有人拿掉它;\`uds update\` 不会修剪它们。`]
3456
+ : [])
3457
+ ]
3458
+ : [
3459
+ `本專案採用 UDS 標準共 **${total}** 條(core ${coreCount}、options ${optionCount}),安裝於 \`.standards/\`。`,
3460
+ '',
3461
+ '權威清單為 `.standards/manifest.json` 的 `standards` 欄位。要知道某標準要求什麼,讀它自己的檔案——並看第一行,已棄用的標準會在那裡寫明。',
3462
+ ...(unresolved.length > 0
3463
+ ? ['', `另有 ${unresolved.length} 筆 manifest 項目沒有已安裝的檔案,未計入上方數字:${unresolved.join('、')}。上游移除的標準會留在 manifest 裡直到有人拿掉它;\`uds update\` 不會修剪它們。`]
3464
+ : [])
3465
+ ];
3440
3466
 
3441
3467
  const plainBody = body.map((l) => l.replace(/`/g, ''));
3442
3468
  return [heading, '', ...(md ? body : plainBody), ''].join('\n');
@@ -3492,7 +3518,7 @@ function withSelectedOptions(manifest) {
3492
3518
  * Both call sites now use this function instead of re-deriving the value.
3493
3519
  *
3494
3520
  * @param {Object} manifest - Project manifest
3495
- * @returns {'en'|'zh-tw'|'bilingual'} Resolved content language
3521
+ * @returns {'en'|'zh-tw'|'zh-cn'|'bilingual'} Resolved content language
3496
3522
  */
3497
3523
  export function resolveIntegrationLanguage(manifest) {
3498
3524
  const selected = manifest.options?.output_language || manifest.options?.commit_language || 'english';
@@ -3500,7 +3526,7 @@ export function resolveIntegrationLanguage(manifest) {
3500
3526
  const fromOutput = selected === 'bilingual'
3501
3527
  ? 'bilingual'
3502
3528
  : selected === 'traditional-chinese' ? 'zh-tw' : 'en';
3503
- return ['en', 'zh-tw', 'bilingual'].includes(display) ? display : fromOutput;
3529
+ return ['en', 'zh-tw', 'zh-cn', 'bilingual'].includes(display) ? display : fromOutput; // wire:integration-language-zh-cn
3504
3530
  }
3505
3531
 
3506
3532
  export function buildToolIntegrationConfig(manifest, tool) {
@@ -26,9 +26,12 @@
26
26
  * @module utils/legacy-hook-migration
27
27
  */
28
28
 
29
- import { existsSync, readFileSync, writeFileSync } from 'fs';
29
+ import { existsSync, readFileSync, writeFileSync, chmodSync } from 'fs';
30
30
  import { join } from 'path';
31
- import { buildPreCommitBlock, UDS_HOOK_MARKER, BARE_UDS_RUNNER_RE, hasBareUdsRunner } from './git-hooks.js';
31
+ import {
32
+ buildPreCommitBlock, buildNativePreCommitHook, classifyNativePreCommitHook,
33
+ UDS_HOOK_MARKER, UDS_HOOK_END_MARKER, BARE_UDS_RUNNER_RE, hasBareUdsRunner
34
+ } from './git-hooks.js';
32
35
  import { getFileRecord, proveUnchanged, recordFile, newRecorder, RECORD_KINDS } from '../core/install-records.js';
33
36
 
34
37
  /** The exact command lines UDS itself has written under the marker, and the extra arguments each carried. */
@@ -110,3 +113,119 @@ export function migrateLegacyHuskyHook(projectPath, { plan = false, manifest = n
110
113
  }
111
114
  return { state: 'migrated', replaced, kept, recorder };
112
115
  }
116
+
117
+ // ─────────────────────────────────────────────────────────────────────────────
118
+ // XSPEC-482 R3 + R5: pre-commit hooks that look like a check and cannot stop a commit.
119
+ //
120
+ // Two shapes are on disk in projects UDS set up earlier, and both let every commit through:
121
+ // - `.git/hooks/pre-commit` of 5.x .. 6.13.1: `uds check 2>/dev/null || true` (the CLI PATH happens to
122
+ // hold, errors thrown away, "Pre-commit checks passed" printed whatever happened);
123
+ // - the hook of 6.14.0-beta.2 .. beta.12 (native file, or the block inside `.husky/pre-commit`): it runs
124
+ // the installed CLI, but `check` without `--ci` exits 0 when a standard file was edited.
125
+ // `uds init` now writes `check --ci`. These functions bring the files already on disk to it.
126
+ //
127
+ // What counts as "UDS wrote this": the whole file equals one of the known texts (native hook), or the
128
+ // block between UDS's two marker lines equals the known block (husky). Exact equality, not a pattern: a
129
+ // hook someone edited is NOT replaced - it is reported with the line number and what to write instead.
130
+ // ─────────────────────────────────────────────────────────────────────────────
131
+
132
+
133
+ /** A hook line that runs a UDS check and is built never to fail: `... check ... || true`. */
134
+ const ALWAYS_PASS_CHECK_RE = /\b(?:uds|universal-dev-standards)\s+check\b[^\n]*\|\|\s*true\b/;
135
+
136
+ /**
137
+ * Bring the native `.git/hooks/pre-commit` of an older UDS to the one this CLI writes.
138
+ *
139
+ * @param {string} projectPath
140
+ * @param {{plan?: boolean}} [opts] plan - report what would change, write nothing
141
+ * @returns {{
142
+ * file: '.git/hooks/pre-commit',
143
+ * state: 'none'|'migrated'|'would-migrate'|'kept'|'error',
144
+ * from?: 'legacy-6.11'|'without-ci',
145
+ * kept: Array<{line: number, text: string}>, // lines that make the check always pass, in a file UDS cannot prove it wrote
146
+ * recorder: object|null, // install record to fold into the manifest when non-null
147
+ * error?: string
148
+ * }}
149
+ */
150
+ export function migrateOlderNativeHook(projectPath, { plan = false } = {}) {
151
+ const file = '.git/hooks/pre-commit';
152
+ const abs = join(projectPath, '.git', 'hooks', 'pre-commit');
153
+ const none = { file, state: 'none', kept: [], recorder: null };
154
+ if (!existsSync(abs)) return none;
155
+
156
+ let content;
157
+ try {
158
+ content = readFileSync(abs, 'utf-8');
159
+ } catch (e) {
160
+ return { ...none, state: 'error', error: e.message };
161
+ }
162
+
163
+ const known = classifyNativePreCommitHook(content);
164
+ if (known === 'legacy-6.11' || known === 'without-ci') {
165
+ if (plan) return { ...none, state: 'would-migrate', from: known };
166
+ try {
167
+ // Keep the file's own line endings: a hook saved with CRLF stays CRLF (the husky path below does the same).
168
+ const fresh = buildNativePreCommitHook();
169
+ writeFileSync(abs, content.includes('\r\n') ? fresh.replace(/\n/g, '\r\n') : fresh, 'utf-8'); // wire:native-migration-keeps-eol
170
+ // writeFileSync keeps an existing file's mode; make sure git will still run it.
171
+ if (process.platform !== 'win32') chmodSync(abs, 0o755);
172
+ } catch (e) {
173
+ return { ...none, state: 'error', from: known, error: e.message };
174
+ }
175
+ // The whole file is UDS's again: record it, so `uds uninstall` can delete it as provably ours.
176
+ const recorder = newRecorder();
177
+ recordFile(recorder, projectPath, file, RECORD_KINDS.GIT_HOOK);
178
+ return { ...none, state: 'migrated', from: known, recorder };
179
+ }
180
+ if (known === 'current') return none;
181
+
182
+ // Not a text UDS wrote: if it still carries the always-pass check, say where. It is not replaced.
183
+ const kept = [];
184
+ content.split('\n').forEach((raw, i) => {
185
+ const text = raw.replace(/\r$/, '');
186
+ if (ALWAYS_PASS_CHECK_RE.test(text)) kept.push({ line: i + 1, text: text.trim() });
187
+ });
188
+ return kept.length > 0 ? { ...none, state: 'kept', kept } : none;
189
+ }
190
+
191
+ /**
192
+ * Bring the block `.husky/pre-commit` carries from beta.2 .. beta.12 (`check` without `--ci`) to the current one.
193
+ * Only the block between UDS's two marker lines, and only when it is exactly the old text; the lines around it
194
+ * are the adopter's and stay as they are.
195
+ *
196
+ * @param {string} projectPath
197
+ * @param {{plan?: boolean, manifest?: object|null}} [opts] manifest - read only to see whether the whole file was provably UDS's
198
+ * @returns {{file: '.husky/pre-commit', state: 'none'|'migrated'|'would-migrate'|'error', recorder: object|null, error?: string}}
199
+ */
200
+ export function migrateHuskyBlockWithoutCi(projectPath, { plan = false, manifest = null } = {}) {
201
+ const file = '.husky/pre-commit';
202
+ const abs = join(projectPath, '.husky', 'pre-commit');
203
+ const none = { file, state: 'none', recorder: null };
204
+ if (!existsSync(abs)) return none;
205
+
206
+ let content;
207
+ try {
208
+ content = readFileSync(abs, 'utf-8');
209
+ } catch (e) {
210
+ return { ...none, state: 'error', error: e.message };
211
+ }
212
+ const eol = content.includes('\r\n') ? '\r\n' : '\n';
213
+ const text = content.replace(/\r\n/g, '\n');
214
+ const oldBlock = buildPreCommitBlock({ ci: false });
215
+ if (!text.includes(oldBlock) || !text.includes(UDS_HOOK_END_MARKER)) return none;
216
+ if (plan) return { ...none, state: 'would-migrate' };
217
+
218
+ const wasProven = !!manifest && !!getFileRecord(manifest, file) && proveUnchanged(manifest, projectPath, file).state === 'proven';
219
+ try {
220
+ const next = text.replace(oldBlock, buildPreCommitBlock());
221
+ writeFileSync(abs, eol === '\r\n' ? next.replace(/\n/g, '\r\n') : next, 'utf-8');
222
+ } catch (e) {
223
+ return { ...none, state: 'error', error: e.message };
224
+ }
225
+ let recorder = null;
226
+ if (wasProven) {
227
+ recorder = newRecorder();
228
+ recordFile(recorder, projectPath, file, RECORD_KINDS.GIT_HOOK);
229
+ }
230
+ return { ...none, state: 'migrated', recorder };
231
+ }