@fmatar/archlens-skill 0.0.1-Alpha-07
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/LICENSE +190 -0
- package/README.md +161 -0
- package/bin/index.js +379 -0
- package/package.json +48 -0
- package/skills/archlens-install-policy/SKILL.md +84 -0
- package/skills/archlens-install-policy/scripts/init_policy.py +325 -0
- package/src/analyzer.js +289 -0
- package/src/installer.js +200 -0
- package/src/ui.js +149 -0
- package/src/updater.js +172 -0
- package/src/upgrader.js +122 -0
package/src/installer.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Archlens Policy & Multi-Agent Skill Installer
|
|
3
|
+
* Scaffolds Clean Architecture policies locally and deploys skills globally.
|
|
4
|
+
* Zero external dependencies.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import * as os from 'node:os';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { generatePolicy } from './analyzer.js';
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = path.dirname(__filename);
|
|
15
|
+
|
|
16
|
+
export const COMPANION_PROTOCOL_HEADER = '## Archlens Clean Architecture Workbench Companion Protocol';
|
|
17
|
+
|
|
18
|
+
export function getCompanionProtocolBlock(serverUrl = 'http://localhost:8088') {
|
|
19
|
+
return `
|
|
20
|
+
${COMPANION_PROTOCOL_HEADER}
|
|
21
|
+
|
|
22
|
+
This project is governed by the **Archlens Dynamic Clean Architecture Workbench**.
|
|
23
|
+
- **Workbench UI & API**: \`${serverUrl}\`
|
|
24
|
+
- **Architectural Policy**: \`.archlens/policy.json\`
|
|
25
|
+
- **Mailbox IPC**:
|
|
26
|
+
- Inbound queue: \`.archlens/to-agent.json\`
|
|
27
|
+
- Outbound response: \`.archlens/to-viewer.json\`
|
|
28
|
+
|
|
29
|
+
### Handling Mailbox Commands:
|
|
30
|
+
1. **REGEN**: Re-index AST, evaluate package dependency rules, and acknowledge.
|
|
31
|
+
2. **APPLY_PROPOSAL**: Reorganize packages to conform to concentric rings (Adapters -> Application -> Domain Core). Where an inner layer relies on an outer layer, apply the **Dependency Inversion Principle** by creating an interface port in the inner layer and implementing it in the outer layer.
|
|
32
|
+
3. **REFRESH_CRAP**: Execute test suite and report code coverage metrics.
|
|
33
|
+
`.trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function installLocalPolicy(projectRoot, options = {}) {
|
|
37
|
+
const root = path.resolve(projectRoot);
|
|
38
|
+
const dryRun = Boolean(options.dryRun);
|
|
39
|
+
const force = Boolean(options.force);
|
|
40
|
+
const serverUrl = options.serverUrl || 'http://localhost:8088';
|
|
41
|
+
|
|
42
|
+
if (!fs.existsSync(root)) {
|
|
43
|
+
throw new Error(`Target directory does not exist: ${root}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const primaryDir = path.join(root, '.archlens');
|
|
47
|
+
const legacyDir = path.join(root, '.uml-viewer');
|
|
48
|
+
|
|
49
|
+
const primaryPolicyFile = path.join(primaryDir, 'policy.json');
|
|
50
|
+
const legacyPolicyFile = path.join(legacyDir, 'policy.json');
|
|
51
|
+
|
|
52
|
+
let targetDir = primaryDir;
|
|
53
|
+
let policyFile = primaryPolicyFile;
|
|
54
|
+
|
|
55
|
+
// Honor legacy directory if present and primary does not exist yet
|
|
56
|
+
if (!fs.existsSync(primaryPolicyFile) && fs.existsSync(legacyPolicyFile)) {
|
|
57
|
+
targetDir = legacyDir;
|
|
58
|
+
policyFile = legacyPolicyFile;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const configFile = path.join(targetDir, 'workbench.config.json');
|
|
62
|
+
|
|
63
|
+
let policyCreated = false;
|
|
64
|
+
let policyData = null;
|
|
65
|
+
|
|
66
|
+
if (!dryRun && !fs.existsSync(targetDir)) {
|
|
67
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (fs.existsSync(policyFile) && !force) {
|
|
71
|
+
policyCreated = false;
|
|
72
|
+
policyData = JSON.parse(fs.readFileSync(policyFile, 'utf8'));
|
|
73
|
+
} else {
|
|
74
|
+
policyData = generatePolicy(root, options);
|
|
75
|
+
if (!dryRun) {
|
|
76
|
+
fs.writeFileSync(policyFile, JSON.stringify(policyData, null, 2) + '\n', 'utf8');
|
|
77
|
+
}
|
|
78
|
+
policyCreated = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const workbenchConfig = {
|
|
82
|
+
serverUrl,
|
|
83
|
+
protocolVersion: '1.0',
|
|
84
|
+
description: 'Visual Workbench communication endpoint and mailbox IPC configuration'
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (!dryRun) {
|
|
88
|
+
fs.writeFileSync(configFile, JSON.stringify(workbenchConfig, null, 2) + '\n', 'utf8');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const companionFiles = ['CLAUDE.md', 'AGENTS.md'];
|
|
92
|
+
const updatedCompanions = [];
|
|
93
|
+
|
|
94
|
+
for (const filename of companionFiles) {
|
|
95
|
+
const filePath = path.join(root, filename);
|
|
96
|
+
const companionBlock = getCompanionProtocolBlock(serverUrl);
|
|
97
|
+
|
|
98
|
+
if (fs.existsSync(filePath)) {
|
|
99
|
+
const existing = fs.readFileSync(filePath, 'utf8');
|
|
100
|
+
if (!existing.includes(COMPANION_PROTOCOL_HEADER)) {
|
|
101
|
+
if (!dryRun) {
|
|
102
|
+
fs.writeFileSync(filePath, existing.trimEnd() + '\n\n' + companionBlock + '\n', 'utf8');
|
|
103
|
+
}
|
|
104
|
+
updatedCompanions.push(filename);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
if (!dryRun) {
|
|
108
|
+
fs.writeFileSync(filePath, `# Assistant Guidelines\n\n${companionBlock}\n`, 'utf8');
|
|
109
|
+
}
|
|
110
|
+
updatedCompanions.push(filename);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
targetDir: root,
|
|
116
|
+
archlensDir: targetDir,
|
|
117
|
+
umlDir: targetDir,
|
|
118
|
+
policyFile,
|
|
119
|
+
configFile,
|
|
120
|
+
policyCreated,
|
|
121
|
+
policyData,
|
|
122
|
+
companionFiles: updatedCompanions,
|
|
123
|
+
dryRun
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function getGlobalSkillDirectories() {
|
|
128
|
+
const home = os.homedir();
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
agent: 'Claude Code',
|
|
132
|
+
baseDir: path.join(home, '.claude', 'skills'),
|
|
133
|
+
targetDir: path.join(home, '.claude', 'skills', 'archlens-install-policy')
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
agent: 'Gemini CLI & Google Antigravity',
|
|
137
|
+
baseDir: path.join(home, '.gemini', 'config', 'skills'),
|
|
138
|
+
targetDir: path.join(home, '.gemini', 'config', 'skills', 'archlens-install-policy')
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
agent: 'Generic Agents Workspace',
|
|
142
|
+
baseDir: path.join(home, '.agents', 'skills'),
|
|
143
|
+
targetDir: path.join(home, '.agents', 'skills', 'archlens-install-policy')
|
|
144
|
+
}
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function installGlobalSkills(options = {}) {
|
|
149
|
+
const dryRun = Boolean(options.dryRun);
|
|
150
|
+
const force = Boolean(options.force);
|
|
151
|
+
const bundledSkillDir = path.resolve(__dirname, '..', 'skills', 'archlens-install-policy');
|
|
152
|
+
|
|
153
|
+
if (!fs.existsSync(bundledSkillDir)) {
|
|
154
|
+
throw new Error(`Bundled skill template directory not found at: ${bundledSkillDir}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const destinations = getGlobalSkillDirectories();
|
|
158
|
+
const installed = [];
|
|
159
|
+
|
|
160
|
+
for (const dest of destinations) {
|
|
161
|
+
// Install if parent agent directory exists or if force flag is enabled
|
|
162
|
+
const agentHomeDir = path.dirname(dest.baseDir);
|
|
163
|
+
const shouldInstall = force || fs.existsSync(agentHomeDir);
|
|
164
|
+
|
|
165
|
+
if (shouldInstall) {
|
|
166
|
+
if (!dryRun) {
|
|
167
|
+
fs.mkdirSync(dest.targetDir, { recursive: true });
|
|
168
|
+
copyDirectorySync(bundledSkillDir, dest.targetDir);
|
|
169
|
+
}
|
|
170
|
+
installed.push({
|
|
171
|
+
agent: dest.agent,
|
|
172
|
+
path: dest.targetDir
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
sourceDir: bundledSkillDir,
|
|
179
|
+
installed,
|
|
180
|
+
dryRun
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function copyDirectorySync(srcDir, destDir) {
|
|
185
|
+
if (!fs.existsSync(destDir)) {
|
|
186
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const entries = fs.readdirSync(srcDir, { withFileTypes: true });
|
|
190
|
+
for (const entry of entries) {
|
|
191
|
+
const srcPath = path.join(srcDir, entry.name);
|
|
192
|
+
const destPath = path.join(destDir, entry.name);
|
|
193
|
+
|
|
194
|
+
if (entry.isDirectory()) {
|
|
195
|
+
copyDirectorySync(srcPath, destPath);
|
|
196
|
+
} else {
|
|
197
|
+
fs.copyFileSync(srcPath, destPath);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
package/src/ui.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Archlens Terminal UI Toolkit
|
|
3
|
+
* Styled ANSI colors, banners, badges, and interactive prompts.
|
|
4
|
+
* Zero external dependencies.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as readline from 'node:readline';
|
|
8
|
+
|
|
9
|
+
export const colors = {
|
|
10
|
+
reset: '\x1b[0m',
|
|
11
|
+
bold: '\x1b[1m',
|
|
12
|
+
dim: '\x1b[2m',
|
|
13
|
+
italic: '\x1b[3m',
|
|
14
|
+
underline: '\x1b[4m',
|
|
15
|
+
|
|
16
|
+
// Foreground
|
|
17
|
+
black: '\x1b[30m',
|
|
18
|
+
red: '\x1b[31m',
|
|
19
|
+
green: '\x1b[32m',
|
|
20
|
+
yellow: '\x1b[33m',
|
|
21
|
+
blue: '\x1b[34m',
|
|
22
|
+
magenta: '\x1b[35m',
|
|
23
|
+
cyan: '\x1b[36m',
|
|
24
|
+
white: '\x1b[37m',
|
|
25
|
+
gray: '\x1b[90m',
|
|
26
|
+
|
|
27
|
+
// Bright Foreground
|
|
28
|
+
brightRed: '\x1b[91m',
|
|
29
|
+
brightGreen: '\x1b[92m',
|
|
30
|
+
brightYellow: '\x1b[93m',
|
|
31
|
+
brightBlue: '\x1b[94m',
|
|
32
|
+
brightMagenta: '\x1b[95m',
|
|
33
|
+
brightCyan: '\x1b[96m',
|
|
34
|
+
brightWhite: '\x1b[97m',
|
|
35
|
+
|
|
36
|
+
// Background
|
|
37
|
+
bgBlue: '\x1b[44m',
|
|
38
|
+
bgMagenta: '\x1b[45m',
|
|
39
|
+
bgCyan: '\x1b[46m',
|
|
40
|
+
bgDark: '\x1b[100m'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const c = colors;
|
|
44
|
+
|
|
45
|
+
export function banner() {
|
|
46
|
+
const art = `
|
|
47
|
+
${c.brightCyan}${c.bold} _ _ _ ____ _ _ _ _
|
|
48
|
+
/ \\ _ __ ___| |__ | | ___ _ __ ___ / ___|| | _ (_) | |
|
|
49
|
+
/ _ \\ | '__/ __| '_ \\| |/ _ \\ '_ \\/ __| \\___ \\| |/ / | | |
|
|
50
|
+
/ ___ \\| | | (__| | | | | __/ | | \\__ \\ ___) | <| | | |
|
|
51
|
+
/_/ \\_\\_| \\___|_| |_|_|\\___|_| |_|___/___|____/|_|\\_\\_|_|_|
|
|
52
|
+
|_____| ${c.reset}
|
|
53
|
+
${c.dim} Clean Architecture Policy Governance & Multi-Agent Installer${c.reset}
|
|
54
|
+
`;
|
|
55
|
+
console.log(art);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function info(message) {
|
|
59
|
+
console.log(`${c.brightCyan}ℹ${c.reset} ${message}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function success(message) {
|
|
63
|
+
console.log(`${c.brightGreen}✔${c.reset} ${c.bold}${message}${c.reset}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function warn(message) {
|
|
67
|
+
console.log(`${c.brightYellow}▲${c.reset} ${message}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function error(message) {
|
|
71
|
+
console.error(`${c.brightRed}✖ ${message}${c.reset}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function step(current, total, title) {
|
|
75
|
+
console.log(`\n${c.cyan}[${current}/${total}]${c.reset} ${c.bold}${title}${c.reset}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function divider() {
|
|
79
|
+
console.log(`${c.gray}${'─'.repeat(64)}${c.reset}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function badge(label, color = c.bgCyan + c.black) {
|
|
83
|
+
return `${color} ${label} ${c.reset}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function table(rows) {
|
|
87
|
+
const maxKeyLen = Math.max(...rows.map(([k]) => k.length), 0);
|
|
88
|
+
for (const [key, value] of rows) {
|
|
89
|
+
console.log(` ${c.dim}${key.padEnd(maxKeyLen + 2)}${c.reset} ${c.brightWhite}${value}${c.reset}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function createPrompt() {
|
|
94
|
+
return readline.createInterface({
|
|
95
|
+
input: process.stdin,
|
|
96
|
+
output: process.stdout
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function askQuestion(query, defaultVal = '') {
|
|
101
|
+
const rl = createPrompt();
|
|
102
|
+
const suffix = defaultVal ? ` ${c.dim}(default: ${defaultVal})${c.reset}: ` : ': ';
|
|
103
|
+
return new Promise((resolve) => {
|
|
104
|
+
rl.question(`${c.brightCyan}?${c.reset} ${query}${suffix}`, (answer) => {
|
|
105
|
+
rl.close();
|
|
106
|
+
resolve(answer.trim() || defaultVal);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function askChoice(title, options) {
|
|
112
|
+
console.log(`\n${c.brightCyan}?${c.reset} ${c.bold}${title}${c.reset}`);
|
|
113
|
+
options.forEach((opt, idx) => {
|
|
114
|
+
console.log(` ${c.cyan}${idx + 1})${c.reset} ${opt.label} ${c.dim}${opt.description || ''}${c.reset}`);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const rl = createPrompt();
|
|
118
|
+
return new Promise((resolve) => {
|
|
119
|
+
const ask = () => {
|
|
120
|
+
rl.question(`\n${c.dim}Select an option [1-${options.length}]: ${c.reset}`, (answer) => {
|
|
121
|
+
const num = parseInt(answer.trim(), 10);
|
|
122
|
+
if (num >= 1 && num <= options.length) {
|
|
123
|
+
rl.close();
|
|
124
|
+
resolve(options[num - 1].value);
|
|
125
|
+
} else {
|
|
126
|
+
console.log(`${c.yellow}Invalid choice. Please enter a number between 1 and ${options.length}.${c.reset}`);
|
|
127
|
+
ask();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
ask();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function askConfirm(query, defaultYes = true) {
|
|
136
|
+
const rl = createPrompt();
|
|
137
|
+
const hint = defaultYes ? '[Y/n]' : '[y/N]';
|
|
138
|
+
return new Promise((resolve) => {
|
|
139
|
+
rl.question(`${c.brightCyan}?${c.reset} ${query} ${c.dim}${hint}${c.reset}: `, (answer) => {
|
|
140
|
+
rl.close();
|
|
141
|
+
const val = answer.trim().toLowerCase();
|
|
142
|
+
if (!val) {
|
|
143
|
+
resolve(defaultYes);
|
|
144
|
+
} else {
|
|
145
|
+
resolve(val === 'y' || val === 'yes');
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
package/src/updater.js
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Archlens Policy & Multi-Agent Skill Updater
|
|
3
|
+
* Re-scans codebases to detect newly added packages, updates policy layers
|
|
4
|
+
* while preserving user custom configurations, and refreshes global agent skills.
|
|
5
|
+
* Zero external dependencies.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as fs from 'node:fs';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import {
|
|
11
|
+
detectProjectLanguage,
|
|
12
|
+
detectSourceRoot,
|
|
13
|
+
findCommonPackagePrefix,
|
|
14
|
+
discoverSubpackages,
|
|
15
|
+
classifyLayers
|
|
16
|
+
} from './analyzer.js';
|
|
17
|
+
import {
|
|
18
|
+
COMPANION_PROTOCOL_HEADER,
|
|
19
|
+
getCompanionProtocolBlock,
|
|
20
|
+
installGlobalSkills,
|
|
21
|
+
getGlobalSkillDirectories
|
|
22
|
+
} from './installer.js';
|
|
23
|
+
|
|
24
|
+
export function updateLocalPolicy(projectRoot, options = {}) {
|
|
25
|
+
const root = path.resolve(projectRoot);
|
|
26
|
+
const dryRun = Boolean(options.dryRun);
|
|
27
|
+
|
|
28
|
+
const primaryDir = path.join(root, '.archlens');
|
|
29
|
+
const legacyDir = path.join(root, '.uml-viewer');
|
|
30
|
+
const primaryPolicy = path.join(primaryDir, 'policy.json');
|
|
31
|
+
const legacyPolicy = path.join(legacyDir, 'policy.json');
|
|
32
|
+
|
|
33
|
+
let targetDir = primaryDir;
|
|
34
|
+
let policyFile = primaryPolicy;
|
|
35
|
+
|
|
36
|
+
if (fs.existsSync(primaryPolicy)) {
|
|
37
|
+
targetDir = primaryDir;
|
|
38
|
+
policyFile = primaryPolicy;
|
|
39
|
+
} else if (fs.existsSync(legacyPolicy)) {
|
|
40
|
+
targetDir = legacyDir;
|
|
41
|
+
policyFile = legacyPolicy;
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error(`Archlens policy not found at ${primaryPolicy}. Run init first.`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const configFile = path.join(targetDir, 'workbench.config.json');
|
|
47
|
+
|
|
48
|
+
if (!fs.existsSync(root)) {
|
|
49
|
+
throw new Error(`Target directory does not exist: ${root}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const existingPolicy = JSON.parse(fs.readFileSync(policyFile, 'utf8'));
|
|
53
|
+
|
|
54
|
+
const lang = existingPolicy.lang || detectProjectLanguage(root);
|
|
55
|
+
const srcRoot = existingPolicy.src || detectSourceRoot(root, lang);
|
|
56
|
+
const fullSrc = path.join(root, srcRoot);
|
|
57
|
+
const prefix = existingPolicy.prefix !== undefined
|
|
58
|
+
? existingPolicy.prefix
|
|
59
|
+
: findCommonPackagePrefix(fullSrc);
|
|
60
|
+
|
|
61
|
+
const discoveredPackages = discoverSubpackages(fullSrc, prefix);
|
|
62
|
+
|
|
63
|
+
// Determine which packages in codebase are not currently listed in existing policy
|
|
64
|
+
const existingOrder = Array.isArray(existingPolicy.order) ? existingPolicy.order : [];
|
|
65
|
+
const existingLevels = Array.isArray(existingPolicy.levels) ? existingPolicy.levels : [];
|
|
66
|
+
|
|
67
|
+
const existingPackageSet = new Set(existingOrder);
|
|
68
|
+
const newPackages = discoveredPackages.filter((p) => !existingPackageSet.has(p));
|
|
69
|
+
|
|
70
|
+
let updatedLevels = existingLevels.map((lvl) => [...lvl]);
|
|
71
|
+
if (updatedLevels.length < 3) {
|
|
72
|
+
while (updatedLevels.length < 3) {
|
|
73
|
+
updatedLevels.push([]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (newPackages.length > 0) {
|
|
78
|
+
const { levels: classifiedNewLevels } = classifyLayers(newPackages);
|
|
79
|
+
|
|
80
|
+
for (let i = 0; i < classifiedNewLevels.length; i++) {
|
|
81
|
+
if (!updatedLevels[i]) {
|
|
82
|
+
updatedLevels[i] = [];
|
|
83
|
+
}
|
|
84
|
+
for (const p of classifiedNewLevels[i]) {
|
|
85
|
+
// Exclude default placeholder names if they were synthetic
|
|
86
|
+
if (newPackages.includes(p) && !updatedLevels[i].includes(p)) {
|
|
87
|
+
updatedLevels[i].push(p);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Rebuild order ensuring all levels are represented sequentially
|
|
94
|
+
const updatedOrder = [];
|
|
95
|
+
for (const group of updatedLevels) {
|
|
96
|
+
for (const p of group) {
|
|
97
|
+
if (!updatedOrder.includes(p)) {
|
|
98
|
+
updatedOrder.push(p);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const mergedPolicy = {
|
|
104
|
+
...existingPolicy,
|
|
105
|
+
title: options.title || existingPolicy.title,
|
|
106
|
+
src: srcRoot,
|
|
107
|
+
prefix,
|
|
108
|
+
order: updatedOrder,
|
|
109
|
+
levels: updatedLevels,
|
|
110
|
+
lang
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (!dryRun) {
|
|
114
|
+
fs.writeFileSync(policyFile, JSON.stringify(mergedPolicy, null, 2) + '\n', 'utf8');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const serverUrl = options.serverUrl || 'http://localhost:8088';
|
|
118
|
+
if (!dryRun) {
|
|
119
|
+
const workbenchConfig = {
|
|
120
|
+
serverUrl,
|
|
121
|
+
protocolVersion: '1.0',
|
|
122
|
+
description: 'Visual Workbench communication endpoint and mailbox IPC configuration'
|
|
123
|
+
};
|
|
124
|
+
fs.writeFileSync(configFile, JSON.stringify(workbenchConfig, null, 2) + '\n', 'utf8');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Refresh companion documentation
|
|
128
|
+
const refreshedCompanions = [];
|
|
129
|
+
for (const filename of ['CLAUDE.md', 'AGENTS.md']) {
|
|
130
|
+
const filePath = path.join(root, filename);
|
|
131
|
+
const companionBlock = getCompanionProtocolBlock(serverUrl);
|
|
132
|
+
|
|
133
|
+
if (fs.existsSync(filePath)) {
|
|
134
|
+
const existing = fs.readFileSync(filePath, 'utf8');
|
|
135
|
+
if (!existing.includes(COMPANION_PROTOCOL_HEADER)) {
|
|
136
|
+
if (!dryRun) {
|
|
137
|
+
fs.writeFileSync(filePath, existing.trimEnd() + '\n\n' + companionBlock + '\n', 'utf8');
|
|
138
|
+
}
|
|
139
|
+
refreshedCompanions.push(filename);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
targetDir: root,
|
|
146
|
+
policyFile,
|
|
147
|
+
newPackages,
|
|
148
|
+
totalPackages: updatedOrder.length,
|
|
149
|
+
refreshedCompanions,
|
|
150
|
+
dryRun
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function updateGlobalSkills(options = {}) {
|
|
155
|
+
const destinations = getGlobalSkillDirectories();
|
|
156
|
+
const existingDestinations = destinations.filter((dest) => fs.existsSync(dest.targetDir));
|
|
157
|
+
|
|
158
|
+
if (existingDestinations.length === 0) {
|
|
159
|
+
// If none installed yet, install to all detected agent environments
|
|
160
|
+
return installGlobalSkills(options);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const installResult = installGlobalSkills({
|
|
164
|
+
...options,
|
|
165
|
+
force: true
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
updatedLocations: installResult.installed,
|
|
170
|
+
dryRun: installResult.dryRun
|
|
171
|
+
};
|
|
172
|
+
}
|
package/src/upgrader.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Archlens Configuration & Mailbox Upgrader
|
|
3
|
+
* Migrates legacy .uml-viewer configurations and mailboxes to the modern .archlens layout.
|
|
4
|
+
* Zero external dependencies.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import { COMPANION_PROTOCOL_HEADER, getCompanionProtocolBlock } from './installer.js';
|
|
10
|
+
|
|
11
|
+
export function upgradeProject(projectRoot, options = {}) {
|
|
12
|
+
const root = path.resolve(projectRoot);
|
|
13
|
+
const dryRun = Boolean(options.dryRun);
|
|
14
|
+
const legacyDir = path.join(root, '.uml-viewer');
|
|
15
|
+
const primaryDir = path.join(root, '.archlens');
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(root)) {
|
|
18
|
+
throw new Error(`Target directory does not exist: ${root}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const legacyExists = fs.existsSync(legacyDir);
|
|
22
|
+
const primaryExists = fs.existsSync(primaryDir);
|
|
23
|
+
|
|
24
|
+
if (!legacyExists && !primaryExists) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`No Archlens configuration found to upgrade in ${root}. Run init to create a new .archlens configuration.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let migrated = false;
|
|
31
|
+
const migratedFiles = [];
|
|
32
|
+
|
|
33
|
+
if (legacyExists) {
|
|
34
|
+
if (!primaryExists) {
|
|
35
|
+
if (dryRun) {
|
|
36
|
+
const files = fs.readdirSync(legacyDir);
|
|
37
|
+
migratedFiles.push(...files);
|
|
38
|
+
migrated = true;
|
|
39
|
+
} else {
|
|
40
|
+
try {
|
|
41
|
+
fs.renameSync(legacyDir, primaryDir);
|
|
42
|
+
const files = fs.readdirSync(primaryDir);
|
|
43
|
+
migratedFiles.push(...files);
|
|
44
|
+
migrated = true;
|
|
45
|
+
} catch {
|
|
46
|
+
// Fallback for cross-device mount links
|
|
47
|
+
fs.mkdirSync(primaryDir, { recursive: true });
|
|
48
|
+
const files = fs.readdirSync(legacyDir);
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
const srcFile = path.join(legacyDir, file);
|
|
51
|
+
const dstFile = path.join(primaryDir, file);
|
|
52
|
+
fs.copyFileSync(srcFile, dstFile);
|
|
53
|
+
migratedFiles.push(file);
|
|
54
|
+
}
|
|
55
|
+
fs.rmSync(legacyDir, { recursive: true, force: true });
|
|
56
|
+
migrated = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
// Both exist: migrate missing files into primaryDir and retire legacyDir
|
|
61
|
+
const files = fs.readdirSync(legacyDir);
|
|
62
|
+
for (const file of files) {
|
|
63
|
+
const srcFile = path.join(legacyDir, file);
|
|
64
|
+
const dstFile = path.join(primaryDir, file);
|
|
65
|
+
if (!fs.existsSync(dstFile)) {
|
|
66
|
+
if (!dryRun) {
|
|
67
|
+
fs.copyFileSync(srcFile, dstFile);
|
|
68
|
+
}
|
|
69
|
+
migratedFiles.push(file);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!dryRun) {
|
|
73
|
+
fs.rmSync(legacyDir, { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
migrated = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Update companion files: CLAUDE.md and AGENTS.md
|
|
80
|
+
const companionFiles = ['CLAUDE.md', 'AGENTS.md'];
|
|
81
|
+
const updatedCompanions = [];
|
|
82
|
+
|
|
83
|
+
for (const filename of companionFiles) {
|
|
84
|
+
const filePath = path.join(root, filename);
|
|
85
|
+
if (!fs.existsSync(filePath)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
90
|
+
let updatedContent = content;
|
|
91
|
+
let modified = false;
|
|
92
|
+
|
|
93
|
+
if (content.includes('.uml-viewer')) {
|
|
94
|
+
updatedContent = updatedContent.replaceAll('.uml-viewer', '.archlens');
|
|
95
|
+
modified = true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!updatedContent.includes(COMPANION_PROTOCOL_HEADER)) {
|
|
99
|
+
const serverUrl = options.serverUrl || 'http://localhost:8088';
|
|
100
|
+
const block = getCompanionProtocolBlock(serverUrl);
|
|
101
|
+
updatedContent = updatedContent.trimEnd() + '\n\n' + block + '\n';
|
|
102
|
+
modified = true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (modified) {
|
|
106
|
+
if (!dryRun) {
|
|
107
|
+
fs.writeFileSync(filePath, updatedContent, 'utf8');
|
|
108
|
+
}
|
|
109
|
+
updatedCompanions.push(filename);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
targetDir: root,
|
|
115
|
+
legacyDir,
|
|
116
|
+
primaryDir,
|
|
117
|
+
migrated,
|
|
118
|
+
migratedFiles,
|
|
119
|
+
updatedCompanions,
|
|
120
|
+
dryRun
|
|
121
|
+
};
|
|
122
|
+
}
|