shoplazza-ai-dev-cli 0.1.22-snapshot.1 → 0.1.22-snapshot.2
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/dist/_chunks/af.mjs +212 -312
- package/dist/_chunks/commands.mjs +13 -5
- package/dist/_chunks/format.mjs +540 -0
- package/dist/_chunks/run2.mjs +308 -0
- package/dist/cli.mjs +7 -0
- package/package.json +1 -1
package/dist/_chunks/af.mjs
CHANGED
|
@@ -1,150 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as SESSION_TOKEN_HEADER, n as ENV_RUNNER_URL, r as ENV_SESSION_TOKEN } from "./executor.mjs";
|
|
2
|
+
import { A as defaultIO, C as EXIT_OK, D as afBrowser, E as afAsk, O as afSubmit, S as usageError, T as EXIT_USAGE, _ as parseRef, a as timelineLines, b as seg, c as checkLine, d as formatTable, f as isPageSlug, g as parseOutput, h as parseArgs$1, k as afTask, l as conflictLine, m as list, o as unwrapJson, p as kvLines, s as KB_PATH, u as emit, v as parseVersion, w as EXIT_REJECTED, x as str, y as query } from "./format.mjs";
|
|
2
3
|
import { request } from "node:http";
|
|
3
4
|
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
-
function defaultIO() {
|
|
5
|
-
return {
|
|
6
|
-
env: process.env,
|
|
7
|
-
out: (l) => process.stdout.write(l + "\n"),
|
|
8
|
-
err: (l) => process.stderr.write(l + "\n"),
|
|
9
|
-
fetch: globalThis.fetch
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
const EXIT_OK = 0;
|
|
13
|
-
const EXIT_REJECTED = 1;
|
|
14
|
-
const EXIT_USAGE = 2;
|
|
15
|
-
async function readJSON(file, io) {
|
|
16
|
-
if (!file) {
|
|
17
|
-
io.err("usage: af submit|ask <file>");
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
return JSON.parse(await readFile(file, "utf8"));
|
|
22
|
-
} catch (err) {
|
|
23
|
-
io.err(`cannot read ${file} as JSON: ${String(err)}`);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async function forward(path, file, io) {
|
|
28
|
-
const body = await readJSON(file, io);
|
|
29
|
-
if (body === void 0) return EXIT_USAGE;
|
|
30
|
-
return post(path, body, io);
|
|
31
|
-
}
|
|
32
|
-
function isEnvelope(v) {
|
|
33
|
-
return typeof v === "object" && v !== null && typeof v.schema === "string" && "payload" in v;
|
|
34
|
-
}
|
|
35
|
-
async function outputSchemaName(io) {
|
|
36
|
-
const file = io.env[ENV_OUTPUT_SCHEMA];
|
|
37
|
-
if (!file) return "";
|
|
38
|
-
try {
|
|
39
|
-
const schema = JSON.parse(await readFile(file, "utf8"));
|
|
40
|
-
return typeof schema.title === "string" ? schema.title : "";
|
|
41
|
-
} catch {
|
|
42
|
-
return "";
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async function post(path, body, io) {
|
|
46
|
-
const base = io.env[ENV_RUNNER_URL];
|
|
47
|
-
const token = io.env[ENV_SESSION_TOKEN];
|
|
48
|
-
if (!base || !token) {
|
|
49
|
-
io.err(`not inside a forge runner session: ${ENV_RUNNER_URL} / ${ENV_SESSION_TOKEN} missing`);
|
|
50
|
-
return EXIT_USAGE;
|
|
51
|
-
}
|
|
52
|
-
const res = await io.fetch(base.replace(/\/$/, "") + path, {
|
|
53
|
-
method: "POST",
|
|
54
|
-
headers: {
|
|
55
|
-
"content-type": "application/json",
|
|
56
|
-
[SESSION_TOKEN_HEADER]: token
|
|
57
|
-
},
|
|
58
|
-
body: JSON.stringify(body)
|
|
59
|
-
});
|
|
60
|
-
const text = await res.text();
|
|
61
|
-
if (res.ok) {
|
|
62
|
-
io.out(text || "{\"code\":\"ok\"}");
|
|
63
|
-
return EXIT_OK;
|
|
64
|
-
}
|
|
65
|
-
io.err(text || `request failed: ${res.status}`);
|
|
66
|
-
return res.status === 400 || res.status === 422 || res.status === 409 ? EXIT_REJECTED : EXIT_USAGE;
|
|
67
|
-
}
|
|
68
|
-
async function afSubmit(file, io = defaultIO()) {
|
|
69
|
-
const content = await readJSON(file, io);
|
|
70
|
-
if (content === void 0) return EXIT_USAGE;
|
|
71
|
-
if (isEnvelope(content)) return post(SESSION_SUBMIT_PATH, content, io);
|
|
72
|
-
const schema = await outputSchemaName(io);
|
|
73
|
-
if (!schema) {
|
|
74
|
-
io.err(`this node has no output schema (${ENV_OUTPUT_SCHEMA} missing); nothing to submit`);
|
|
75
|
-
return EXIT_USAGE;
|
|
76
|
-
}
|
|
77
|
-
return post(SESSION_SUBMIT_PATH, {
|
|
78
|
-
schema,
|
|
79
|
-
payload: content
|
|
80
|
-
}, io);
|
|
81
|
-
}
|
|
82
|
-
function afAsk(file, io = defaultIO()) {
|
|
83
|
-
return forward(SESSION_ASK_PATH, file, io);
|
|
84
|
-
}
|
|
85
|
-
function afBrowser(args, io = defaultIO()) {
|
|
86
|
-
const [op, ...values] = args;
|
|
87
|
-
let body;
|
|
88
|
-
switch (op) {
|
|
89
|
-
case "snapshot":
|
|
90
|
-
if (values.length === 0) body = { op };
|
|
91
|
-
break;
|
|
92
|
-
case "navigate":
|
|
93
|
-
if (values.length === 1 && /^https?:\/\//.test(values[0])) body = {
|
|
94
|
-
op,
|
|
95
|
-
url: values[0]
|
|
96
|
-
};
|
|
97
|
-
break;
|
|
98
|
-
case "click": {
|
|
99
|
-
const coordinates = values.map(Number);
|
|
100
|
-
if (coordinates.length === 2 && coordinates.every((n) => Number.isInteger(n) && n >= 0)) body = {
|
|
101
|
-
op,
|
|
102
|
-
x: coordinates[0],
|
|
103
|
-
y: coordinates[1]
|
|
104
|
-
};
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
case "scroll":
|
|
108
|
-
if (values.length === 1 && Number.isInteger(Number(values[0]))) body = {
|
|
109
|
-
op,
|
|
110
|
-
delta_y: Number(values[0])
|
|
111
|
-
};
|
|
112
|
-
break;
|
|
113
|
-
case "type":
|
|
114
|
-
if (values.length === 1 && values[0]) body = {
|
|
115
|
-
op,
|
|
116
|
-
text: values[0]
|
|
117
|
-
};
|
|
118
|
-
break;
|
|
119
|
-
case "key":
|
|
120
|
-
if (values.length === 1 && values[0]) body = {
|
|
121
|
-
op,
|
|
122
|
-
key: values[0]
|
|
123
|
-
};
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
if (!body) {
|
|
127
|
-
io.err("usage: af browser snapshot|navigate <url>|click <x> <y>|scroll <delta>|type <text>|key <key>");
|
|
128
|
-
return Promise.resolve(EXIT_USAGE);
|
|
129
|
-
}
|
|
130
|
-
return post(SESSION_BROWSER_PATH, body, io);
|
|
131
|
-
}
|
|
132
|
-
function afTask(args, io = defaultIO()) {
|
|
133
|
-
const [action, taskNo] = args;
|
|
134
|
-
if (!action || !taskNo || ![
|
|
135
|
-
"status",
|
|
136
|
-
"pause",
|
|
137
|
-
"resume"
|
|
138
|
-
].includes(action)) {
|
|
139
|
-
io.err("usage: af task status|pause|resume <task_no>");
|
|
140
|
-
return Promise.resolve(EXIT_USAGE);
|
|
141
|
-
}
|
|
142
|
-
return post(SESSION_TASK_PATH, {
|
|
143
|
-
action,
|
|
144
|
-
task_no: taskNo
|
|
145
|
-
}, io);
|
|
146
|
-
}
|
|
147
5
|
const CALL_TIMEOUT_MS = 33e4;
|
|
6
|
+
async function readStdinText(io) {
|
|
7
|
+
if (io.readStdin !== void 0) return io.readStdin();
|
|
8
|
+
const chunks = [];
|
|
9
|
+
for await (const c of process.stdin) chunks.push(Buffer.from(c));
|
|
10
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
11
|
+
}
|
|
148
12
|
const nodeTransport = (call) => new Promise((resolve, reject) => {
|
|
149
13
|
const req = request(call.url, {
|
|
150
14
|
method: call.method,
|
|
@@ -249,9 +113,9 @@ const REQUIRED_FIELDS = [
|
|
|
249
113
|
"feishu_mode"
|
|
250
114
|
];
|
|
251
115
|
const ID_FLAG = "--id";
|
|
252
|
-
const USAGE$
|
|
116
|
+
const USAGE$2 = "usage: af task draft <file> [--id <draft_id>]";
|
|
253
117
|
async function afTaskDraft(args, io) {
|
|
254
|
-
const parsed = parseArgs
|
|
118
|
+
const parsed = parseArgs(args);
|
|
255
119
|
if (typeof parsed === "string") {
|
|
256
120
|
io.err(parsed);
|
|
257
121
|
return EXIT_USAGE;
|
|
@@ -278,22 +142,22 @@ async function afTaskDraft(args, io) {
|
|
|
278
142
|
io.out(summarize(reply.text));
|
|
279
143
|
return EXIT_OK;
|
|
280
144
|
}
|
|
281
|
-
function parseArgs
|
|
145
|
+
function parseArgs(args) {
|
|
282
146
|
let file;
|
|
283
147
|
let id;
|
|
284
148
|
for (let i = 0; i < args.length; i++) {
|
|
285
149
|
const a = args[i];
|
|
286
150
|
if (a === ID_FLAG) {
|
|
287
151
|
id = args[++i];
|
|
288
|
-
if (id === void 0 || id === "" || id.startsWith("--")) return `${ID_FLAG} needs a draft id; ${USAGE$
|
|
152
|
+
if (id === void 0 || id === "" || id.startsWith("--")) return `${ID_FLAG} needs a draft id; ${USAGE$2}`;
|
|
289
153
|
} else if (a.startsWith(`${ID_FLAG}=`)) {
|
|
290
154
|
id = a.slice(5);
|
|
291
|
-
if (id === "") return `${ID_FLAG} needs a draft id; ${USAGE$
|
|
292
|
-
} else if (a.startsWith("--")) return `unknown option ${a}; ${USAGE$
|
|
155
|
+
if (id === "") return `${ID_FLAG} needs a draft id; ${USAGE$2}`;
|
|
156
|
+
} else if (a.startsWith("--")) return `unknown option ${a}; ${USAGE$2}`;
|
|
293
157
|
else if (file === void 0) file = a;
|
|
294
|
-
else return `unexpected argument ${a}; ${USAGE$
|
|
158
|
+
else return `unexpected argument ${a}; ${USAGE$2}`;
|
|
295
159
|
}
|
|
296
|
-
return file === void 0 ? USAGE$
|
|
160
|
+
return file === void 0 ? USAGE$2 : {
|
|
297
161
|
file,
|
|
298
162
|
id
|
|
299
163
|
};
|
|
@@ -332,137 +196,6 @@ function summarize(text) {
|
|
|
332
196
|
});
|
|
333
197
|
return text || "{\"code\":\"ok\"}";
|
|
334
198
|
}
|
|
335
|
-
const PAGE_SLUG_RE = /^[a-z0-9][a-z0-9_-]*$/;
|
|
336
|
-
const ALL_DIGITS_RE = /^[0-9]+$/;
|
|
337
|
-
const PAGE_SLUG_MAX_LEN = 64;
|
|
338
|
-
const BASE_SLUG_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
339
|
-
const BASE_SLUG_MAX_LEN = 64;
|
|
340
|
-
const VERSION_RE = /^(d(0|[1-9]\d*)|[1-9]\d*)$/;
|
|
341
|
-
const REF_HELP = "引用格式:页面 id,或 <库 slug>:<路径>(路径是祖先 slug 用 / 拼接,如 work:flow/apollo-key)";
|
|
342
|
-
function isPageSlug(s) {
|
|
343
|
-
return s.length <= PAGE_SLUG_MAX_LEN && PAGE_SLUG_RE.test(s) && !ALL_DIGITS_RE.test(s);
|
|
344
|
-
}
|
|
345
|
-
function parseRef(text) {
|
|
346
|
-
if (ALL_DIGITS_RE.test(text)) return {
|
|
347
|
-
kind: "id",
|
|
348
|
-
raw: text
|
|
349
|
-
};
|
|
350
|
-
const colon = text.indexOf(":");
|
|
351
|
-
const slug = colon < 0 ? "" : text.slice(0, colon);
|
|
352
|
-
const path = colon < 0 ? "" : text.slice(colon + 1);
|
|
353
|
-
return slug.length <= BASE_SLUG_MAX_LEN && BASE_SLUG_RE.test(slug) && path !== "" && path.split("/").every(isPageSlug) ? {
|
|
354
|
-
kind: "path",
|
|
355
|
-
raw: text
|
|
356
|
-
} : `页面引用 ${JSON.stringify(text)} 不合法。${REF_HELP}`;
|
|
357
|
-
}
|
|
358
|
-
function parseVersion(v) {
|
|
359
|
-
return VERSION_RE.test(v);
|
|
360
|
-
}
|
|
361
|
-
function parseOutput(args) {
|
|
362
|
-
const rest = [];
|
|
363
|
-
let output = "table";
|
|
364
|
-
for (let i = 0; i < args.length; i++) {
|
|
365
|
-
const a = args[i];
|
|
366
|
-
let value;
|
|
367
|
-
if (a === "--") {
|
|
368
|
-
rest.push(...args.slice(i));
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
if (a === "--output" || a === "-o") value = args[++i] ?? "";
|
|
372
|
-
else if (a.startsWith("--output=")) value = a.slice(9);
|
|
373
|
-
else {
|
|
374
|
-
rest.push(a);
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
if (value !== "table" && value !== "json") return `--output 只能是 table 或 json(收到 ${JSON.stringify(value)})`;
|
|
378
|
-
output = value;
|
|
379
|
-
}
|
|
380
|
-
return {
|
|
381
|
-
output,
|
|
382
|
-
rest
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
function parseArgs(args, spec) {
|
|
386
|
-
const bools = spec.bools ?? [];
|
|
387
|
-
const known = new Set([...spec.values, ...bools]);
|
|
388
|
-
const pos = [];
|
|
389
|
-
const flags = /* @__PURE__ */ new Map();
|
|
390
|
-
const fail = (msg) => `${msg};${spec.usage}`;
|
|
391
|
-
for (let i = 0; i < args.length; i++) {
|
|
392
|
-
const a = args[i];
|
|
393
|
-
if (a === "--") {
|
|
394
|
-
pos.push(...args.slice(i + 1));
|
|
395
|
-
break;
|
|
396
|
-
}
|
|
397
|
-
if (!a.startsWith("--")) {
|
|
398
|
-
pos.push(a);
|
|
399
|
-
continue;
|
|
400
|
-
}
|
|
401
|
-
const eq = a.indexOf("=");
|
|
402
|
-
const name = eq < 0 ? a.slice(2) : a.slice(2, eq);
|
|
403
|
-
if (!known.has(name)) return fail(`未知选项 --${name}`);
|
|
404
|
-
if (flags.has(name)) return fail(`--${name} 重复了`);
|
|
405
|
-
if (bools.includes(name)) {
|
|
406
|
-
if (eq >= 0) return fail(`--${name} 不带值`);
|
|
407
|
-
flags.set(name, "true");
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
const value = eq < 0 ? args[++i] : a.slice(eq + 1);
|
|
411
|
-
if (value === void 0 || eq < 0 && value.startsWith("--") && known.has(value.slice(2))) return fail(`--${name} 需要一个值`);
|
|
412
|
-
flags.set(name, value);
|
|
413
|
-
}
|
|
414
|
-
if (pos.length < spec.min || pos.length > spec.max) return fail(pos.length < spec.min ? "缺少参数" : `多余的参数 ${pos[spec.max]}`);
|
|
415
|
-
return {
|
|
416
|
-
pos,
|
|
417
|
-
flags
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
function formatTable(headers, rows) {
|
|
421
|
-
const cell = (v) => str(v).replace(/\s*\n\s*/g, " ");
|
|
422
|
-
return [headers.join(" "), ...rows.map((r) => r.map(cell).join(" "))];
|
|
423
|
-
}
|
|
424
|
-
function str(v) {
|
|
425
|
-
if (v === void 0 || v === null) return "";
|
|
426
|
-
return typeof v === "string" ? v : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
427
|
-
}
|
|
428
|
-
function list(data, key) {
|
|
429
|
-
const v = data[key];
|
|
430
|
-
return Array.isArray(v) ? v : [];
|
|
431
|
-
}
|
|
432
|
-
function query(params) {
|
|
433
|
-
const qs = new URLSearchParams();
|
|
434
|
-
for (const [k, v] of Object.entries(params)) if (v !== void 0) qs.set(k, v);
|
|
435
|
-
const s = qs.toString();
|
|
436
|
-
return s === "" ? "" : `?${s}`;
|
|
437
|
-
}
|
|
438
|
-
function seg(v) {
|
|
439
|
-
return encodeURIComponent(v);
|
|
440
|
-
}
|
|
441
|
-
const KB_PATH = "/session/kb";
|
|
442
|
-
function checkLine(item) {
|
|
443
|
-
const where = [str(item.page_id) === "" ? "" : `页面 ${str(item.page_id)}`, str(item.block_id) === "" ? "" : `段 ${str(item.block_id)}`].filter((s) => s !== "").join(" ");
|
|
444
|
-
return `[${str(item.code)}]${where === "" ? "" : ` ${where}`}:${str(item.message)}`;
|
|
445
|
-
}
|
|
446
|
-
function conflictLine(item) {
|
|
447
|
-
const blocks = Array.isArray(item.block_ids) ? item.block_ids.map(str) : [];
|
|
448
|
-
const whole = item.whole_page === true;
|
|
449
|
-
if (blocks.length === 0) return `页面 ${str(item.page_id)} 整页冲突`;
|
|
450
|
-
return `页面 ${str(item.page_id)} 的段 ${blocks.join(", ")}${whole ? ";另有整页冲突(页头、位置或删改)" : ""}`;
|
|
451
|
-
}
|
|
452
|
-
function emit(ctx, data, render) {
|
|
453
|
-
if (ctx.output === "json") {
|
|
454
|
-
ctx.io.out(JSON.stringify(data));
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
for (const line of render()) ctx.io.out(line);
|
|
458
|
-
}
|
|
459
|
-
function usageError(ctx, message) {
|
|
460
|
-
ctx.io.err(message);
|
|
461
|
-
return EXIT_USAGE;
|
|
462
|
-
}
|
|
463
|
-
function kvLines(pairs) {
|
|
464
|
-
return pairs.filter(([, v]) => str(v) !== "").map(([k, v]) => `${k}:${str(v)}`);
|
|
465
|
-
}
|
|
466
199
|
const SCOPES = [
|
|
467
200
|
"full",
|
|
468
201
|
"outline",
|
|
@@ -473,7 +206,7 @@ const SCOPES = [
|
|
|
473
206
|
const DETAILS = ["simple", "with-ids"];
|
|
474
207
|
const DEFAULT_RAW_FILE_PREFIX = "raw-";
|
|
475
208
|
const kbList = async (args, ctx) => {
|
|
476
|
-
const p = parseArgs(args, {
|
|
209
|
+
const p = parseArgs$1(args, {
|
|
477
210
|
values: [],
|
|
478
211
|
min: 0,
|
|
479
212
|
max: 0,
|
|
@@ -498,7 +231,7 @@ const kbList = async (args, ctx) => {
|
|
|
498
231
|
return EXIT_OK;
|
|
499
232
|
};
|
|
500
233
|
const kbGet = async (args, ctx) => {
|
|
501
|
-
const p = parseArgs(args, {
|
|
234
|
+
const p = parseArgs$1(args, {
|
|
502
235
|
values: [],
|
|
503
236
|
min: 1,
|
|
504
237
|
max: 1,
|
|
@@ -528,7 +261,7 @@ const kbGet = async (args, ctx) => {
|
|
|
528
261
|
return EXIT_OK;
|
|
529
262
|
};
|
|
530
263
|
const kbSearch = async (args, ctx) => {
|
|
531
|
-
const p = parseArgs(args, {
|
|
264
|
+
const p = parseArgs$1(args, {
|
|
532
265
|
values: [
|
|
533
266
|
"kb",
|
|
534
267
|
"type",
|
|
@@ -567,7 +300,7 @@ const kbSearch = async (args, ctx) => {
|
|
|
567
300
|
return EXIT_OK;
|
|
568
301
|
};
|
|
569
302
|
const kbPageList = async (args, ctx) => {
|
|
570
|
-
const p = parseArgs(args, {
|
|
303
|
+
const p = parseArgs$1(args, {
|
|
571
304
|
values: [
|
|
572
305
|
"parent",
|
|
573
306
|
"cursor",
|
|
@@ -602,7 +335,7 @@ const kbPageList = async (args, ctx) => {
|
|
|
602
335
|
};
|
|
603
336
|
const kbPageFetch = async (args, ctx) => {
|
|
604
337
|
const usage = "用法:af kb page fetch <引用> [--scope full|outline|section|keyword|range] [--start-block-id <段 id>] [--end-block-id <段 id>] [--keyword <词>] [--draft <草稿 id>] [--detail simple|with-ids]";
|
|
605
|
-
const p = parseArgs(args, {
|
|
338
|
+
const p = parseArgs$1(args, {
|
|
606
339
|
values: [
|
|
607
340
|
"scope",
|
|
608
341
|
"start-block-id",
|
|
@@ -657,7 +390,7 @@ function renderPage(d) {
|
|
|
657
390
|
return lines;
|
|
658
391
|
}
|
|
659
392
|
const kbStale = async (args, ctx) => {
|
|
660
|
-
const p = parseArgs(args, {
|
|
393
|
+
const p = parseArgs$1(args, {
|
|
661
394
|
values: [],
|
|
662
395
|
min: 1,
|
|
663
396
|
max: 1,
|
|
@@ -678,7 +411,7 @@ const kbStale = async (args, ctx) => {
|
|
|
678
411
|
return EXIT_OK;
|
|
679
412
|
};
|
|
680
413
|
const kbRawList = async (args, ctx) => {
|
|
681
|
-
const p = parseArgs(args, {
|
|
414
|
+
const p = parseArgs$1(args, {
|
|
682
415
|
values: [],
|
|
683
416
|
min: 1,
|
|
684
417
|
max: 1,
|
|
@@ -703,7 +436,7 @@ const kbRawList = async (args, ctx) => {
|
|
|
703
436
|
return EXIT_OK;
|
|
704
437
|
};
|
|
705
438
|
const kbRawGet = async (args, ctx) => {
|
|
706
|
-
const p = parseArgs(args, {
|
|
439
|
+
const p = parseArgs$1(args, {
|
|
707
440
|
values: ["out"],
|
|
708
441
|
min: 1,
|
|
709
442
|
max: 1,
|
|
@@ -748,7 +481,7 @@ function claimRows(claims) {
|
|
|
748
481
|
]));
|
|
749
482
|
}
|
|
750
483
|
const kbClaimsGet = async (args, ctx) => {
|
|
751
|
-
const p = parseArgs(args, {
|
|
484
|
+
const p = parseArgs$1(args, {
|
|
752
485
|
values: ["draft"],
|
|
753
486
|
min: 1,
|
|
754
487
|
max: 1,
|
|
@@ -764,7 +497,7 @@ const kbClaimsGet = async (args, ctx) => {
|
|
|
764
497
|
};
|
|
765
498
|
const kbClaimsList = async (args, ctx) => {
|
|
766
499
|
const usage = "用法:af kb claims list <库> --evidence <证据前缀,如 task://>";
|
|
767
|
-
const p = parseArgs(args, {
|
|
500
|
+
const p = parseArgs$1(args, {
|
|
768
501
|
values: ["evidence"],
|
|
769
502
|
min: 1,
|
|
770
503
|
max: 1,
|
|
@@ -779,7 +512,7 @@ const kbClaimsList = async (args, ctx) => {
|
|
|
779
512
|
return EXIT_OK;
|
|
780
513
|
};
|
|
781
514
|
const kbSourceGet = async (args, ctx) => {
|
|
782
|
-
const p = parseArgs(args, {
|
|
515
|
+
const p = parseArgs$1(args, {
|
|
783
516
|
values: [],
|
|
784
517
|
min: 1,
|
|
785
518
|
max: 1,
|
|
@@ -800,6 +533,31 @@ const kbSourceGet = async (args, ctx) => {
|
|
|
800
533
|
]);
|
|
801
534
|
return EXIT_OK;
|
|
802
535
|
};
|
|
536
|
+
const USAGE$1 = "用法:af kb create --file <草稿.json>(本人在对话里明确确认创建之后才能调用)";
|
|
537
|
+
const kbCreate = async (args, ctx) => {
|
|
538
|
+
const p = parseArgs$1(args, {
|
|
539
|
+
values: ["file"],
|
|
540
|
+
min: 0,
|
|
541
|
+
max: 0,
|
|
542
|
+
usage: USAGE$1
|
|
543
|
+
});
|
|
544
|
+
if (typeof p === "string") return usageError(ctx, p);
|
|
545
|
+
const file = p.flags.get("file");
|
|
546
|
+
if (file === void 0 || file.trim() === "") return usageError(ctx, `缺少 --file;${USAGE$1}`);
|
|
547
|
+
let raw;
|
|
548
|
+
let draft;
|
|
549
|
+
try {
|
|
550
|
+
raw = await readFile(file, "utf8");
|
|
551
|
+
draft = JSON.parse(raw);
|
|
552
|
+
} catch (err) {
|
|
553
|
+
return usageError(ctx, `无法把 ${file} 读成 JSON:${String(err)}`);
|
|
554
|
+
}
|
|
555
|
+
if (typeof draft !== "object" || draft === null || Array.isArray(draft)) return usageError(ctx, `${file} 必须是 JSON 对象(知识库草稿)`);
|
|
556
|
+
const r = await ctx.request("POST", `${KB_PATH}/bases`, raw);
|
|
557
|
+
if ("exit" in r) return r.exit;
|
|
558
|
+
emit(ctx, r.data, () => kvLines([["已创建知识库", r.data.slug], ["页面路径", r.data.page_path]]));
|
|
559
|
+
return EXIT_OK;
|
|
560
|
+
};
|
|
803
561
|
const RISKS = [
|
|
804
562
|
"low",
|
|
805
563
|
"medium",
|
|
@@ -839,7 +597,7 @@ function parseNumber(text) {
|
|
|
839
597
|
}
|
|
840
598
|
const kbNote = async (args, ctx) => {
|
|
841
599
|
const usage = "用法:af kb note \"<要记的内容>\" [--link <网址>]";
|
|
842
|
-
const p = parseArgs(args, {
|
|
600
|
+
const p = parseArgs$1(args, {
|
|
843
601
|
values: ["link"],
|
|
844
602
|
min: 1,
|
|
845
603
|
max: 1,
|
|
@@ -858,7 +616,7 @@ const kbNote = async (args, ctx) => {
|
|
|
858
616
|
return EXIT_OK;
|
|
859
617
|
};
|
|
860
618
|
const kbPoolClaim = async (args, ctx) => {
|
|
861
|
-
const p = parseArgs(args, {
|
|
619
|
+
const p = parseArgs$1(args, {
|
|
862
620
|
values: [],
|
|
863
621
|
min: 0,
|
|
864
622
|
max: 0,
|
|
@@ -886,7 +644,7 @@ const kbPoolClaim = async (args, ctx) => {
|
|
|
886
644
|
};
|
|
887
645
|
const kbAnnotate = async (args, ctx) => {
|
|
888
646
|
const usage = "用法:af kb annotate [--kb <库>] [--page <页面 id> [--block <段 id> --quote \"<原句>\"]] \"<批注内容>\"";
|
|
889
|
-
const p = parseArgs(args, {
|
|
647
|
+
const p = parseArgs$1(args, {
|
|
890
648
|
values: [
|
|
891
649
|
"kb",
|
|
892
650
|
"page",
|
|
@@ -917,7 +675,7 @@ const kbAnnotate = async (args, ctx) => {
|
|
|
917
675
|
return EXIT_OK;
|
|
918
676
|
};
|
|
919
677
|
const kbDraftCreate = async (args, ctx) => {
|
|
920
|
-
const p = parseArgs(args, {
|
|
678
|
+
const p = parseArgs$1(args, {
|
|
921
679
|
values: ["title"],
|
|
922
680
|
min: 1,
|
|
923
681
|
max: 1,
|
|
@@ -935,7 +693,7 @@ const kbDraftCreate = async (args, ctx) => {
|
|
|
935
693
|
return EXIT_OK;
|
|
936
694
|
};
|
|
937
695
|
const kbDraftCheck = async (args, ctx) => {
|
|
938
|
-
const p = parseArgs(args, {
|
|
696
|
+
const p = parseArgs$1(args, {
|
|
939
697
|
values: [],
|
|
940
698
|
min: 1,
|
|
941
699
|
max: 1,
|
|
@@ -955,7 +713,7 @@ const kbDraftCheck = async (args, ctx) => {
|
|
|
955
713
|
return errors.length > 0 ? EXIT_REJECTED : EXIT_OK;
|
|
956
714
|
};
|
|
957
715
|
const kbDraftSync = async (args, ctx) => {
|
|
958
|
-
const p = parseArgs(args, {
|
|
716
|
+
const p = parseArgs$1(args, {
|
|
959
717
|
values: [],
|
|
960
718
|
min: 1,
|
|
961
719
|
max: 1,
|
|
@@ -992,7 +750,7 @@ function draftPagePath(draft, refText) {
|
|
|
992
750
|
}
|
|
993
751
|
const kbPageCreate = async (args, ctx) => {
|
|
994
752
|
const usage = "用法:af kb page create --draft <草稿 id> --slug <页面 slug> --type <类型> --title <标题> --description <一句话说明> --parent <父页路径,建在顶层写 --parent=> [--after <前一个同级页引用>] [--content-file <正文文件>]";
|
|
995
|
-
const p = parseArgs(args, {
|
|
753
|
+
const p = parseArgs$1(args, {
|
|
996
754
|
values: [
|
|
997
755
|
"draft",
|
|
998
756
|
"parent",
|
|
@@ -1049,7 +807,7 @@ const kbPagePatch = async (args, ctx) => {
|
|
|
1049
807
|
" str_replace:find, replace | append:content | set_meta:meta | move:parent, slug | delete:无",
|
|
1050
808
|
"最小示例:{\"op\":\"block_replace\",\"block\":\"a1b2\",\"content\":\"新的段落内容\"}"
|
|
1051
809
|
].join("\n");
|
|
1052
|
-
const p = parseArgs(args, {
|
|
810
|
+
const p = parseArgs$1(args, {
|
|
1053
811
|
values: [
|
|
1054
812
|
"draft",
|
|
1055
813
|
"version",
|
|
@@ -1089,7 +847,7 @@ async function postOp(target, body, ctx) {
|
|
|
1089
847
|
}
|
|
1090
848
|
const kbPageMove = async (args, ctx) => {
|
|
1091
849
|
const usage = "用法:af kb page move <引用> --draft <草稿 id> --version <版本> [--parent <新父页路径,留空=顶层>] [--slug <新 slug>]";
|
|
1092
|
-
const p = parseArgs(args, {
|
|
850
|
+
const p = parseArgs$1(args, {
|
|
1093
851
|
values: [
|
|
1094
852
|
"draft",
|
|
1095
853
|
"version",
|
|
@@ -1118,7 +876,7 @@ const kbPageMove = async (args, ctx) => {
|
|
|
1118
876
|
};
|
|
1119
877
|
const kbPageDelete = async (args, ctx) => {
|
|
1120
878
|
const usage = "用法:af kb page delete <引用> --draft <草稿 id> --version <版本>";
|
|
1121
|
-
const p = parseArgs(args, {
|
|
879
|
+
const p = parseArgs$1(args, {
|
|
1122
880
|
values: ["draft", "version"],
|
|
1123
881
|
min: 1,
|
|
1124
882
|
max: 1,
|
|
@@ -1136,7 +894,7 @@ const kbPageDelete = async (args, ctx) => {
|
|
|
1136
894
|
};
|
|
1137
895
|
const kbClaimsSet = async (args, ctx) => {
|
|
1138
896
|
const usage = "用法:af kb claims set <引用> --draft <草稿 id> --version <版本> --file <claims.json>(论断数组,或 {\"claims\": [...]})";
|
|
1139
|
-
const p = parseArgs(args, {
|
|
897
|
+
const p = parseArgs$1(args, {
|
|
1140
898
|
values: [
|
|
1141
899
|
"draft",
|
|
1142
900
|
"version",
|
|
@@ -1167,7 +925,7 @@ const kbClaimsSet = async (args, ctx) => {
|
|
|
1167
925
|
};
|
|
1168
926
|
const kbMrCreate = async (args, ctx) => {
|
|
1169
927
|
const usage = "用法:af kb mr create --draft <草稿 id> --title <标题> --summary <说明> --risk low|medium|high";
|
|
1170
|
-
const p = parseArgs(args, {
|
|
928
|
+
const p = parseArgs$1(args, {
|
|
1171
929
|
values: [
|
|
1172
930
|
"draft",
|
|
1173
931
|
"title",
|
|
@@ -1197,7 +955,7 @@ const kbMrCreate = async (args, ctx) => {
|
|
|
1197
955
|
};
|
|
1198
956
|
const kbMrUpdate = async (args, ctx) => {
|
|
1199
957
|
const usage = "用法:af kb mr update <编号> [--title <标题>] [--summary <说明>] [--risk low|medium|high]";
|
|
1200
|
-
const p = parseArgs(args, {
|
|
958
|
+
const p = parseArgs$1(args, {
|
|
1201
959
|
values: [
|
|
1202
960
|
"title",
|
|
1203
961
|
"summary",
|
|
@@ -1228,7 +986,7 @@ const kbMrUpdate = async (args, ctx) => {
|
|
|
1228
986
|
};
|
|
1229
987
|
const kbMrReady = async (args, ctx) => {
|
|
1230
988
|
const usage = "用法:af kb mr ready <编号>";
|
|
1231
|
-
const p = parseArgs(args, {
|
|
989
|
+
const p = parseArgs$1(args, {
|
|
1232
990
|
values: [],
|
|
1233
991
|
min: 1,
|
|
1234
992
|
max: 1,
|
|
@@ -1253,7 +1011,7 @@ function commentRows(comments, depth = 0) {
|
|
|
1253
1011
|
}
|
|
1254
1012
|
const kbMrCommentList = async (args, ctx) => {
|
|
1255
1013
|
const usage = "用法:af kb mr comment list <编号>";
|
|
1256
|
-
const p = parseArgs(args, {
|
|
1014
|
+
const p = parseArgs$1(args, {
|
|
1257
1015
|
values: [],
|
|
1258
1016
|
min: 1,
|
|
1259
1017
|
max: 1,
|
|
@@ -1275,7 +1033,7 @@ const kbMrCommentList = async (args, ctx) => {
|
|
|
1275
1033
|
};
|
|
1276
1034
|
const kbMrCommentAdd = async (args, ctx) => {
|
|
1277
1035
|
const usage = "用法:af kb mr comment add <编号> [--reply-to <评论 id>] \"<内容>\"";
|
|
1278
|
-
const p = parseArgs(args, {
|
|
1036
|
+
const p = parseArgs$1(args, {
|
|
1279
1037
|
values: ["reply-to"],
|
|
1280
1038
|
min: 2,
|
|
1281
1039
|
max: 2,
|
|
@@ -1301,6 +1059,7 @@ const KB_USAGE = [
|
|
|
1301
1059
|
" page fetch <引用> [--scope full|outline|section|keyword|range --start-block-id --end-block-id --keyword --draft --detail simple|with-ids] |",
|
|
1302
1060
|
" stale <库> | raw list <库> | raw get <id> [--out <文件>] | claims get <引用> [--draft] | claims list <库> --evidence <前缀> | source get <id>",
|
|
1303
1061
|
"收录作业:af kb pool claim(领取资料池里待整理的资料)",
|
|
1062
|
+
"创建(仅知识库构建器对话,本人确认后):af kb create --file <草稿.json>",
|
|
1304
1063
|
"记录:af kb note \"<内容>\" [--link <网址>] | annotate [--kb <库>] [--page <页面 id> --block <段 id> --quote \"<原句>\"] \"<批注>\"",
|
|
1305
1064
|
"改写(仅知识库作业):af kb draft create <库> [--title] | draft check <草稿 id> | draft sync <草稿 id> |",
|
|
1306
1065
|
" page create --draft <id> --slug --type --title --description [--parent --after --content-file] |",
|
|
@@ -1382,6 +1141,7 @@ function group(name, actions) {
|
|
|
1382
1141
|
}
|
|
1383
1142
|
const COMMANDS = {
|
|
1384
1143
|
list: kbList,
|
|
1144
|
+
create: kbCreate,
|
|
1385
1145
|
get: kbGet,
|
|
1386
1146
|
search: kbSearch,
|
|
1387
1147
|
stale: kbStale,
|
|
@@ -1441,8 +1201,10 @@ async function afKb(args, io) {
|
|
|
1441
1201
|
return handler(rest, makeCtx(io, parsed.output));
|
|
1442
1202
|
}
|
|
1443
1203
|
const SESSION_SCHEDULES_PATH = "/session/schedules";
|
|
1204
|
+
const SESSION_SCHEDULE_OPTIONS_PATH = "/session/schedules/options";
|
|
1444
1205
|
const TEMPLATES = ["kb_ingest", "kb_health"];
|
|
1445
|
-
const USAGE = "usage: af schedule create --template kb_ingest|kb_health --kb <slug> [--name <name>] [--at HH:MM] [--weekday 1-7] [--agent <agent_id>]";
|
|
1206
|
+
const USAGE = "usage: af schedule create --template kb_ingest|kb_health --kb <slug> [--name <name>] [--at HH:MM] [--weekday 1-7] [--agent <agent_id>] | af schedule create --module <module_id> --file <spec.json> | af schedule options";
|
|
1207
|
+
const MODULE_ID_PATTERN = /^\d+$/;
|
|
1446
1208
|
const AT_PATTERN = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
1447
1209
|
const WEEKDAY_MIN = 1;
|
|
1448
1210
|
const WEEKDAY_MAX = 7;
|
|
@@ -1456,10 +1218,12 @@ const OPTIONS = {
|
|
|
1456
1218
|
};
|
|
1457
1219
|
async function afSchedule(args, io) {
|
|
1458
1220
|
const [sub, ...rest] = args;
|
|
1221
|
+
if (sub === "options") return afScheduleOptions(rest, io);
|
|
1459
1222
|
if (sub !== "create") {
|
|
1460
1223
|
io.err(USAGE);
|
|
1461
1224
|
return EXIT_USAGE;
|
|
1462
1225
|
}
|
|
1226
|
+
if (rest.some((a) => /^--(module|file)(=|$)/.test(a))) return createFromSpec(rest, io);
|
|
1463
1227
|
const body = parseCreateArgs(rest);
|
|
1464
1228
|
if (typeof body === "string") {
|
|
1465
1229
|
io.err(body);
|
|
@@ -1508,6 +1272,140 @@ function isWeekday(text) {
|
|
|
1508
1272
|
const n = Number(text);
|
|
1509
1273
|
return /^\d+$/.test(text) && n >= WEEKDAY_MIN && n <= WEEKDAY_MAX;
|
|
1510
1274
|
}
|
|
1275
|
+
async function afScheduleOptions(args, io) {
|
|
1276
|
+
if (args.length > 0) {
|
|
1277
|
+
io.err(`af schedule options 不带参数; ${USAGE}`);
|
|
1278
|
+
return EXIT_USAGE;
|
|
1279
|
+
}
|
|
1280
|
+
const reply = await callSession("GET", SESSION_SCHEDULE_OPTIONS_PATH, void 0, io);
|
|
1281
|
+
if ("exit" in reply) return reply.exit;
|
|
1282
|
+
if (!isOK(reply.status)) return reportFailure(reply, io);
|
|
1283
|
+
const data = unwrapData(reply.text);
|
|
1284
|
+
io.out(data === void 0 ? reply.text : JSON.stringify(data));
|
|
1285
|
+
return EXIT_OK;
|
|
1286
|
+
}
|
|
1287
|
+
const SPEC_OPTIONS = ["module", "file"];
|
|
1288
|
+
async function createFromSpec(args, io) {
|
|
1289
|
+
const given = /* @__PURE__ */ new Map();
|
|
1290
|
+
for (let i = 0; i < args.length; i++) {
|
|
1291
|
+
const a = args[i];
|
|
1292
|
+
const eq = a.indexOf("=");
|
|
1293
|
+
const name = a.startsWith("--") ? eq < 0 ? a.slice(2) : a.slice(2, eq) : "";
|
|
1294
|
+
if (!SPEC_OPTIONS.includes(name)) {
|
|
1295
|
+
io.err(`--module / --file 不能和 ${a} 同用(知识库定时作业与通用自动任务是两种形态); ${USAGE}`);
|
|
1296
|
+
return EXIT_USAGE;
|
|
1297
|
+
}
|
|
1298
|
+
const value = eq < 0 ? args[++i] : a.slice(eq + 1);
|
|
1299
|
+
if (value === void 0 || value.trim() === "" || value.startsWith("--")) {
|
|
1300
|
+
io.err(`--${name} needs a value; ${USAGE}`);
|
|
1301
|
+
return EXIT_USAGE;
|
|
1302
|
+
}
|
|
1303
|
+
given.set(name, value);
|
|
1304
|
+
}
|
|
1305
|
+
const moduleID = given.get("module");
|
|
1306
|
+
const file = given.get("file");
|
|
1307
|
+
if (moduleID === void 0 || file === void 0) {
|
|
1308
|
+
io.err(`--module and --file are both required; ${USAGE}`);
|
|
1309
|
+
return EXIT_USAGE;
|
|
1310
|
+
}
|
|
1311
|
+
if (!MODULE_ID_PATTERN.test(moduleID)) {
|
|
1312
|
+
io.err(`--module must be a numeric module id (quoted string in JSON); ${USAGE}`);
|
|
1313
|
+
return EXIT_USAGE;
|
|
1314
|
+
}
|
|
1315
|
+
const raw = await readSpec(file, io);
|
|
1316
|
+
if (raw === void 0) return EXIT_USAGE;
|
|
1317
|
+
const reply = await callSession("POST", SESSION_SCHEDULES_PATH, `{"module_id":${JSON.stringify(moduleID)},"spec":${raw}}`, io);
|
|
1318
|
+
if ("exit" in reply) return reply.exit;
|
|
1319
|
+
if (!isOK(reply.status)) return reportFailure(reply, io);
|
|
1320
|
+
const data = unwrapData(reply.text);
|
|
1321
|
+
io.out(data === void 0 ? reply.text : JSON.stringify(data));
|
|
1322
|
+
return EXIT_OK;
|
|
1323
|
+
}
|
|
1324
|
+
async function readSpec(file, io) {
|
|
1325
|
+
let raw;
|
|
1326
|
+
let parsed;
|
|
1327
|
+
try {
|
|
1328
|
+
raw = await readFile(file, "utf8");
|
|
1329
|
+
parsed = JSON.parse(raw);
|
|
1330
|
+
} catch (err) {
|
|
1331
|
+
io.err(`cannot read ${file} as JSON: ${String(err)}`);
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
1335
|
+
io.err(`${file} must contain a JSON object (the schedule spec)`);
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
return raw;
|
|
1339
|
+
}
|
|
1340
|
+
const CURRENT_TASK = "current";
|
|
1341
|
+
const COMMENT_USAGE = "用法:af comment [--task <任务号>] <文件 | ->(- 表示读标准输入;文件内容就是评论正文)";
|
|
1342
|
+
const TIMELINE_USAGE = "用法:af task timeline [<任务号>] [--after <序号>] [--limit N] [--json](不写任务号看当前会话关联的任务)";
|
|
1343
|
+
function taskPath(task, suffix) {
|
|
1344
|
+
return `/session/tasks/${task === void 0 ? CURRENT_TASK : encodeURIComponent(task)}/${suffix}`;
|
|
1345
|
+
}
|
|
1346
|
+
async function afComment(args, io) {
|
|
1347
|
+
const p = parseArgs$1(args, {
|
|
1348
|
+
values: ["task"],
|
|
1349
|
+
min: 1,
|
|
1350
|
+
max: 1,
|
|
1351
|
+
usage: COMMENT_USAGE
|
|
1352
|
+
});
|
|
1353
|
+
if (typeof p === "string") {
|
|
1354
|
+
io.err(p);
|
|
1355
|
+
return EXIT_USAGE;
|
|
1356
|
+
}
|
|
1357
|
+
const source = p.pos[0];
|
|
1358
|
+
let text;
|
|
1359
|
+
try {
|
|
1360
|
+
text = source === "-" ? await readStdinText(io) : await readFile(source, "utf8");
|
|
1361
|
+
} catch (err) {
|
|
1362
|
+
io.err(`无法读取评论内容 ${source}:${String(err)}`);
|
|
1363
|
+
return EXIT_USAGE;
|
|
1364
|
+
}
|
|
1365
|
+
if (text.trim() === "") {
|
|
1366
|
+
io.err(`评论内容不能为空;${COMMENT_USAGE}`);
|
|
1367
|
+
return EXIT_USAGE;
|
|
1368
|
+
}
|
|
1369
|
+
const reply = await callSession("POST", taskPath(p.flags.get("task"), "comments"), JSON.stringify({ body: text }), io);
|
|
1370
|
+
if ("exit" in reply) return reply.exit;
|
|
1371
|
+
if (!isOK(reply.status)) return reportFailure(reply, io);
|
|
1372
|
+
const data = unwrapJson(reply.text);
|
|
1373
|
+
io.out(Object.keys(data).length === 0 ? reply.text : JSON.stringify(data));
|
|
1374
|
+
return EXIT_OK;
|
|
1375
|
+
}
|
|
1376
|
+
async function afTaskTimeline(args, io) {
|
|
1377
|
+
const p = parseArgs$1(args, {
|
|
1378
|
+
values: ["after", "limit"],
|
|
1379
|
+
bools: ["json"],
|
|
1380
|
+
min: 0,
|
|
1381
|
+
max: 1,
|
|
1382
|
+
usage: TIMELINE_USAGE
|
|
1383
|
+
});
|
|
1384
|
+
if (typeof p === "string") {
|
|
1385
|
+
io.err(p);
|
|
1386
|
+
return EXIT_USAGE;
|
|
1387
|
+
}
|
|
1388
|
+
for (const name of ["after", "limit"]) {
|
|
1389
|
+
const v = p.flags.get(name);
|
|
1390
|
+
if (v !== void 0 && !/^\d+$/.test(v)) {
|
|
1391
|
+
io.err(`--${name} 需要非负整数;${TIMELINE_USAGE}`);
|
|
1392
|
+
return EXIT_USAGE;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
const qs = query({
|
|
1396
|
+
after_seq: p.flags.get("after"),
|
|
1397
|
+
limit: p.flags.get("limit")
|
|
1398
|
+
});
|
|
1399
|
+
const reply = await callSession("GET", taskPath(p.pos[0], "events") + qs, void 0, io);
|
|
1400
|
+
if ("exit" in reply) return reply.exit;
|
|
1401
|
+
if (!isOK(reply.status)) return reportFailure(reply, io);
|
|
1402
|
+
if (p.flags.has("json")) {
|
|
1403
|
+
io.out(reply.text.trim());
|
|
1404
|
+
return EXIT_OK;
|
|
1405
|
+
}
|
|
1406
|
+
for (const line of timelineLines(unwrapJson(reply.text))) io.out(line);
|
|
1407
|
+
return EXIT_OK;
|
|
1408
|
+
}
|
|
1511
1409
|
const SESSION_WIKI_ASK_PATH = "/session/wiki/ask";
|
|
1512
1410
|
const SESSION_WIKI_LINES_PATH = "/session/wiki/lines";
|
|
1513
1411
|
const LINE_FLAG = "--line";
|
|
@@ -1628,7 +1526,7 @@ function printAnswer(text, io) {
|
|
|
1628
1526
|
io.out("来源:");
|
|
1629
1527
|
for (const s of sources) io.out(`- ${String(s.title ?? "")} ${String(s.url ?? "")}`.trimEnd());
|
|
1630
1528
|
}
|
|
1631
|
-
const AF_USAGE = "用法:af submit <产出文件> | af ask <提问文件> | af task status|pause|resume <任务号> | af task draft <草稿文件> [--id <草稿 id>] | af wiki ask \"<问题>\" [--line <产品线>] | af wiki lines | af schedule create --template <模板> --kb <库> | af kb <子命令>(af kb --help 看全部:list / get / search / page / note / annotate 等)| af browser snapshot|navigate|click|scroll|type|key";
|
|
1529
|
+
const AF_USAGE = "用法:af submit <产出文件> | af ask <提问文件> | af task status|pause|resume <任务号> | af task draft <草稿文件> [--id <草稿 id>] | af task timeline [<任务号>] [--after <序号>] [--limit N] | af comment [--task <任务号>] <文件|-> | af wiki ask \"<问题>\" [--line <产品线>] | af wiki lines | af schedule options | af schedule create --template <模板> --kb <库> | af schedule create --module <模块 id> --file <spec.json> | af kb create --file <草稿.json> | af kb <子命令>(af kb --help 看全部:list / get / search / page / note / annotate 等)| af browser snapshot|navigate|click|scroll|type|key";
|
|
1632
1530
|
async function runAf(args, io = defaultIO()) {
|
|
1633
1531
|
const [sub, ...rest] = args;
|
|
1634
1532
|
switch (sub) {
|
|
@@ -1637,7 +1535,9 @@ async function runAf(args, io = defaultIO()) {
|
|
|
1637
1535
|
case "browser": return afBrowser(rest, io);
|
|
1638
1536
|
case "task":
|
|
1639
1537
|
if (rest[0] === "draft") return afTaskDraft(rest.slice(1), io);
|
|
1538
|
+
if (rest[0] === "timeline") return afTaskTimeline(rest.slice(1), io);
|
|
1640
1539
|
return afTask(rest, io);
|
|
1540
|
+
case "comment": return afComment(rest, io);
|
|
1641
1541
|
case "wiki": return afWiki(rest, io);
|
|
1642
1542
|
case "schedule": return afSchedule(rest, io);
|
|
1643
1543
|
case "kb": return afKb(rest, io);
|