superun-ai-cli 0.1.33 → 0.1.35
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/README.en.md +1 -0
- package/README.md +4 -1
- package/dist/commands/chat/publish.js +3 -2
- package/dist/commands/chat/publish.js.map +1 -1
- package/dist/commands/shared.d.ts +4 -0
- package/dist/commands/shared.js +46 -28
- package/dist/commands/shared.js.map +1 -1
- package/dist/config/state-directory.d.ts +1 -0
- package/dist/config/state-directory.js +14 -0
- package/dist/config/state-directory.js.map +1 -0
- package/dist/conversation/agent-friendly.js +3 -2
- package/dist/conversation/agent-friendly.js.map +1 -1
- package/dist/conversation/next-actions.js +2 -0
- package/dist/conversation/next-actions.js.map +1 -1
- package/dist/conversation/user-choice-guidance.d.ts +2 -0
- package/dist/conversation/user-choice-guidance.js +3 -0
- package/dist/conversation/user-choice-guidance.js.map +1 -0
- package/dist/interactions/draft-store.d.ts +8 -0
- package/dist/interactions/draft-store.js +163 -70
- package/dist/interactions/draft-store.js.map +1 -1
- package/dist/interactions/state-storage.d.ts +4 -0
- package/dist/interactions/state-storage.js +65 -0
- package/dist/interactions/state-storage.js.map +1 -0
- package/dist/output/exit-codes.d.ts +4 -0
- package/dist/output/exit-codes.js +4 -0
- package/dist/output/exit-codes.js.map +1 -1
- package/dist/program.js +4 -1
- package/dist/program.js.map +1 -1
- package/dist/session/binding.d.ts +14 -61
- package/dist/session/binding.js +65 -60
- package/dist/session/binding.js.map +1 -1
- package/dist/session/project-bindings.d.ts +8 -0
- package/dist/session/project-bindings.js +57 -0
- package/dist/session/project-bindings.js.map +1 -0
- package/dist/session/remember-worker.d.ts +1 -0
- package/dist/session/remember-worker.js +46 -0
- package/dist/session/remember-worker.js.map +1 -0
- package/dist/session/remember.d.ts +9 -0
- package/dist/session/remember.js +14 -0
- package/dist/session/remember.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/** 按环境和凭据隔离交互草稿,串行保存回答与创建进度。@author xiuyu.yi */
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { mkdir, open, readFile, rename, unlink } from 'node:fs/promises';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
import { stateDirectory } from '../config/state-directory.js';
|
|
6
6
|
import { CliError } from '../output/exit-codes.js';
|
|
7
|
+
import { filesystemCode, stateOperation, withStateCleanup } from './state-storage.js';
|
|
7
8
|
export const fingerprint = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
9
|
+
// 同一进程同一目录只检查一次;实际操作仍处理权限变化与磁盘异常。
|
|
10
|
+
const checkedDirectories = new Map();
|
|
8
11
|
export class InteractionDraftStore {
|
|
9
12
|
scope;
|
|
10
13
|
root;
|
|
11
|
-
constructor(scope, root =
|
|
14
|
+
constructor(scope, root = stateDirectory('interactions')) {
|
|
12
15
|
this.scope = scope;
|
|
13
16
|
this.root = root;
|
|
14
17
|
}
|
|
@@ -16,87 +19,177 @@ export class InteractionDraftStore {
|
|
|
16
19
|
return join(this.root, this.scope, `${fingerprint(key)}.json`);
|
|
17
20
|
}
|
|
18
21
|
async read(key) {
|
|
22
|
+
const path = this.path(key);
|
|
23
|
+
const content = await stateOperation('read', path, async () => {
|
|
24
|
+
try {
|
|
25
|
+
return await readFile(path, 'utf8');
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
if (filesystemCode(error) === 'ENOENT')
|
|
29
|
+
return undefined;
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (content === undefined)
|
|
34
|
+
return undefined;
|
|
19
35
|
try {
|
|
20
|
-
return JSON.parse(
|
|
36
|
+
return JSON.parse(content);
|
|
21
37
|
}
|
|
22
|
-
catch
|
|
23
|
-
|
|
24
|
-
return undefined;
|
|
25
|
-
throw new CliError('PROTOCOL_ERROR', '交互草稿无法读取,请保留文件排查,勿重复创建');
|
|
38
|
+
catch {
|
|
39
|
+
throw new CliError('PROTOCOL_ERROR', '本地状态文件格式无效,请保留文件排查,勿重复创建', { path });
|
|
26
40
|
}
|
|
27
41
|
}
|
|
42
|
+
remove(path) {
|
|
43
|
+
return stateOperation('unlink', path, async () => {
|
|
44
|
+
try {
|
|
45
|
+
await unlink(path);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (filesystemCode(error) !== 'ENOENT')
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
close(file, path) {
|
|
54
|
+
return stateOperation('close', path, () => file.close());
|
|
55
|
+
}
|
|
56
|
+
async writeFile(path, content) {
|
|
57
|
+
const file = await stateOperation('create', path, () => open(path, 'wx', 0o600));
|
|
58
|
+
await withStateCleanup(async () => {
|
|
59
|
+
await stateOperation('write', path, () => file.writeFile(content));
|
|
60
|
+
await stateOperation('fsync', path, () => file.sync());
|
|
61
|
+
}, [() => this.close(file, path)]);
|
|
62
|
+
}
|
|
63
|
+
prepare() {
|
|
64
|
+
const directory = resolve(this.root, this.scope);
|
|
65
|
+
let checked = checkedDirectories.get(directory);
|
|
66
|
+
if (!checked) {
|
|
67
|
+
checked = this.checkDirectory(directory).catch((error) => {
|
|
68
|
+
checkedDirectories.delete(directory);
|
|
69
|
+
throw error;
|
|
70
|
+
});
|
|
71
|
+
checkedDirectories.set(directory, checked);
|
|
72
|
+
}
|
|
73
|
+
return checked;
|
|
74
|
+
}
|
|
75
|
+
async checkDirectory(directory) {
|
|
76
|
+
await stateOperation('mkdir', directory, () => mkdir(directory, { recursive: true, mode: 0o700 }));
|
|
77
|
+
const temp = join(directory, `.state-probe-${randomUUID()}.tmp`);
|
|
78
|
+
const target = `${temp}.ready`;
|
|
79
|
+
// 检查失败最多留下诊断文件,不能先创建真实业务锁;清理失败保留路径。
|
|
80
|
+
await withStateCleanup(async () => {
|
|
81
|
+
await this.writeFile(temp, '{}');
|
|
82
|
+
await stateOperation('rename', temp, () => rename(temp, target));
|
|
83
|
+
// 同时验证覆盖已存在文件的原子改名,避免首次绑定成功、后续更新才失败。
|
|
84
|
+
await this.writeFile(temp, '{}');
|
|
85
|
+
await stateOperation('rename', temp, () => rename(temp, target));
|
|
86
|
+
}, [() => this.remove(temp), () => this.remove(target)]);
|
|
87
|
+
}
|
|
28
88
|
async write(key, value) {
|
|
29
|
-
await
|
|
89
|
+
await this.prepare();
|
|
30
90
|
const path = this.path(key), temp = `${path}.${randomUUID()}.tmp`;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
await file.close();
|
|
38
|
-
}
|
|
39
|
-
await rename(temp, path);
|
|
91
|
+
await withStateCleanup(async () => {
|
|
92
|
+
await this.writeFile(temp, JSON.stringify(value));
|
|
93
|
+
await stateOperation('rename', temp, () => rename(temp, path));
|
|
94
|
+
}, [() => this.remove(temp)]);
|
|
40
95
|
}
|
|
41
|
-
async
|
|
42
|
-
await
|
|
43
|
-
const path = `${this.path(key)}.lock`;
|
|
44
|
-
// 不回收无法确认归属的锁。已退出进程的遗留锁可在下一次操作恢复。
|
|
45
|
-
let lock;
|
|
46
|
-
try {
|
|
47
|
-
lock = await open(path, 'wx', 0o600);
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
if (error.code !== 'EEXIST')
|
|
51
|
-
throw error;
|
|
52
|
-
// 遗留锁回收也必须互斥,避免两个恢复进程误删对方刚取得的新锁。
|
|
53
|
-
const recoveryPath = `${path}.recovery`;
|
|
54
|
-
let recovery;
|
|
96
|
+
async owner(path) {
|
|
97
|
+
const content = await stateOperation('read-lock', path, async () => {
|
|
55
98
|
try {
|
|
56
|
-
|
|
99
|
+
return await readFile(path, 'utf8');
|
|
57
100
|
}
|
|
58
|
-
catch {
|
|
59
|
-
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (filesystemCode(error) === 'ENOENT')
|
|
103
|
+
throw new CliError('LOCAL_STATE_LOCKED', '本地状态锁已变化,请重新查询状态', { path });
|
|
104
|
+
throw error;
|
|
60
105
|
}
|
|
106
|
+
});
|
|
107
|
+
const pid = Number(content);
|
|
108
|
+
return Number.isSafeInteger(pid) && pid > 0 ? pid : undefined;
|
|
109
|
+
}
|
|
110
|
+
async alive(pid, path) {
|
|
111
|
+
return stateOperation('check-lock-owner', path, async () => {
|
|
61
112
|
try {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
113
|
+
process.kill(pid, 0);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (filesystemCode(error) === 'ESRCH')
|
|
118
|
+
return false;
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
recoveryRequired(path, lockPid) {
|
|
124
|
+
return new CliError('LOCAL_STATE_RECOVERY_REQUIRED', '本地状态锁无法安全自动回收;请先确认没有写入进程,再备份并恢复所列锁文件,不要反复重试或按文件年龄强制删除', { path, lockPid });
|
|
125
|
+
}
|
|
126
|
+
async locked(key, run) {
|
|
127
|
+
await this.prepare();
|
|
128
|
+
const path = `${this.path(key)}.lock`;
|
|
129
|
+
let lock;
|
|
130
|
+
const acquire = () => open(path, 'wx', 0o600);
|
|
131
|
+
return withStateCleanup(async () => {
|
|
132
|
+
// 恢复分支清理失败时,外层仍会释放刚取得的业务锁。
|
|
133
|
+
await stateOperation('acquire-lock', path, async () => {
|
|
80
134
|
try {
|
|
81
|
-
lock = await
|
|
135
|
+
lock = await acquire();
|
|
136
|
+
return;
|
|
82
137
|
}
|
|
83
|
-
catch {
|
|
84
|
-
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (filesystemCode(error) !== 'EEXIST')
|
|
140
|
+
throw error;
|
|
85
141
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
142
|
+
const recoveryPath = `${path}.recovery`;
|
|
143
|
+
const recovery = await stateOperation('acquire-recovery-lock', recoveryPath, async () => {
|
|
144
|
+
try {
|
|
145
|
+
return await open(recoveryPath, 'wx', 0o600);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (filesystemCode(error) !== 'EEXIST')
|
|
149
|
+
throw error;
|
|
150
|
+
const pid = await this.owner(recoveryPath);
|
|
151
|
+
if (pid !== undefined && (await this.alive(pid, recoveryPath)))
|
|
152
|
+
throw new CliError('LOCAL_STATE_LOCKED', '本地状态锁正在恢复,请等待持有进程结束', {
|
|
153
|
+
path: recoveryPath,
|
|
154
|
+
lockPid: pid,
|
|
155
|
+
});
|
|
156
|
+
// 旧空锁或已退出恢复进程的锁无法凭年龄判断归属,必须显式维护。
|
|
157
|
+
throw this.recoveryRequired(recoveryPath, pid);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
await withStateCleanup(async () => {
|
|
161
|
+
await stateOperation('write-lock-owner', recoveryPath, () => recovery.writeFile(String(process.pid)));
|
|
162
|
+
const pid = await this.owner(path);
|
|
163
|
+
if (pid === undefined)
|
|
164
|
+
throw this.recoveryRequired(path);
|
|
165
|
+
if (await this.alive(pid, path))
|
|
166
|
+
throw new CliError('LOCAL_STATE_LOCKED', '本地状态正在由其他进程更新,请等待该进程结束', {
|
|
167
|
+
path,
|
|
168
|
+
lockPid: pid,
|
|
169
|
+
});
|
|
170
|
+
await this.remove(path);
|
|
171
|
+
try {
|
|
172
|
+
lock = await acquire();
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (filesystemCode(error) !== 'EEXIST')
|
|
176
|
+
throw error;
|
|
177
|
+
throw new CliError('LOCAL_STATE_LOCKED', '其他进程已取得本地状态锁,请稍后查询', { path });
|
|
178
|
+
}
|
|
179
|
+
}, [() => this.close(recovery, recoveryPath), () => this.remove(recoveryPath)]);
|
|
180
|
+
});
|
|
181
|
+
await stateOperation('write-lock-owner', path, () => lock.writeFile(String(process.pid)));
|
|
182
|
+
return run();
|
|
183
|
+
}, [
|
|
184
|
+
async () => {
|
|
185
|
+
if (lock)
|
|
186
|
+
await this.close(lock, path);
|
|
187
|
+
},
|
|
188
|
+
async () => {
|
|
189
|
+
if (lock)
|
|
190
|
+
await this.remove(path);
|
|
191
|
+
},
|
|
192
|
+
]);
|
|
100
193
|
}
|
|
101
194
|
}
|
|
102
195
|
//# sourceMappingURL=draft-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft-store.js","sourceRoot":"","sources":["../../src/interactions/draft-store.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"draft-store.js","sourceRoot":"","sources":["../../src/interactions/draft-store.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAy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error: unknown): string | undefined;
|
|
2
|
+
export declare function stateOperation<T>(operation: string, path: string, run: () => Promise<T>): Promise<T>;
|
|
3
|
+
/** 所有清理均尝试执行;清理异常不能覆盖首次异常。 */
|
|
4
|
+
export declare function withStateCleanup<T>(run: () => Promise<T>, cleanup: Array<() => Promise<unknown>>): Promise<T>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** 保留状态操作与清理失败的诊断信息,不输出状态内容。@author xiuyu.yi */
|
|
2
|
+
import { CliError } from '../output/exit-codes.js';
|
|
3
|
+
export function filesystemCode(error) {
|
|
4
|
+
return error && typeof error === 'object' && 'code' in error && typeof error.code === 'string'
|
|
5
|
+
? error.code
|
|
6
|
+
: undefined;
|
|
7
|
+
}
|
|
8
|
+
export async function stateOperation(operation, path, run) {
|
|
9
|
+
try {
|
|
10
|
+
return await run();
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
if (error instanceof CliError)
|
|
14
|
+
throw error;
|
|
15
|
+
const code = filesystemCode(error);
|
|
16
|
+
const denied = code === 'EPERM' || code === 'EACCES';
|
|
17
|
+
throw new CliError(denied ? 'LOCAL_STATE_PERMISSION_DENIED' : 'LOCAL_STATE_IO_ERROR', denied
|
|
18
|
+
? '本地状态目录权限不足,请检查所列路径的文件操作权限;不要重复提交业务请求'
|
|
19
|
+
: '本地状态文件操作失败,请根据操作和路径排查;不要重复提交业务请求', { filesystemCode: code, operation, path });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** 所有清理均尝试执行;清理异常不能覆盖首次异常。 */
|
|
23
|
+
export async function withStateCleanup(run, cleanup) {
|
|
24
|
+
let failed = false;
|
|
25
|
+
let primary;
|
|
26
|
+
let result;
|
|
27
|
+
try {
|
|
28
|
+
result = await run();
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
failed = true;
|
|
32
|
+
primary = error;
|
|
33
|
+
}
|
|
34
|
+
const errors = [];
|
|
35
|
+
for (const clean of cleanup) {
|
|
36
|
+
try {
|
|
37
|
+
await clean();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
errors.push(error instanceof CliError ? error : new CliError('LOCAL_STATE_IO_ERROR', '本地状态清理失败'));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (errors.length) {
|
|
44
|
+
const first = failed
|
|
45
|
+
? primary instanceof CliError
|
|
46
|
+
? primary
|
|
47
|
+
: new CliError('PROTOCOL_ERROR', '操作失败且本地状态清理失败,请保留现场排查')
|
|
48
|
+
: errors.shift();
|
|
49
|
+
throw new CliError(first.code, first.message, {
|
|
50
|
+
...first.details,
|
|
51
|
+
...(errors.length
|
|
52
|
+
? {
|
|
53
|
+
cleanupErrors: [
|
|
54
|
+
...(Array.isArray(first.details.cleanupErrors) ? first.details.cleanupErrors : []),
|
|
55
|
+
...errors.map((error) => ({ ...error.details, code: error.code })),
|
|
56
|
+
],
|
|
57
|
+
}
|
|
58
|
+
: {}),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (failed)
|
|
62
|
+
throw primary;
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=state-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-storage.js","sourceRoot":"","sources":["../../src/interactions/state-storage.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAC5F,CAAC,CAAC,KAAK,CAAC,IAAI;QACZ,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAI,SAAiB,EAAE,IAAY,EAAE,GAAqB;IAC5F,IAAI,CA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AC;QAClB,MAAM,KAAK,GAAG,MAAM;YAClB,CAAC,CAAC,OAAO,YAAY,QAAQ;gBAC3B,CAAC,CAAC,OAAO;gBACT,CAAC,CAAC,IAAI,QAAQ,CAAC,gBAAgB,EAAE,uBAAuB,CAAC;YAC3D,CAAC,CAAC,MAAM,CAAC,KAAK,EAAG,CAAC;QACpB,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE;YAC5C,GAAG,KAAK,CAAC,OAAO;YAChB,GAAG,CAAC,MAAM,CAAC,MAAM;gBACf,CAAC,CAAC;oBACE,aAAa,EAAE;wBACb,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;wBAClF,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;qBACnE;iBACF;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM;QAAE,MAAM,OAAO,CAAC;IAC1B,OAAO,MAAO,CAAC;AACjB,CAAC"}
|
|
@@ -12,6 +12,10 @@ export declare const EXIT_CODES: {
|
|
|
12
12
|
readonly UNSUPPORTED_INTERACTION: 6;
|
|
13
13
|
readonly LOCAL_WAIT_TIMEOUT: 7;
|
|
14
14
|
readonly PROTOCOL_ERROR: 8;
|
|
15
|
+
readonly LOCAL_STATE_PERMISSION_DENIED: 9;
|
|
16
|
+
readonly LOCAL_STATE_IO_ERROR: 9;
|
|
17
|
+
readonly LOCAL_STATE_LOCKED: 9;
|
|
18
|
+
readonly LOCAL_STATE_RECOVERY_REQUIRED: 9;
|
|
15
19
|
readonly INTERRUPTED: 130;
|
|
16
20
|
};
|
|
17
21
|
export type ErrorCode = keyof typeof EXIT_CODES;
|
|
@@ -12,6 +12,10 @@ export const EXIT_CODES = {
|
|
|
12
12
|
UNSUPPORTED_INTERACTION: 6,
|
|
13
13
|
LOCAL_WAIT_TIMEOUT: 7,
|
|
14
14
|
PROTOCOL_ERROR: 8,
|
|
15
|
+
LOCAL_STATE_PERMISSION_DENIED: 9,
|
|
16
|
+
LOCAL_STATE_IO_ERROR: 9,
|
|
17
|
+
LOCAL_STATE_LOCKED: 9,
|
|
18
|
+
LOCAL_STATE_RECOVERY_REQUIRED: 9,
|
|
15
19
|
INTERRUPTED: 130,
|
|
16
20
|
};
|
|
17
21
|
export class CliError extends Error {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exit-codes.js","sourceRoot":"","sources":["../../src/output/exit-codes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,gBAAgB,EAAE,CAAC;IACnB,aAAa,EAAE,CAAC;IAChB,eAAe,EAAE,CAAC;IAClB,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE,CAAC;IACvB,cAAc,EAAE,CAAC;IACjB,iBAAiB,EAAE,CAAC;IACpB,qBAAqB,EAAE,CAAC;IACxB,eAAe,EAAE,CAAC;IAClB,uBAAuB,EAAE,CAAC;IAC1B,kBAAkB,EAAE,CAAC;IACrB,cAAc,EAAE,CAAC;IACjB,WAAW,EAAE,GAAG;CACR,CAAC;AAIX,MAAM,OAAO,QAAS,SAAQ,KAAK;IAEtB;IAEA;IAHX,YACW,IAAe,EACxB,OAAe,EACN,UAAmC,EAAE;QAE9C,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAW;QAEf,YAAO,GAAP,OAAO,CAA8B;QAG9C,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"exit-codes.js","sourceRoot":"","sources":["../../src/output/exit-codes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,gBAAgB,EAAE,CAAC;IACnB,aAAa,EAAE,CAAC;IAChB,eAAe,EAAE,CAAC;IAClB,aAAa,EAAE,CAAC;IAChB,oBAAoB,EAAE,CAAC;IACvB,cAAc,EAAE,CAAC;IACjB,iBAAiB,EAAE,CAAC;IACpB,qBAAqB,EAAE,CAAC;IACxB,eAAe,EAAE,CAAC;IAClB,uBAAuB,EAAE,CAAC;IAC1B,kBAAkB,EAAE,CAAC;IACrB,cAAc,EAAE,CAAC;IACjB,6BAA6B,EAAE,CAAC;IAChC,oBAAoB,EAAE,CAAC;IACvB,kBAAkB,EAAE,CAAC;IACrB,6BAA6B,EAAE,CAAC;IAChC,WAAW,EAAE,GAAG;CACR,CAAC;AAIX,MAAM,OAAO,QAAS,SAAQ,KAAK;IAEtB;IAEA;IAHX,YACW,IAAe,EACxB,OAAe,EACN,UAAmC,EAAE;QAE9C,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAW;QAEf,YAAO,GAAP,OAAO,CAA8B;QAG9C,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF"}
|
package/dist/program.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** 命令树与公共选项。@author xiuyu.yi */
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { COMMAND_NAME, PACKAGE_VERSION } from './config/constants.js';
|
|
4
|
-
import { requireCredentials } from './commands/shared.js';
|
|
4
|
+
import { requireCredentials, rememberExplicitSession } from './commands/shared.js';
|
|
5
5
|
import { registerAuth } from './commands/auth/index.js';
|
|
6
6
|
import { registerSession } from './commands/session/index.js';
|
|
7
7
|
import { registerChat } from './commands/chat/index.js';
|
|
@@ -20,6 +20,8 @@ export function createProgram(context, hooks) {
|
|
|
20
20
|
context.connection = undefined;
|
|
21
21
|
context.sessionBinding = undefined;
|
|
22
22
|
context.selectedSessionId = undefined;
|
|
23
|
+
context.selectionRequestedAt = new Date().toISOString();
|
|
24
|
+
context.rememberSession = undefined;
|
|
23
25
|
const rootCommand = action.parent === program;
|
|
24
26
|
const authCommand = action.parent?.name() === 'auth' && action.parent.parent === program;
|
|
25
27
|
const offline = (rootCommand && (action.name() === 'version' || action.name() === 'update')) ||
|
|
@@ -29,6 +31,7 @@ export function createProgram(context, hooks) {
|
|
|
29
31
|
await hooks.beforeBusiness();
|
|
30
32
|
if (!(authCommand && action.name() === 'login'))
|
|
31
33
|
await requireCredentials(context, action, !authCommand);
|
|
34
|
+
rememberExplicitSession(context, action);
|
|
32
35
|
});
|
|
33
36
|
registerAuth(program, context);
|
|
34
37
|
registerSession(program, context);
|
package/dist/program.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MA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E,OAAO;QAC1C,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;QAC7B,IAAI,CAAC,CAAC,WAAW,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,OAAO,CAAC;YAAE,MAAM,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,WAAW,CAAC,CAAC;QACzG,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/B,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/B,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtD,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACrC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,74 +1,27 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
import type { CreationRuntime } from '../runtime.js';
|
|
3
2
|
import type { HostContext } from './host-context.js';
|
|
4
|
-
declare const recordSchema: z.ZodEffects<z.ZodObject<{
|
|
5
|
-
version: z.ZodLiteral<1>;
|
|
6
|
-
revision: z.ZodString;
|
|
7
|
-
updatedAt: z.ZodString;
|
|
8
|
-
state: z.ZodEnum<["UNBOUND", "BOUND", "CREATING", "CREATE_FAILED", "CREATE_UNKNOWN"]>;
|
|
9
|
-
sessionId: z.ZodOptional<z.ZodString>;
|
|
10
|
-
}, "strict", z.ZodTypeAny, {
|
|
11
|
-
version: 1;
|
|
12
|
-
revision: string;
|
|
13
|
-
updatedAt: string;
|
|
14
|
-
state: "UNBOUND" | "BOUND" | "CREATING" | "CREATE_FAILED" | "CREATE_UNKNOWN";
|
|
15
|
-
sessionId?: string | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
version: 1;
|
|
18
|
-
revision: string;
|
|
19
|
-
updatedAt: string;
|
|
20
|
-
state: "UNBOUND" | "BOUND" | "CREATING" | "CREATE_FAILED" | "CREATE_UNKNOWN";
|
|
21
|
-
sessionId?: string | undefined;
|
|
22
|
-
}>, {
|
|
23
|
-
version: 1;
|
|
24
|
-
revision: string;
|
|
25
|
-
updatedAt: string;
|
|
26
|
-
state: "UNBOUND" | "BOUND" | "CREATING" | "CREATE_FAILED" | "CREATE_UNKNOWN";
|
|
27
|
-
sessionId?: string | undefined;
|
|
28
|
-
}, {
|
|
29
|
-
version: 1;
|
|
30
|
-
revision: string;
|
|
31
|
-
updatedAt: string;
|
|
32
|
-
state: "UNBOUND" | "BOUND" | "CREATING" | "CREATE_FAILED" | "CREATE_UNKNOWN";
|
|
33
|
-
sessionId?: string | undefined;
|
|
34
|
-
}>;
|
|
35
|
-
type BindingRecord = z.infer<typeof recordSchema>;
|
|
36
|
-
type BindingValue = Pick<BindingRecord, 'state' | 'sessionId'>;
|
|
37
3
|
export declare class SessionBinding {
|
|
38
4
|
readonly host: HostContext;
|
|
39
|
-
private readonly
|
|
5
|
+
private readonly creationStore;
|
|
6
|
+
private readonly bindings;
|
|
40
7
|
private readonly key;
|
|
41
8
|
constructor(host: HostContext, endpoint: string, userCode: string, root?: string);
|
|
42
|
-
static connect(service: CreationRuntime, host: HostContext): Promise<SessionBinding>;
|
|
43
|
-
private
|
|
44
|
-
read(): Promise<BindingRecord | undefined>;
|
|
9
|
+
static connect(service: Pick<CreationRuntime, 'client'>, host: HostContext): Promise<SessionBinding>;
|
|
10
|
+
private creation;
|
|
45
11
|
current(): Promise<{
|
|
46
|
-
|
|
12
|
+
state: "CREATING" | "CREATE_UNKNOWN" | "CREATE_FAILED" | "RESOLVED";
|
|
47
13
|
revision: string;
|
|
48
|
-
|
|
49
|
-
state: "UNBOUND" | "BOUND" | "CREATING" | "CREATE_FAILED" | "CREATE_UNKNOWN";
|
|
50
|
-
sessionId?: string | undefined;
|
|
14
|
+
requestedAt: string;
|
|
51
15
|
host: HostContext;
|
|
52
16
|
} | {
|
|
53
|
-
state: "UNBOUND";
|
|
54
|
-
host: HostContext;
|
|
55
|
-
}>;
|
|
56
|
-
private save;
|
|
57
|
-
select(service: CreationRuntime, sessionId: string): Promise<{
|
|
58
|
-
version: 1;
|
|
59
|
-
revision: string;
|
|
60
|
-
updatedAt: string;
|
|
61
|
-
state: "UNBOUND" | "BOUND" | "CREATING" | "CREATE_FAILED" | "CREATE_UNKNOWN";
|
|
62
|
-
sessionId?: string | undefined;
|
|
63
|
-
}>;
|
|
64
|
-
clear(): Promise<{
|
|
65
|
-
version: 1;
|
|
66
|
-
revision: string;
|
|
67
|
-
updatedAt: string;
|
|
68
|
-
state: "UNBOUND" | "BOUND" | "CREATING" | "CREATE_FAILED" | "CREATE_UNKNOWN";
|
|
69
17
|
sessionId?: string | undefined;
|
|
18
|
+
host: HostContext;
|
|
19
|
+
state: "BOUND" | "UNBOUND";
|
|
70
20
|
}>;
|
|
71
|
-
|
|
72
|
-
|
|
21
|
+
select(service: CreationRuntime, sessionId: string): Promise<void>;
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
remember(sessionId: string, requestedAt: string): Promise<void>;
|
|
24
|
+
beginCreation(requestedAt?: string): Promise<string>;
|
|
25
|
+
matchesCreation(revision: string): Promise<boolean>;
|
|
26
|
+
finishCreation(revision: string, state: 'CREATE_FAILED' | 'CREATE_UNKNOWN' | 'RESOLVED'): Promise<boolean>;
|
|
73
27
|
}
|
|
74
|
-
export {};
|