@gaoding/cli 1.3.1 → 1.4.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/contracts/operations/model.get/output.schema.json +13 -0
- package/dist/bin/agent-worker.js +13 -1
- package/dist/bin/gd-cli.js +7 -0
- package/dist/bin/insmind-cli.js +7 -0
- package/dist/bin/postinstall.js +11 -2
- package/dist/src/bootstrap/create-cli.js +15 -7
- package/dist/src/bootstrap/create-runtime.js +79 -36
- package/dist/src/bootstrap/run-agent-worker.js +12 -1
- package/dist/src/cli/action-binding.js +1 -2
- package/dist/src/cli/errors.js +5 -3
- package/dist/src/cli/task-commands.js +3 -2
- package/dist/src/features/agent/creative-agent-adapter.js +1 -0
- package/dist/src/features/agent/creative-protocol.js +4 -2
- package/dist/src/features/auth/access-policy.js +8 -0
- package/dist/src/features/auth/sso-service.js +76 -26
- package/dist/src/features/auth/use-cases.js +1 -1
- package/dist/src/features/dam/file-downloader.js +6 -6
- package/dist/src/features/dam/object-storage.js +6 -4
- package/dist/src/features/editor/bridge-process.js +9 -3
- package/dist/src/features/editor/bridge-server.js +4 -2
- package/dist/src/features/org/use-cases.js +8 -3
- package/dist/src/features/task/store.js +34 -2
- package/dist/src/features/task/use-cases.js +71 -6
- package/dist/src/features/tool/dynamic-schema.js +35 -7
- package/dist/src/features/tool/mns-catalog-adapter.js +30 -10
- package/dist/src/features/tool/tool-api-adapter.js +1 -0
- package/dist/src/features/update/update-notification.js +4 -2
- package/dist/src/platform/file-lock.js +68 -0
- package/dist/src/platform/redact.js +1 -1
- package/dist/src/platform/safe-upload-file.js +3 -3
- package/dist/src/platform/signed-http-transport.js +23 -9
- package/dist/src/telemetry/invocation.js +74 -122
- package/dist/src/telemetry/process-errors.js +43 -0
- package/dist/src/telemetry/sanitize.js +72 -0
- package/dist/src/telemetry/sls-sink.js +209 -22
- package/package.json +4 -4
- package/skills/gd-cli/references/creation.md +12 -0
|
@@ -1,30 +1,217 @@
|
|
|
1
|
-
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readdir, readFile, unlink, mkdir, chmod } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { cleanDiagnostic } from "./sanitize.js";
|
|
5
|
+
import { createLocalJsonFile } from "../platform/local-json-file.js";
|
|
6
|
+
import { withFileLock } from "../platform/file-lock.js";
|
|
7
|
+
const TTL = 7 * 86_400_000;
|
|
8
|
+
const CAPACITY = 10 * 1024 * 1024;
|
|
9
|
+
const BUDGET = 2_000;
|
|
10
|
+
export function eventKey(event) {
|
|
11
|
+
const key = event.event_name === "request_sent" || event.event_name === "result_ready"
|
|
12
|
+
? [event.cli_name, event.env, event.cli_task_id, event.event_name]
|
|
13
|
+
: [event.cli_name, event.env, event.trace_id, event.process_role, Number(event.record_seq)];
|
|
14
|
+
return createHash("sha256").update(JSON.stringify(key)).digest("hex");
|
|
15
|
+
}
|
|
16
|
+
export function wireEvent(event) {
|
|
17
|
+
const safe = cleanDiagnostic(event);
|
|
18
|
+
const wire = {};
|
|
19
|
+
for (const [key, value] of Object.entries(safe)) {
|
|
20
|
+
if (value !== undefined)
|
|
21
|
+
wire[key] = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
22
|
+
}
|
|
23
|
+
for (const key of ["error_stack", "remote_error_body", "error_message"]) {
|
|
24
|
+
if (wire[key] && wire[key].length > 8192) {
|
|
25
|
+
wire[key] = wire[key].slice(0, 8192);
|
|
26
|
+
wire.truncated = "true";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (wire.parameters && Buffer.byteLength(wire.parameters) > 32 * 1024) {
|
|
30
|
+
wire.parameters = JSON.stringify({ truncated: true, preview: utf8Prefix(wire.parameters, 8 * 1024) });
|
|
31
|
+
wire.truncated = "true";
|
|
32
|
+
}
|
|
33
|
+
if (Buffer.byteLength(JSON.stringify(wire)) > 64 * 1024) {
|
|
34
|
+
wire.truncated = "true";
|
|
35
|
+
for (const key of ["parameters", "remote_error_body", "error_stack", "error_message"]) {
|
|
36
|
+
delete wire[key];
|
|
37
|
+
if (Buffer.byteLength(JSON.stringify(wire)) <= 64 * 1024)
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
// Keep the envelope valid even for unexpectedly large identity or adapter fields.
|
|
41
|
+
for (const [key, value] of Object.entries(wire))
|
|
42
|
+
wire[key] = utf8Prefix(value, 1024);
|
|
43
|
+
}
|
|
44
|
+
return wire;
|
|
45
|
+
}
|
|
46
|
+
function utf8Prefix(value, bytes) {
|
|
47
|
+
let size = 0;
|
|
48
|
+
let result = "";
|
|
49
|
+
for (const char of value) {
|
|
50
|
+
size += Buffer.byteLength(char);
|
|
51
|
+
if (size > bytes)
|
|
52
|
+
break;
|
|
53
|
+
result += char;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
2
57
|
export function createSlsTelemetrySink(options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
58
|
+
const now = options.now ?? Date.now;
|
|
59
|
+
const entries = new Map();
|
|
60
|
+
let writes = Promise.resolve();
|
|
61
|
+
const file = (id) => createLocalJsonFile({ directory: options.directory, filename: `${id}.json` });
|
|
62
|
+
const locked = (run) => options.directory
|
|
63
|
+
? withFileLock(join(options.directory, ".lock"), run) : run();
|
|
64
|
+
async function load() {
|
|
65
|
+
if (!options.directory)
|
|
66
|
+
return;
|
|
67
|
+
entries.clear();
|
|
68
|
+
await mkdir(options.directory, { recursive: true, mode: 0o700 });
|
|
69
|
+
await chmod(options.directory, 0o700);
|
|
70
|
+
for (const name of await readdir(options.directory)) {
|
|
71
|
+
// All writers hold the same lock, so remaining atomic-write temporaries are orphaned.
|
|
72
|
+
if (/^(?:[a-f0-9]{64}|delivery-status)\.json\.tmp-[a-f0-9-]+$/u.test(name)) {
|
|
73
|
+
await unlink(join(options.directory, name)).catch(() => undefined);
|
|
74
|
+
await dropped("interrupted_write", 1);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (!/^[a-f0-9]{64}\.json$/u.test(name))
|
|
78
|
+
continue;
|
|
7
79
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
redirect: "error",
|
|
13
|
-
signal: AbortSignal.timeout(TIMEOUT_MS)
|
|
14
|
-
});
|
|
80
|
+
const entry = JSON.parse(await readFile(join(options.directory, name), "utf8"));
|
|
81
|
+
if (!Number.isFinite(entry.queuedAt) || !entry.event || eventKey(entry.event) !== name.slice(0, -5))
|
|
82
|
+
throw new Error();
|
|
83
|
+
entries.set(name.slice(0, -5), entry);
|
|
15
84
|
}
|
|
16
85
|
catch {
|
|
17
|
-
|
|
86
|
+
await unlink(join(options.directory, name)).catch(() => undefined);
|
|
87
|
+
await dropped("corrupt", 1);
|
|
18
88
|
}
|
|
19
89
|
}
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function wireEvent(event) {
|
|
23
|
-
const wire = {};
|
|
24
|
-
for (const [key, value] of Object.entries(event)) {
|
|
25
|
-
if (value === undefined)
|
|
26
|
-
continue;
|
|
27
|
-
wire[key] = key === "parameters" ? JSON.stringify(value) : String(value);
|
|
28
90
|
}
|
|
29
|
-
|
|
91
|
+
async function dropped(reason, count) {
|
|
92
|
+
if (!options.directory)
|
|
93
|
+
return;
|
|
94
|
+
const status = createLocalJsonFile({ directory: options.directory, filename: "delivery-status.json" });
|
|
95
|
+
let prior = {};
|
|
96
|
+
try {
|
|
97
|
+
prior = JSON.parse(await status.readText() ?? "{}");
|
|
98
|
+
}
|
|
99
|
+
catch { /* Replace corrupt diagnostic status. */ }
|
|
100
|
+
await status.writeTextAtomically(JSON.stringify({ count: (prior.count ?? 0) + count,
|
|
101
|
+
first_at_ms: prior.first_at_ms ?? now(), last_at_ms: now(), reason }));
|
|
102
|
+
}
|
|
103
|
+
async function remove(id) {
|
|
104
|
+
entries.delete(id);
|
|
105
|
+
if (options.directory)
|
|
106
|
+
await file(id).remove();
|
|
107
|
+
}
|
|
108
|
+
async function persist(id, entry) {
|
|
109
|
+
entries.set(id, entry);
|
|
110
|
+
if (options.directory)
|
|
111
|
+
await file(id).writeTextAtomically(JSON.stringify(entry));
|
|
112
|
+
}
|
|
113
|
+
async function trim() {
|
|
114
|
+
for (const [id, entry] of entries) {
|
|
115
|
+
if (now() - entry.queuedAt > (options.retentionMs ?? TTL)) {
|
|
116
|
+
await remove(id);
|
|
117
|
+
await dropped("expired", 1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let size = [...entries.values()].reduce((sum, e) => sum + Buffer.byteLength(JSON.stringify(e)), 0);
|
|
121
|
+
const priority = (e) => e.event.event_name === "request_sent" || e.event.event_name === "result_ready" ? 2
|
|
122
|
+
: "outcome" in e.event && e.event.outcome !== "success" ? 1 : 0;
|
|
123
|
+
for (const [id, entry] of [...entries].sort((a, b) => priority(a[1]) - priority(b[1]) || a[1].queuedAt - b[1].queuedAt)) {
|
|
124
|
+
if (size <= (options.maxBytes ?? CAPACITY))
|
|
125
|
+
break;
|
|
126
|
+
size -= Buffer.byteLength(JSON.stringify(entry));
|
|
127
|
+
await remove(id);
|
|
128
|
+
await dropped("capacity", 1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function enqueue(events) {
|
|
132
|
+
writes = writes.catch(() => undefined).then(() => locked(async () => {
|
|
133
|
+
await load();
|
|
134
|
+
for (const event of events) {
|
|
135
|
+
const id = eventKey(event);
|
|
136
|
+
if (entries.has(id))
|
|
137
|
+
continue;
|
|
138
|
+
// Persist the sanitized, bounded wire payload and replay it unchanged.
|
|
139
|
+
await persist(id, { event: wireEvent(event), queuedAt: now(), nextAttempt: 0, attempts: 0 });
|
|
140
|
+
}
|
|
141
|
+
await trim();
|
|
142
|
+
})).catch(() => undefined);
|
|
143
|
+
if (options.background)
|
|
144
|
+
void writes.then(() => { if (!sending)
|
|
145
|
+
void start(Date.now() + BUDGET); });
|
|
146
|
+
return writes;
|
|
147
|
+
}
|
|
148
|
+
let sending;
|
|
149
|
+
async function flush(deadline) {
|
|
150
|
+
for (let attempt = 0; attempt < 2 && Date.now() < deadline; attempt++) {
|
|
151
|
+
let batch = [];
|
|
152
|
+
await locked(async () => {
|
|
153
|
+
await load();
|
|
154
|
+
await trim();
|
|
155
|
+
let bytes = 0;
|
|
156
|
+
batch = [...entries].filter(([, e]) => e.nextAttempt <= now()).filter(([, e]) => {
|
|
157
|
+
bytes += Buffer.byteLength(JSON.stringify(e.event));
|
|
158
|
+
return bytes <= 512 * 1024;
|
|
159
|
+
}).slice(0, 100);
|
|
160
|
+
});
|
|
161
|
+
if (!batch.length || Date.now() >= deadline)
|
|
162
|
+
return;
|
|
163
|
+
let response;
|
|
164
|
+
let retryAfter = 0;
|
|
165
|
+
try {
|
|
166
|
+
const timeout = Math.max(1, deadline - Date.now());
|
|
167
|
+
const signal = AbortSignal.timeout(timeout);
|
|
168
|
+
// Bound even a custom fetch that ignores AbortSignal.
|
|
169
|
+
response = await new Promise((resolve, reject) => {
|
|
170
|
+
const abort = () => reject(signal.reason);
|
|
171
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
172
|
+
options.fetch(options.trackingUrl, { method: "POST", headers: { "Content-Type": "application/json" },
|
|
173
|
+
body: JSON.stringify({ __logs__: batch.map(([, e]) => e.event) }), redirect: "error", signal })
|
|
174
|
+
.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
175
|
+
});
|
|
176
|
+
const header = response.headers.get("Retry-After");
|
|
177
|
+
if (header)
|
|
178
|
+
retryAfter = Math.max(0, /^\d+$/u.test(header) ? Number(header) * 1000 : Date.parse(header) - now()) || 0;
|
|
179
|
+
await response.body?.cancel().catch(() => undefined);
|
|
180
|
+
}
|
|
181
|
+
catch { /* Retain the original records for the next invocation. */ }
|
|
182
|
+
const accepted = response?.ok === true;
|
|
183
|
+
const rejected = response !== undefined && response.status >= 400 && response.status < 500 && response.status !== 429;
|
|
184
|
+
await locked(async () => {
|
|
185
|
+
await load();
|
|
186
|
+
for (const [id, original] of batch) {
|
|
187
|
+
const entry = entries.get(id);
|
|
188
|
+
if (!entry)
|
|
189
|
+
continue;
|
|
190
|
+
if (accepted || rejected)
|
|
191
|
+
await remove(id);
|
|
192
|
+
else
|
|
193
|
+
await persist(id, { ...entry, attempts: original.attempts + 1,
|
|
194
|
+
nextAttempt: now() + Math.max(retryAfter, attempt === 0 ? 0 : Math.min(60_000, 1000 * 2 ** Math.min(6, original.attempts))) });
|
|
195
|
+
}
|
|
196
|
+
if (rejected)
|
|
197
|
+
await dropped(`http_${response.status}`, batch.length);
|
|
198
|
+
});
|
|
199
|
+
if (!accepted && (retryAfter > 0 || rejected))
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function start(deadline) {
|
|
204
|
+
sending ??= flush(deadline).catch(() => undefined).finally(() => { sending = undefined; });
|
|
205
|
+
return sending;
|
|
206
|
+
}
|
|
207
|
+
return { enqueue,
|
|
208
|
+
async send(events) {
|
|
209
|
+
const deadline = Date.now() + BUDGET;
|
|
210
|
+
await enqueue(events);
|
|
211
|
+
if (sending)
|
|
212
|
+
await sending;
|
|
213
|
+
if (Date.now() < deadline)
|
|
214
|
+
await start(deadline);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
30
217
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaoding/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Gaoding command-line interface for agents and people.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"vitest": "4.1.10"
|
|
56
56
|
},
|
|
57
57
|
"gaodingRelease": {
|
|
58
|
-
"sourceCommit": "
|
|
59
|
-
"pipelineId": "
|
|
60
|
-
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/
|
|
58
|
+
"sourceCommit": "d1bad7971a87411d6cc35728f35449915e120f96",
|
|
59
|
+
"pipelineId": "185792",
|
|
60
|
+
"pipelineUrl": "https://git.intra.gaoding.com/gtt/gaoding-cli/-/pipelines/185792"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# 创作
|
|
2
2
|
|
|
3
|
+
## 需求与素材
|
|
4
|
+
|
|
5
|
+
忠实传递用户需求、已提供素材和明确约束。缺少完成任务所必需的信息或素材时,由宿主向用户澄清,或将原始需求交给业务 Agent 判断并追问;不要擅自添加生成替代素材、忽略约束或改变任务目标的指令。用户明确允许自由创作、使用示意素材或自行补全的,按其授权执行。
|
|
6
|
+
|
|
7
|
+
以缺失内容是否影响任务成立、对象一致性或明确要求的满足为判断依据;可选的风格偏好不必一律追问。
|
|
8
|
+
|
|
9
|
+
例如,用户说“为这件商品制作宣传图”却没有提供可识别该商品的素材:
|
|
10
|
+
|
|
11
|
+
- 正例:请求补充商品图;或将这句原始需求交给业务 Agent,由其判断需要哪些素材并追问。
|
|
12
|
+
- 反例:自行加上“没有原图,先生成一个示意商品”。即使标注“概念展示”,也改变了用户指定的对象;应先取得用户选择。
|
|
13
|
+
- 自由创作的区别:“设计一件虚构商品并制作宣传图”已允许创造对象,可以直接创作;仅未指定配色或版式时,可自行设计这些风格细节。
|
|
14
|
+
|
|
3
15
|
## Creation Route
|
|
4
16
|
|
|
5
17
|
先判断 Creation Route,再选择或校验 Model。Model 和参数不决定 Agent 或 Tool 路由;两条路由都支持指定 Model 及其参数,`model list` 和 `model get` 是共享的实时发现能力。
|