@guandata/decidex 0.4.0 → 0.6.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/src/cli.js CHANGED
@@ -7,7 +7,7 @@ import { homedir } from "node:os";
7
7
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
8
8
  import { parseArgs } from "node:util";
9
9
 
10
- import { ADAPTED_SERVER_VERSION, ADAPTED_SERVER_COMMIT, COMMAND_COMPATIBILITY, compareVersions, resolveCommandCompatibility, adaptAutomationSchedule } from "./compatibility.js";
10
+ import { ADAPTED_SERVER_VERSION, ADAPTED_SERVER_COMMIT, COLLABORATION_DISCLOSURE_VERSION, LEGACY_COLLABORATION_VERSIONS, COMMAND_COMPATIBILITY, compareVersions, resolveCommandCompatibility, adaptAutomationSchedule } from "./compatibility.js";
11
11
 
12
12
  import { apiCatalog, apiOperation, parameterFlag, operationPath, appendQuery } from "./catalog.js";
13
13
 
@@ -42,16 +42,19 @@ Usage:
42
42
  decidex agent file delete ID FILE_ID
43
43
  decidex agent file download ID FILE_ID FILE
44
44
  decidex agent models ID
45
+ decidex agent improvement get|enable|disable AGENT_ID
45
46
  decidex agent run ID (--message TEXT | --input FILE | --attach FILE) [--model-entry-id ID] [--reasoning-effort LEVEL] [--wait] [--follow] [--output FILE] [--timeout SECONDS]
46
47
 
47
48
  decidex session list [--status all|running|completed] [--query TEXT] [--cursor CURSOR] [--agent-id ID] [--pinned-session-id ID] [--pinned-agent-id ID]
48
49
  decidex session view SESSION_ID [--before CURSOR | --since CURSOR]
50
+ decidex session follow-ups SESSION_ID --run-id RUN_ID
49
51
  decidex session send SESSION_ID (--message TEXT | --input FILE) [--wait] [--follow]
50
52
  decidex session stop SESSION_ID
51
53
  decidex session rename SESSION_ID TITLE
52
54
  decidex session delete SESSION_ID
53
55
  decidex session model SESSION_ID MODEL_ENTRY_ID
54
56
  decidex session fork SESSION_ID RUN_ID
57
+ decidex session collaboration status|disclosure|consent|activate|continue|stop|task|download ...
55
58
  decidex session queue list SESSION_ID
56
59
  decidex session queue edit SESSION_ID DRAFT_ID (--message TEXT | --input FILE)
57
60
  decidex session queue delete SESSION_ID DRAFT_ID
@@ -114,6 +117,7 @@ Usage:
114
117
  decidex api METHOD PATH [--data FILE] [--output FILE]
115
118
  decidex version --json # local CLI version
116
119
  decidex server version # target version and commit
120
+ decidex server license # product license status; server >= 0.0.9
117
121
  decidex server check [COMMAND...] # version rules and selected protocol
118
122
 
119
123
  Turn options (agent run / session send):
@@ -199,6 +203,7 @@ released minimum versions are checked against the target server.`,
199
203
  decidex agent knowledge list|add|remove ...
200
204
  decidex agent file list|add|delete|download ...
201
205
  decidex agent models AGENT_ID
206
+ decidex agent improvement get|enable|disable AGENT_ID
202
207
  decidex agent run AGENT_ID (--message TEXT | --input FILE) [--wait] [--follow] [--output FILE]`,
203
208
  "agent run": `Usage:
204
209
  decidex agent run AGENT_ID (--message TEXT | --input FILE | --attach FILE) [--model-entry-id ID] [--reasoning-effort LEVEL] [--wait] [--follow] [--output FILE] [--timeout SECONDS]
@@ -210,15 +215,41 @@ to stderr, so stdout or --output remains machine-readable.
210
215
  --attach FILE is repeatable. --context-references FILE and --conversation-references FILE
211
216
  accept JSON arrays. --reasoning-effort null uses the model default.
212
217
  Use agent models AGENT_ID to discover supported catalog entries and efforts.`,
