@tulcn/lxz 0.3.1 → 0.4.0
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.md +6 -6
- package/dist/application.js +4 -2
- package/dist/cli/background.d.ts +14 -0
- package/dist/cli/background.js +35 -0
- package/dist/cli/contracts.d.ts +4 -10
- package/dist/cli/contracts.js +9 -4
- package/dist/cli/device-login.d.ts +1 -1
- package/dist/cli/device-login.js +36 -35
- package/dist/cli/identity-commands.d.ts +2 -2
- package/dist/cli/identity-commands.js +8 -6
- package/dist/cli/init.js +1 -1
- package/dist/cli/output.d.ts +2 -1
- package/dist/cli/output.js +10 -8
- package/dist/cli/runtime.js +31 -15
- package/dist/cli/schemas.js +0 -1
- package/dist/doctor.js +1 -1
- package/dist/skills/agents.js +1 -1
- package/dist/skills/commands.d.ts +2 -2
- package/dist/skills/commands.js +3 -3
- package/dist/skills/delivery.js +2 -2
- package/package.json +1 -1
- package/skills/SKILL.md +5 -5
- package/skills/bundle.json +2 -2
- package/skills/commands.md +17 -29
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
准备 Node.js >=22.12 和 pnpm 12。从 npm 官方源直接运行推荐版(`latest`),以下命令适用于 pwsh 和 bash:
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
pnpm dlx @tulcn/lxz --version
|
|
10
|
+
pnpm dlx @tulcn/lxz --version
|
|
11
11
|
pnpm dlx @tulcn/lxz --help
|
|
12
12
|
```
|
|
13
13
|
|
|
@@ -20,7 +20,7 @@ lxz --version
|
|
|
20
20
|
|
|
21
21
|
安装输出提示 `Ignored build scripts`,或使用 `--ignore-scripts` 等不运行安装脚本的方式安装时,按下文“Agent 接入”运行 `install skill` 补装。
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
普通命令、帮助和版本输出文本;Agent 使用 `--non-interactive`,失败时读取 stderr 和退出码。`lxz auth --schema --json` 返回授权分组的 JSON 契约。输出按 UTF-8 解码;PowerShell 捕获输出时,在当前会话先执行:
|
|
24
24
|
|
|
25
25
|
```powershell
|
|
26
26
|
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
|
|
@@ -36,8 +36,8 @@ lxz --version
|
|
|
36
36
|
|
|
37
37
|
```sh
|
|
38
38
|
pnpm dlx @tulcn/lxz auth login --client-id '<CLI 标识>'
|
|
39
|
-
pnpm dlx @tulcn/lxz auth status --client-id '<CLI 标识>'
|
|
40
|
-
pnpm dlx @tulcn/lxz doctor --client-id '<CLI 标识>'
|
|
39
|
+
pnpm dlx @tulcn/lxz auth status --client-id '<CLI 标识>'
|
|
40
|
+
pnpm dlx @tulcn/lxz doctor --client-id '<CLI 标识>'
|
|
41
41
|
pnpm dlx @tulcn/lxz auth logout --client-id '<CLI 标识>'
|
|
42
42
|
```
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ pnpm dlx @tulcn/lxz auth logout --client-id '<CLI 标识>'
|
|
|
45
45
|
|
|
46
46
|
Agent 或脚本登录时加 `--device-login --non-interactive`,默认仍打开浏览器。命令拿到授权链接和用户码后立即返回 `status: pending`,由后台进程继续等待;把链接和用户码交给用户,再运行 `auth status --wait-seconds 170`(带同样的 `--client-id`),批准后立即返回。再加 `--no-browser` 时不打开浏览器,可在另一设备打开链接;需要原命令一直等到批准时加 `--wait`,默认最多 660 秒。
|
|
47
47
|
|
|
48
|
-
`pnpm dlx @tulcn/lxz auth whoami --client-id '<CLI 标识>'
|
|
48
|
+
`pnpm dlx @tulcn/lxz auth whoami --client-id '<CLI 标识>'` 显示本机保存的人员编号 `account`、登录名 `loginName`、显示名 `displayName` 及授权有效期。`clientId` 是 CLI 标识;身份字段按后端实际提供的内容显示。服务端在执行业务请求时校验权限。
|
|
49
49
|
|
|
50
50
|
`doctor` 检查 Node.js 与 pnpm 版本、pnpm 为 `@tulcn` 包配置的源(未单独配置时为默认源)能否取到 `@tulcn/lxz`、授权服务和本机登录状态,不发起登录。
|
|
51
51
|
|
|
@@ -57,7 +57,7 @@ Agent 或脚本登录时加 `--device-login --non-interactive`,默认仍打开
|
|
|
57
57
|
pnpm dlx @tulcn/lxz install skill --skills-dir '<Agent 的 Skills 根目录>'
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
Skill 写入该目录下的 `lxz/`。安装目录优先使用 `--skills-dir`,其次为 `LXZ_SKILLS_DIR
|
|
60
|
+
Skill 写入该目录下的 `lxz/`。安装目录优先使用 `--skills-dir`,其次为 `LXZ_SKILLS_DIR`,首次默认安装到 `~/.linkwise/skills`。安装位置会登记,后续未指定目录时同步已登记的位置;`LXZ_SKILLS_STATE_DIR` 可指定登记记录的目录。
|
|
61
61
|
|
|
62
62
|
全局安装时,postinstall 在获准运行后自动安装 Skill;pnpm 默认会跳过它,其他包管理器或公司策略也可能跳过,请显式运行上述命令确认安装(已安装同一版本时不会重复写入)。本地修改引起冲突时先备份,再使用 `--skill-conflict replace` 替换。
|
|
63
63
|
|
package/dist/application.js
CHANGED
|
@@ -4,14 +4,16 @@ import { identityCommands, registerCommandModules } from './cli/index.js';
|
|
|
4
4
|
import { BundledSkill, skillCommands } from './skills/index.js';
|
|
5
5
|
import { doctor } from './doctor.js';
|
|
6
6
|
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
7
|
-
const
|
|
7
|
+
const output = { jsonOutput: 'schema' };
|
|
8
|
+
const commands = identityCommands((input) => defaultIdentity(typeof input['client-id'] === 'string' ? input['client-id'] : undefined), 'pnpm dlx @tulcn/lxz auth', output);
|
|
8
9
|
for (const command of Object.values(commands))
|
|
9
10
|
command.parameters = { ...command.parameters, 'client-id': { type: 'string', description: 'Client ID to manage; defaults to LXZ_AUTH_CLIENT_ID' } };
|
|
10
11
|
export const application = {
|
|
11
12
|
name: 'lxz', packageName: pkg.name, version: pkg.version, description: 'Linkwise CLI authorization and diagnostics',
|
|
13
|
+
...output,
|
|
12
14
|
commands: registerCommandModules([
|
|
13
15
|
{ id: 'authorization', commands: { ...Object.fromEntries(Object.entries(commands).map(([name, command]) => ['auth ' + name, command])), 'auth whoami': { ...commands.status, description: 'Show the local account authorized for this CLI' } } },
|
|
14
16
|
{ id: 'diagnostics', commands: { doctor } },
|
|
15
|
-
{ id: 'skill', commands: skillCommands(new BundledSkill(new URL('../', import.meta.url), 'lxz'), 'pnpm dlx @tulcn/lxz') },
|
|
17
|
+
{ id: 'skill', commands: skillCommands(new BundledSkill(new URL('../', import.meta.url), 'lxz'), 'pnpm dlx @tulcn/lxz', output) },
|
|
16
18
|
]),
|
|
17
19
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { failure } from './errors.js';
|
|
2
|
+
export declare const backgroundArgument = "--lxz-background";
|
|
3
|
+
export type BackgroundResult = {
|
|
4
|
+
ok: true;
|
|
5
|
+
data: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
error: ReturnType<typeof failure>;
|
|
9
|
+
};
|
|
10
|
+
export declare function readBackgroundResult(value: unknown): BackgroundResult | undefined;
|
|
11
|
+
export declare function backgroundInvocation(argv: string[]): {
|
|
12
|
+
argv: string[];
|
|
13
|
+
complete(result: BackgroundResult): Promise<void> | undefined;
|
|
14
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { exitCodes } from './errors.js';
|
|
2
|
+
export const backgroundArgument = '--lxz-background';
|
|
3
|
+
function errorCode(value) {
|
|
4
|
+
return typeof value === 'string' && Object.hasOwn(exitCodes, value);
|
|
5
|
+
}
|
|
6
|
+
export function readBackgroundResult(value) {
|
|
7
|
+
if (typeof value !== 'object' || value === null || !('type' in value) || value.type !== 'lxz:result' || !('ok' in value))
|
|
8
|
+
return;
|
|
9
|
+
if (value.ok === true && 'data' in value)
|
|
10
|
+
return { ok: true, data: value.data };
|
|
11
|
+
if (value.ok !== false || !('error' in value) || typeof value.error !== 'object' || value.error === null)
|
|
12
|
+
return;
|
|
13
|
+
const error = value.error;
|
|
14
|
+
if ('code' in error && errorCode(error.code) && 'message' in error && typeof error.message === 'string'
|
|
15
|
+
&& 'next' in error && typeof error.next === 'string' && 'retryable' in error && typeof error.retryable === 'boolean') {
|
|
16
|
+
return { ok: false, error: { code: error.code, message: error.message, next: error.next, retryable: error.retryable, ...('details' in error ? { details: error.details } : {}) } };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function backgroundInvocation(argv) {
|
|
20
|
+
const enabled = process.connected && argv.at(-1) === backgroundArgument;
|
|
21
|
+
return {
|
|
22
|
+
argv: enabled ? argv.slice(0, -1) : argv,
|
|
23
|
+
complete(result) {
|
|
24
|
+
if (!enabled || !process.connected)
|
|
25
|
+
return;
|
|
26
|
+
return new Promise(resolve => {
|
|
27
|
+
process.send({ type: 'lxz:result', ...result }, () => {
|
|
28
|
+
if (process.connected)
|
|
29
|
+
process.disconnect();
|
|
30
|
+
resolve();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
package/dist/cli/contracts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ArgDef } from 'citty';
|
|
2
2
|
export declare const contractVersion = "1.0.0";
|
|
3
|
+
export type CharacterEscaping = 'escaped' | 'literal';
|
|
3
4
|
export interface Parameter {
|
|
4
5
|
type: 'string' | 'boolean';
|
|
5
6
|
description: string;
|
|
@@ -36,19 +37,12 @@ export interface Application {
|
|
|
36
37
|
version: string;
|
|
37
38
|
description: string;
|
|
38
39
|
defaultCommand?: string;
|
|
40
|
+
characterEscaping?: CharacterEscaping;
|
|
41
|
+
jsonOutput?: boolean | 'schema';
|
|
39
42
|
commands: Record<string, Command>;
|
|
40
43
|
}
|
|
41
44
|
export declare const commonParameters: Record<string, Parameter>;
|
|
42
|
-
export declare function commandParameters(command?: Command):
|
|
43
|
-
'timeout-ms'?: {
|
|
44
|
-
description: string;
|
|
45
|
-
default?: string | boolean;
|
|
46
|
-
type: "string" | "boolean";
|
|
47
|
-
required?: boolean;
|
|
48
|
-
choices?: string[];
|
|
49
|
-
pattern?: string;
|
|
50
|
-
} | undefined;
|
|
51
|
-
};
|
|
45
|
+
export declare function commandParameters(command?: Command, options?: Pick<Application, 'jsonOutput'>): Record<string, Parameter>;
|
|
52
46
|
export declare function argumentDefinitions(parameters: Record<string, Parameter>): Record<string, ArgDef>;
|
|
53
47
|
export declare function describe(app: Application, scope?: string): {
|
|
54
48
|
contractVersion: string;
|
package/dist/cli/contracts.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
export const contractVersion = '1.0.0';
|
|
2
2
|
export const commonParameters = {
|
|
3
|
-
json: { type: 'boolean', description: 'Return a JSON receipt
|
|
3
|
+
json: { type: 'boolean', description: 'Return a JSON receipt for programmatic parsing', default: false },
|
|
4
4
|
'non-interactive': { type: 'boolean', description: 'Use command parameters without interactive prompts', default: false },
|
|
5
5
|
'timeout-ms': { type: 'string', description: 'Non-interactive deadline in ms (1-3600000); interactive prompts exit after 60 seconds without input', default: '120000', pattern: '^(?:[1-9][0-9]{0,5}|[12][0-9]{6}|3[0-5][0-9]{5}|3600000)$' },
|
|
6
6
|
help: { type: 'boolean', description: 'Show help for this command or group; same as -h' },
|
|
7
7
|
version: { type: 'boolean', description: 'Show version' },
|
|
8
8
|
schema: { type: 'boolean', description: 'Show command, input and result schemas' },
|
|
9
9
|
};
|
|
10
|
-
export function commandParameters(command) {
|
|
11
|
-
|
|
10
|
+
export function commandParameters(command, options = {}) {
|
|
11
|
+
const parameters = { ...commonParameters, ...(command?.timeoutMs || command?.interactiveTimeout === 'total' ? { 'timeout-ms': {
|
|
12
12
|
...commonParameters['timeout-ms'],
|
|
13
13
|
...(command.timeoutMs ? { default: String(command.timeoutMs) } : {}),
|
|
14
14
|
...(command.interactiveTimeout === 'total' ? { description: 'Total deadline in ms (1-3600000), including approval waits; keyboard inactivity does not end authorization' } : {}),
|
|
15
15
|
} } : {}), ...command?.parameters };
|
|
16
|
+
if (options.jsonOutput === false || options.jsonOutput === 'schema')
|
|
17
|
+
delete parameters.json;
|
|
18
|
+
if (options.jsonOutput === 'schema')
|
|
19
|
+
parameters.schema = { ...parameters.schema, description: 'Show command, input and result schemas; add --json for a JSON receipt' };
|
|
20
|
+
return parameters;
|
|
16
21
|
}
|
|
17
22
|
export function argumentDefinitions(parameters) {
|
|
18
23
|
return Object.fromEntries(Object.entries(parameters).map(([key, { choices, pattern, ...definition }]) => [key, definition]));
|
|
@@ -27,7 +32,7 @@ export function describe(app, scope) {
|
|
|
27
32
|
examples: command.examples,
|
|
28
33
|
input: {
|
|
29
34
|
type: 'object', additionalProperties: false,
|
|
30
|
-
properties: Object.fromEntries(Object.entries(commandParameters(command)).map(([name, { description, type, default: value, choices, pattern }]) => [name, {
|
|
35
|
+
properties: Object.fromEntries(Object.entries(commandParameters(command, app)).map(([name, { description, type, default: value, choices, pattern }]) => [name, {
|
|
31
36
|
type, description, ...(value === undefined ? {} : { default: value }), ...(choices ? { enum: choices } : {}), ...(pattern ? { pattern } : {}),
|
|
32
37
|
}])),
|
|
33
38
|
required: Object.entries(command.parameters ?? {}).filter(([, p]) => p.required).map(([name]) => name),
|
|
@@ -25,5 +25,5 @@ export declare const pendingProperties: {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
export declare function waitsInBackground(input: Record<string, string | boolean>, context: Context): boolean;
|
|
28
|
-
export declare function approvalNext(link: AuthorizationLink, status: string): string;
|
|
28
|
+
export declare function approvalNext(link: AuthorizationLink, status: string, json?: boolean): string;
|
|
29
29
|
export declare function deviceLoginInBackground(input: Record<string, string | boolean>, context: Context, pending: (link: AuthorizationLink) => unknown, entry?: string): Promise<unknown>;
|
package/dist/cli/device-login.js
CHANGED
|
@@ -5,6 +5,7 @@ import { join } from 'node:path';
|
|
|
5
5
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
6
|
import { openBrowser } from './browser.js';
|
|
7
7
|
import { CliError } from './errors.js';
|
|
8
|
+
import { backgroundArgument, readBackgroundResult } from './background.js';
|
|
8
9
|
const urlLabel = 'Authorization URL: ', codeLabel = 'User code: ';
|
|
9
10
|
export const authorizationPrompt = (url, code) => `${urlLabel}${url}\n${codeLabel}${code}`;
|
|
10
11
|
const labelled = (text, label) => text.split(/\r?\n/).find(line => line.startsWith(label))?.slice(label.length).trim();
|
|
@@ -12,7 +13,7 @@ export const statusWaitLimitSeconds = 170;
|
|
|
12
13
|
const linkDeadlineMs = 30000;
|
|
13
14
|
// An approval that is already done, or an issuer that approves at once, still finishes in the foreground.
|
|
14
15
|
const graceMs = 3000;
|
|
15
|
-
export const waitParameter = { type: 'boolean', description: 'With --device-login in non-interactive mode, wait for approval in the foreground
|
|
16
|
+
export const waitParameter = { type: 'boolean', description: 'With --device-login in non-interactive mode, wait for browser approval in the foreground', default: false };
|
|
16
17
|
export const pendingProperties = {
|
|
17
18
|
authorizationUrl: { type: 'string' }, userCode: { type: 'string' },
|
|
18
19
|
browserOpened: { type: 'boolean', description: 'This command opened the authorization page in the system browser' },
|
|
@@ -21,31 +22,21 @@ export const pendingProperties = {
|
|
|
21
22
|
export function waitsInBackground(input, context) {
|
|
22
23
|
return Boolean(input['device-login'] && !context.interactive && !input.wait && context.argv);
|
|
23
24
|
}
|
|
24
|
-
export function approvalNext(link, status) {
|
|
25
|
+
export function approvalNext(link, status, json = true) {
|
|
25
26
|
return (link.browserOpened
|
|
26
27
|
? 'The authorization page is open in the system browser on this computer. Tell the user to switch to the browser, check that it shows userCode and approve; also give the link and userCode in your reply in case the page did not appear. '
|
|
27
28
|
: 'Give the link and userCode in your reply and ask the user to open the link in the system browser, check userCode and approve. ')
|
|
28
|
-
+ 'Write authorizationUrl unchanged as a Markdown link on a line of its own, for example [Open the authorization page](authorizationUrl) with the label in the user\'s language
|
|
29
|
+
+ 'Write authorizationUrl unchanged as a Markdown link on a line of its own, for example [Open the authorization page](authorizationUrl), with the label in the user\'s language. Keep the link on its own line and write userCode on a separate line. '
|
|
29
30
|
+ 'In Linkwise a clicked link opens in the built-in browser, so tell the user to right-click it and choose to open it in the system browser. '
|
|
30
|
-
+ `
|
|
31
|
+
+ `In the same turn, immediately run ${status} --wait-seconds ${statusWaitLimitSeconds}${json ? ' --json' : ''} --non-interactive; it returns once the user approves. Continue the user's original task after approval. Reuse this authorization link while it is valid.`;
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (receipt.ok)
|
|
44
|
-
return receipt.data;
|
|
45
|
-
const { code, message, next, retryable, details } = receipt.error;
|
|
46
|
-
throw new CliError(code, message, next, retryable, details);
|
|
47
|
-
}
|
|
48
|
-
throw new CliError('UNAVAILABLE', 'Background authorization stopped without a result.', 'Run the command again.');
|
|
33
|
+
function finalResult(result) {
|
|
34
|
+
if (!result)
|
|
35
|
+
throw new CliError('UNAVAILABLE', 'Background authorization stopped without a result.', 'Run the command again.');
|
|
36
|
+
if (result.ok)
|
|
37
|
+
return result.data;
|
|
38
|
+
const { code, message, next, retryable, details } = result.error;
|
|
39
|
+
throw new CliError(code, message, next, retryable, details);
|
|
49
40
|
}
|
|
50
41
|
// Agents that show output only after a command exits cannot show the link of a device login that waits.
|
|
51
42
|
// A detached copy of this command waits instead; this one opens the browser once and returns the link.
|
|
@@ -53,8 +44,13 @@ export async function deviceLoginInBackground(input, context, pending, entry = p
|
|
|
53
44
|
const log = join(mkdtempSync(join(tmpdir(), 'lxz-authorization-')), 'authorization.log');
|
|
54
45
|
const output = openSync(log, 'a');
|
|
55
46
|
let exited = false;
|
|
47
|
+
let result;
|
|
48
|
+
let disconnect = () => { };
|
|
56
49
|
try {
|
|
57
|
-
const child = spawn(process.execPath, [...process.execArgv, entry, ...context.argv, '--wait', '--no-browser', '--non-interactive',
|
|
50
|
+
const child = spawn(process.execPath, [...process.execArgv, entry, ...context.argv, '--wait', '--no-browser', '--non-interactive', backgroundArgument], { detached: true, windowsHide: true, stdio: ['ignore', output, output, 'ipc'] });
|
|
51
|
+
child.once('message', message => { result = readBackgroundResult(message); });
|
|
52
|
+
disconnect = () => { if (child.connected)
|
|
53
|
+
child.disconnect(); };
|
|
58
54
|
child.once('exit', () => { exited = true; });
|
|
59
55
|
child.once('error', () => { exited = true; });
|
|
60
56
|
child.unref();
|
|
@@ -69,19 +65,24 @@ export async function deviceLoginInBackground(input, context, pending, entry = p
|
|
|
69
65
|
return '';
|
|
70
66
|
} };
|
|
71
67
|
let seen = 0, browser;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
68
|
+
try {
|
|
69
|
+
for (const start = Date.now(); Date.now() - start < linkDeadlineMs;) {
|
|
70
|
+
await delay(200, undefined, { signal: context.signal });
|
|
71
|
+
const text = read();
|
|
72
|
+
if (result || exited)
|
|
73
|
+
return finalResult(result);
|
|
74
|
+
const authorizationUrl = labelled(text, urlLabel), userCode = labelled(text, codeLabel);
|
|
75
|
+
if (!authorizationUrl || !userCode)
|
|
76
|
+
continue;
|
|
77
|
+
seen ||= Date.now();
|
|
78
|
+
browser ??= input.browser === false ? Promise.resolve(false) : openBrowser(authorizationUrl, context.signal);
|
|
79
|
+
if (Date.now() - seen < graceMs)
|
|
80
|
+
continue;
|
|
81
|
+
return pending({ authorizationUrl, userCode, browserOpened: await browser, log });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
disconnect();
|
|
85
86
|
}
|
|
86
87
|
throw new CliError('UNAVAILABLE', 'Could not get an authorization link in time.', `Check the network and run the command again; the background log is ${log}.`, true);
|
|
87
88
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Command } from './contracts.js';
|
|
1
|
+
import type { Application, Command } from './contracts.js';
|
|
2
2
|
import type { IdentityPort } from './init.js';
|
|
3
|
-
export declare function identityCommands(identity: (input: Record<string, string | boolean>) => IdentityPort, invoke: string): Record<string, Command>;
|
|
3
|
+
export declare function identityCommands(identity: (input: Record<string, string | boolean>) => IdentityPort, invoke: string, options?: Pick<Application, 'jsonOutput'>): Record<string, Command>;
|
|
@@ -2,14 +2,16 @@ import { setTimeout as delay } from 'node:timers/promises';
|
|
|
2
2
|
import { errorSchema } from './schemas.js';
|
|
3
3
|
import { approvalNext, deviceLoginInBackground, pendingProperties, statusWaitLimitSeconds, waitParameter, waitsInBackground } from './device-login.js';
|
|
4
4
|
const pollMs = 2000;
|
|
5
|
-
export function identityCommands(identity, invoke) {
|
|
5
|
+
export function identityCommands(identity, invoke, options = {}) {
|
|
6
|
+
const json = options.jsonOutput !== false && options.jsonOutput !== 'schema';
|
|
7
|
+
const outputFlag = json ? ' --json' : '';
|
|
6
8
|
const status = {
|
|
7
9
|
description: 'Show this CLI authorization status and current account', effects: 'none', timeoutMs: (statusWaitLimitSeconds + 5) * 1000,
|
|
8
10
|
parameters: {
|
|
9
11
|
'wait-seconds': { type: 'string', default: '0', pattern: `^(?:0|[1-9][0-9]?|1[0-6][0-9]|${statusWaitLimitSeconds})$`, description: `Wait up to this many seconds (0-${statusWaitLimitSeconds}) for a pending browser approval; returns as soon as it is approved` },
|
|
10
12
|
},
|
|
11
13
|
result: { type: 'object', properties: { authorized: { type: 'boolean', description: 'Local session exists within its refresh lifetime; server status has not been checked' }, account: { type: 'string', description: 'Backend account ID; defaults to token sub, which may differ from the login name' }, loginName: { type: 'string', description: 'Backend login name from token name; omitted when unavailable' }, clientId: { type: 'string', description: 'CLI client ID, separate from account identity' }, displayName: { type: 'string', description: 'Backend display name; omitted when unavailable' }, accessExpiresAt: { type: 'number' }, refreshExpiresAt: { type: 'number' }, next: { type: 'string', description: 'What to do when the approval did not arrive in time' } }, required: ['authorized'] },
|
|
12
|
-
examples: [invoke +
|
|
14
|
+
examples: [invoke + ` status${outputFlag} --non-interactive`, `${invoke} status --wait-seconds ${statusWaitLimitSeconds}${outputFlag} --non-interactive`],
|
|
13
15
|
async run(input, context) {
|
|
14
16
|
const seconds = Number(input['wait-seconds'] ?? 0);
|
|
15
17
|
const deadline = Date.now() + seconds * 1000;
|
|
@@ -20,7 +22,7 @@ export function identityCommands(identity, invoke) {
|
|
|
20
22
|
if (Date.now() >= deadline)
|
|
21
23
|
return seconds ? {
|
|
22
24
|
authorized: false,
|
|
23
|
-
next: `Not approved within ${seconds} seconds. Ask the user whether they approved in the browser. If the link is still valid, run ${statusCommand(input)} --wait-seconds ${statusWaitLimitSeconds} --
|
|
25
|
+
next: `Not approved within ${seconds} seconds. Ask the user whether they approved in the browser. If the link is still valid, run ${statusCommand(input)} --wait-seconds ${statusWaitLimitSeconds}${outputFlag} --non-interactive again; if it expired or was refused, run the init or login command again with --device-login --non-interactive${outputFlag} for a new link.`,
|
|
24
26
|
} : { authorized: false };
|
|
25
27
|
await delay(Math.min(pollMs, deadline - Date.now()), undefined, { signal: context.signal });
|
|
26
28
|
}
|
|
@@ -37,10 +39,10 @@ export function identityCommands(identity, invoke) {
|
|
|
37
39
|
browser: { type: 'boolean', description: 'Open the authorization page in the default browser; use --no-browser to open the URL on another device', default: true },
|
|
38
40
|
},
|
|
39
41
|
result: { type: 'object', properties: { account: { type: 'string' }, status: { const: 'pending' }, ...pendingProperties, next: { type: 'string', description: 'What to do next while authorization is pending' } } },
|
|
40
|
-
examples: [invoke + ' login', invoke +
|
|
42
|
+
examples: [invoke + ' login', invoke + ` login --device-login${outputFlag} --non-interactive`],
|
|
41
43
|
async run(input, context) {
|
|
42
44
|
if (waitsInBackground(input, context) && !await identity(input).status(context.signal).then(Boolean, () => true)) {
|
|
43
|
-
return deviceLoginInBackground(input, context, link => ({ status: 'pending', ...link, next: approvalNext(link, statusCommand(input)) }));
|
|
45
|
+
return deviceLoginInBackground(input, context, link => ({ status: 'pending', ...link, next: approvalNext(link, statusCommand(input), json) }));
|
|
44
46
|
}
|
|
45
47
|
return identity(input).login({ ...context, allowDeviceLogin: Boolean(input['device-login']), browser: input.browser !== false });
|
|
46
48
|
},
|
|
@@ -49,7 +51,7 @@ export function identityCommands(identity, invoke) {
|
|
|
49
51
|
logout: {
|
|
50
52
|
description: 'Revoke this CLI grant and delete local tokens; other devices and CLIs are unaffected', effects: 'remote',
|
|
51
53
|
result: { type: 'object', properties: { loggedOut: { const: true }, clientId: { type: 'string' }, impact: { type: 'string' }, revocation: { enum: ['revoked', 'failed', 'not-needed'] }, warning: { type: 'string' }, revocationError: errorSchema }, required: ['loggedOut', 'clientId', 'impact'] },
|
|
52
|
-
examples: [invoke +
|
|
54
|
+
examples: [invoke + ` logout${outputFlag} --non-interactive`],
|
|
53
55
|
run: (input, context) => identity(input).logout(context.signal),
|
|
54
56
|
},
|
|
55
57
|
};
|
package/dist/cli/init.js
CHANGED
|
@@ -21,7 +21,7 @@ export function initCommand(identity, skill, clientId, example) {
|
|
|
21
21
|
'device-login': { type: 'boolean', description: 'Allow device authorization in non-interactive mode; returns the link at once and waits for approval in the background', default: false },
|
|
22
22
|
wait: waitParameter,
|
|
23
23
|
browser: { type: 'boolean', description: 'Open the authorization page in the default browser; use --no-browser to open the URL on another device', default: true },
|
|
24
|
-
'skills-dir': { type: 'string', description: 'Skills root; overrides LXZ_SKILLS_DIR.
|
|
24
|
+
'skills-dir': { type: 'string', description: 'Skills root; overrides LXZ_SKILLS_DIR. Defaults to registered roots or ~/.linkwise/skills on first install' },
|
|
25
25
|
'skill-conflict': { type: 'string', description: 'Local Skill changes: error keeps them; replace overwrites managed files', choices: ['error', 'replace'], default: 'error' },
|
|
26
26
|
},
|
|
27
27
|
result: initializationSchema, examples: [example],
|
package/dist/cli/output.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { CharacterEscaping } from './contracts.js';
|
|
1
2
|
export declare function jsonText(value: unknown, space?: number): string;
|
|
2
|
-
export declare function rowText(value: unknown): string;
|
|
3
|
+
export declare function rowText(value: unknown, characters?: CharacterEscaping): string;
|
package/dist/cli/output.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
// Console decoders such as PowerShell on Chinese Windows read stdout with the local code page; ASCII JSON parses the same everywhere.
|
|
2
1
|
export function jsonText(value, space) {
|
|
3
|
-
return JSON.stringify(value, null, space)
|
|
2
|
+
return JSON.stringify(value, null, space);
|
|
4
3
|
}
|
|
5
|
-
function
|
|
4
|
+
function escapedCell(value) {
|
|
6
5
|
return typeof value === 'string' ? JSON.stringify(value).slice(1, -1) : value === undefined ? '' : String(value);
|
|
7
6
|
}
|
|
7
|
+
function literalCell(value) {
|
|
8
|
+
return value === undefined ? '' : String(value);
|
|
9
|
+
}
|
|
8
10
|
function scalar(value) {
|
|
9
11
|
return value === null || typeof value !== 'object';
|
|
10
12
|
}
|
|
11
|
-
function rows(value) {
|
|
13
|
+
function rows(value, cell) {
|
|
12
14
|
if (scalar(value))
|
|
13
15
|
return [cell(value)];
|
|
14
16
|
if (Array.isArray(value)) {
|
|
@@ -21,15 +23,15 @@ function rows(value) {
|
|
|
21
23
|
if (columns.length)
|
|
22
24
|
return [columns.map(key => cell(key)).join('\t'), ...value.map(item => columns.map(key => Object.hasOwn(item, key) ? cell(item[key]) : '').join('\t'))];
|
|
23
25
|
}
|
|
24
|
-
return value.flatMap((item, index) => [`[${index}]:`, ...rows(item).map(line => ' ' + line)]);
|
|
26
|
+
return value.flatMap((item, index) => [`[${index}]:`, ...rows(item, cell).map(line => ' ' + line)]);
|
|
25
27
|
}
|
|
26
28
|
const entries = Object.entries(value).filter(([, item]) => item !== undefined);
|
|
27
29
|
if (!entries.length)
|
|
28
30
|
return ['{}'];
|
|
29
31
|
return entries.flatMap(([key, item]) => scalar(item)
|
|
30
32
|
? [`${cell(key)}\t${cell(item)}`]
|
|
31
|
-
: [`${cell(key)}:`, ...rows(item).map(line => ' ' + line)]);
|
|
33
|
+
: [`${cell(key)}:`, ...rows(item, cell).map(line => ' ' + line)]);
|
|
32
34
|
}
|
|
33
|
-
export function rowText(value) {
|
|
34
|
-
return typeof value === 'string' ? value : rows(value).join('\n');
|
|
35
|
+
export function rowText(value, characters = 'escaped') {
|
|
36
|
+
return typeof value === 'string' ? value : rows(value, characters === 'literal' ? literalCell : escapedCell).join('\n');
|
|
35
37
|
}
|
package/dist/cli/runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defineCommand, renderUsage } from 'citty';
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
|
-
import { argumentDefinitions,
|
|
3
|
+
import { argumentDefinitions, commandParameters, commonParameters, contractVersion, describe } from './contracts.js';
|
|
4
|
+
import { backgroundInvocation } from './background.js';
|
|
4
5
|
import { CliError, exitCodes, failure } from './errors.js';
|
|
5
6
|
import { jsonText, rowText } from './output.js';
|
|
6
7
|
function jsonLine(value) {
|
|
@@ -16,15 +17,15 @@ function validate(input, parameters, required) {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
let enabled
|
|
20
|
+
function booleanMode(raw, parameters, name) {
|
|
21
|
+
let enabled;
|
|
21
22
|
for (let index = 0; index < raw.length; index++) {
|
|
22
23
|
const flag = raw[index];
|
|
23
24
|
if (flag === '--')
|
|
24
25
|
break;
|
|
25
|
-
if (flag ===
|
|
26
|
+
if (flag === `--${name}` || flag === `--${name}=true`)
|
|
26
27
|
enabled = true;
|
|
27
|
-
else if (flag ===
|
|
28
|
+
else if (flag === `--no-${name}` || flag === `--${name}=false`)
|
|
28
29
|
enabled = false;
|
|
29
30
|
else if (!flag.includes('=') && parameters[flag.slice(2)]?.type === 'string' && !raw[index + 1]?.startsWith('-'))
|
|
30
31
|
index++;
|
|
@@ -32,10 +33,16 @@ function jsonMode(raw, parameters) {
|
|
|
32
33
|
return enabled;
|
|
33
34
|
}
|
|
34
35
|
export async function runApplication(app, argv = process.argv.slice(2)) {
|
|
36
|
+
const background = backgroundInvocation(argv);
|
|
37
|
+
argv = background.argv;
|
|
35
38
|
argv = argv.map((value) => value === '-h' ? '--help' : value === '-v' ? '--version' : value);
|
|
36
39
|
let json = false;
|
|
40
|
+
const characters = app.characterEscaping ?? 'escaped';
|
|
37
41
|
const meta = { contractVersion, cli: app.packageName, version: app.version };
|
|
38
|
-
const write =
|
|
42
|
+
const write = async (data, format) => {
|
|
43
|
+
process.stdout.write(json ? jsonLine({ ok: true, data, meta }) : (format ? format(data) : rowText(data, characters)) + '\n');
|
|
44
|
+
await background.complete({ ok: true, data });
|
|
45
|
+
};
|
|
39
46
|
let dispose = () => { };
|
|
40
47
|
try {
|
|
41
48
|
const names = [...new Set(Object.keys(app.commands).flatMap((name) => {
|
|
@@ -43,14 +50,15 @@ export async function runApplication(app, argv = process.argv.slice(2)) {
|
|
|
43
50
|
return words.map((_, index) => words.slice(0, index + 1).join(' '));
|
|
44
51
|
}))].sort((a, b) => b.length - a.length);
|
|
45
52
|
const leading = [];
|
|
53
|
+
const globals = commandParameters();
|
|
46
54
|
let offset = 0;
|
|
47
55
|
while (argv[offset]?.startsWith('--')) {
|
|
48
56
|
const name = argv[offset].slice(2).split('=')[0].replace(/^no-/, '');
|
|
49
|
-
if (!
|
|
57
|
+
if (!globals[name])
|
|
50
58
|
break;
|
|
51
59
|
const flag = argv[offset++];
|
|
52
60
|
leading.push(flag);
|
|
53
|
-
if (
|
|
61
|
+
if (globals[name].type === 'string' && !flag.includes('=') && argv[offset] !== undefined)
|
|
54
62
|
leading.push(argv[offset++]);
|
|
55
63
|
}
|
|
56
64
|
const remaining = argv.slice(offset);
|
|
@@ -58,9 +66,16 @@ export async function runApplication(app, argv = process.argv.slice(2)) {
|
|
|
58
66
|
const explicitRoute = names.find((name) => name.split(' ').every((word, i) => remaining[i] === word));
|
|
59
67
|
const route = explicitRoute ?? app.defaultCommand;
|
|
60
68
|
const command = route ? app.commands[route] : undefined;
|
|
61
|
-
const parameters = commandParameters(command);
|
|
69
|
+
const parameters = commandParameters(command, app);
|
|
62
70
|
const raw = [...leading, ...(explicitRoute ? remaining.slice(explicitRoute.split(' ').length) : remaining)];
|
|
63
|
-
|
|
71
|
+
if (app.jsonOutput === 'schema' && booleanMode(raw, parameters, 'schema') && !booleanMode(raw, parameters, 'version'))
|
|
72
|
+
parameters.json = commonParameters.json;
|
|
73
|
+
const requestedJson = booleanMode(raw, parameters, 'json');
|
|
74
|
+
if (app.jsonOutput === 'schema' && !parameters.json && requestedJson !== undefined) {
|
|
75
|
+
const commandPath = app.name + (explicitRoute ? ' ' + explicitRoute : '');
|
|
76
|
+
throw new CliError('INVALID_INPUT', 'JSON output is available only with --schema.', `Run ${commandPath} --help for command options, or ${commandPath} --schema --json for the contract.`);
|
|
77
|
+
}
|
|
78
|
+
json = Boolean(parameters.json && requestedJson);
|
|
64
79
|
let input;
|
|
65
80
|
try {
|
|
66
81
|
const parsed = parseArgs({ args: raw, options: Object.fromEntries(Object.entries(parameters).map(([key, p]) => [key, { type: p.type, default: p.default }])), allowNegative: true, strict: true, allowPositionals: false });
|
|
@@ -70,11 +85,11 @@ export async function runApplication(app, argv = process.argv.slice(2)) {
|
|
|
70
85
|
throw new CliError('INVALID_INPUT', 'Unknown command, option or invalid option type.', `Use ${app.name} --help to view commands and options.`);
|
|
71
86
|
}
|
|
72
87
|
if (input.version) {
|
|
73
|
-
write({ version: app.version, contractVersion });
|
|
88
|
+
await write({ version: app.version, contractVersion });
|
|
74
89
|
return;
|
|
75
90
|
}
|
|
76
91
|
if (input.schema) {
|
|
77
|
-
write(describe(app, explicitRoute));
|
|
92
|
+
await write(describe(app, explicitRoute));
|
|
78
93
|
return;
|
|
79
94
|
}
|
|
80
95
|
if (input.help || (!argv.length && !app.defaultCommand)) {
|
|
@@ -82,7 +97,7 @@ export async function runApplication(app, argv = process.argv.slice(2)) {
|
|
|
82
97
|
const usage = await renderUsage(definition);
|
|
83
98
|
const children = Object.entries(app.commands).filter(([name]) => !route || name.startsWith(route + ' '));
|
|
84
99
|
const commands = children.length ? `\nCommands:\n${children.map(([name, c]) => ` ${route ? name.slice(route.length + 1) : name} ${c.description}`).join('\n')}\n\nUse ${route ? `${app.name} ${route}` : app.name} <command> -h for options and examples.` : '';
|
|
85
|
-
write(`${usage}${command ? `\nExamples:\n${command.examples.join('\n')}` : ''}${commands}`);
|
|
100
|
+
await write(`${usage}${command ? `\nExamples:\n${command.examples.join('\n')}` : ''}${commands}`);
|
|
86
101
|
return;
|
|
87
102
|
}
|
|
88
103
|
if (!command)
|
|
@@ -121,15 +136,16 @@ export async function runApplication(app, argv = process.argv.slice(2)) {
|
|
|
121
136
|
interactive, argv,
|
|
122
137
|
signal: controller.signal, log: (message) => process.stderr.write(`${message}\n`),
|
|
123
138
|
}), aborted]);
|
|
124
|
-
write(
|
|
139
|
+
await write(result, command.format);
|
|
125
140
|
}
|
|
126
141
|
catch (error) {
|
|
127
142
|
const detail = failure(error);
|
|
128
143
|
if (json)
|
|
129
144
|
process.stdout.write(jsonLine({ ok: false, error: detail, meta }));
|
|
130
145
|
else
|
|
131
|
-
process.stderr.write(`${detail.code}: ${detail.message}\nNext: ${detail.next}\n${detail.details ? rowText(detail.details) + '\n' : ''}`);
|
|
146
|
+
process.stderr.write(`${detail.code}: ${detail.message}\nNext: ${detail.next}\n${detail.details ? rowText(detail.details, characters) + '\n' : ''}`);
|
|
132
147
|
process.exitCode = exitCodes[detail.code];
|
|
148
|
+
await background.complete({ ok: false, error: detail });
|
|
133
149
|
}
|
|
134
150
|
finally {
|
|
135
151
|
dispose();
|
package/dist/cli/schemas.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { contractVersion, describe } from './contracts.js';
|
|
2
2
|
import { exitCodes } from './errors.js';
|
|
3
|
-
// Kept as a $schema member: the dialect is a schema identifier, not an address the CLI contacts, and code checks read it so
|
|
4
3
|
const dialect = { $schema: 'https://json-schema.org/draft/2020-12/schema' };
|
|
5
4
|
export const schemaDialect = dialect.$schema;
|
|
6
5
|
export const errorSchema = {
|
package/dist/doctor.js
CHANGED
|
@@ -24,7 +24,7 @@ async function packageRegistry(signal) {
|
|
|
24
24
|
export const doctor = {
|
|
25
25
|
description: 'Check runtime, package registry, authorization service and local session without logging in', effects: 'none',
|
|
26
26
|
parameters: { 'client-id': { type: 'string', description: 'Client ID to check; defaults to LXZ_AUTH_CLIENT_ID' } },
|
|
27
|
-
examples: ['pnpm dlx @tulcn/lxz doctor --
|
|
27
|
+
examples: ['pnpm dlx @tulcn/lxz doctor --non-interactive', 'pnpm dlx @tulcn/lxz doctor --client-id crm-demo1 --non-interactive'], result: { type: 'object', required: ['checks', 'healthy'] },
|
|
28
28
|
async run(input, context) {
|
|
29
29
|
const clientId = typeof input['client-id'] === 'string' ? input['client-id'] : undefined;
|
|
30
30
|
const checks = {};
|
package/dist/skills/agents.js
CHANGED
|
@@ -7,5 +7,5 @@ export const agentSkillDirectories = {
|
|
|
7
7
|
linkwise: '.linkwise/skills',
|
|
8
8
|
};
|
|
9
9
|
export function defaultSkillDirectories() {
|
|
10
|
-
return [
|
|
10
|
+
return [join(homedir(), agentSkillDirectories.linkwise)];
|
|
11
11
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Command } from '../cli/index.js';
|
|
1
|
+
import type { Application, Command } from '../cli/index.js';
|
|
2
2
|
export interface SkillSyncPort {
|
|
3
3
|
sync(directory: string | undefined, conflict: 'error' | 'replace', signal: AbortSignal): Promise<unknown>;
|
|
4
4
|
}
|
|
5
|
-
export declare function skillCommands(skill: SkillSyncPort, invoke: string): Record<string, Command>;
|
|
5
|
+
export declare function skillCommands(skill: SkillSyncPort, invoke: string, options?: Pick<Application, 'jsonOutput'>): Record<string, Command>;
|
package/dist/skills/commands.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export function skillCommands(skill, invoke) {
|
|
1
|
+
export function skillCommands(skill, invoke, options = {}) {
|
|
2
2
|
return {
|
|
3
3
|
'install skill': {
|
|
4
4
|
description: 'Install the bundled Skill for this version; synchronize registered directories on upgrade or rollback',
|
|
5
5
|
effects: 'local',
|
|
6
6
|
parameters: {
|
|
7
|
-
'skills-dir': { type: 'string', description: 'Skills root; overrides LXZ_SKILLS_DIR.
|
|
7
|
+
'skills-dir': { type: 'string', description: 'Skills root; overrides LXZ_SKILLS_DIR. Defaults to registered roots or ~/.linkwise/skills on first install' },
|
|
8
8
|
'skill-conflict': { type: 'string', description: 'Local changes: error keeps them; replace overwrites files managed by this CLI', choices: ['error', 'replace'], default: 'error' },
|
|
9
9
|
},
|
|
10
10
|
result: { type: 'object', required: ['installed'], properties: { installed: { type: 'array', items: { type: 'object', required: ['directory', 'version', 'action'], properties: { directory: { type: 'string' }, version: { type: 'string' }, action: { enum: ['installed', 'updated', 'unchanged'] } } } } } },
|
|
11
|
-
examples: [invoke + ' install skill', invoke +
|
|
11
|
+
examples: [invoke + ' install skill', invoke + ` install skill --skills-dir ./ceshi123/skills${options.jsonOutput === false || options.jsonOutput === 'schema' ? '' : ' --json'} --non-interactive`],
|
|
12
12
|
format(result) {
|
|
13
13
|
return result.installed.map((item) => `Agent Skill: ${item.directory}\nVersion: ${item.version}; ${{ installed: 'installed', updated: 'updated', unchanged: 'already current' }[item.action]}`).join('\n\n');
|
|
14
14
|
},
|
package/dist/skills/delivery.js
CHANGED
|
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
6
6
|
import { CliError, failure } from '../cli/index.js';
|
|
7
7
|
import { loadSkill } from './bundle.js';
|
|
8
8
|
import { SkillInstaller, legacyPackageName } from './installer.js';
|
|
9
|
-
import { defaultSkillDirectories } from './agents.js';
|
|
9
|
+
import { agentSkillDirectories, defaultSkillDirectories } from './agents.js';
|
|
10
10
|
export class BundledSkill {
|
|
11
11
|
name;
|
|
12
12
|
env;
|
|
@@ -25,7 +25,7 @@ export class BundledSkill {
|
|
|
25
25
|
return { installer: new SkillInstaller(bundle), registry: registryOf(pkg.name), legacyRegistry: legacy && registryOf(legacy) };
|
|
26
26
|
}
|
|
27
27
|
directory(input) {
|
|
28
|
-
const value = input ?? (this.env.LXZ_SKILLS_DIR || join(homedir(),
|
|
28
|
+
const value = input ?? (this.env.LXZ_SKILLS_DIR || join(homedir(), agentSkillDirectories.linkwise));
|
|
29
29
|
if (!value.trim())
|
|
30
30
|
throw new CliError('INVALID_INPUT', 'The Skill installation directory must not be empty.', 'Pass --skills-dir <agent-skills-root>.');
|
|
31
31
|
return resolve(value.replace(/^~(?=$|[\\/])/, () => homedir()));
|
package/package.json
CHANGED
package/skills/SKILL.md
CHANGED
|
@@ -5,21 +5,21 @@ description: 管理指定 CLI 的登录授权并检查运行环境
|
|
|
5
5
|
|
|
6
6
|
# lxz
|
|
7
7
|
|
|
8
|
-
此说明对应 @tulcn/lxz@0.
|
|
8
|
+
此说明对应 @tulcn/lxz@0.4.0。优先使用已安装且版本匹配的 lxz;未安装时,可用 `pnpm dlx @tulcn/lxz@<版本>`(`<版本>` 取上面的版本号)作为调用前缀。以下命令适用于 pwsh 和 bash,选择 dlx 时替换调用前缀。
|
|
9
9
|
|
|
10
10
|
功能定位可按需读取同目录 [features.md](features.md);它由当前命令注册自动生成,再沿子命令帮助查询参数。
|
|
11
11
|
|
|
12
12
|
## 按任务查帮助
|
|
13
13
|
|
|
14
|
-
先核对版本,再从 `lxz -h` 查找所需功能,沿分组逐层查询。例如授权任务先看 `lxz auth -h`,再看选定子命令的 `-h
|
|
14
|
+
先核对版本,再从 `lxz -h` 查找所需功能,沿分组逐层查询。例如授权任务先看 `lxz auth -h`,再看选定子命令的 `-h`,按当前帮助提供参数。
|
|
15
15
|
|
|
16
16
|
需要结构化的输入和结果约束时,在选定命令或分组后加 `--schema --json`,只获取该范围的契约;根入口 `lxz --schema --json` 返回全量,仅在需要总览时使用。完整命令参考 [commands.md](commands.md),按需定位相关命令。本说明只保留流程和判断规则,子功能细节以当前帮助为准。
|
|
17
17
|
|
|
18
|
-
Agent 使用 `--non-interactive`
|
|
18
|
+
Agent 使用 `--non-interactive` 读取文本结果,查询契约时使用 `--schema --json`。输出按 UTF-8 解码,失败时读取 stderr 和退出码。
|
|
19
19
|
|
|
20
20
|
## 和用户沟通
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
用业务语言说明任务结果、实际影响和下一步,例如“已经检查过,可以提交”。遇到需要用户处理的问题,说明原因及恢复方式。授权时原样提供链接和用户码。
|
|
23
23
|
|
|
24
24
|
## 授权与诊断
|
|
25
25
|
|
|
@@ -27,7 +27,7 @@ Agent 使用 `--non-interactive` 读取默认行数据,失败时读取 stderr
|
|
|
27
27
|
|
|
28
28
|
默认连接正式授权中心;切换测试环境前确认目标地址、该环境的 CLI 登记和人员使用权,授权与令牌不跨环境复用。未知配置联系维护者,不猜测权限。状态查询和普通诊断不应自行触发登录。
|
|
29
29
|
|
|
30
|
-
仅在用户要求登录时发起授权,先查登录帮助。`lxz auth login --client-id <CLI 标识> --device-login --non-interactive
|
|
30
|
+
仅在用户要求登录时发起授权,先查登录帮助。`lxz auth login --client-id <CLI 标识> --device-login --non-interactive` 几秒内以行数据返回待批准状态、授权链接和用户码,后台继续等待:把 `authorizationUrl` 和 `userCode` 原样写给用户。链接写成单独一行的 Markdown 链接,例如 `[打开授权页面](authorizationUrl)`;用户码另起一行原样写出。`browserOpened` 为 true 时请用户切到已打开的浏览器核对用户码,为 false 时请用户在系统浏览器打开链接(联小助里请右键选择用系统浏览器打开)。随即在同一轮运行结果 `next` 中带同一 `--client-id` 的 `auth status --wait-seconds 170` 命令,批准后立即返回并继续用户原来的任务。仍未批准时按 `next` 询问用户;链接有效期间不重复登录,拒绝或到期后停止,不自动重复登录。只有能实时看到输出的终端才用 `--wait` 前台等待;需要在另一设备确认时加 `--no-browser`。
|
|
31
31
|
|
|
32
32
|
将后端失败原因与恢复提示如实告知用户。不得展示设备码、读取或复制令牌缓存,不在日志、结果或业务文档中记录访问令牌和刷新令牌。
|
|
33
33
|
|
package/skills/bundle.json
CHANGED
package/skills/commands.md
CHANGED
|
@@ -4,8 +4,6 @@ Sign in using a browser and authorize this CLI
|
|
|
4
4
|
|
|
5
5
|
Effects: local; Preview: false.
|
|
6
6
|
|
|
7
|
-
- --json (boolean): Return a JSON receipt instead of compact rows; use for programmatic parsing; default false
|
|
8
|
-
|
|
9
7
|
- --non-interactive (boolean): Use command parameters without interactive prompts; default false
|
|
10
8
|
|
|
11
9
|
- --timeout-ms (string): Total deadline in ms (1-3600000), including approval waits; keyboard inactivity does not end authorization; default "660000"
|
|
@@ -14,11 +12,11 @@ Effects: local; Preview: false.
|
|
|
14
12
|
|
|
15
13
|
- --version (boolean): Show version
|
|
16
14
|
|
|
17
|
-
- --schema (boolean): Show command, input and result schemas
|
|
15
|
+
- --schema (boolean): Show command, input and result schemas; add --json for a JSON receipt
|
|
18
16
|
|
|
19
17
|
- --device-login (boolean): Allow device authorization in non-interactive mode; returns the link at once and waits for approval in the background; default false
|
|
20
18
|
|
|
21
|
-
- --wait (boolean): With --device-login in non-interactive mode, wait for approval in the foreground
|
|
19
|
+
- --wait (boolean): With --device-login in non-interactive mode, wait for browser approval in the foreground; default false
|
|
22
20
|
|
|
23
21
|
- --browser (boolean): Open the authorization page in the default browser; use --no-browser to open the URL on another device; default true
|
|
24
22
|
|
|
@@ -67,7 +65,7 @@ pnpm dlx @tulcn/lxz auth login
|
|
|
67
65
|
**pwsh / bash**
|
|
68
66
|
|
|
69
67
|
```sh
|
|
70
|
-
pnpm dlx @tulcn/lxz auth login --device-login --
|
|
68
|
+
pnpm dlx @tulcn/lxz auth login --device-login --non-interactive
|
|
71
69
|
```
|
|
72
70
|
|
|
73
71
|
### lxz auth status
|
|
@@ -76,8 +74,6 @@ Show this CLI authorization status and current account
|
|
|
76
74
|
|
|
77
75
|
Effects: none; Preview: false.
|
|
78
76
|
|
|
79
|
-
- --json (boolean): Return a JSON receipt instead of compact rows; use for programmatic parsing; default false
|
|
80
|
-
|
|
81
77
|
- --non-interactive (boolean): Use command parameters without interactive prompts; default false
|
|
82
78
|
|
|
83
79
|
- --timeout-ms (string): Non-interactive deadline in ms (1-3600000); interactive prompts exit after 60 seconds without input; default "175000"
|
|
@@ -86,7 +82,7 @@ Effects: none; Preview: false.
|
|
|
86
82
|
|
|
87
83
|
- --version (boolean): Show version
|
|
88
84
|
|
|
89
|
-
- --schema (boolean): Show command, input and result schemas
|
|
85
|
+
- --schema (boolean): Show command, input and result schemas; add --json for a JSON receipt
|
|
90
86
|
|
|
91
87
|
- --wait-seconds (string): Wait up to this many seconds (0-170) for a pending browser approval; returns as soon as it is approved; default "0"
|
|
92
88
|
|
|
@@ -138,13 +134,13 @@ Result schema:
|
|
|
138
134
|
**pwsh / bash**
|
|
139
135
|
|
|
140
136
|
```sh
|
|
141
|
-
pnpm dlx @tulcn/lxz auth status --
|
|
137
|
+
pnpm dlx @tulcn/lxz auth status --non-interactive
|
|
142
138
|
```
|
|
143
139
|
|
|
144
140
|
**pwsh / bash**
|
|
145
141
|
|
|
146
142
|
```sh
|
|
147
|
-
pnpm dlx @tulcn/lxz auth status --wait-seconds 170 --
|
|
143
|
+
pnpm dlx @tulcn/lxz auth status --wait-seconds 170 --non-interactive
|
|
148
144
|
```
|
|
149
145
|
|
|
150
146
|
### lxz auth logout
|
|
@@ -153,8 +149,6 @@ Revoke this CLI grant and delete local tokens; other devices and CLIs are unaffe
|
|
|
153
149
|
|
|
154
150
|
Effects: remote; Preview: false.
|
|
155
151
|
|
|
156
|
-
- --json (boolean): Return a JSON receipt instead of compact rows; use for programmatic parsing; default false
|
|
157
|
-
|
|
158
152
|
- --non-interactive (boolean): Use command parameters without interactive prompts; default false
|
|
159
153
|
|
|
160
154
|
- --timeout-ms (string): Non-interactive deadline in ms (1-3600000); interactive prompts exit after 60 seconds without input; default "120000"
|
|
@@ -163,7 +157,7 @@ Effects: remote; Preview: false.
|
|
|
163
157
|
|
|
164
158
|
- --version (boolean): Show version
|
|
165
159
|
|
|
166
|
-
- --schema (boolean): Show command, input and result schemas
|
|
160
|
+
- --schema (boolean): Show command, input and result schemas; add --json for a JSON receipt
|
|
167
161
|
|
|
168
162
|
- --client-id (string): Client ID to manage; defaults to LXZ_AUTH_CLIENT_ID
|
|
169
163
|
|
|
@@ -242,7 +236,7 @@ Result schema:
|
|
|
242
236
|
**pwsh / bash**
|
|
243
237
|
|
|
244
238
|
```sh
|
|
245
|
-
pnpm dlx @tulcn/lxz auth logout --
|
|
239
|
+
pnpm dlx @tulcn/lxz auth logout --non-interactive
|
|
246
240
|
```
|
|
247
241
|
|
|
248
242
|
### lxz auth whoami
|
|
@@ -251,8 +245,6 @@ Show the local account authorized for this CLI
|
|
|
251
245
|
|
|
252
246
|
Effects: none; Preview: false.
|
|
253
247
|
|
|
254
|
-
- --json (boolean): Return a JSON receipt instead of compact rows; use for programmatic parsing; default false
|
|
255
|
-
|
|
256
248
|
- --non-interactive (boolean): Use command parameters without interactive prompts; default false
|
|
257
249
|
|
|
258
250
|
- --timeout-ms (string): Non-interactive deadline in ms (1-3600000); interactive prompts exit after 60 seconds without input; default "175000"
|
|
@@ -261,7 +253,7 @@ Effects: none; Preview: false.
|
|
|
261
253
|
|
|
262
254
|
- --version (boolean): Show version
|
|
263
255
|
|
|
264
|
-
- --schema (boolean): Show command, input and result schemas
|
|
256
|
+
- --schema (boolean): Show command, input and result schemas; add --json for a JSON receipt
|
|
265
257
|
|
|
266
258
|
- --wait-seconds (string): Wait up to this many seconds (0-170) for a pending browser approval; returns as soon as it is approved; default "0"
|
|
267
259
|
|
|
@@ -313,13 +305,13 @@ Result schema:
|
|
|
313
305
|
**pwsh / bash**
|
|
314
306
|
|
|
315
307
|
```sh
|
|
316
|
-
pnpm dlx @tulcn/lxz auth status --
|
|
308
|
+
pnpm dlx @tulcn/lxz auth status --non-interactive
|
|
317
309
|
```
|
|
318
310
|
|
|
319
311
|
**pwsh / bash**
|
|
320
312
|
|
|
321
313
|
```sh
|
|
322
|
-
pnpm dlx @tulcn/lxz auth status --wait-seconds 170 --
|
|
314
|
+
pnpm dlx @tulcn/lxz auth status --wait-seconds 170 --non-interactive
|
|
323
315
|
```
|
|
324
316
|
|
|
325
317
|
### lxz doctor
|
|
@@ -328,8 +320,6 @@ Check runtime, package registry, authorization service and local session without
|
|
|
328
320
|
|
|
329
321
|
Effects: none; Preview: false.
|
|
330
322
|
|
|
331
|
-
- --json (boolean): Return a JSON receipt instead of compact rows; use for programmatic parsing; default false
|
|
332
|
-
|
|
333
323
|
- --non-interactive (boolean): Use command parameters without interactive prompts; default false
|
|
334
324
|
|
|
335
325
|
- --timeout-ms (string): Non-interactive deadline in ms (1-3600000); interactive prompts exit after 60 seconds without input; default "120000"
|
|
@@ -338,7 +328,7 @@ Effects: none; Preview: false.
|
|
|
338
328
|
|
|
339
329
|
- --version (boolean): Show version
|
|
340
330
|
|
|
341
|
-
- --schema (boolean): Show command, input and result schemas
|
|
331
|
+
- --schema (boolean): Show command, input and result schemas; add --json for a JSON receipt
|
|
342
332
|
|
|
343
333
|
- --client-id (string): Client ID to check; defaults to LXZ_AUTH_CLIENT_ID
|
|
344
334
|
|
|
@@ -357,13 +347,13 @@ Result schema:
|
|
|
357
347
|
**pwsh / bash**
|
|
358
348
|
|
|
359
349
|
```sh
|
|
360
|
-
pnpm dlx @tulcn/lxz doctor --
|
|
350
|
+
pnpm dlx @tulcn/lxz doctor --non-interactive
|
|
361
351
|
```
|
|
362
352
|
|
|
363
353
|
**pwsh / bash**
|
|
364
354
|
|
|
365
355
|
```sh
|
|
366
|
-
pnpm dlx @tulcn/lxz doctor --client-id crm-demo1 --
|
|
356
|
+
pnpm dlx @tulcn/lxz doctor --client-id crm-demo1 --non-interactive
|
|
367
357
|
```
|
|
368
358
|
|
|
369
359
|
### lxz install skill
|
|
@@ -372,8 +362,6 @@ Install the bundled Skill for this version; synchronize registered directories o
|
|
|
372
362
|
|
|
373
363
|
Effects: local; Preview: false.
|
|
374
364
|
|
|
375
|
-
- --json (boolean): Return a JSON receipt instead of compact rows; use for programmatic parsing; default false
|
|
376
|
-
|
|
377
365
|
- --non-interactive (boolean): Use command parameters without interactive prompts; default false
|
|
378
366
|
|
|
379
367
|
- --timeout-ms (string): Non-interactive deadline in ms (1-3600000); interactive prompts exit after 60 seconds without input; default "120000"
|
|
@@ -382,9 +370,9 @@ Effects: local; Preview: false.
|
|
|
382
370
|
|
|
383
371
|
- --version (boolean): Show version
|
|
384
372
|
|
|
385
|
-
- --schema (boolean): Show command, input and result schemas
|
|
373
|
+
- --schema (boolean): Show command, input and result schemas; add --json for a JSON receipt
|
|
386
374
|
|
|
387
|
-
- --skills-dir (string): Skills root; overrides LXZ_SKILLS_DIR.
|
|
375
|
+
- --skills-dir (string): Skills root; overrides LXZ_SKILLS_DIR. Defaults to registered roots or ~/.linkwise/skills on first install
|
|
388
376
|
|
|
389
377
|
- --skill-conflict (string): Local changes: error keeps them; replace overwrites files managed by this CLI; default "error"; choices ["error","replace"]
|
|
390
378
|
|
|
@@ -436,5 +424,5 @@ pnpm dlx @tulcn/lxz install skill
|
|
|
436
424
|
**pwsh / bash**
|
|
437
425
|
|
|
438
426
|
```sh
|
|
439
|
-
pnpm dlx @tulcn/lxz install skill --skills-dir ./ceshi123/skills --
|
|
427
|
+
pnpm dlx @tulcn/lxz install skill --skills-dir ./ceshi123/skills --non-interactive
|
|
440
428
|
```
|