shennian 0.2.5 → 0.2.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.
Files changed (85) hide show
  1. package/package.json +1 -1
  2. package/dist/bin/shennian.d.ts +0 -2
  3. package/dist/bin/shennian.js +0 -2
  4. package/dist/src/agents/adapter.d.ts +0 -35
  5. package/dist/src/agents/adapter.js +0 -19
  6. package/dist/src/agents/claude.d.ts +0 -25
  7. package/dist/src/agents/claude.js +0 -234
  8. package/dist/src/agents/codex.d.ts +0 -49
  9. package/dist/src/agents/codex.js +0 -794
  10. package/dist/src/agents/command-spec.d.ts +0 -36
  11. package/dist/src/agents/command-spec.js +0 -303
  12. package/dist/src/agents/cursor.d.ts +0 -22
  13. package/dist/src/agents/cursor.js +0 -248
  14. package/dist/src/agents/custom.d.ts +0 -30
  15. package/dist/src/agents/custom.js +0 -210
  16. package/dist/src/agents/detect.d.ts +0 -9
  17. package/dist/src/agents/detect.js +0 -46
  18. package/dist/src/agents/gemini.d.ts +0 -17
  19. package/dist/src/agents/gemini.js +0 -172
  20. package/dist/src/agents/model-registry/cache.d.ts +0 -4
  21. package/dist/src/agents/model-registry/cache.js +0 -37
  22. package/dist/src/agents/model-registry/discovery.d.ts +0 -4
  23. package/dist/src/agents/model-registry/discovery.js +0 -161
  24. package/dist/src/agents/model-registry/parsers.d.ts +0 -11
  25. package/dist/src/agents/model-registry/parsers.js +0 -349
  26. package/dist/src/agents/model-registry/runner.d.ts +0 -6
  27. package/dist/src/agents/model-registry/runner.js +0 -29
  28. package/dist/src/agents/model-registry/service.d.ts +0 -6
  29. package/dist/src/agents/model-registry/service.js +0 -71
  30. package/dist/src/agents/model-registry/types.d.ts +0 -30
  31. package/dist/src/agents/model-registry/types.js +0 -8
  32. package/dist/src/agents/model-registry.d.ts +0 -13
  33. package/dist/src/agents/model-registry.js +0 -15
  34. package/dist/src/agents/openclaw.d.ts +0 -20
  35. package/dist/src/agents/openclaw.js +0 -273
  36. package/dist/src/agents/pi.d.ts +0 -51
  37. package/dist/src/agents/pi.js +0 -793
  38. package/dist/src/commands/agent.d.ts +0 -2
  39. package/dist/src/commands/agent.js +0 -131
  40. package/dist/src/commands/daemon.d.ts +0 -35
  41. package/dist/src/commands/daemon.js +0 -612
  42. package/dist/src/commands/pair-qr.d.ts +0 -4
  43. package/dist/src/commands/pair-qr.js +0 -6
  44. package/dist/src/commands/pair.d.ts +0 -8
  45. package/dist/src/commands/pair.js +0 -162
  46. package/dist/src/commands/upgrade.d.ts +0 -5
  47. package/dist/src/commands/upgrade.js +0 -145
  48. package/dist/src/config/index.d.ts +0 -32
  49. package/dist/src/config/index.js +0 -31
  50. package/dist/src/fs/handler.d.ts +0 -26
  51. package/dist/src/fs/handler.js +0 -130
  52. package/dist/src/fs/security.d.ts +0 -2
  53. package/dist/src/fs/security.js +0 -32
  54. package/dist/src/index.d.ts +0 -1
  55. package/dist/src/index.js +0 -277
  56. package/dist/src/log-reporter.d.ts +0 -18
  57. package/dist/src/log-reporter.js +0 -16
  58. package/dist/src/native-fusion/parsers.d.ts +0 -12
  59. package/dist/src/native-fusion/parsers.js +0 -687
  60. package/dist/src/native-fusion/service.d.ts +0 -25
  61. package/dist/src/native-fusion/service.js +0 -176
  62. package/dist/src/native-fusion/state.d.ts +0 -3
  63. package/dist/src/native-fusion/state.js +0 -22
  64. package/dist/src/native-fusion/types.d.ts +0 -24
  65. package/dist/src/native-fusion/types.js +0 -1
  66. package/dist/src/region.d.ts +0 -15
  67. package/dist/src/region.js +0 -99
  68. package/dist/src/relay/client.d.ts +0 -62
  69. package/dist/src/relay/client.js +0 -311
  70. package/dist/src/session/handlers/agents.d.ts +0 -4
  71. package/dist/src/session/handlers/agents.js +0 -55
  72. package/dist/src/session/handlers/chat.d.ts +0 -4
  73. package/dist/src/session/handlers/chat.js +0 -326
  74. package/dist/src/session/handlers/control.d.ts +0 -5
  75. package/dist/src/session/handlers/control.js +0 -57
  76. package/dist/src/session/handlers/fs.d.ts +0 -10
  77. package/dist/src/session/handlers/fs.js +0 -256
  78. package/dist/src/session/manager.d.ts +0 -28
  79. package/dist/src/session/manager.js +0 -174
  80. package/dist/src/session/store.d.ts +0 -7
  81. package/dist/src/session/store.js +0 -46
  82. package/dist/src/session/types.d.ts +0 -35
  83. package/dist/src/session/types.js +0 -4
  84. package/dist/src/upgrade/engine.d.ts +0 -64
  85. package/dist/src/upgrade/engine.js +0 -238