218
+ "agent improvement": `Usage:
219
+ decidex agent improvement get|enable|disable AGENT_ID
220
+
221
+ Requires server >= 0.0.8 and edit permission. Enabling processes new feedback only;
222
+ it does not replay feedback collected while disabled. Generated changes still require review.`,
223
+ "session collaboration": `Usage:
224
+ decidex session collaboration status SESSION_ID
225
+ decidex session collaboration disclosure [--agent-id ID]
226
+ decidex session collaboration consent --accept-governance-notice
227
+ decidex session collaboration activate SESSION_ID --accept-governance-notice
228
+ decidex session collaboration continue SESSION_ID --submission-id UUID
229
+ decidex session collaboration stop SESSION_ID --epoch N
230
+ decidex session collaboration task SESSION_ID TASK_ID
231
+ decidex session collaboration download SESSION_ID REMOTE_PATH FILE
232
+
233
+ Requires server >= 0.0.8. Only an idle normal Personal Agent user session can activate.
234
+ On >= 0.0.9, read disclosure and explicitly consent first; consent is saved for the current
235
+ organization membership (notice version 1), not automatically by activate.
236
+ On >= 0.0.10, the Agent must enable betaFeatures.collaborationEnabled before session creation.
237
+ Experts work with the owner's authority and may consume additional model credits.
238
+ Expert maintainers can review received and shared materials; share only necessary data.
239
+ Read status for the current work epoch before stopping. Keep the same submission UUID
240
+ for the same continuation; after an uncertain response inspect status, do not blindly retry.
241
+ download uses a material path returned by status, not a local path.`,
213
242
  session: `Usage:
214
243
  decidex session list [--status all|running|completed] [--query TEXT] [--cursor CURSOR] [--agent-id ID] [--pinned-session-id ID] [--pinned-agent-id ID]
215
244
  decidex session view SESSION_ID [--before CURSOR | --since CURSOR]
245
+ decidex session follow-ups SESSION_ID --run-id RUN_ID
216
246
  decidex session send SESSION_ID (--message TEXT | --input FILE) [--wait] [--follow]
217
247
  decidex session stop SESSION_ID
218
248
  decidex session rename SESSION_ID TITLE
219
249
  decidex session delete SESSION_ID
220
250
  decidex session model SESSION_ID MODEL_ENTRY_ID
221
251
  decidex session fork SESSION_ID RUN_ID
252
+ decidex session collaboration status|disclosure|consent|activate|continue|stop|task|download ...
222
253
  decidex session queue list SESSION_ID
223
254
  decidex session queue edit SESSION_ID DRAFT_ID (--message TEXT | --input FILE)
224
255
  decidex session queue delete SESSION_ID DRAFT_ID
@@ -285,6 +316,7 @@ Runtime Pod termination details require backend support.`,
285
316
  decidex ontology versions create NETWORK_ID [--description TEXT]`,
286
317
  server: `Usage:
287
318
  decidex server version
319
+ decidex server license # product license status; server >= 0.0.9
288
320
  decidex server check [COMMAND...]
289
321
 
