universal-dev-standards 6.14.0-beta.5 → 6.14.0-beta.6
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/bin/uds.js +2 -1
- package/bundled/ai/standards/commit-message.ai.yaml +6 -2
- package/bundled/locales/zh-CN/CHANGELOG.md +27 -3
- package/bundled/locales/zh-CN/README.md +1 -1
- package/bundled/locales/zh-CN/SECURITY.md +1 -1
- package/bundled/locales/zh-CN/docs/CHEATSHEET.md +2 -2
- package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +3 -2
- package/bundled/locales/zh-TW/CHANGELOG.md +27 -3
- package/bundled/locales/zh-TW/README.md +1 -1
- package/bundled/locales/zh-TW/SECURITY.md +1 -1
- package/bundled/locales/zh-TW/docs/CHEATSHEET.md +2 -2
- package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +3 -2
- package/package.json +1 -1
- package/src/commands/deps.js +31 -1
- package/src/commands/simulate.js +20 -8
- package/src/commands/skills.js +42 -2
- package/src/commands/spec.js +14 -8
- package/src/commands/update.js +45 -5
- package/src/core/manifest.js +12 -10
- package/src/core/marketplace-sentinel.js +5 -0
- package/src/core/project-config.js +58 -38
- package/src/i18n/messages.js +27 -0
- package/src/reconciler/backup-locations.js +75 -0
- package/src/reconciler/backup-manager.js +29 -45
- package/src/reconciler/index.js +20 -3
- package/src/utils/commit-message-judge.js +137 -0
- package/src/utils/deps-applicability.js +25 -0
- package/src/utils/installed-names-ownership.js +114 -0
- package/src/utils/sdd-header.js +65 -0
- package/src/utils/standard-validator.js +98 -27
- package/src/vibe/micro-spec.js +15 -0
- package/standards-registry.json +7 -7
package/src/core/manifest.js
CHANGED
|
@@ -851,11 +851,10 @@ export function areCommandsInstalled(manifest) {
|
|
|
851
851
|
return manifest.commands?.installed || false;
|
|
852
852
|
}
|
|
853
853
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
export const MARKETPLACE_NAMES_SENTINEL = 'all-via-plugin';
|
|
854
|
+
// Placeholder stored in `skills.names` when skills come from the Claude Code plugin marketplace.
|
|
855
|
+
// It lives in its own module so the name-ownership code can read it without loading this whole module.
|
|
856
|
+
export { MARKETPLACE_NAMES_SENTINEL } from './marketplace-sentinel.js';
|
|
857
|
+
import { MARKETPLACE_NAMES_SENTINEL } from './marketplace-sentinel.js';
|
|
859
858
|
|
|
860
859
|
/**
|
|
861
860
|
* Merge the names actually installed by a run into a manifest name list.
|
|
@@ -872,11 +871,14 @@ export const MARKETPLACE_NAMES_SENTINEL = 'all-via-plugin';
|
|
|
872
871
|
* update.js and config.js, and a private copy per module is how the writers drift
|
|
873
872
|
* apart again.
|
|
874
873
|
*
|
|
875
|
-
*
|
|
876
|
-
* (
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
*
|
|
874
|
+
* This function only ever adds; removing is a separate step done right after it
|
|
875
|
+
* (XSPEC-456 R4, `utils/installed-names-ownership.js`). The earlier version of this
|
|
876
|
+
* comment said pruning was unnecessary because "over-reporting is harmless" - it is
|
|
877
|
+
* not: after an update removed the five non-skill directories an old deny-list bug
|
|
878
|
+
* had misfiled as skills (`_shared`, `agents`, `ai`, `tools`, `workflows`), the
|
|
879
|
+
* manifest still named them as installed skills, next to a `skillHashes` that had
|
|
880
|
+
* been cleaned. A name that UDS does not ship, or that is not on disk where it was
|
|
881
|
+
* installed, is dropped by `uds update`.
|
|
880
882
|
*
|
|
881
883
|
* @param {string[]} existing - Current manifest list
|
|
882
884
|
* @param {Object} installResult - Result from installSkills/CommandsToMultipleAgents
|
|
@@ -4,13 +4,23 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { existsSync, readFileSync } from 'fs';
|
|
6
6
|
import { join } from 'path';
|
|
7
|
+
import * as yaml from 'js-yaml';
|
|
7
8
|
|
|
8
9
|
const CONFIG_FILENAME = 'uds.project.yaml';
|
|
9
10
|
|
|
11
|
+
/** Sections whose entries are `intent: command` pairs. */
|
|
12
|
+
const COMMAND_SECTIONS = ['commands', 'custom'];
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Parse uds.project.yaml from the given project path.
|
|
12
16
|
* Returns null if the file does not exist.
|
|
13
17
|
* Throws if the file exists but is invalid.
|
|
18
|
+
*
|
|
19
|
+
* XSPEC-456 R1: the file is read as YAML. It used to go through a hand-written line parser that
|
|
20
|
+
* kept everything after the first colon as the value, so a trailing comment
|
|
21
|
+
* (`test: dotnet test X.csproj # 90 tests pass`) became part of the command. A POSIX shell hides
|
|
22
|
+
* that (an unquoted `#` starts a comment), `cmd.exe` does not - the comment reached MSBuild as
|
|
23
|
+
* arguments. Reading the value the way YAML defines it removes the comment before anything is run.
|
|
14
24
|
*/
|
|
15
25
|
export function loadProjectConfig(projectPath = '.') {
|
|
16
26
|
const configPath = join(projectPath, CONFIG_FILENAME);
|
|
@@ -18,55 +28,64 @@ export function loadProjectConfig(projectPath = '.') {
|
|
|
18
28
|
|
|
19
29
|
const raw = readFileSync(configPath, 'utf8');
|
|
20
30
|
|
|
21
|
-
|
|
22
|
-
// We deliberately avoid a heavy dependency — uds.project.yaml is intentionally simple.
|
|
23
|
-
const config = parseMinimalYaml(raw, configPath);
|
|
31
|
+
const config = parseProjectYaml(raw, configPath);
|
|
24
32
|
validateConfig(config, configPath);
|
|
25
33
|
return config;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
/**
|
|
29
|
-
* Parse a
|
|
30
|
-
*
|
|
37
|
+
* Parse the file with a real YAML parser and normalise it to the shape callers use:
|
|
38
|
+
* top-level scalars and the `commands` / `custom` sections are strings.
|
|
31
39
|
*/
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
function parseProjectYaml(raw, filePath) {
|
|
41
|
+
let doc;
|
|
42
|
+
try {
|
|
43
|
+
doc = yaml.load(raw);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
const line = err?.mark ? ` (line ${err.mark.line + 1})` : '';
|
|
46
|
+
const reason = err?.reason || err?.message || String(err);
|
|
47
|
+
// A double-quoted YAML value reads backslashes as escapes. Windows paths written that way
|
|
48
|
+
// used to work (the old parser kept them verbatim), so say what to do instead of only failing.
|
|
49
|
+
const hint = /escape|hexadecimal/i.test(reason)
|
|
50
|
+
? ' Inside double quotes a backslash starts an escape sequence; write Windows paths in single quotes or without quotes.'
|
|
51
|
+
: '';
|
|
52
|
+
throw new Error(`${filePath}: not valid YAML${line}: ${reason}.${hint}`);
|
|
53
|
+
}
|
|
54
|
+
if (doc === null || doc === undefined) return {};
|
|
55
|
+
if (typeof doc !== 'object' || Array.isArray(doc)) {
|
|
56
|
+
throw new Error(`${filePath}: the file must be a mapping of keys to values.`);
|
|
57
|
+
}
|
|
45
58
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} else {
|
|
55
|
-
result[key] = {};
|
|
56
|
-
currentSection = key;
|
|
57
|
-
}
|
|
58
|
-
} else if (currentSection && indent > 0) {
|
|
59
|
-
// Nested key under current section
|
|
60
|
-
const match = trimmed.trim().match(/^([a-zA-Z_][a-zA-Z0-9_-]*):\s*(.*)$/);
|
|
61
|
-
if (!match) continue;
|
|
62
|
-
const [, key, value] = match;
|
|
63
|
-
result[currentSection][key] = value.trim().replace(/^["']|["']$/g, '');
|
|
59
|
+
const result = {};
|
|
60
|
+
for (const [key, value] of Object.entries(doc)) {
|
|
61
|
+
if (COMMAND_SECTIONS.includes(key)) {
|
|
62
|
+
result[key] = normaliseCommandSection(key, value, filePath);
|
|
63
|
+
} else if (value !== null && typeof value === 'object') {
|
|
64
|
+
result[key] = value;
|
|
65
|
+
} else if (value !== null && value !== undefined) {
|
|
66
|
+
result[key] = String(value);
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
|
-
|
|
67
69
|
return result;
|
|
68
70
|
}
|
|
69
71
|
|
|
72
|
+
function normaliseCommandSection(name, value, filePath) {
|
|
73
|
+
if (value === null || value === undefined) return {};
|
|
74
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
75
|
+
throw new Error(`${filePath}: "${name}" must be a mapping of intent: command pairs.`);
|
|
76
|
+
}
|
|
77
|
+
const out = {};
|
|
78
|
+
for (const [intent, command] of Object.entries(value)) {
|
|
79
|
+
if (command === null || command === undefined) continue;
|
|
80
|
+
if (typeof command === 'object') {
|
|
81
|
+
throw new Error(`${filePath}: "${name}.${intent}" must be a single command string, not a list or mapping.`);
|
|
82
|
+
}
|
|
83
|
+
const text = String(command).trim();
|
|
84
|
+
if (text) out[intent] = text;
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
70
89
|
function validateConfig(config, filePath) {
|
|
71
90
|
if (!config.version) {
|
|
72
91
|
throw new Error(
|
|
@@ -85,7 +104,8 @@ function validateConfig(config, filePath) {
|
|
|
85
104
|
*/
|
|
86
105
|
export function getCommand(config, intent) {
|
|
87
106
|
if (!config) return undefined;
|
|
88
|
-
|
|
107
|
+
const own = (section) => (section && Object.prototype.hasOwnProperty.call(section, intent) ? section[intent] : undefined);
|
|
108
|
+
return own(config.commands) ?? own(config.custom);
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
export { CONFIG_FILENAME };
|
package/src/i18n/messages.js
CHANGED
|
@@ -65,6 +65,7 @@ export const messages = {
|
|
|
65
65
|
error: 'Failed to generate spec',
|
|
66
66
|
listTitle: 'Micro-Specs',
|
|
67
67
|
noSpecs: 'No micro-specs found.',
|
|
68
|
+
statusUnparsed: 'format: SDD (status not parsed)',
|
|
68
69
|
createHint: 'Create one with: uds spec create "your intent"',
|
|
69
70
|
total: 'Total',
|
|
70
71
|
noId: 'Error: Please provide a spec ID.',
|
|
@@ -709,6 +710,12 @@ export const messages = {
|
|
|
709
710
|
seeGuide: 'See: https://github.com/AsiaOstrich/universal-dev-standards/blob/main/adoption/ADOPTION-GUIDE.md'
|
|
710
711
|
},
|
|
711
712
|
|
|
713
|
+
// deps command (XSPEC-456 R6)
|
|
714
|
+
deps: {
|
|
715
|
+
notApplicableNoPackageJson: 'Not applicable: there is no package.json, so nothing was checked',
|
|
716
|
+
notApplicableNoRuntimeDeps: 'Not applicable: this package declares no runtime dependencies, so nothing was checked'
|
|
717
|
+
},
|
|
718
|
+
|
|
712
719
|
// skills command
|
|
713
720
|
skills: {
|
|
714
721
|
title: 'Universal Dev Standards - Installed Skills',
|
|
@@ -721,6 +728,7 @@ export const messages = {
|
|
|
721
728
|
manualInstallDeprecated: '⚠ Manual installation is deprecated.',
|
|
722
729
|
manualInstallHint: 'Consider migrating to Plugin Marketplace.',
|
|
723
730
|
totalUniqueSkills: 'Total unique skills',
|
|
731
|
+
skillFilesTracked: '`uds check` tracks {files} skill files for these skills (it counts files across every tool, not skills).',
|
|
724
732
|
recommendation: 'Recommendation: Migrate to Plugin Marketplace',
|
|
725
733
|
benefits: 'Benefits: Automatic updates, better integration',
|
|
726
734
|
migrateCommand: 'To migrate, run:'
|
|
@@ -1071,6 +1079,7 @@ export const messages = {
|
|
|
1071
1079
|
droppedRetiredHashes: 'Dropped {count} manifest record(s) for files UDS no longer ships and that are already gone:',
|
|
1072
1080
|
droppedForeignSkillHashes: 'Dropped {count} skill record(s) that do not describe files UDS installed.',
|
|
1073
1081
|
droppedForeignCommandHashes: 'Dropped {count} command record(s) for commands UDS does not ship.',
|
|
1082
|
+
droppedForeignNames: 'Dropped {count} skill/command name(s) from the manifest that UDS does not ship or that are not installed.',
|
|
1074
1083
|
// Success
|
|
1075
1084
|
updateSuccess: '✓ Standards updated successfully!',
|
|
1076
1085
|
versionUpdated: 'Version: {current} → {latest}',
|
|
@@ -1352,6 +1361,7 @@ export const messages = {
|
|
|
1352
1361
|
error: '生成規格失敗',
|
|
1353
1362
|
listTitle: '微規格列表',
|
|
1354
1363
|
noSpecs: '沒有找到微規格。',
|
|
1364
|
+
statusUnparsed: '格式:SDD(狀態未解析)',
|
|
1355
1365
|
createHint: '使用以下命令建立:uds spec create "您的意圖"',
|
|
1356
1366
|
total: '總計',
|
|
1357
1367
|
noId: '錯誤:請提供規格 ID。',
|
|
@@ -1996,6 +2006,12 @@ export const messages = {
|
|
|
1996
2006
|
seeGuide: '參閱:https://github.com/AsiaOstrich/universal-dev-standards/blob/main/adoption/ADOPTION-GUIDE.md'
|
|
1997
2007
|
},
|
|
1998
2008
|
|
|
2009
|
+
// deps command (XSPEC-456 R6)
|
|
2010
|
+
deps: {
|
|
2011
|
+
notApplicableNoPackageJson: '不適用:沒有 package.json,未檢查任何東西',
|
|
2012
|
+
notApplicableNoRuntimeDeps: '不適用:這個套件沒有宣告執行期相依,未檢查任何東西'
|
|
2013
|
+
},
|
|
2014
|
+
|
|
1999
2015
|
// skills command
|
|
2000
2016
|
skills: {
|
|
2001
2017
|
title: '通用開發標準 - 已安裝的 Skills',
|
|
@@ -2008,6 +2024,7 @@ export const messages = {
|
|
|
2008
2024
|
manualInstallDeprecated: '⚠ 手動安裝已棄用。',
|
|
2009
2025
|
manualInstallHint: '建議遷移到 Plugin Marketplace。',
|
|
2010
2026
|
totalUniqueSkills: '唯一 Skills 總數',
|
|
2027
|
+
skillFilesTracked: '`uds check` 追蹤這些技能的 {files} 個技能檔案(它計的是所有工具的檔案數,不是技能數)。',
|
|
2011
2028
|
recommendation: '建議:遷移到 Plugin Marketplace',
|
|
2012
2029
|
benefits: '好處:自動更新、更好的整合',
|
|
2013
2030
|
migrateCommand: '遷移指令:'
|
|
@@ -2353,6 +2370,7 @@ export const messages = {
|
|
|
2353
2370
|
droppedRetiredHashes: '已清掉 {count} 筆 manifest 紀錄——這些檔案 UDS 已不再出貨,而且本來就已經不在了:',
|
|
2354
2371
|
droppedForeignSkillHashes: '已清掉 {count} 筆技能紀錄——它們描述的不是 UDS 安裝的檔案。',
|
|
2355
2372
|
droppedForeignCommandHashes: '已清掉 {count} 筆命令紀錄——UDS 不出貨這些命令。',
|
|
2373
|
+
droppedForeignNames: '已從 manifest 清掉 {count} 個技能/命令名稱——UDS 不出貨,或並未安裝。',
|
|
2356
2374
|
// Success
|
|
2357
2375
|
updateSuccess: '✓ 標準更新成功!',
|
|
2358
2376
|
versionUpdated: '版本:{current} → {latest}',
|
|
@@ -2632,6 +2650,7 @@ export const messages = {
|
|
|
2632
2650
|
error: '生成规格失败',
|
|
2633
2651
|
listTitle: '微规格列表',
|
|
2634
2652
|
noSpecs: '没有找到微规格。',
|
|
2653
|
+
statusUnparsed: '格式:SDD(状态未解析)',
|
|
2635
2654
|
createHint: '使用以下命令创建:uds spec create "您的意图"',
|
|
2636
2655
|
total: '总计',
|
|
2637
2656
|
noId: '错误:请提供规格 ID。',
|
|
@@ -3292,6 +3311,12 @@ export const messages = {
|
|
|
3292
3311
|
runCheck: '执行 `uds check` 验证采用状态'
|
|
3293
3312
|
},
|
|
3294
3313
|
|
|
3314
|
+
// deps command (XSPEC-456 R6)
|
|
3315
|
+
deps: {
|
|
3316
|
+
notApplicableNoPackageJson: '不适用:没有 package.json,未检查任何东西',
|
|
3317
|
+
notApplicableNoRuntimeDeps: '不适用:这个包没有声明运行时依赖,未检查任何东西'
|
|
3318
|
+
},
|
|
3319
|
+
|
|
3295
3320
|
// skills command
|
|
3296
3321
|
skills: {
|
|
3297
3322
|
title: '通用开发标准 - 已安装的 Skills',
|
|
@@ -3304,6 +3329,7 @@ export const messages = {
|
|
|
3304
3329
|
manualInstallDeprecated: '⚠ 手动安装已弃用。',
|
|
3305
3330
|
manualInstallHint: '建议迁移到 Plugin Marketplace。',
|
|
3306
3331
|
totalUniqueSkills: '唯一 Skills 总数',
|
|
3332
|
+
skillFilesTracked: '`uds check` 跟踪这些技能的 {files} 个技能文件(它计的是所有工具的文件数,不是技能数)。',
|
|
3307
3333
|
recommendation: '建议:迁移到 Plugin Marketplace',
|
|
3308
3334
|
benefits: '好处:自动更新、更好的集成',
|
|
3309
3335
|
migrateCommand: '迁移指令:'
|
|
@@ -3557,6 +3583,7 @@ export const messages = {
|
|
|
3557
3583
|
droppedRetiredHashes: '已清掉 {count} 笔 manifest 记录——这些文件 UDS 已不再发布,而且本来就已经不在了:',
|
|
3558
3584
|
droppedForeignSkillHashes: '已清掉 {count} 条技能记录——它们描述的不是 UDS 安装的文件。',
|
|
3559
3585
|
droppedForeignCommandHashes: '已清掉 {count} 条命令记录——UDS 不发布这些命令。',
|
|
3586
|
+
droppedForeignNames: '已从 manifest 清掉 {count} 个技能/命令名称——UDS 不发布,或并未安装。',
|
|
3560
3587
|
// Success
|
|
3561
3588
|
updateSuccess: '✓ 标准更新成功!',
|
|
3562
3589
|
versionUpdated: '版本:{current} → {latest}',
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where UDS update backups live (XSPEC-456 R7).
|
|
3
|
+
*
|
|
4
|
+
* New backups all go into ONE folder, `.uds-backups/`, one subfolder per backup. Backups made before
|
|
5
|
+
* XSPEC-456 R7 are single folders named `.uds-backup-<time>-<NNNN>` directly in the project root; they are
|
|
6
|
+
* not moved and are still backups. A `backupId` is the backup folder's path relative to the project root
|
|
7
|
+
* (`.uds-backups/<time>-<NNNN>` or `.uds-backup-<time>-<NNNN>`), so everything that joins it onto the project
|
|
8
|
+
* root works for both.
|
|
9
|
+
*
|
|
10
|
+
* @module reconciler/backup-locations
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'fs';
|
|
14
|
+
import { join } from 'path';
|
|
15
|
+
|
|
16
|
+
/** The one folder new backups go into. */
|
|
17
|
+
export const BACKUPS_DIR = '.uds-backups';
|
|
18
|
+
/** Backups made before XSPEC-456 R7: one folder each, directly in the project root. */
|
|
19
|
+
export const LEGACY_BACKUP_PREFIX = '.uds-backup-';
|
|
20
|
+
|
|
21
|
+
let counter = 0;
|
|
22
|
+
|
|
23
|
+
/** A fresh backup id, relative to the project root. The counter orders two backups made in the same millisecond. */
|
|
24
|
+
export function newBackupId() {
|
|
25
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
26
|
+
return `${BACKUPS_DIR}/${timestamp}-${String(++counter).padStart(4, '0')}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Make sure `.uds-backups/` exists and hides itself from git.
|
|
31
|
+
*
|
|
32
|
+
* WHY THIS IS NOT A LINE IN THE ADOPTER'S .gitignore. We create this directory in someone else's repository;
|
|
33
|
+
* making it disappear is our job, but editing their .gitignore to do it is not - that file is theirs, it may
|
|
34
|
+
* be generated, and a tool appending to it on every update is a worse trade than the problem. A `*` inside
|
|
35
|
+
* the folder ignores everything in it (this file included, which is fine: git reads .gitignore whether or
|
|
36
|
+
* not it is tracked), so `git status` and `git add -A` never see a backup, and nothing outside is touched.
|
|
37
|
+
*
|
|
38
|
+
* WHY IT EXISTS. Nothing ignored the backup folders, so `git add -A` in two sibling repos committed them:
|
|
39
|
+
* EngramGraph's 0.8.0 release commit took in 5 backups - 360 files, 73,992 lines - and dev-platform took one.
|
|
40
|
+
* Both were public. (Until XSPEC-456 R7 each backup carried its own copy of this file.)
|
|
41
|
+
*
|
|
42
|
+
* Git is not the only thing that reads a project folder: indexers, IDE search and grep do not look at
|
|
43
|
+
* .gitignore, which is why the backups share ONE folder name that is easy to exclude (the update summary
|
|
44
|
+
* says so).
|
|
45
|
+
*
|
|
46
|
+
* @param {string} projectPath
|
|
47
|
+
* @param {string[]} errors - Receives an error message when it did not work
|
|
48
|
+
*/
|
|
49
|
+
export function ensureBackupsDir(projectPath, errors) {
|
|
50
|
+
const dir = join(projectPath, BACKUPS_DIR);
|
|
51
|
+
try {
|
|
52
|
+
mkdirSync(dir, { recursive: true });
|
|
53
|
+
const ignoreFile = join(dir, '.gitignore');
|
|
54
|
+
if (!existsSync(ignoreFile)) writeFileSync(ignoreFile, '*\n', 'utf8');
|
|
55
|
+
} catch (err) {
|
|
56
|
+
// A backup that git can see still beats no backup - the caller records this and carries on.
|
|
57
|
+
errors.push(`Failed to write ${BACKUPS_DIR}/.gitignore: ${err.message}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Ids of the backups in the shared folder. */
|
|
62
|
+
export function sharedBackupIds(projectPath) {
|
|
63
|
+
const dir = join(projectPath, BACKUPS_DIR);
|
|
64
|
+
if (!existsSync(dir)) return [];
|
|
65
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
66
|
+
.filter((entry) => entry.isDirectory())
|
|
67
|
+
.map((entry) => `${BACKUPS_DIR}/${entry.name}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Add the ids of the backups an older UDS left in the project root to `into`. */
|
|
71
|
+
export function addLegacyBackupIds(projectPath, into) {
|
|
72
|
+
for (const entry of readdirSync(projectPath, { withFileTypes: true })) {
|
|
73
|
+
if (entry.isDirectory() && entry.name.startsWith(LEGACY_BACKUP_PREFIX)) into.push(entry.name);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
* Backup Manager
|
|
3
3
|
* Creates backups before reconciliation, enables rollback, and auto-cleans old backups.
|
|
4
4
|
*
|
|
5
|
-
* Backup structure:
|
|
6
|
-
* .uds-
|
|
7
|
-
* ├──
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* Backup structure (XSPEC-456 R7: all backups live under ONE folder in the project root):
|
|
6
|
+
* .uds-backups/
|
|
7
|
+
* ├── .gitignore # `*` - git never sees any backup
|
|
8
|
+
* └── <ISO timestamp>-<NNNN>/ # one backup
|
|
9
|
+
* ├── backup-manifest.json # Backup metadata + rollback instructions
|
|
10
|
+
* ├── .standards/ # Backed up standard files (and manifest.json)
|
|
11
|
+
* ├── CLAUDE.md # Backed up integration files
|
|
12
|
+
* └── .claude/skills/... # Backed up skill files
|
|
13
|
+
*
|
|
14
|
+
* Before 6.14.0 (this change) every backup was its own folder in the project root, `.uds-backup-<ISO timestamp>/`.
|
|
15
|
+
* Those are NOT moved, and they are still backups: `backupId` is the backup folder's path relative to the
|
|
16
|
+
* project root (`.uds-backups/<time>-<NNNN>` or `.uds-backup-<time>-<NNNN>`), so every place that builds a
|
|
17
|
+
* path from it works for both layouts, and listing, chaining, rollback and "keep the 5 most recent" look at
|
|
18
|
+
* both places and order them together by time.
|
|
11
19
|
*
|
|
12
20
|
* Only the paths a step will touch are backed up (minimal footprint). Keeps the 5 most recent
|
|
13
21
|
* backups; auto-cleans older ones.
|
|
@@ -39,12 +47,11 @@ import {
|
|
|
39
47
|
} from 'fs';
|
|
40
48
|
import { createHash } from 'crypto';
|
|
41
49
|
import { join, dirname, isAbsolute, sep } from 'path';
|
|
50
|
+
import { newBackupId, ensureBackupsDir, sharedBackupIds, addLegacyBackupIds } from './backup-locations.js';
|
|
42
51
|
|
|
43
52
|
const MAX_BACKUPS = 5;
|
|
44
|
-
const BACKUP_PREFIX = '.uds-backup-';
|
|
45
53
|
const MANIFEST_REL = '.standards/manifest.json';
|
|
46
54
|
const FORMAT_VERSION = 2;
|
|
47
|
-
let _backupCounter = 0;
|
|
48
55
|
|
|
49
56
|
const toPosix = (p) => p.split(sep).join('/');
|
|
50
57
|
|
|
@@ -127,12 +134,6 @@ function ancestorsOf(rel) {
|
|
|
127
134
|
return out;
|
|
128
135
|
}
|
|
129
136
|
|
|
130
|
-
function newBackupId() {
|
|
131
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
132
|
-
const counter = String(++_backupCounter).padStart(4, '0');
|
|
133
|
-
return `${BACKUP_PREFIX}${timestamp}-${counter}`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
137
|
/**
|
|
137
138
|
* Snapshot `paths` into a new backup directory.
|
|
138
139
|
*
|
|
@@ -150,34 +151,14 @@ function snapshot(projectPath, spec) {
|
|
|
150
151
|
const backedUp = [];
|
|
151
152
|
const errors = [];
|
|
152
153
|
|
|
154
|
+
// The shared folder first (with its .gitignore), then this backup inside it.
|
|
155
|
+
ensureBackupsDir(projectPath, errors);
|
|
153
156
|
try {
|
|
154
157
|
mkdirSync(backupDir, { recursive: true });
|
|
155
158
|
} catch (err) {
|
|
156
159
|
return { backupId, backupDir, backedUp, errors: [`Failed to create backup directory: ${err.message}`] };
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
// Make the backup invisible to git, from inside itself.
|
|
160
|
-
//
|
|
161
|
-
// WHY THIS IS NOT A LINE IN THE ADOPTER'S .gitignore. We create this directory
|
|
162
|
-
// in someone else's repository; making it disappear is our job, but editing
|
|
163
|
-
// their .gitignore to do it is not — that file is theirs, it may be generated,
|
|
164
|
-
// and a tool appending to it on every update is a worse trade than the problem.
|
|
165
|
-
// A `*` here ignores everything in this directory (this file included, which is
|
|
166
|
-
// fine: git reads .gitignore whether or not it is tracked), so `git status` and
|
|
167
|
-
// `git add -A` never see the backup at all, and nothing outside is touched.
|
|
168
|
-
//
|
|
169
|
-
// WHY IT EXISTS. Nothing ignored these directories, so `git add -A` in two
|
|
170
|
-
// sibling repos committed them: EngramGraph's 0.8.0 release commit took in 5
|
|
171
|
-
// backups — 360 files, 73,992 lines — and dev-platform took one. Both were
|
|
172
|
-
// public. The adopter is not the right place to put this responsibility: they
|
|
173
|
-
// did not create the directory and have no reason to expect it.
|
|
174
|
-
try {
|
|
175
|
-
writeFileSync(join(backupDir, '.gitignore'), '*\n', 'utf8');
|
|
176
|
-
} catch (err) {
|
|
177
|
-
// A backup that git can see still beats no backup — record and carry on.
|
|
178
|
-
errors.push(`Failed to write backup .gitignore: ${err.message}`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
162
|
const notBackedUp = [...(spec.notBackedUp || [])];
|
|
182
163
|
const mustBackUp = [];
|
|
183
164
|
for (const p of spec.mustBackUp || []) {
|
|
@@ -547,17 +528,18 @@ export function rollback(projectPath, backupId = null) {
|
|
|
547
528
|
*/
|
|
548
529
|
export function listBackups(projectPath) {
|
|
549
530
|
try {
|
|
550
|
-
const entries = readdirSync(projectPath, { withFileTypes: true });
|
|
551
531
|
const backups = [];
|
|
552
532
|
|
|
553
|
-
|
|
554
|
-
|
|
533
|
+
// Where backups can be: the shared folder (new), and the project root (backups from before R7).
|
|
534
|
+
const places = [];
|
|
535
|
+
places.push(...sharedBackupIds(projectPath));
|
|
536
|
+
addLegacyBackupIds(projectPath, places);
|
|
555
537
|
|
|
556
|
-
|
|
557
|
-
const manifestPath = join(
|
|
538
|
+
for (const backupId of places) {
|
|
539
|
+
const manifestPath = join(projectPath, backupId, 'backup-manifest.json');
|
|
558
540
|
|
|
559
541
|
const info = {
|
|
560
|
-
backupId
|
|
542
|
+
backupId,
|
|
561
543
|
createdAt: '',
|
|
562
544
|
actionCount: 0,
|
|
563
545
|
label: null,
|
|
@@ -580,9 +562,11 @@ export function listBackups(projectPath) {
|
|
|
580
562
|
backups.push(info);
|
|
581
563
|
}
|
|
582
564
|
|
|
583
|
-
// Sort newest first. The id carries a per-process counter after the timestamp, so
|
|
584
|
-
// `createdAt` (two steps in the same millisecond) still order by creation
|
|
585
|
-
|
|
565
|
+
// Sort newest first, both places together. The id carries a per-process counter after the timestamp, so
|
|
566
|
+
// ties on `createdAt` (two steps in the same millisecond) still order by creation - compared on the
|
|
567
|
+
// folder name, not the whole id, so the two layouts compare with each other.
|
|
568
|
+
const leaf = (id) => id.slice(id.lastIndexOf('/') + 1).replace(/^\.uds-backup-/, '');
|
|
569
|
+
backups.sort((a, b) => b.createdAt.localeCompare(a.createdAt) || leaf(b.backupId).localeCompare(leaf(a.backupId)));
|
|
586
570
|
return backups;
|
|
587
571
|
} catch {
|
|
588
572
|
return [];
|
package/src/reconciler/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import { executePlan } from './plan-executor.js';
|
|
|
30
30
|
import { rollback } from './backup-manager.js';
|
|
31
31
|
import { pruneForeignSkillHashes } from '../utils/skill-hash-ownership.js';
|
|
32
32
|
import { pruneForeignCommandHashes } from '../utils/command-hash-ownership.js';
|
|
33
|
+
import { pruneForeignSkillNames, pruneForeignCommandNames } from '../utils/installed-names-ownership.js';
|
|
33
34
|
|
|
34
35
|
/**
|
|
35
36
|
* Full reconciliation pipeline.
|
|
@@ -86,11 +87,25 @@ function reconcileFileHashes(manifest, verifiedPristine) {
|
|
|
86
87
|
const commandProbe = { commandHashes: { ...(manifest.commandHashes || {}) } };
|
|
87
88
|
const foreignCommandKeys = pruneForeignCommandHashes(commandProbe);
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
// XSPEC-456 R4: and the NAME lists. The hash records above were cleaned and these were not, so a
|
|
91
|
+
// project could read "56 skills installed, 61 skills named". Ownership test only (no disk test): the
|
|
92
|
+
// plan below is what installs or removes files, and a name is judged against what UDS ships.
|
|
93
|
+
const namesProbe = {
|
|
94
|
+
skills: { names: [...(manifest.skills?.names || [])] },
|
|
95
|
+
commands: { names: [...(manifest.commands?.names || [])] }
|
|
96
|
+
};
|
|
97
|
+
const namesBefore = { skills: namesProbe.skills.names.length, commands: namesProbe.commands.names.length };
|
|
98
|
+
pruneForeignSkillNames(namesProbe, '');
|
|
99
|
+
pruneForeignCommandNames(namesProbe, '');
|
|
100
|
+
const foreignSkillNames = namesBefore.skills - namesProbe.skills.names.length;
|
|
101
|
+
const foreignCommandNames = namesBefore.commands - namesProbe.commands.names.length;
|
|
102
|
+
|
|
103
|
+
if (!verifiedPristine?.length && stale.length === 0 && foreignSkillKeys.length === 0 && foreignCommandKeys.length === 0
|
|
104
|
+
&& foreignSkillNames === 0 && foreignCommandNames === 0) return null;
|
|
90
105
|
|
|
91
106
|
const kept = Object.fromEntries(Object.entries(current).filter(([k]) => !stale.includes(k)));
|
|
92
107
|
const corrected = {};
|
|
93
|
-
let count = stale.length + foreignSkillKeys.length + foreignCommandKeys.length;
|
|
108
|
+
let count = stale.length + foreignSkillKeys.length + foreignCommandKeys.length + foreignSkillNames + foreignCommandNames;
|
|
94
109
|
|
|
95
110
|
for (const entry of verifiedPristine || []) {
|
|
96
111
|
const key = entry.path.replace(/\\/g, '/');
|
|
@@ -110,7 +125,9 @@ function reconcileFileHashes(manifest, verifiedPristine) {
|
|
|
110
125
|
...manifest,
|
|
111
126
|
fileHashes: { ...kept, ...corrected },
|
|
112
127
|
...(foreignSkillKeys.length > 0 ? { skillHashes: skillProbe.skillHashes } : {}),
|
|
113
|
-
...(foreignCommandKeys.length > 0 ? { commandHashes: commandProbe.commandHashes } : {})
|
|
128
|
+
...(foreignCommandKeys.length > 0 ? { commandHashes: commandProbe.commandHashes } : {}),
|
|
129
|
+
...(foreignSkillNames > 0 ? { skills: { ...manifest.skills, names: namesProbe.skills.names } } : {}),
|
|
130
|
+
...(foreignCommandNames > 0 ? { commands: { ...manifest.commands, names: namesProbe.commands.names } } : {})
|
|
114
131
|
},
|
|
115
132
|
count
|
|
116
133
|
};
|