@@ -1,64 +0,0 @@
1
- export type UpgradeProgress = {
2
- step: 'checking';
3
- } | {
4
- step: 'backing-up';
5
- } | {
6
- step: 'installing';
7
- version: string;
8
- } | {
9
- step: 'verifying';
10
- version: string;
11
- } | {
12
- step: 'restarting';
13
- from: string;
14
- to: string;
15
- } | {
16
- step: 'done';
17
- from: string;
18
- to: string;
19
- };
20
- export type UpgradeResult = {
21
- ok: true;
22
- from: string;
23
- to: string;
24
- } | {
25
- ok: false;
26
- error: string;
27
- rolledBack?: boolean;
28
- };
29
- type UpgradeAttempt = {
30
- from: string;
31
- to: string;
32
- attemptCount: number;
33
- attemptAt: number;
34
- };
35
- export declare function getCurrentVersion(): string;
36
- export declare function fetchLatestVersion(): Promise<string>;
37
- /**
38
- * Compare semver strings. Returns:
39
- * 'none' — same or older
40
- * 'patch' — only patch differs
41
- * 'minor' — minor or patch differs
42
- * 'major' — major differs
43
- */
44
- export declare function compareVersions(current: string, latest: string): 'none' | 'patch' | 'minor' | 'major';
45
- export declare function readUpgradeAttempt(): UpgradeAttempt | null;
46
- export declare function writeUpgradeAttempt(attempt: UpgradeAttempt): void;
47
- export declare function clearUpgradeAttempt(): void;
48
- /**
49
- * Called on daemon startup. Detects crash loops from a failed upgrade and
50
- * initiates rollback if crash count exceeds threshold.
51
- * Returns true if rollback was performed (caller should exit and let service manager restart).
52
- */
53
- export declare function handleStartupCrashCheck(): Promise<boolean>;
54
- export declare function performUpgrade(targetVersion: string, onProgress: (p: UpgradeProgress) => void): Promise<UpgradeResult>;
55
- export type VersionCheckResult = {
56
- hasUpdate: false;
57
- } | {
58
- hasUpdate: true;
59
- current: string;
60
- latest: string;
61
- changeType: 'patch' | 'minor' | 'major';
62
- };
63
- export declare function checkForUpdate(): Promise<VersionCheckResult>;
64
- export {};
@@ -1,238 +0,0 @@
1
- // @arch docs/architecture/cli/upgrade.md
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- import { execSync, exec as execCb } from 'node:child_process';
5
- import { promisify } from 'node:util';
6
- import { getShennianDir, resolveShennianPath } from '../config/index.js';
7
- const exec = promisify(execCb);
8
- const SHENNIAN_DIR = getShennianDir();
9
- const BACKUP_DIR = resolveShennianPath('backup');
10
- const UPGRADE_ATTEMPT_FILE = resolveShennianPath('upgrade-attempt.json');
11
- const MAX_CRASH_COUNT = 3;
12
- const BACKUP_TTL_DAYS = 7;
13
- // ─── Version helpers ─────────────────────────────────────────────────────────
14
- export function getCurrentVersion() {
15
- try {
16
- const pkgPath = findPackageJson();
17
- if (pkgPath) {
18
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
19
- return pkg.version;
20
- }
21
- }
22
- catch { /* noop */ }
23
- return '0.0.0';
24
- }
25
- function findPackageJson() {
26
- // Walk up from this file's location to find package.json
27
- let dir = path.dirname(new URL(import.meta.url).pathname);
28
- for (let i = 0; i < 6; i++) {
29
- const candidate = path.join(dir, 'package.json');
30
- if (fs.existsSync(candidate)) {
31
- const pkg = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
32
- if (pkg.name === 'shennian')
33
- return candidate;
34
- }
35
- dir = path.dirname(dir);
36
- }
37
- return null;
38
- }
39
- export async function fetchLatestVersion() {
40
- const res = await fetch('https://registry.npmjs.org/shennian/latest', {
41
- headers: { Accept: 'application/json' },
42
- signal: AbortSignal.timeout(10_000),
43
- });
44
- if (!res.ok)
45
- throw new Error(`npm registry returned ${res.status}`);
46
- const data = (await res.json());
47
- return data.version;
48
- }
49
- /**
50
- * Compare semver strings. Returns:
51
- * 'none' — same or older
52
- * 'patch' — only patch differs
53
- * 'minor' — minor or patch differs
54
- * 'major' — major differs
55
- */
56
- export function compareVersions(current, latest) {
57
- const parse = (v) => v.replace(/^v/, '').split('.').map(Number);
58
- const [cMaj, cMin, cPat] = parse(current);
59
- const [lMaj, lMin, lPat] = parse(latest);
60
- if (lMaj > cMaj)
61
- return 'major';
62
- if (lMaj === cMaj && lMin > cMin)
63
- return 'minor';
64
- if (lMaj === cMaj && lMin === cMin && lPat > cPat)
65
- return 'patch';
66
- return 'none';
67
- }
68
- // ─── npm global path helpers ──────────────────────────────────────────────────
69
- function getNpmGlobalRoot() {
70
- return execSync('npm root -g', { encoding: 'utf-8', stdio: 'pipe' }).trim();
71
- }
72
- function getGlobalPkgDir() {
73
- return path.join(getNpmGlobalRoot(), 'shennian');
74
- }
75
- function getGlobalBinScript() {
76
- const root = getNpmGlobalRoot();
77
- return path.join(root, 'shennian', 'dist', 'bin', 'shennian.js');
78
- }
79
- // ─── Backup / Restore ─────────────────────────────────────────────────────────
80
- function backupVersion(version) {
81
- const pkgDir = getGlobalPkgDir();
82
- const dest = path.join(BACKUP_DIR, version);
83
- fs.mkdirSync(dest, { recursive: true });
84
- fs.cpSync(pkgDir, dest, { recursive: true });
85
- }
86
- function restoreVersion(version) {
87
- const src = path.join(BACKUP_DIR, version);
88
- if (!fs.existsSync(src))
89
- throw new Error(`Backup for ${version} not found`);
90
- const pkgDir = getGlobalPkgDir();
91
- fs.cpSync(src, pkgDir, { recursive: true, force: true });
92
- }
93
- function cleanOldBackups() {
94
- try {
95
- if (!fs.existsSync(BACKUP_DIR))
96
- return;
97
- const cutoff = Date.now() - BACKUP_TTL_DAYS * 86400_000;
98
- for (const entry of fs.readdirSync(BACKUP_DIR)) {
99
- const full = path.join(BACKUP_DIR, entry);
100
- const stat = fs.statSync(full);
101
- if (stat.mtimeMs < cutoff) {
102
- fs.rmSync(full, { recursive: true, force: true });
103
- }
104
- }
105
- }
106
- catch { /* noop */ }
107
- }
108
- // ─── Upgrade attempt tracking (crash detection) ───────────────────────────────
109
- export function readUpgradeAttempt() {
110
- try {
111
- return JSON.parse(fs.readFileSync(UPGRADE_ATTEMPT_FILE, 'utf-8'));
112
- }
113
- catch {
114
- return null;
115
- }
116
- }
117
- export function writeUpgradeAttempt(attempt) {
118
- fs.mkdirSync(SHENNIAN_DIR, { recursive: true });
119
- fs.writeFileSync(UPGRADE_ATTEMPT_FILE, JSON.stringify(attempt, null, 2));
120
- }
121
- export function clearUpgradeAttempt() {
122
- try {
123
- fs.unlinkSync(UPGRADE_ATTEMPT_FILE);
124
- }
125
- catch { /* noop */ }
126
- }
127
- /**
128
- * Called on daemon startup. Detects crash loops from a failed upgrade and
129
- * initiates rollback if crash count exceeds threshold.
130
- * Returns true if rollback was performed (caller should exit and let service manager restart).
131
- */
132
- export async function handleStartupCrashCheck() {
133
- const attempt = readUpgradeAttempt();
134
- if (!attempt)
135
- return false;
136
- const elapsed = Date.now() - attempt.attemptAt;
137
- // If more than 10 minutes have passed, this is a stale record — clear and continue
138
- if (elapsed > 10 * 60 * 1000) {
139
- clearUpgradeAttempt();
140
- return false;
141
- }
142
- attempt.attemptCount++;
143
- if (attempt.attemptCount >= MAX_CRASH_COUNT) {
144
- console.error(`[upgrade] New version crashed ${attempt.attemptCount} times, rolling back to ${attempt.from}...`);
145
- try {
146
- restoreVersion(attempt.from);
147
- clearUpgradeAttempt();
148
- console.error(`[upgrade] Rolled back to ${attempt.from}. Restarting...`);
149
- return true;
150
- }
151
- catch (err) {
152
- console.error(`[upgrade] Rollback failed: ${err instanceof Error ? err.message : String(err)}`);
153
- clearUpgradeAttempt();
154
- return false;
155
- }
156
- }
157
- writeUpgradeAttempt(attempt);
158
- return false;
159
- }
160
- // ─── Core upgrade ─────────────────────────────────────────────────────────────
161
- export async function performUpgrade(targetVersion, onProgress) {
162
- const currentVersion = getCurrentVersion();
163
- if (currentVersion === targetVersion) {
164
- return { ok: false, error: `Already on version ${targetVersion}` };
165
- }
166
- // Step 1: Verify npm is accessible
167
- onProgress({ step: 'checking' });
168
- try {
169
- execSync('npm --version', { stdio: 'pipe' });
170
- }
171
- catch {
172
- return { ok: false, error: 'npm is not available in PATH' };
173
- }
174
- // Step 2: Backup current version
175
- onProgress({ step: 'backing-up' });
176
- try {
177
- fs.mkdirSync(BACKUP_DIR, { recursive: true });
178
- backupVersion(currentVersion);
179
- }
180
- catch (err) {
181
- return { ok: false, error: `Backup failed: ${err instanceof Error ? err.message : String(err)}` };
182
- }
183
- // Step 3: npm install new version
184
- onProgress({ step: 'installing', version: targetVersion });
185
- try {
186
- await exec(`npm install -g shennian@${targetVersion}`, { timeout: 120_000 });
187
- }
188
- catch (err) {
189
- // Restore backup and abort
190
- try {
191
- restoreVersion(currentVersion);
192
- }
193
- catch { /* best effort */ }
194
- return {
195
- ok: false,
196
- error: `npm install failed: ${err instanceof Error ? err.message : String(err)}`,
197
- rolledBack: true,
198
- };
199
- }
200
- // Step 4: Smoke test — verify the new binary works
201
- onProgress({ step: 'verifying', version: targetVersion });
202
- try {
203
- const binScript = getGlobalBinScript();
204
- const { stdout } = await exec(`node "${binScript}" --version`, { timeout: 10_000 });
205
- if (!stdout.trim())
206
- throw new Error('Empty output from --version check');
207
- }
208
- catch (err) {
209
- try {
210
- restoreVersion(currentVersion);
211
- }
212
- catch { /* best effort */ }
213
- return {
214
- ok: false,
215
- error: `Smoke test failed: ${err instanceof Error ? err.message : String(err)}`,
216
- rolledBack: true,
217
- };
218
- }
219
- // Step 5: Write upgrade attempt file (crash detection on restart)
220
- writeUpgradeAttempt({
221
- from: currentVersion,
222
- to: targetVersion,
223
- attemptCount: 0,
224
- attemptAt: Date.now(),
225
- });
226
- cleanOldBackups();
227
- // Step 6: Signal restart (caller sends upgrade.status: restarting before killing)
228
- onProgress({ step: 'restarting', from: currentVersion, to: targetVersion });
229
- return { ok: true, from: currentVersion, to: targetVersion };
230
- }
231
- export async function checkForUpdate() {
232
- const current = getCurrentVersion();
233
- const latest = await fetchLatestVersion();
234
- const changeType = compareVersions(current, latest);
235
- if (changeType === 'none')
236
- return { hasUpdate: false };
237
- return { hasUpdate: true, current, latest, changeType };
238
- }