@lark-codem/codem-cli 0.1.274-test.202611170849.0.gc5a50ef → 0.1.274
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 +6 -6
- package/bin/codem-service.js +132 -132
- package/bin/codem.js +250 -250
- package/bin/linco-paths.js +45 -45
- package/bin/platform-child-process.js +178 -178
- package/bin/process-tree.js +217 -0
- package/bin/tt-env.js +171 -171
- package/bin/worker-runtime-telemetry.js +75 -75
- package/bin/worker-runtime.js +345 -294
- package/package.json +9 -9
- package/profile/config-lock.js +512 -512
- package/profile/credential-errors.js +37 -37
- package/profile/credential-metadata.js +29 -29
- package/profile/debug.js +104 -104
- package/profile/device-identity.js +95 -95
- package/profile/diagnostic-id.js +47 -47
- package/profile/index.d.ts +61 -61
- package/profile/index.js +17 -17
- package/profile/profile-io.js +70 -70
- package/profile/profile-migration.js +1022 -1022
- package/profile/profile-snapshot.js +120 -120
- package/profile/profile-writers.js +296 -296
- package/profile/runtime-logs.js +660 -660
- package/profile/slardar-pc-transport.js +42 -42
- package/profile/worker-runtime-observation.js +10 -10
package/profile/index.d.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
export interface ProfileAccount {
|
|
2
|
-
readonly userId: string
|
|
3
|
-
readonly tenantId: string
|
|
4
|
-
readonly displayName: string | null
|
|
5
|
-
readonly avatarUrl: string | null
|
|
6
|
-
}
|
|
7
|
-
export interface ProfileSnapshot {
|
|
8
|
-
readonly schemaVersion: 1
|
|
9
|
-
readonly user: { readonly userId: string | null; readonly tenantId: string | null; readonly displayName: string | null; readonly avatarUrl: string | null }
|
|
10
|
-
readonly serverUrl: string | null
|
|
11
|
-
readonly account: ProfileAccount | null
|
|
12
|
-
readonly device: { readonly id: string; readonly name: string | null; readonly binding: 'ready' | 'missing' } | null
|
|
13
|
-
readonly identityRevision: string | null
|
|
14
|
-
}
|
|
15
|
-
export interface ProfileWriterBlocker {
|
|
16
|
-
readonly kind: 'app-process' | 'cli-process' | 'codem-process' | 'session-handle'
|
|
17
|
-
readonly processId: number | null
|
|
18
|
-
readonly processName: string | null
|
|
19
|
-
}
|
|
20
|
-
export type ProfileSetupChoice = { readonly kind: 'migrate'; readonly home: string } | { readonly kind: 'new' | 'defer' | 'resume' }
|
|
21
|
-
export interface ProfileSetupSnapshot {
|
|
22
|
-
readonly stage: 'choice' | 'welcome' | 'working' | 'blocked'
|
|
23
|
-
readonly situation: 'accounts' | 'devices' | 'recovery' | 'desktop-data'
|
|
24
|
-
readonly targetHome: string
|
|
25
|
-
readonly environment: string
|
|
26
|
-
readonly backupHome: string
|
|
27
|
-
readonly profiles: {
|
|
28
|
-
readonly home: string
|
|
29
|
-
readonly accountKey: string | null
|
|
30
|
-
readonly accountLabel: string
|
|
31
|
-
readonly deviceId: string | null
|
|
32
|
-
readonly status: 'available' | 'signed-out' | 'recovery' | 'other-environment'
|
|
33
|
-
readonly issue: string | null
|
|
34
|
-
}[]
|
|
35
|
-
readonly recommendedHome: string
|
|
36
|
-
readonly busy: boolean
|
|
37
|
-
readonly blockers: ProfileWriterBlocker[]
|
|
38
|
-
readonly notice: string | null
|
|
39
|
-
readonly diagnosticId: string | null
|
|
40
|
-
}
|
|
41
|
-
export interface ProfileMigrationOptions {
|
|
42
|
-
readonly mode: 'automatic' | 'maintenance'
|
|
43
|
-
readonly targetHome: string
|
|
44
|
-
readonly legacyHomes: readonly string[]
|
|
45
|
-
readonly backupHome: string
|
|
46
|
-
readonly serverOrigin: string
|
|
47
|
-
readonly migrateSessions: (sessionRoots: readonly string[]) => Promise<void>
|
|
48
|
-
readonly choose: (snapshot: ProfileSetupSnapshot) => Promise<ProfileSetupChoice>
|
|
49
|
-
}
|
|
50
|
-
export type ProfileMigrationResult = { readonly kind: 'ready'; readonly backupHome: string | null; readonly legacyCleanupPending: boolean } | { readonly kind: 'defer' }
|
|
51
|
-
export class CodeMProfileMigrationError extends Error {}
|
|
52
|
-
export class CodeMProfileMigrationBlockedError extends CodeMProfileMigrationError {
|
|
53
|
-
readonly code: 'CODEM_PROFILE_MIGRATION_BLOCKED'
|
|
54
|
-
readonly reason: 'daemon-active' | 'session-writer-active' | 'writer-inspection-failed'
|
|
55
|
-
readonly blockers: readonly ProfileWriterBlocker[]
|
|
56
|
-
constructor(detail: string, reason: CodeMProfileMigrationBlockedError['reason'], blockers: readonly ProfileWriterBlocker[], options?: ErrorOptions)
|
|
57
|
-
}
|
|
58
|
-
export function readProfileSnapshot(home: string): Promise<ProfileSnapshot>
|
|
59
|
-
export function canonicalCodeMProfileHome(home: string): Promise<string>
|
|
60
|
-
export function migrateCodeMProfile(options: ProfileMigrationOptions): Promise<ProfileMigrationResult>
|
|
61
|
-
export function withProfileSessionMaintenance<T>(home: string, operation: () => Promise<T>): Promise<T>
|
|
1
|
+
export interface ProfileAccount {
|
|
2
|
+
readonly userId: string
|
|
3
|
+
readonly tenantId: string
|
|
4
|
+
readonly displayName: string | null
|
|
5
|
+
readonly avatarUrl: string | null
|
|
6
|
+
}
|
|
7
|
+
export interface ProfileSnapshot {
|
|
8
|
+
readonly schemaVersion: 1
|
|
9
|
+
readonly user: { readonly userId: string | null; readonly tenantId: string | null; readonly displayName: string | null; readonly avatarUrl: string | null }
|
|
10
|
+
readonly serverUrl: string | null
|
|
11
|
+
readonly account: ProfileAccount | null
|
|
12
|
+
readonly device: { readonly id: string; readonly name: string | null; readonly binding: 'ready' | 'missing' } | null
|
|
13
|
+
readonly identityRevision: string | null
|
|
14
|
+
}
|
|
15
|
+
export interface ProfileWriterBlocker {
|
|
16
|
+
readonly kind: 'app-process' | 'cli-process' | 'codem-process' | 'session-handle'
|
|
17
|
+
readonly processId: number | null
|
|
18
|
+
readonly processName: string | null
|
|
19
|
+
}
|
|
20
|
+
export type ProfileSetupChoice = { readonly kind: 'migrate'; readonly home: string } | { readonly kind: 'new' | 'defer' | 'resume' }
|
|
21
|
+
export interface ProfileSetupSnapshot {
|
|
22
|
+
readonly stage: 'choice' | 'welcome' | 'working' | 'blocked'
|
|
23
|
+
readonly situation: 'accounts' | 'devices' | 'recovery' | 'desktop-data'
|
|
24
|
+
readonly targetHome: string
|
|
25
|
+
readonly environment: string
|
|
26
|
+
readonly backupHome: string
|
|
27
|
+
readonly profiles: {
|
|
28
|
+
readonly home: string
|
|
29
|
+
readonly accountKey: string | null
|
|
30
|
+
readonly accountLabel: string
|
|
31
|
+
readonly deviceId: string | null
|
|
32
|
+
readonly status: 'available' | 'signed-out' | 'recovery' | 'other-environment'
|
|
33
|
+
readonly issue: string | null
|
|
34
|
+
}[]
|
|
35
|
+
readonly recommendedHome: string
|
|
36
|
+
readonly busy: boolean
|
|
37
|
+
readonly blockers: ProfileWriterBlocker[]
|
|
38
|
+
readonly notice: string | null
|
|
39
|
+
readonly diagnosticId: string | null
|
|
40
|
+
}
|
|
41
|
+
export interface ProfileMigrationOptions {
|
|
42
|
+
readonly mode: 'automatic' | 'maintenance'
|
|
43
|
+
readonly targetHome: string
|
|
44
|
+
readonly legacyHomes: readonly string[]
|
|
45
|
+
readonly backupHome: string
|
|
46
|
+
readonly serverOrigin: string
|
|
47
|
+
readonly migrateSessions: (sessionRoots: readonly string[]) => Promise<void>
|
|
48
|
+
readonly choose: (snapshot: ProfileSetupSnapshot) => Promise<ProfileSetupChoice>
|
|
49
|
+
}
|
|
50
|
+
export type ProfileMigrationResult = { readonly kind: 'ready'; readonly backupHome: string | null; readonly legacyCleanupPending: boolean } | { readonly kind: 'defer' }
|
|
51
|
+
export class CodeMProfileMigrationError extends Error {}
|
|
52
|
+
export class CodeMProfileMigrationBlockedError extends CodeMProfileMigrationError {
|
|
53
|
+
readonly code: 'CODEM_PROFILE_MIGRATION_BLOCKED'
|
|
54
|
+
readonly reason: 'daemon-active' | 'session-writer-active' | 'writer-inspection-failed'
|
|
55
|
+
readonly blockers: readonly ProfileWriterBlocker[]
|
|
56
|
+
constructor(detail: string, reason: CodeMProfileMigrationBlockedError['reason'], blockers: readonly ProfileWriterBlocker[], options?: ErrorOptions)
|
|
57
|
+
}
|
|
58
|
+
export function readProfileSnapshot(home: string): Promise<ProfileSnapshot>
|
|
59
|
+
export function canonicalCodeMProfileHome(home: string): Promise<string>
|
|
60
|
+
export function migrateCodeMProfile(options: ProfileMigrationOptions): Promise<ProfileMigrationResult>
|
|
61
|
+
export function withProfileSessionMaintenance<T>(home: string, operation: () => Promise<T>): Promise<T>
|
package/profile/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export { readProfileSnapshot } from "./profile-snapshot.js";
|
|
2
|
-
export {
|
|
3
|
-
canonicalCodeMProfileHome,
|
|
4
|
-
migrateCodeMProfile,
|
|
5
|
-
CodeMProfileMigrationError,
|
|
6
|
-
CodeMProfileMigrationBlockedError
|
|
7
|
-
} from "./profile-migration.js";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { withCodeMConfigLock } from "./profile-io.js";
|
|
10
|
-
import { requireIdleProfileSessions } from "./profile-writers.js";
|
|
11
|
-
|
|
12
|
-
export async function withProfileSessionMaintenance(home, operation) {
|
|
13
|
-
return withCodeMConfigLock(join(home, "config.json"), async () => {
|
|
14
|
-
await requireIdleProfileSessions(home);
|
|
15
|
-
return operation();
|
|
16
|
-
});
|
|
17
|
-
}
|
|
1
|
+
export { readProfileSnapshot } from "./profile-snapshot.js";
|
|
2
|
+
export {
|
|
3
|
+
canonicalCodeMProfileHome,
|
|
4
|
+
migrateCodeMProfile,
|
|
5
|
+
CodeMProfileMigrationError,
|
|
6
|
+
CodeMProfileMigrationBlockedError
|
|
7
|
+
} from "./profile-migration.js";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { withCodeMConfigLock } from "./profile-io.js";
|
|
10
|
+
import { requireIdleProfileSessions } from "./profile-writers.js";
|
|
11
|
+
|
|
12
|
+
export async function withProfileSessionMaintenance(home, operation) {
|
|
13
|
+
return withCodeMConfigLock(join(home, "config.json"), async () => {
|
|
14
|
+
await requireIdleProfileSessions(home);
|
|
15
|
+
return operation();
|
|
16
|
+
});
|
|
17
|
+
}
|
package/profile/profile-io.js
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
3
|
-
import { mkdir, open, rename, rm } from "node:fs/promises";
|
|
4
|
-
import { basename, dirname, join, posix, win32 } from "node:path";
|
|
5
|
-
import { acquireConfigLock } from "./config-lock.js";
|
|
6
|
-
|
|
7
|
-
export async function withCodeMConfigLock(path, operation) {
|
|
8
|
-
const release = await acquireConfigLock(path);
|
|
9
|
-
try { return await operation(); } finally { await release(); }
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function probeProcessLiveness(pid) {
|
|
13
|
-
try { process.kill(pid, 0); return { kind: "alive" }; }
|
|
14
|
-
catch (cause) { return cause.code === "ESRCH" ? { kind: "missing" } : { kind: "unavailable", cause }; }
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function samePathForPlatform(left, right, platform) {
|
|
18
|
-
const api = platform === "win32" ? win32 : posix;
|
|
19
|
-
const normalize = value => platform === "win32" ? api.resolve(value).toLowerCase() : api.resolve(value);
|
|
20
|
-
return normalize(left) === normalize(right);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function writeFileAtomically(path, contents, label) {
|
|
24
|
-
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
25
|
-
const temporary = join(dirname(path), `.${basename(path)}.${randomUUID()}.tmp`);
|
|
26
|
-
try {
|
|
27
|
-
const file = await open(temporary, "wx", 0o600);
|
|
28
|
-
try { await file.writeFile(contents); await file.sync(); }
|
|
29
|
-
finally { await file.close(); }
|
|
30
|
-
await rename(temporary, path);
|
|
31
|
-
} catch (cause) {
|
|
32
|
-
await rm(temporary, { force: true }).catch(() => undefined);
|
|
33
|
-
throw new Error(`Cannot persist ${label}`, { cause });
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function writeJsonFileAtomically(path, value, label) {
|
|
38
|
-
return writeFileAtomically(path, `${JSON.stringify(value, null, 2)}\n`, label);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function runProcessResult(options) {
|
|
42
|
-
return new Promise(resolve => {
|
|
43
|
-
execFile(options.executable, options.arguments, {
|
|
44
|
-
timeout: options.timeoutMilliseconds,
|
|
45
|
-
maxBuffer: options.maximumOutputBytes,
|
|
46
|
-
windowsHide: true,
|
|
47
|
-
encoding: "utf8"
|
|
48
|
-
}, (error, stdout, stderr) => resolve({
|
|
49
|
-
stdout, stderr,
|
|
50
|
-
termination: error
|
|
51
|
-
? typeof error.code === "number"
|
|
52
|
-
? { kind: "exit", exitCode: error.code }
|
|
53
|
-
: { kind: "failure" }
|
|
54
|
-
: { kind: "exit", exitCode: 0 }
|
|
55
|
-
}));
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function isProcessExit(outcome, code) {
|
|
60
|
-
return outcome.termination.kind === "exit" && outcome.termination.exitCode === code;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function requireProcessSuccess(outcome) {
|
|
64
|
-
if (!isProcessExit(outcome, 0)) throw new Error("Profile writer inspection failed");
|
|
65
|
-
return outcome;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function runProcess(options) {
|
|
69
|
-
return requireProcessSuccess(await runProcessResult(options));
|
|
70
|
-
}
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { mkdir, open, rename, rm } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, join, posix, win32 } from "node:path";
|
|
5
|
+
import { acquireConfigLock } from "./config-lock.js";
|
|
6
|
+
|
|
7
|
+
export async function withCodeMConfigLock(path, operation) {
|
|
8
|
+
const release = await acquireConfigLock(path);
|
|
9
|
+
try { return await operation(); } finally { await release(); }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function probeProcessLiveness(pid) {
|
|
13
|
+
try { process.kill(pid, 0); return { kind: "alive" }; }
|
|
14
|
+
catch (cause) { return cause.code === "ESRCH" ? { kind: "missing" } : { kind: "unavailable", cause }; }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function samePathForPlatform(left, right, platform) {
|
|
18
|
+
const api = platform === "win32" ? win32 : posix;
|
|
19
|
+
const normalize = value => platform === "win32" ? api.resolve(value).toLowerCase() : api.resolve(value);
|
|
20
|
+
return normalize(left) === normalize(right);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function writeFileAtomically(path, contents, label) {
|
|
24
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
25
|
+
const temporary = join(dirname(path), `.${basename(path)}.${randomUUID()}.tmp`);
|
|
26
|
+
try {
|
|
27
|
+
const file = await open(temporary, "wx", 0o600);
|
|
28
|
+
try { await file.writeFile(contents); await file.sync(); }
|
|
29
|
+
finally { await file.close(); }
|
|
30
|
+
await rename(temporary, path);
|
|
31
|
+
} catch (cause) {
|
|
32
|
+
await rm(temporary, { force: true }).catch(() => undefined);
|
|
33
|
+
throw new Error(`Cannot persist ${label}`, { cause });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function writeJsonFileAtomically(path, value, label) {
|
|
38
|
+
return writeFileAtomically(path, `${JSON.stringify(value, null, 2)}\n`, label);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function runProcessResult(options) {
|
|
42
|
+
return new Promise(resolve => {
|
|
43
|
+
execFile(options.executable, options.arguments, {
|
|
44
|
+
timeout: options.timeoutMilliseconds,
|
|
45
|
+
maxBuffer: options.maximumOutputBytes,
|
|
46
|
+
windowsHide: true,
|
|
47
|
+
encoding: "utf8"
|
|
48
|
+
}, (error, stdout, stderr) => resolve({
|
|
49
|
+
stdout, stderr,
|
|
50
|
+
termination: error
|
|
51
|
+
? typeof error.code === "number"
|
|
52
|
+
? { kind: "exit", exitCode: error.code }
|
|
53
|
+
: { kind: "failure" }
|
|
54
|
+
: { kind: "exit", exitCode: 0 }
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isProcessExit(outcome, code) {
|
|
60
|
+
return outcome.termination.kind === "exit" && outcome.termination.exitCode === code;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function requireProcessSuccess(outcome) {
|
|
64
|
+
if (!isProcessExit(outcome, 0)) throw new Error("Profile writer inspection failed");
|
|
65
|
+
return outcome;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function runProcess(options) {
|
|
69
|
+
return requireProcessSuccess(await runProcessResult(options));
|
|
70
|
+
}
|