290
322
  Unknown rules report supported=null; a newer server alone is not proof of compatibility.`,
@@ -422,6 +454,8 @@ async function request(path, { method = "GET", body, deadline, headers: extraHea
422
454
  const error = new Error(`Decidex ${response.status}: ${detail || response.statusText}`);
423
455
  error.httpStatus = response.status;
424
456
  error.code = payload && typeof payload === "object" ? payload.code : undefined;
457
+ error.reason = payload && typeof payload === "object" ? payload.reason : undefined;
458
+ if (error.code === "decidexLicenseAdmissionBlocked") error.message += ";请用 decidex server license 查询产品授权状态,这不等同于登录失效";
425
459
  error.requestId = payload && typeof payload === "object" ? payload.requestId : undefined;
426
460
  throw error;
427
461
  }
@@ -865,6 +899,10 @@ async function readIdentity(command, values) {
865
899
 
866
900
  async function serverCommand(action, args) {
867
901
  const { values, positionals } = commandArgs(args);
902
+ if (action === "license") {
903
+ expectPositionals(positionals, 0, "server license");
904
+ return print(await taskApi("decidex-license.list", {}, { values }));
905
+ }
868
906
  if (!["version", "check"].includes(action)) throw new Error(`未知 server 命令:${action || "(空)"}`);
869
907
  if (action === "version") expectPositionals(positionals, 0, "server version");
870
908
  const server = await targetVersion(values);
@@ -1000,6 +1038,12 @@ async function agentCommand(action, args) {
1000
1038
  const result = await request(`/api/personal-agents/${agentId}/sessions`, { values });
1001
1039
  return print({ schemaVersion: 1, modelCatalog: result.modelCatalog });
1002
1040
  }
1041
+ if (action === "improvement") {
1042
+ expectPositionals(positionals, 2, "agent improvement get|enable|disable AGENT_ID");
1043
+ const [operation, agentId] = positionals;
1044
+ if (!["get", "enable", "disable"].includes(operation)) throw new Error("improvement 只支持 get、enable、disable");
1045
+ return print(await taskApi(`personal-agents.background-improvement.${operation === "get" ? "list" : "put"}`, { agentId }, { body: operation === "get" ? undefined : { enabled: operation === "enable" }, values, deadline: Date.now() + positiveSeconds(values.timeout) * 1000 }));
1046
+ }
1003
1047
  if (action === "get") return print(await request(`/api/personal-agents/${encodeURIComponent(required(positionals[0], "ID"))}`, { values }));
1004
1048
  if (action === "apply") {
1005
1049
  expectPositionals(positionals, 1, "agent apply FILE");
@@ -1007,11 +1051,31 @@ async function agentCommand(action, args) {
1007
1051
  if (!spec || typeof spec !== "object" || Array.isArray(spec)) throw new Error("Agent 文件必须是 JSON 对象");
1008
1052
  const id = spec.id;
1009
1053
  if (id !== undefined && (typeof id !== "string" || !id.trim())) throw new Error("Agent id 必须是非空字符串");
1010
- const allowed = new Set(["id", "name", "description", "instructions", "avatarIcon", "avatarColor", "avatarImageDataUrl", "openingMessage", "presetQuestions", "contextReferences", "bizOntologyBindings", "betaFeatures", "actionSuggestionsEnabled", "biUserPropertiesEnabled", "biUserPropertyKeys", "biExplorationPolicy", "pluginSelection", "useScope", "sessionDefaultModelCatalogEntryId", "sessionDefaultReasoningEffort", ...(id ? ["builtInInstructions"] : [])]);
1054
+ const allowed = new Set(["id", "name", "description", "instructions", "avatarIcon", "avatarColor", "avatarImageDataUrl", "openingMessage", "presetQuestions", "contextReferences", "bizOntologyBindings", "betaFeatures", "actionSuggestionsEnabled", "promptSuggestionsEnabled", "biUserPropertiesEnabled", "biUserPropertyKeys", "biExplorationPolicy", "pluginSelection", "useScope", "sessionDefaultModelCatalogEntryId", "sessionDefaultReasoningEffort", ...(id ? ["builtInInstructions"] : [])]);
1011
1055
  const unknown = Object.keys(spec).filter((key) => !allowed.has(key));
1012
1056
  if (unknown.length) throw new Error(`Agent 文件包含不支持的字段:${unknown.join(", ")}`);
1013
1057
  const body = { ...spec };
1014
1058
  delete body.id;
1059
+ if (body.promptSuggestionsEnabled !== undefined) {
1060
+ if (typeof body.promptSuggestionsEnabled !== "boolean") throw new Error("promptSuggestionsEnabled 必须是布尔值");
1061
+ await commandCompatibility("agent apply prompt-suggestions", values);
1062
+ }
1063
+ if (body.betaFeatures?.collaborationDefaultEnabled !== undefined || body.betaFeatures?.collaborationExpertEnabled !== undefined) {
1064
+ if ([body.betaFeatures.collaborationDefaultEnabled, body.betaFeatures.collaborationExpertEnabled].some((value) => value !== undefined && typeof value !== "boolean")) throw new Error("旧协作开关必须是布尔值");
1065
+ const server = await targetVersion(values);
1066
+ if (compareVersions(server.version, LEGACY_COLLABORATION_VERSIONS.minVersion) < 0 || compareVersions(server.version, LEGACY_COLLABORATION_VERSIONS.before) >= 0) throw new Error("collaborationDefaultEnabled / collaborationExpertEnabled 仅适用于服务端 0.0.9;0.0.10 起需显式迁移为 collaborationEnabled 和专家名单,不能自动转换授权");
1067
+ }
1068
+ if (body.betaFeatures?.collaborationEnabled !== undefined || body.betaFeatures?.collaborationExpertAgentIds !== undefined) {
1069
+ const features = body.betaFeatures;
1070
+ if (features.collaborationEnabled !== undefined && typeof features.collaborationEnabled !== "boolean") throw new Error("collaborationEnabled 必须是布尔值");
1071
+ if (features.collaborationExpertAgentIds !== undefined) {
1072
+ const ids = features.collaborationExpertAgentIds;
1073
+ if (!Array.isArray(ids) || ids.length > 20 || ids.some((id) => typeof id !== "string" || !id.trim() || id.trim().length > 120)) throw new Error("collaborationExpertAgentIds 最多 20 项,每项为 1..120 字符的 Agent ID");
1074
+ features.collaborationExpertAgentIds = ids.map((id) => id.trim());
1075
+ if (new Set(features.collaborationExpertAgentIds).size !== ids.length) throw new Error("专家名单不能重复");
1076
+ }
1077
+ await commandCompatibility("agent apply collaboration", values);
1078
+ }
1015
1079
  if (body.biUserPropertiesEnabled !== undefined || body.biUserPropertyKeys !== undefined) {
1016
1080
  if (body.biUserPropertiesEnabled !== undefined && typeof body.biUserPropertiesEnabled !== "boolean") throw new Error("biUserPropertiesEnabled 必须是布尔值");
1017
1081
  if (body.biUserPropertyKeys !== undefined) {
@@ -1102,6 +1166,10 @@ async function sessionCommand(action, args) {
1102
1166
  "agent-id": { type: "string" },
1103
1167
  "pinned-session-id": { type: "string", multiple: true },
1104
1168
  "pinned-agent-id": { type: "string", multiple: true },
1169
+ "accept-governance-notice": { type: "boolean", default: false },
1170
+ "submission-id": { type: "string" },
1171
+ "run-id": { type: "string" },
1172
+ epoch: { type: "string" },
1105
1173
  "model-entry-id": { type: "string" },
1106
1174
  before: { type: "string" },
1107
1175
  since: { type: "string" },
@@ -1120,6 +1188,51 @@ async function sessionCommand(action, args) {
1120
1188
  timeout: { type: "string", default: "600" },
1121
1189
  wait: { type: "boolean", default: false },
1122
1190
  });
1191
+ if (action === "collaboration") {
1192
+ const [operation, sessionId, third, fourth] = positionals;
1193
+ if (["disclosure", "consent"].includes(operation)) {
1194
+ expectPositionals(positionals, 1, `session collaboration ${operation}`);
1195
+ if (operation === "consent" && !values["accept-governance-notice"]) throw new Error("确认材料共享、专家管理者审查及模型消耗后添加 --accept-governance-notice;本确认按当前组织成员保存");
1196
+ const disclosure = await taskApi("agent-collaboration.disclosure.list", {}, { query: values["agent-id"] ? { agentId: values["agent-id"] } : {}, values });
1197
+ if (operation === "disclosure") return emit(disclosure, values.output);
1198
+ if (!disclosure.available) throw new Error("目标尚未开放专家协作,未保存确认");
1199
+ if (disclosure.version !== COLLABORATION_DISCLOSURE_VERSION) throw new Error("协作说明版本已变化,请更新 CLI 并重新阅读说明,未保存确认");
1200
+ if (disclosure.accepted) return emit(disclosure, values.output);
1201
+ return emit(await taskApi("agent-collaboration.disclosure.create", {}, { body: { version: disclosure.version }, values }), values.output);
1202
+ }
1203
+ if (!["status", "activate", "continue", "stop", "task", "download"].includes(operation)) throw new Error("collaboration 只支持 status、activate、continue、stop、task、download");
1204
+ expectPositionals(positionals, operation === "download" ? 4 : operation === "task" ? 3 : 2, `session collaboration ${operation} SESSION_ID${operation === "download" ? " REMOTE_PATH FILE" : operation === "task" ? " TASK_ID" : ""}`);
1205
+ let body;
1206
+ if (operation === "activate") {
1207
+ if (!values["accept-governance-notice"]) throw new Error("专家使用会话所有者权限并可能增加模型消耗;确认后添加 --accept-governance-notice");
1208
+ body = { action: "activate", acceptGovernanceNotice: true };
1209
+ }
1210
+ if (operation === "continue") {
1211
+ const submissionId = required(values["submission-id"], "--submission-id UUID");
1212
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(submissionId)) throw new Error("--submission-id 必须是 UUID;同一次继续操作保持此值不变");
1213
+ body = { action: "continue", submissionId };
1214
+ }
1215
+ if (operation === "stop") body = { action: "stop", expectedEpoch: positiveInteger(required(values.epoch, "--epoch N"), "epoch") };
1216
+ if (operation === "download" && (!third || third.length > 2048)) throw new Error("REMOTE_PATH 需要 1..2048 字符的远端材料路径");
1217
+ const deadline = Date.now() + positiveSeconds(values.timeout) * 1000;
1218
+ const session = await resolveSession(sessionId, values, deadline);
1219
+ if (operation === "activate" && (await commandCompatibility("session collaboration", values)).protocol === "member-disclosure") {
1220
+ const disclosure = await taskApi("agent-collaboration.disclosure.list", {}, { query: { agentId: session.agentId }, values, deadline });
1221
+ if (!disclosure.available) throw new Error("目标尚未开放专家协作");
1222
+ if (!disclosure.accepted) throw new Error("请先阅读 session collaboration --help,然后显式运行 session collaboration consent --accept-governance-notice;本确认按当前组织成员保存");
1223
+ }
1224
+ const parameters = { agentId: session.agentId, sessionId, ...(operation === "task" ? { taskId: third } : {}) };
1225
+ const id = operation === "download" ? "materials.list" : operation === "task" ? "tasks.get" : body ? "create" : "list";
1226
+ const result = await taskApi(`personal-agents.sessions.collaboration.${id}`, parameters, { body, query: operation === "download" ? { path: third } : {}, output: operation === "download" ? fourth : undefined, values, deadline });
1227
+ return operation === "download" ? print(result) : emit(result, values.output);
1228
+ }
1229
+ if (action === "follow-ups") {
1230
+ expectPositionals(positionals, 1, "session follow-ups SESSION_ID --run-id RUN_ID");
1231
+ const runId = required(values["run-id"], "--run-id RUN_ID");
1232
+ const deadline = Date.now() + positiveSeconds(values.timeout) * 1000;
1233
+ const session = await resolveSession(positionals[0], values, deadline);
1234
+ return emit(await taskApi("personal-agents.sessions.follow-ups.list", { agentId: session.agentId, sessionId: positionals[0] }, { query: { runId }, values, deadline }), values.output);
1235
+ }
1123
1236
  if (action === "list") {
1124
1237
  expectPositionals(positionals, 0, "session list");
1125
1238
  if (!new Set(["all", "running", "completed"]).has(values.status)) throw new Error("--status 只支持 all、running、completed");
@@ -2093,7 +2206,7 @@ async function main() {
2093
2206
 
2094
2207
  main().catch((error) => {
2095
2208
  if (process.argv.includes("--json")) {
2096
- process.stderr.write(`${JSON.stringify({ schemaVersion: 1, error: { message: error.message, httpStatus: error.httpStatus ?? null, code: error.code ?? null, requestId: error.requestId ?? null } })}\n`);
2209
+ process.stderr.write(`${JSON.stringify({ schemaVersion: 1, error: { message: error.message, httpStatus: error.httpStatus ?? null, code: error.code ?? null, requestId: error.requestId ?? null, ...(error.reason !== undefined ? { reason: error.reason } : {}) } })}\n`);
2097
2210
  } else {
2098
2211
  const command = process.argv.slice(2, 4).filter((item) => !item.startsWith("-")).join(" ");
2099
2212
  process.stderr.write(`Error: ${error.message}${command ? `\nTry: decidex ${command} --help` : ""}\n`);
@@ -1,5 +1,7 @@
1
- export const ADAPTED_SERVER_VERSION = "0.0.7";
2
- export const ADAPTED_SERVER_COMMIT = "cfdf08dbab954510ea1ebb4dba6a50d6b2af8c82";
1
+ export const ADAPTED_SERVER_VERSION = "0.0.10";
2
+ export const ADAPTED_SERVER_COMMIT = "b14beee9a0478a102e93894b53c5eaa042a7e2ce";
3
+ export const COLLABORATION_DISCLOSURE_VERSION = 1; // Identical in tags 0.0.9 and 0.0.10.
4
+ export const LEGACY_COLLABORATION_VERSIONS = { minVersion: "0.0.9", before: "0.0.10" };
3
5
 
4
6
  // Version boundaries must be backed by release tags, not the current main version.
5
7
  // /api/auth/context first appears between tags 0.0.4 and 0.0.5 (a860e97ad).
@@ -15,6 +17,13 @@ export const COMMAND_COMPATIBILITY = {
15
17
  "session list pinned": { minVersion: "0.0.7" },
16
18
  "automation apply bi-groups": { minVersion: "0.0.7" },
17
19
  "automation apply partial": { minVersion: "0.0.7" },
20
+ // Collaboration routes and the background improvement switch first ship in 0.0.8.
21
+ "session collaboration": { minVersion: "0.0.8", protocol: "member-disclosure", legacy: { before: "0.0.9", protocol: "session-notice" } },
22
+ "agent improvement": { minVersion: "0.0.8" },
23
+ "server license": { minVersion: "0.0.9" },
24
+ "session follow-ups": { minVersion: "0.0.9" },
25
+ "agent apply prompt-suggestions": { minVersion: "0.0.9" },
26
+ "agent apply collaboration": { minVersion: "0.0.10" },
18
27
  };
19
28
 
20
29
  export function adaptAutomationSchedule(input, protocol, now = Date.now()) {