@thinkingai/ae-cli 6.0.55 → 6.0.57

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.
Files changed (169) hide show
  1. package/README.md +35 -6
  2. package/README.zh.md +35 -6
  3. package/bin/ae-cli.js +5 -0
  4. package/bin/runtime-capabilities.json +5 -0
  5. package/cli-installation-guide.md +24 -3
  6. package/dist/{auth-RQBO6MTY.js → auth-YEIJLBFY.js} +61 -19
  7. package/dist/{automation-VAAQBM7Y.js → automation-NAR5DDGL.js} +94 -38
  8. package/dist/{capability-JRIFC4AJ.js → capability-P7DD4Q73.js} +50 -21
  9. package/dist/{chunk-5XJYLEVC.js → chunk-72NJKS7O.js} +4 -4
  10. package/dist/chunk-752BSLZC.js +222 -0
  11. package/dist/{chunk-RGYPSEYD.js → chunk-7ABK2PEJ.js} +3 -3
  12. package/dist/{chunk-Q5US7JC5.js → chunk-7JAVT5TK.js} +3 -3
  13. package/dist/{chunk-GHXZK54S.js → chunk-H3K5UGYC.js} +41 -13
  14. package/dist/{chunk-OP44TT4H.js → chunk-IN7KKL6K.js} +4 -2
  15. package/dist/{chunk-VZZNLV3I.js → chunk-JCWM2TYP.js} +61 -15
  16. package/dist/{chunk-S6M42KND.js → chunk-JEUXDY3B.js} +1 -1
  17. package/dist/{chunk-ZL7SGNIA.js → chunk-JNVVJ273.js} +58 -46
  18. package/dist/chunk-N6XBLRB7.js +105 -0
  19. package/dist/{chunk-AP7YP2NX.js → chunk-OAWPT7VP.js} +2 -2
  20. package/dist/{chunk-7KU2WNQE.js → chunk-QEMQKVHW.js} +37 -15
  21. package/dist/{chunk-CT7QDJS6.js → chunk-QVRIDN42.js} +2 -2
  22. package/dist/{chunk-RPBOAQQQ.js → chunk-QZUVLFNR.js} +1 -1
  23. package/dist/{chunk-3YVEAZUN.js → chunk-RJHGDWSC.js} +32 -21
  24. package/dist/{chunk-374V5R6N.js → chunk-TKVVACEJ.js} +6 -4
  25. package/dist/chunk-TULINOLS.js +2283 -0
  26. package/dist/chunk-YVG6QD3V.js +233 -0
  27. package/dist/{chunk-WNGFSIOB.js → chunk-Z3Q2AEIN.js} +237 -86
  28. package/dist/chunk-ZGIYG473.js +132 -0
  29. package/dist/{community-report-client-PEERQCX2.js → community-report-client-TJVCLZ3K.js} +1 -1
  30. package/dist/compat-check-PMEGUPZU.js +32 -0
  31. package/dist/{config-SICKWZ2A.js → config-VWVPR4WW.js} +43 -10
  32. package/dist/{context-NGVFPCBK.js → context-F6FCGTF3.js} +4 -4
  33. package/dist/{data-integration-BCLQFTGU.js → data-integration-6UAZO4GG.js} +207 -24
  34. package/dist/evaluation-4LO2O4AF.js +3714 -0
  35. package/dist/index.js +343 -79
  36. package/dist/{local-data-upload-client-TWMHFLUA.js → local-data-upload-client-KCMG6J62.js} +1 -1
  37. package/dist/{memory-CQKH2JAV.js → memory-HHPX3NF2.js} +6 -6
  38. package/dist/{metadata-EMFGUI2W.js → metadata-HEQQEEG3.js} +17 -9
  39. package/dist/{model-VX5M2CJ6.js → model-7UHGWYVR.js} +4 -4
  40. package/dist/{personal-semantic-preference-SLWVVYZ4.js → personal-semantic-preference-V4L6ZWR2.js} +7 -6
  41. package/dist/{project-semantic-DPSZBKQD.js → project-semantic-NKHKJX6M.js} +7 -6
  42. package/dist/{sync-RZIAV37C.js → sync-ZJMXCRIN.js} +8 -7
  43. package/dist/{te-agent-AORRE2FM.js → te-agent-WBKIFEQD.js} +757 -94
  44. package/dist/{te-analysis-ISXKJKRT.js → te-analysis-ADX7RKO4.js} +578 -94
  45. package/dist/{te-community-42M7ICDO.js → te-community-PREDRXG3.js} +722 -228
  46. package/dist/{te-dataops-BNKNZ4F2.js → te-dataops-ITWJHO2U.js} +9 -6
  47. package/dist/{te-engage-BZE3MBKT.js → te-engage-VE2NUH5V.js} +7 -6
  48. package/dist/{te-kb-ULATOTQ3.js → te-kb-WSMOW7WS.js} +407 -83
  49. package/dist/{te-system-UGHVKBVV.js → te-system-YM657FKO.js} +6 -6
  50. package/dist/{te-team-YA6SNOJ3.js → te-team-T2WRLOOD.js} +64 -41
  51. package/dist/{things-DTCOQIQB.js → things-6QOMFXOG.js} +7 -7
  52. package/dist/{update-ESNYKUVR.js → update-I4MOUYOX.js} +11 -7
  53. package/dist/{workspace-JEOHKFPX.js → workspace-LYDAP647.js} +6 -6
  54. package/package.json +25 -11
  55. package/skills/ae-agent/SKILL.md +20 -3
  56. package/skills/ae-agent/references/command_index.md +8 -0
  57. package/skills/ae-agent/references/resource-package.md +57 -0
  58. package/skills/ae-analysis/SKILL.md +23 -10
  59. package/skills/ae-analysis/references/adhoc_export.md +1 -1
  60. package/skills/ae-analysis/references/agent_review_preflight.md +55 -10
  61. package/skills/ae-analysis/references/agent_review_priorities_comparisons.md +5 -3
  62. package/skills/ae-analysis/references/agent_review_submit_to_page.md +60 -24
  63. package/skills/ae-analysis/references/ai_models/event.md +58 -2
  64. package/skills/ae-analysis/references/ai_models/rank_list.md +1 -0
  65. package/skills/ae-analysis/references/ai_models/retention.md +2 -0
  66. package/skills/ae-analysis/references/ai_models/revenue.md +2 -0
  67. package/skills/ae-analysis/references/analysis_data_export.md +11 -1
  68. package/skills/ae-analysis/references/asset_batch_info_export.md +2 -2
  69. package/skills/ae-analysis/references/asset_batch_sql_export.md +2 -2
  70. package/skills/ae-analysis/references/asset_export.md +1 -1
  71. package/skills/ae-analysis/references/bi_panel_page_data_export.md +1 -1
  72. package/skills/ae-analysis/references/check_export.md +1 -1
  73. package/skills/ae-analysis/references/command_index.md +39 -26
  74. package/skills/ae-analysis/references/dashboard_report_data_export.md +2 -0
  75. package/skills/ae-analysis/references/dashboard_report_get.md +6 -2
  76. package/skills/ae-analysis/references/dashboard_report_update.md +24 -5
  77. package/skills/ae-analysis/references/feedback_submit.md +1 -1
  78. package/skills/ae-analysis/references/governance_recommendation_export.md +40 -18
  79. package/skills/ae-analysis/references/governance_recommendation_run_update.md +13 -0
  80. package/skills/ae-analysis/references/live_data_export.md +1 -1
  81. package/skills/ae-analysis/references/metric_create.md +29 -0
  82. package/skills/ae-analysis/references/metric_get.md +2 -0
  83. package/skills/ae-analysis/references/metric_update.md +2 -0
  84. package/skills/ae-analysis/references/operation_record_export.md +1 -1
  85. package/skills/ae-analysis/references/plan_change_log_export.md +1 -1
  86. package/skills/ae-analysis/references/plan_export.md +1 -1
  87. package/skills/ae-analysis/references/project_info_get.md +4 -0
  88. package/skills/ae-analysis/references/project_member_group_add_members.md +35 -0
  89. package/skills/ae-analysis/references/project_member_group_create.md +25 -0
  90. package/skills/ae-analysis/references/project_member_group_delete.md +34 -0
  91. package/skills/ae-analysis/references/project_member_group_list.md +29 -0
  92. package/skills/ae-analysis/references/project_member_group_members.md +28 -0
  93. package/skills/ae-analysis/references/project_member_group_remove_members.md +35 -0
  94. package/skills/ae-analysis/references/project_member_group_rename.md +26 -0
  95. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +9 -1
  96. package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +6 -1
  97. package/skills/ae-analysis/references/report_data_export.md +1 -1
  98. package/skills/ae-analysis/references/scenario_append.md +31 -0
  99. package/skills/ae-analysis/references/scenario_begin.md +11 -0
  100. package/skills/ae-analysis/references/scenario_collect.md +43 -0
  101. package/skills/ae-analysis/references/scenario_evaluation.md +18 -0
  102. package/skills/ae-analysis/references/scenario_get.md +15 -0
  103. package/skills/ae-analysis/references/scenario_list.md +64 -0
  104. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +73 -4
  105. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +14 -1
  106. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +5 -1
  107. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/execution-contract.mjs +173 -0
  108. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/generate-build-ir.mjs +109 -64
  109. package/skills/ae-automation/SKILL.md +2 -2
  110. package/skills/ae-automation/references/cli.md +18 -1
  111. package/skills/ae-capability/SKILL.md +7 -3
  112. package/skills/ae-community/SKILL.md +77 -27
  113. package/skills/ae-community/references/community-analyzing-theme-comment.md +10 -8
  114. package/skills/ae-community/references/community-data-quality.md +68 -0
  115. package/skills/ae-community/references/community-query-evidence.md +85 -0
  116. package/skills/ae-community/references/community-scenario-capabilities.md +137 -0
  117. package/skills/ae-community/references/community-weekly-report.md +6 -3
  118. package/skills/ae-community/references/get_channel_info.md +7 -4
  119. package/skills/ae-community/references/get_comment_tag_analysis.md +3 -3
  120. package/skills/ae-community/references/get_comments_summary.md +4 -4
  121. package/skills/ae-community/references/get_corpus_tags.md +3 -3
  122. package/skills/ae-community/references/get_daily_summary.md +3 -3
  123. package/skills/ae-community/references/get_hot_topics.md +3 -3
  124. package/skills/ae-community/references/get_livestream_analysis.md +3 -3
  125. package/skills/ae-community/references/get_livestream_detail.md +4 -4
  126. package/skills/ae-community/references/get_livestream_list.md +3 -3
  127. package/skills/ae-community/references/get_livestream_overview.md +3 -3
  128. package/skills/ae-community/references/get_livestream_room_metrics.md +3 -3
  129. package/skills/ae-community/references/get_livestream_rooms.md +3 -3
  130. package/skills/ae-community/references/get_overview_metrics.md +3 -3
  131. package/skills/ae-community/references/get_post_detail.md +4 -4
  132. package/skills/ae-community/references/get_risk_content.md +5 -5
  133. package/skills/ae-community/references/get_sentiment_overview.md +4 -4
  134. package/skills/ae-community/references/get_tag_trends.md +3 -3
  135. package/skills/ae-community/references/get_topic_detail.md +3 -3
  136. package/skills/ae-community/references/list_sources.md +28 -0
  137. package/skills/ae-community/references/list_spaces.md +39 -0
  138. package/skills/ae-community/references/search_posts.md +21 -7
  139. package/skills/ae-data-integration/SKILL.md +6 -4
  140. package/skills/ae-data-integration/references/error-handling.md +1 -0
  141. package/skills/ae-data-integration/references/handoff.md +1 -1
  142. package/skills/ae-data-integration/references/sink-upload.md +11 -0
  143. package/skills/ae-data-integration/references/source-inspect.md +2 -1
  144. package/skills/ae-data-integration/references/transform.md +1 -1
  145. package/skills/ae-data-integration/references/ue-mapping.md +1 -1
  146. package/skills/ae-evaluation/SKILL.md +83 -0
  147. package/skills/ae-evaluation/references/access-and-members.md +55 -0
  148. package/skills/ae-evaluation/references/connections.md +78 -0
  149. package/skills/ae-evaluation/references/datasets.md +57 -0
  150. package/skills/ae-evaluation/references/evaluators.md +81 -0
  151. package/skills/ae-evaluation/references/files.md +33 -0
  152. package/skills/ae-evaluation/references/integrations.md +39 -0
  153. package/skills/ae-evaluation/references/runs.md +160 -0
  154. package/skills/ae-evaluation/references/schedules.md +31 -0
  155. package/skills/ae-kb/SKILL.md +33 -6
  156. package/skills/ae-kb/references/publication.md +81 -0
  157. package/skills/ae-kb/references/query-workflow.md +14 -1
  158. package/skills/ae-metadata/SKILL.md +3 -2
  159. package/skills/ae-metadata/references/metadata_data_table_download.md +7 -1
  160. package/skills/ae-metadata/references/metadata_data_table_get.md +37 -0
  161. package/skills/ae-team/SKILL.md +2 -2
  162. package/skills/ae-team/references/run-start.md +1 -0
  163. package/skills/ae-team/references/run-watch.md +7 -5
  164. package/skills/ae-things/SKILL.md +53 -51
  165. package/skills/ae-things/references/cli.md +56 -54
  166. package/skills/ae-things-progress/SKILL.md +20 -20
  167. package/skills/ae-things-review/SKILL.md +19 -19
  168. package/dist/chunk-6VNIR4AP.js +0 -1422
  169. package/dist/chunk-CI24BDR2.js +0 -43
@@ -2,23 +2,44 @@ import { createRequire as __createRequire } from 'node:module'; const require =
2
2
  import {
3
3
  kbApi,
4
4
  kbUpload
5
- } from "./chunk-7KU2WNQE.js";
5
+ } from "./chunk-QEMQKVHW.js";
6
6
  import {
7
7
  TeAgentApiError
8
- } from "./chunk-3YVEAZUN.js";
8
+ } from "./chunk-RJHGDWSC.js";
9
9
  import {
10
10
  CapabilityGatewayError
11
- } from "./chunk-VZZNLV3I.js";
11
+ } from "./chunk-JCWM2TYP.js";
12
12
  import {
13
13
  printError
14
- } from "./chunk-6VNIR4AP.js";
14
+ } from "./chunk-752BSLZC.js";
15
15
  import "./chunk-Y74WTIKJ.js";
16
- import "./chunk-GHXZK54S.js";
17
- import "./chunk-ZL7SGNIA.js";
16
+ import "./chunk-TULINOLS.js";
17
+ import "./chunk-H3K5UGYC.js";
18
+ import "./chunk-JNVVJ273.js";
18
19
  import {
20
+ CliApiError,
19
21
  CliValidationError,
20
- PermissionError
21
- } from "./chunk-WNGFSIOB.js";
22
+ PermissionError,
23
+ kbExecutionContextRequired
24
+ } from "./chunk-Z3Q2AEIN.js";
25
+
26
+ // src/commands/te-kb/project-target.ts
27
+ var API_PATH = "/agent/api/project-semantic-target";
28
+ var projectTargetGet = {
29
+ service: "kb",
30
+ resource: "project-target",
31
+ command: "get",
32
+ description: "Resolve the company project semantic KB on the server, including disabled and inaccessible candidates. Never select a different target on permission denial.",
33
+ flags: [{ name: "project-id", type: "string", required: true, desc: "Exact project ID" }],
34
+ risk: "read",
35
+ validate(ctx) {
36
+ if (!/^[1-9]\d{0,15}$/.test(ctx.str("project-id"))) throw new Error("A valid --project-id is required.");
37
+ },
38
+ dryRun(ctx) {
39
+ return { method: "GET", url: `${ctx.host().replace(/\/$/, "")}${API_PATH}`, params: { projectId: ctx.str("project-id") } };
40
+ },
41
+ execute: async (ctx) => kbApi(ctx, "GET", API_PATH, { projectId: ctx.str("project-id") })
42
+ };
22
43
 
23
44
  // src/commands/te-kb/target-scope.ts
24
45
  function getExternalKnowledgeBaseTargetScope(ctx) {
@@ -30,8 +51,244 @@ function getExternalKnowledgeBaseTargetScope(ctx) {
30
51
  );
31
52
  }
32
53
 
54
+ // src/commands/te-kb/publication.ts
55
+ var root = "/agent/api/external/knowledge-bases";
56
+ var options = { preserveErrorMetadata: true, retryUnauthorized: false };
57
+ var targets = [
58
+ { name: "name", type: "string", required: true, desc: "Knowledge base name" },
59
+ {
60
+ name: "scope",
61
+ type: "string",
62
+ desc: "personal | company; omit for personal then company lookup"
63
+ }
64
+ ];
65
+ var candidate = {
66
+ name: "candidate",
67
+ type: "string",
68
+ required: true,
69
+ desc: "Immutable candidate ID returned by publication get"
70
+ };
71
+ function selector(ctx) {
72
+ return {
73
+ name: ctx.str("name"),
74
+ ...getExternalKnowledgeBaseTargetScope(ctx) ? { scope: getExternalKnowledgeBaseTargetScope(ctx) } : {}
75
+ };
76
+ }
77
+ function candidatePath(ctx) {
78
+ const id = ctx.str("candidate");
79
+ if (!/^[A-Za-z0-9_-]{1,191}$/.test(id)) throw new CliValidationError("Invalid --candidate");
80
+ return `${root}/publication-candidates/${id}`;
81
+ }
82
+ function targetCommand(resource, command2, suffix, extra = []) {
83
+ const method = command2 === "discard" ? "POST" : "GET";
84
+ const endpoint3 = (ctx) => resource === "publication" ? `${root}/publication` : candidatePath(ctx) + suffix;
85
+ const params = (ctx) => ({
86
+ ...selector(ctx),
87
+ ...command2 === "read" ? { path: ctx.str("path") } : {},
88
+ ...command2 === "changes" ? changesParams(ctx) : {}
89
+ });
90
+ return {
91
+ service: "kb",
92
+ resource,
93
+ command: command2,
94
+ risk: command2 === "discard" ? "high-risk-write" : "read",
95
+ description: command2 === "discard" ? "Close a retryable failed candidate after a confirmed failed publication; pending requests use approval cancel." : `Read ${resource} ${command2} from immutable publication metadata.`,
96
+ flags: [...targets, ...resource === "candidate" ? [candidate] : [], ...extra],
97
+ validate: (ctx) => {
98
+ selector(ctx);
99
+ endpoint3(ctx);
100
+ if (command2 === "changes") changesParams(ctx);
101
+ },
102
+ dryRun: (ctx) => ({
103
+ method,
104
+ url: ctx.host().replace(/\/$/, "") + endpoint3(ctx),
105
+ params: params(ctx),
106
+ ...method === "POST" ? { body: {} } : {}
107
+ }),
108
+ execute: async (ctx) => {
109
+ const result = await kbApi(
110
+ ctx,
111
+ method,
112
+ endpoint3(ctx),
113
+ params(ctx),
114
+ method === "POST" ? {} : void 0,
115
+ options
116
+ );
117
+ if (command2 === "changes") {
118
+ const query6 = changesParams(ctx);
119
+ const directoryRequested = !query6.entryId && ["group", "search", "change", "offset", "limit"].some((key) => key in query6);
120
+ const memberRequested = query6.entryId && ["fileOffset", "fileLimit", "fileSearch"].some((key) => key in query6);
121
+ const body4 = result && typeof result === "object" ? result : {};
122
+ if (directoryRequested && !body4.page || memberRequested && !body4.filePage)
123
+ throw new CliApiError(
124
+ "This server does not support filtered or paginated candidate changes.",
125
+ {
126
+ code: "KB_CANDIDATE_PAGING_UNSUPPORTED",
127
+ hint: "Deploy a compatible server or omit the new paging and filter flags."
128
+ }
129
+ );
130
+ }
131
+ return result;
132
+ }
133
+ };
134
+ }
135
+ var publicationGet = targetCommand("publication", "get", "");
136
+ var candidateGet = targetCommand("candidate", "get", "");
137
+ var candidateRead = targetCommand("candidate", "read", "/files", [
138
+ {
139
+ name: "path",
140
+ type: "string",
141
+ required: true,
142
+ desc: "index.md, CLAUDE.md or wiki Markdown path from the candidate"
143
+ }
144
+ ]);
145
+ function changesParams(ctx) {
146
+ const entryId = ctx.str("entry-id");
147
+ const file = ctx.str("file");
148
+ const context = ctx.optionalNum("context");
149
+ if (file && !entryId) throw new CliValidationError("--file requires --entry-id");
150
+ if (context !== void 0 && context !== 0 && context !== 3)
151
+ throw new CliValidationError("--context must be 0 or 3");
152
+ const group = ctx.str("group");
153
+ const change = ctx.str("change");
154
+ const search = ctx.str("search");
155
+ const fileSearch = ctx.str("file-search");
156
+ if (group && !["sources", "wiki", "index"].includes(group))
157
+ throw new CliValidationError("--group must be sources, wiki or index");
158
+ if (change && !["added", "modified", "deleted"].includes(change))
159
+ throw new CliValidationError("--change must be added, modified or deleted");
160
+ if (search.length > 500 || fileSearch.length > 500)
161
+ throw new CliValidationError("Search text must not exceed 500 characters");
162
+ const paging = {};
163
+ for (const [flag2, key, min, max] of [
164
+ ["offset", "offset", 0, 1e6],
165
+ ["limit", "limit", 1, 200],
166
+ ["file-offset", "fileOffset", 0, 1e6],
167
+ ["file-limit", "fileLimit", 1, 200]
168
+ ]) {
169
+ const value = ctx.optionalNum(flag2);
170
+ if (value === void 0) continue;
171
+ if (!Number.isInteger(value) || value < min || value > max)
172
+ throw new CliValidationError(`--${flag2} must be an integer between ${min} and ${max}`);
173
+ paging[key] = value;
174
+ }
175
+ if ((fileSearch || "fileOffset" in paging || "fileLimit" in paging) && !entryId)
176
+ throw new CliValidationError("Member search and pagination require --entry-id");
177
+ return {
178
+ ...paging,
179
+ ...group ? { group } : {},
180
+ ...change ? { change } : {},
181
+ ...search ? { search } : {},
182
+ ...fileSearch ? { fileSearch } : {},
183
+ ...entryId ? { entryId } : {},
184
+ ...file ? { file } : {},
185
+ ...context !== void 0 ? { context } : {}
186
+ };
187
+ }
188
+ var candidateChanges = targetCommand("candidate", "changes", "/changes", [
189
+ { name: "group", type: "string", desc: "Filter changed entries: sources | wiki | index" },
190
+ { name: "search", type: "string", desc: "Search changed names or paths (up to 500 characters)" },
191
+ { name: "change", type: "string", desc: "Filter change type: added | modified | deleted" },
192
+ { name: "offset", type: "number", desc: "Changed entry offset (0 to 1000000)" },
193
+ {
194
+ name: "limit",
195
+ type: "number",
196
+ desc: "Changed entry page size (1 to 200); omit for legacy full list"
197
+ },
198
+ { name: "file-offset", type: "number", desc: "Changed member offset (0 to 1000000)" },
199
+ { name: "file-limit", type: "number", desc: "Changed member page size (1 to 200)" },
200
+ { name: "file-search", type: "string", desc: "Search changed member paths" },
201
+ {
202
+ name: "entry-id",
203
+ type: "string",
204
+ desc: "Changed entry ID returned by candidate changes; omit to list changes"
205
+ },
206
+ {
207
+ name: "file",
208
+ type: "string",
209
+ desc: "Changed member path returned by an entry detail; requires --entry-id"
210
+ },
211
+ {
212
+ name: "context",
213
+ type: "number",
214
+ desc: "Unchanged context lines: 0 (default) or 3"
215
+ }
216
+ ]);
217
+ var candidateDiscard = targetCommand("candidate", "discard", "/discard");
218
+ function createBody(ctx) {
219
+ const sources = ctx.json("sources");
220
+ if (sources !== void 0 && sources !== null && (!Array.isArray(sources) || sources.length > 100 || sources.some(
221
+ (source) => !source || !["personal", "company", "system"].includes(source.scope) || typeof source.name !== "string" || !source.name || Object.keys(source).some((key) => !["name", "scope"].includes(key))
222
+ )))
223
+ throw new CliValidationError("--sources must be an array of {scope,name}");
224
+ return {
225
+ ...sources ? { sources } : {},
226
+ ...ctx.str("locale") ? { locale: ctx.str("locale") } : {}
227
+ };
228
+ }
229
+ var readContextCreate = {
230
+ service: "kb",
231
+ resource: "read-context",
232
+ command: "create",
233
+ risk: "read",
234
+ description: "Pin the current authorized formal KB views for subsequent reads (15 minutes).",
235
+ flags: [
236
+ {
237
+ name: "sources",
238
+ type: "json",
239
+ desc: "Optional array of {scope,name}; omit to discover authorized published KBs"
240
+ },
241
+ { name: "locale", type: "string", desc: "zh | en | ja | ko" }
242
+ ],
243
+ validate: (ctx) => {
244
+ createBody(ctx);
245
+ },
246
+ dryRun: (ctx) => ({
247
+ method: "POST",
248
+ url: ctx.host().replace(/\/$/, "") + `${root}/read-contexts`,
249
+ body: createBody(ctx)
250
+ }),
251
+ execute: (ctx) => kbApi(ctx, "POST", `${root}/read-contexts`, {}, createBody(ctx), options)
252
+ };
253
+ var readContextRelease = {
254
+ service: "kb",
255
+ resource: "read-context",
256
+ command: "release",
257
+ risk: "write",
258
+ description: "Release a read context owned by the current user.",
259
+ flags: [
260
+ {
261
+ name: "id",
262
+ type: "string",
263
+ required: true,
264
+ desc: "readContextId returned by read-context create"
265
+ }
266
+ ],
267
+ dryRun: (ctx) => ({
268
+ method: "DELETE",
269
+ url: ctx.host().replace(/\/$/, "") + `${root}/read-contexts/${encodeURIComponent(ctx.str("id"))}`
270
+ }),
271
+ execute: (ctx) => kbApi(
272
+ ctx,
273
+ "DELETE",
274
+ `${root}/read-contexts/${encodeURIComponent(ctx.str("id"))}`,
275
+ {},
276
+ {},
277
+ options
278
+ )
279
+ };
280
+ var publicationCommands = [
281
+ publicationGet,
282
+ candidateGet,
283
+ candidateRead,
284
+ candidateChanges,
285
+ candidateDiscard,
286
+ readContextCreate,
287
+ readContextRelease
288
+ ];
289
+
33
290
  // src/commands/te-kb/source-check-url-updates.ts
34
- var API_PATH = "/agent/api/external/knowledge-bases/sources/check-url-updates";
291
+ var API_PATH2 = "/agent/api/external/knowledge-bases/sources/check-url-updates";
35
292
  function body(ctx) {
36
293
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
37
294
  return { name: ctx.str("name").trim(), sourceId: ctx.str("id").trim(), ...scope ? { scope } : {} };
@@ -54,15 +311,15 @@ var sourceCheckUrlUpdates = {
54
311
  }
55
312
  getExternalKnowledgeBaseTargetScope(ctx);
56
313
  },
57
- dryRun: (ctx) => ({ method: "POST", url: `${ctx.host().replace(/\/$/, "")}${API_PATH}`, body: body(ctx) }),
58
- execute: (ctx) => kbApi(ctx, "POST", API_PATH, {}, body(ctx), { preserveErrorMetadata: true })
314
+ dryRun: (ctx) => ({ method: "POST", url: `${ctx.host().replace(/\/$/, "")}${API_PATH2}`, body: body(ctx) }),
315
+ execute: (ctx) => kbApi(ctx, "POST", API_PATH2, {}, body(ctx), { preserveErrorMetadata: true })
59
316
  };
60
317
 
61
318
  // src/commands/te-kb/schema-import.ts
62
319
  import { promises as fs } from "fs";
63
320
  import path from "path";
64
321
  var ROOT = "/agent/api/external/knowledge-bases/schema";
65
- var options = { preserveBusinessErrorCode: true, preserveErrorMetadata: true };
322
+ var options2 = { preserveBusinessErrorCode: true, preserveErrorMetadata: true };
66
323
  var flag = (name, type, desc, required = false) => ({ name, type, desc, required });
67
324
  var targetFlags = [flag("name", "string", "Knowledge base name", true), flag("scope", "string", "Exact scope: personal | company")];
68
325
  var identityFlags = [flag("import-id", "string", "Stable import ID", true)];
@@ -121,7 +378,7 @@ async function waitSchemaImport(ctx, initial, api = kbApi, sleep = (ms) => new P
121
378
  let current = initial;
122
379
  while (current.task && Date.now() < deadline) {
123
380
  await sleep(Math.min(2e3, Math.max(1, deadline - Date.now())));
124
- current = await api(ctx, "GET", `${ROOT}/imports/${encodeURIComponent(initial.id)}`, {}, void 0, options);
381
+ current = await api(ctx, "GET", `${ROOT}/imports/${encodeURIComponent(initial.id)}`, {}, void 0, options2);
125
382
  }
126
383
  return { ...current, waitTimedOut: Boolean(current.task) };
127
384
  }
@@ -140,10 +397,10 @@ async function executeSchemaImport(ctx, action, api = kbApi, upload = kbUpload)
140
397
  form.set("replacesImportId", ctx.str("replaces-import-id"));
141
398
  form.set("expectedReplacedRevision", String(ctx.num("replaced-revision")));
142
399
  }
143
- result = await upload(ctx, endpoint(ctx, action), form, {}, options);
400
+ result = await upload(ctx, endpoint(ctx, action), form, {}, options2);
144
401
  } else if (["download", "list", "status", "content", "diff"].includes(action)) {
145
402
  const binary = action === "download" || action === "content" && Boolean(ctx.str("output"));
146
- result = await api(ctx, "GET", endpoint(ctx, action), query(ctx, action), void 0, { ...options, ...binary ? { responseType: "bytes" } : {} });
403
+ result = await api(ctx, "GET", endpoint(ctx, action), query(ctx, action), void 0, { ...options2, ...binary ? { responseType: "bytes" } : {} });
147
404
  if (binary) {
148
405
  const output = path.resolve(ctx.str("output"));
149
406
  const bytes = Buffer.from(result.bytes);
@@ -161,7 +418,7 @@ async function executeSchemaImport(ctx, action, api = kbApi, upload = kbUpload)
161
418
  const { bytes } = await readMarkdown(ctx);
162
419
  input.content = bytes.toString("utf8");
163
420
  }
164
- result = await api(ctx, action === "save" ? "PUT" : "POST", endpoint(ctx, action), {}, input, options);
421
+ result = await api(ctx, action === "save" ? "PUT" : "POST", endpoint(ctx, action), {}, input, options2);
165
422
  }
166
423
  return ctx.bool("wait") && result.task ? waitSchemaImport(ctx, result, api) : result;
167
424
  }
@@ -183,7 +440,7 @@ var schemaImportAbandon = command("abandon", "+schema-import-abandon", "Abandon
183
440
  var schemaImportCommands = [schemaDownload, schemaImport, schemaImportList, schemaImportStatus, schemaImportContent, schemaImportDiff, schemaImportSave, schemaImportValidate, schemaImportOptimize, schemaImportReject, schemaImportApply, schemaImportAbandon];
184
441
 
185
442
  // src/commands/te-kb/source-check-updates.ts
186
- var API_PATH2 = "/agent/api/external/knowledge-bases/sources/check-updates";
443
+ var API_PATH3 = "/agent/api/external/knowledge-bases/sources/check-updates";
187
444
  function body3(ctx) {
188
445
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
189
446
  return { name: ctx.str("name").trim(), sourceId: ctx.str("id").trim(), ...scope ? { scope } : {} };
@@ -206,10 +463,10 @@ var sourceCheckUpdates = {
206
463
  }
207
464
  getExternalKnowledgeBaseTargetScope(ctx);
208
465
  },
209
- dryRun: (ctx) => ({ method: "POST", url: `${ctx.host().replace(/\/$/, "")}${API_PATH2}`, body: body3(ctx) }),
466
+ dryRun: (ctx) => ({ method: "POST", url: `${ctx.host().replace(/\/$/, "")}${API_PATH3}`, body: body3(ctx) }),
210
467
  execute: async (ctx) => {
211
468
  try {
212
- return await kbApi(ctx, "POST", API_PATH2, {}, body3(ctx), { preserveErrorMetadata: true });
469
+ return await kbApi(ctx, "POST", API_PATH3, {}, body3(ctx), { preserveErrorMetadata: true });
213
470
  } catch (error) {
214
471
  const hint = "Read kb +list-sources to confirm the current source state before retrying.";
215
472
  if (error instanceof PermissionError) {
@@ -595,7 +852,7 @@ var sourceCancel = {
595
852
  import { promises as fs4 } from "fs";
596
853
  import * as path4 from "path";
597
854
  import TurndownService from "turndown";
598
- var API_PATH3 = "/agent/api/external/knowledge-bases/sources/upload";
855
+ var API_PATH4 = "/agent/api/external/knowledge-bases/sources/upload";
599
856
  var SUPPORTED_EXTENSIONS = /* @__PURE__ */ new Set([
600
857
  ".zip",
601
858
  ".md",
@@ -819,7 +1076,7 @@ var add = {
819
1076
  body4.contentType = "multipart/form-data";
820
1077
  return {
821
1078
  method: "POST",
822
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH3}`,
1079
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH4}`,
823
1080
  body: body4
824
1081
  };
825
1082
  },
@@ -828,7 +1085,7 @@ var add = {
828
1085
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
829
1086
  const files = await collectFiles(ctx);
830
1087
  const form = buildForm(name, scope, files);
831
- const result = await kbUpload(ctx, API_PATH3, form);
1088
+ const result = await kbUpload(ctx, API_PATH4, form);
832
1089
  return {
833
1090
  uploaded: files.map((f) => ({ filename: f.filename, origin: f.origin, source: f.source })),
834
1091
  result
@@ -837,7 +1094,7 @@ var add = {
837
1094
  };
838
1095
 
839
1096
  // src/commands/te-kb/compile.ts
840
- var API_PATH4 = "/agent/api/external/knowledge-bases/compile";
1097
+ var API_PATH5 = "/agent/api/external/knowledge-bases/compile";
841
1098
  var VALID_MODES = /* @__PURE__ */ new Set(["incremental", "full"]);
842
1099
  function getMode(ctx) {
843
1100
  const mode = ctx.str("mode") || "incremental";
@@ -874,14 +1131,14 @@ var compile = {
874
1131
  },
875
1132
  dryRun: (ctx) => ({
876
1133
  method: "POST",
877
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH4}`,
1134
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH5}`,
878
1135
  body: buildBody(ctx)
879
1136
  }),
880
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH4, {}, buildBody(ctx))
1137
+ execute: async (ctx) => kbApi(ctx, "POST", API_PATH5, {}, buildBody(ctx))
881
1138
  };
882
1139
 
883
1140
  // src/commands/te-kb/remove.ts
884
- var API_PATH5 = "/agent/api/external/knowledge-bases";
1141
+ var API_PATH6 = "/agent/api/external/knowledge-bases";
885
1142
  function buildBody2(ctx) {
886
1143
  const body4 = { name: ctx.str("name") };
887
1144
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
@@ -902,14 +1159,14 @@ var remove = {
902
1159
  },
903
1160
  dryRun: (ctx) => ({
904
1161
  method: "DELETE",
905
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH5}`,
1162
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH6}`,
906
1163
  body: buildBody2(ctx)
907
1164
  }),
908
- execute: async (ctx) => kbApi(ctx, "DELETE", API_PATH5, {}, buildBody2(ctx))
1165
+ execute: async (ctx) => kbApi(ctx, "DELETE", API_PATH6, {}, buildBody2(ctx))
909
1166
  };
910
1167
 
911
1168
  // src/commands/te-kb/create.ts
912
- var API_PATH6 = "/agent/api/external/knowledge-bases/create";
1169
+ var API_PATH7 = "/agent/api/external/knowledge-bases/create";
913
1170
  var VALID_SCOPES = /* @__PURE__ */ new Set(["personal", "company"]);
914
1171
  function getScope(ctx) {
915
1172
  const scope = ctx.str("scope") || "company";
@@ -943,7 +1200,16 @@ function buildBody3(ctx) {
943
1200
  };
944
1201
  const description = ctx.str("description");
945
1202
  if (description) body4.description = description;
946
- const tags = normalizeTags(ctx.json("tags"));
1203
+ const purpose = ctx.str("purpose");
1204
+ if (purpose) {
1205
+ if (purpose !== "project-semantic" || getScope(ctx) !== "company" || !/^[1-9]\d{0,15}$/.test(ctx.str("project-id")))
1206
+ throw new Error("--purpose project-semantic requires company scope and a valid --project-id.");
1207
+ body4.purpose = purpose;
1208
+ }
1209
+ const supplied = normalizeTags(ctx.json("tags"));
1210
+ const tags = purpose ? [.../* @__PURE__ */ new Set(["\u9879\u76EE\u8BED\u4E49", ...supplied ?? []])] : supplied;
1211
+ if (tags && (tags.length > 2 || tags.some((tag) => tag.length > 15)))
1212
+ throw new Error("Tags must contain at most 2 entries, each at most 15 characters.");
947
1213
  if (tags && tags.length > 0) body4.tags = tags;
948
1214
  const projectId = ctx.str("project-id");
949
1215
  if (projectId) body4.projectId = projectId;
@@ -960,24 +1226,24 @@ var create = {
960
1226
  { name: "name", type: "string", required: true, desc: "Knowledge base name (\u226430 chars, unique per scope)" },
961
1227
  { name: "description", type: "string", required: false, desc: "Optional description (\u2264200 chars)" },
962
1228
  { name: "tags", type: "json", required: false, desc: `Optional JSON array of tags (max 2, each \u226415 chars). Example: '["t1","t2"]'` },
1229
+ { name: "purpose", type: "string", required: false, desc: "Optional project-semantic purpose: presets the fixed semantic tag and checks the existing project target before creation" },
963
1230
  { name: "project-id", type: "string", required: false, desc: "Optional project ID to bind" },
964
1231
  { name: "project-name", type: "string", required: false, desc: "Optional project display name" }
965
1232
  ],
966
1233
  risk: "write",
967
1234
  validate: (ctx) => {
968
- getScope(ctx);
969
- normalizeTags(ctx.json("tags"));
1235
+ buildBody3(ctx);
970
1236
  },
971
1237
  dryRun: (ctx) => ({
972
1238
  method: "POST",
973
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH6}`,
1239
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH7}`,
974
1240
  body: buildBody3(ctx)
975
1241
  }),
976
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH6, {}, buildBody3(ctx))
1242
+ execute: async (ctx) => kbApi(ctx, "POST", API_PATH7, {}, buildBody3(ctx))
977
1243
  };
978
1244
 
979
1245
  // src/commands/te-kb/rm-source.ts
980
- var API_PATH7 = "/agent/api/external/knowledge-bases/sources";
1246
+ var API_PATH8 = "/agent/api/external/knowledge-bases/sources";
981
1247
  function sourceSelector(ctx) {
982
1248
  const id = ctx.str("id").trim();
983
1249
  if (id) return { id };
@@ -991,13 +1257,18 @@ function buildBody4(ctx) {
991
1257
  };
992
1258
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
993
1259
  if (scope) body4.scope = scope;
994
- return { ...body4, ...sourceSelector(ctx) };
1260
+ const cancelCandidate = ctx.bool("cancel-candidate");
1261
+ const expectedCandidateId = ctx.str("expected-candidate-id");
1262
+ if (cancelCandidate !== Boolean(expectedCandidateId)) throw new CliValidationError("--cancel-candidate and --expected-candidate-id must be supplied together.");
1263
+ return { ...body4, ...sourceSelector(ctx), ...cancelCandidate ? { cancelCandidate, expectedCandidateId } : {} };
995
1264
  }
996
1265
  var rmSource = {
997
1266
  service: "kb",
998
1267
  command: "+rm-source",
999
1268
  description: "Delete one source from a knowledge base by ID or exact display name.",
1000
1269
  flags: [
1270
+ { name: "cancel-candidate", type: "boolean", desc: "Atomically cancel the pending candidate approval before deleting its source" },
1271
+ { name: "expected-candidate-id", type: "string", desc: "Exact active candidate ID; required with --cancel-candidate" },
1001
1272
  { name: "name", type: "string", required: true, desc: "Knowledge base name (looked up personal \u2192 company)" },
1002
1273
  { name: "scope", type: "string", required: false, desc: "Exact knowledge base scope: personal | company (omit for personal \u2192 company fallback)" },
1003
1274
  { name: "id", type: "string", required: false, desc: "Source ID copied from +list-sources (preferred)" },
@@ -1006,14 +1277,14 @@ var rmSource = {
1006
1277
  risk: "high-risk-write",
1007
1278
  validate: (ctx) => {
1008
1279
  getExternalKnowledgeBaseTargetScope(ctx);
1009
- sourceSelector(ctx);
1280
+ buildBody4(ctx);
1010
1281
  },
1011
1282
  dryRun: (ctx) => ({
1012
1283
  method: "DELETE",
1013
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH7}`,
1284
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH8}`,
1014
1285
  body: buildBody4(ctx)
1015
1286
  }),
1016
- execute: async (ctx) => kbApi(ctx, "DELETE", API_PATH7, {}, buildBody4(ctx), {
1287
+ execute: async (ctx) => kbApi(ctx, "DELETE", API_PATH8, {}, buildBody4(ctx), {
1017
1288
  preserveErrorMetadata: true
1018
1289
  })
1019
1290
  };
@@ -1021,7 +1292,7 @@ var rmSource = {
1021
1292
  // src/commands/te-kb/schema.ts
1022
1293
  import fs5 from "fs";
1023
1294
  import path5 from "path";
1024
- var API_PATH8 = "/agent/api/external/knowledge-bases/schema";
1295
+ var API_PATH9 = "/agent/api/external/knowledge-bases/schema";
1025
1296
  var MAX_CUSTOM_INSTRUCTIONS_CHARS = 1e4;
1026
1297
  function getCustomInstructions(ctx) {
1027
1298
  const inline = ctx.str("custom-instructions");
@@ -1052,7 +1323,7 @@ function buildBody5(ctx) {
1052
1323
  return body4;
1053
1324
  }
1054
1325
  async function executeSchema(ctx, api = kbApi) {
1055
- return api(ctx, "POST", API_PATH8, {}, buildBody5(ctx), {
1326
+ return api(ctx, "POST", API_PATH9, {}, buildBody5(ctx), {
1056
1327
  preserveBusinessErrorCode: true
1057
1328
  });
1058
1329
  }
@@ -1087,14 +1358,14 @@ var schema = {
1087
1358
  },
1088
1359
  dryRun: (ctx) => ({
1089
1360
  method: "POST",
1090
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH8}`,
1361
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH9}`,
1091
1362
  body: buildBody5(ctx)
1092
1363
  }),
1093
1364
  execute: executeSchema
1094
1365
  };
1095
1366
 
1096
1367
  // src/commands/te-kb/status.ts
1097
- var API_PATH9 = "/agent/api/external/knowledge-bases/status";
1368
+ var API_PATH10 = "/agent/api/external/knowledge-bases/status";
1098
1369
  function buildBody6(ctx) {
1099
1370
  const body4 = {
1100
1371
  name: ctx.str("name")
@@ -1117,14 +1388,14 @@ var status = {
1117
1388
  },
1118
1389
  dryRun: (ctx) => ({
1119
1390
  method: "POST",
1120
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH9}`,
1391
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH10}`,
1121
1392
  body: buildBody6(ctx)
1122
1393
  }),
1123
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH9, {}, buildBody6(ctx))
1394
+ execute: async (ctx) => kbApi(ctx, "POST", API_PATH10, {}, buildBody6(ctx))
1124
1395
  };
1125
1396
 
1126
1397
  // src/commands/te-kb/kb-index.ts
1127
- var API_PATH10 = "/agent/api/external/knowledge-bases/index";
1398
+ var API_PATH11 = "/agent/api/external/knowledge-bases/index";
1128
1399
  function buildBody7(ctx) {
1129
1400
  const body4 = {};
1130
1401
  const sources = ctx.json("sources");
@@ -1138,6 +1409,7 @@ var kbIndex = {
1138
1409
  command: "+index",
1139
1410
  description: "List accessible knowledge bases and their index.md navigation maps via POST /agent/api/external/knowledge-bases/index. Call this first to see the layout, then use +grep to locate and +read to open pages.",
1140
1411
  flags: [
1412
+ { name: "read-context", type: "string", required: false, desc: "Pin reads to an existing read context" },
1141
1413
  {
1142
1414
  name: "sources",
1143
1415
  type: "json",
@@ -1149,18 +1421,18 @@ var kbIndex = {
1149
1421
  risk: "read",
1150
1422
  dryRun: (ctx) => ({
1151
1423
  method: "POST",
1152
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH10}`,
1424
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH11}`,
1153
1425
  body: buildBody7(ctx)
1154
1426
  }),
1155
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH10, {}, buildBody7(ctx))
1427
+ execute: async (ctx) => kbApi(ctx, "POST", API_PATH11, {}, buildBody7(ctx))
1156
1428
  };
1157
1429
 
1158
1430
  // src/commands/te-kb/kb-list.ts
1159
- var API_PATH11 = "/agent/api/external/knowledge-bases/list";
1431
+ var API_PATH12 = "/agent/api/external/knowledge-bases/list";
1160
1432
  var DEFAULT_BUILD_STATUS = "compiled";
1161
1433
  var VALID_BUILD_STATUSES = ["idle", "pending", "compiling", "compiled", "failed"];
1162
1434
  function getBuildStatus(ctx) {
1163
- return ctx.str("build-status") || DEFAULT_BUILD_STATUS;
1435
+ return ctx.str("build-status") || (ctx.str("view") === "published" || ctx.str("read-context") || kbExecutionContextRequired() ? void 0 : DEFAULT_BUILD_STATUS);
1164
1436
  }
1165
1437
  function validateBuildStatus(ctx) {
1166
1438
  const value = ctx.str("build-status");
@@ -1174,7 +1446,8 @@ function validateBuildStatus(ctx) {
1174
1446
  }
1175
1447
  function buildBody8(ctx) {
1176
1448
  const body4 = {
1177
- buildStatus: getBuildStatus(ctx)
1449
+ ...getBuildStatus(ctx) ? { buildStatus: getBuildStatus(ctx) } : {},
1450
+ ...ctx.str("view") ? { view: ctx.str("view") } : {}
1178
1451
  };
1179
1452
  const locale = ctx.str("locale");
1180
1453
  if (locale) body4.locale = locale;
@@ -1185,11 +1458,12 @@ var kbList = {
1185
1458
  command: "+list",
1186
1459
  description: "List accessible knowledge bases via POST /agent/api/external/knowledge-bases/list. Filters by buildStatus (default: compiled). Returns KB metadata including buildStatus, without index.md navigation maps.",
1187
1460
  flags: [
1461
+ { name: "view", type: "string", required: false, desc: "Use published for formal views without an implicit build-status filter" },
1462
+ { name: "read-context", type: "string", required: false, desc: "Pin reads to an existing read context" },
1188
1463
  {
1189
1464
  name: "build-status",
1190
1465
  type: "string",
1191
1466
  required: false,
1192
- default: DEFAULT_BUILD_STATUS,
1193
1467
  desc: `Filter by knowledge base build status: ${VALID_BUILD_STATUSES.join(" | ")} (default: ${DEFAULT_BUILD_STATUS} when omitted)`
1194
1468
  },
1195
1469
  { name: "locale", type: "string", required: false, desc: "Optional locale: zh | en | ja | ko" }
@@ -1197,23 +1471,39 @@ var kbList = {
1197
1471
  risk: "read",
1198
1472
  validate: (ctx) => {
1199
1473
  validateBuildStatus(ctx);
1474
+ if (ctx.str("view") && ctx.str("view") !== "published") throw new Error("Invalid --view: expected published");
1200
1475
  },
1201
1476
  dryRun: (ctx) => ({
1202
1477
  method: "POST",
1203
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH11}`,
1478
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH12}`,
1204
1479
  body: buildBody8(ctx)
1205
1480
  }),
1206
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH11, {}, buildBody8(ctx))
1481
+ execute: async (ctx) => {
1482
+ if (ctx.str("view") !== "published" || ctx.str("read-context") || kbExecutionContextRequired())
1483
+ return kbApi(ctx, "POST", API_PATH12, {}, buildBody8(ctx));
1484
+ const endpoint3 = "/agent/api/external/knowledge-bases/read-contexts";
1485
+ const options3 = { preserveErrorMetadata: true, retryUnauthorized: false };
1486
+ const created = await kbApi(ctx, "POST", endpoint3, {}, ctx.str("locale") ? { locale: ctx.str("locale") } : {}, options3);
1487
+ if (typeof created?.readContextId !== "string" || !/^[A-Za-z0-9_-]{1,191}$/.test(created.readContextId))
1488
+ throw new Error("KB_READ_CONTEXT_CAPABILITY_UNAVAILABLE");
1489
+ const pinned = Object.create(ctx);
1490
+ pinned.str = (name) => name === "read-context" ? created.readContextId : ctx.str(name);
1491
+ try {
1492
+ return await kbApi(pinned, "POST", API_PATH12, {}, buildBody8(ctx), options3);
1493
+ } finally {
1494
+ await kbApi(ctx, "DELETE", `${endpoint3}/${encodeURIComponent(created.readContextId)}`, {}, {}, options3);
1495
+ }
1496
+ }
1207
1497
  };
1208
1498
 
1209
1499
  // src/commands/te-kb/list-sources.ts
1210
- var API_PATH12 = "/agent/api/external/knowledge-bases/sources";
1500
+ var API_PATH13 = "/agent/api/external/knowledge-bases/sources";
1211
1501
  var MAX_KNOWLEDGE_BASE_NAME_LENGTH = 200;
1212
1502
  function knowledgeBaseName(ctx) {
1213
1503
  return ctx.str("name").trim();
1214
1504
  }
1215
1505
  function buildUrl(ctx) {
1216
- const url2 = new URL(`${ctx.host().replace(/\/$/, "")}${API_PATH12}`);
1506
+ const url2 = new URL(`${ctx.host().replace(/\/$/, "")}${API_PATH13}`);
1217
1507
  url2.searchParams.set("name", knowledgeBaseName(ctx));
1218
1508
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
1219
1509
  if (scope) url2.searchParams.set("scope", scope);
@@ -1266,7 +1556,7 @@ var listSources = {
1266
1556
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
1267
1557
  if (scope) params.scope = scope;
1268
1558
  if (ctx.str("content-type")) params.contentType = ctx.str("content-type");
1269
- return kbApi(ctx, "GET", API_PATH12, params, void 0, {
1559
+ return kbApi(ctx, "GET", API_PATH13, params, void 0, {
1270
1560
  preserveErrorMetadata: true,
1271
1561
  retryUnauthorized: false
1272
1562
  });
@@ -1274,7 +1564,7 @@ var listSources = {
1274
1564
  };
1275
1565
 
1276
1566
  // src/commands/te-kb/usage-list.ts
1277
- var API_PATH13 = "/agent/api/external/knowledge-bases/usage-logs";
1567
+ var API_PATH14 = "/agent/api/external/knowledge-bases/usage-logs";
1278
1568
  function query3(ctx) {
1279
1569
  const scope = getExternalKnowledgeBaseTargetScope(ctx);
1280
1570
  return {
@@ -1307,10 +1597,10 @@ var usageList = {
1307
1597
  }
1308
1598
  }
1309
1599
  },
1310
- dryRun: (ctx) => ({ method: "GET", url: `${ctx.host().replace(/\/$/, "")}${API_PATH13}`, params: query3(ctx) }),
1600
+ dryRun: (ctx) => ({ method: "GET", url: `${ctx.host().replace(/\/$/, "")}${API_PATH14}`, params: query3(ctx) }),
1311
1601
  execute: async (ctx) => {
1312
1602
  try {
1313
- return await kbApi(ctx, "GET", API_PATH13, query3(ctx), void 0, { preserveErrorMetadata: true });
1603
+ return await kbApi(ctx, "GET", API_PATH14, query3(ctx), void 0, { preserveErrorMetadata: true });
1314
1604
  } catch (error) {
1315
1605
  if (error instanceof PermissionError) {
1316
1606
  error.message = "Permission denied when reading knowledge base usage logs.";
@@ -1329,7 +1619,7 @@ var usageList = {
1329
1619
  };
1330
1620
 
1331
1621
  // src/commands/te-kb/kb-grep.ts
1332
- var API_PATH14 = "/agent/api/external/knowledge-bases/grep";
1622
+ var API_PATH15 = "/agent/api/external/knowledge-bases/grep";
1333
1623
  function buildBody9(ctx) {
1334
1624
  const body4 = {
1335
1625
  query: ctx.str("query"),
@@ -1347,6 +1637,7 @@ var kbGrep = {
1347
1637
  command: "+grep",
1348
1638
  description: "Keyword-search knowledge base pages via POST /agent/api/external/knowledge-bases/grep. Returns a page-level results array: one entry per page with hitCount (full match count), pageKind (content/catalog), up to 4 sections previews (breadcrumb, sectionStartLine/sectionEndLine, text excerpt) and moreSections. Copy --paths from +index (wiki pages, module catalog pages, or subdirectories); read the matched section range with +read.",
1349
1639
  flags: [
1640
+ { name: "read-context", type: "string", required: false, desc: "Pin reads to an existing read context" },
1350
1641
  {
1351
1642
  name: "query",
1352
1643
  type: "string",
@@ -1372,14 +1663,14 @@ var kbGrep = {
1372
1663
  risk: "read",
1373
1664
  dryRun: (ctx) => ({
1374
1665
  method: "POST",
1375
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH14}`,
1666
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH15}`,
1376
1667
  body: buildBody9(ctx)
1377
1668
  }),
1378
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH14, {}, buildBody9(ctx))
1669
+ execute: async (ctx) => kbApi(ctx, "POST", API_PATH15, {}, buildBody9(ctx))
1379
1670
  };
1380
1671
 
1381
1672
  // src/commands/te-kb/kb-read.ts
1382
- var API_PATH15 = "/agent/api/external/knowledge-bases/read";
1673
+ var API_PATH16 = "/agent/api/external/knowledge-bases/read";
1383
1674
  var VALID_EXPAND_MODES = /* @__PURE__ */ new Set(["block", "none"]);
1384
1675
  var MAX_READ_LIMIT = 2e3;
1385
1676
  function readExpand(ctx) {
@@ -1423,6 +1714,7 @@ var kbRead = {
1423
1714
  command: "+read",
1424
1715
  description: "Read a full knowledge base page (or a line window) via POST /agent/api/external/knowledge-bases/read. Use after +index / +grep locate a candidate page. Pass --outline to get only the page heading tree (no content) and pick a section to read.",
1425
1716
  flags: [
1717
+ { name: "read-context", type: "string", required: false, desc: "Pin reads to an existing read context" },
1426
1718
  {
1427
1719
  name: "source",
1428
1720
  type: "json",
@@ -1457,10 +1749,10 @@ var kbRead = {
1457
1749
  },
1458
1750
  dryRun: (ctx) => ({
1459
1751
  method: "POST",
1460
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH15}`,
1752
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH16}`,
1461
1753
  body: buildBody10(ctx)
1462
1754
  }),
1463
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH15, {}, buildBody10(ctx))
1755
+ execute: async (ctx) => kbApi(ctx, "POST", API_PATH16, {}, buildBody10(ctx))
1464
1756
  };
1465
1757
 
1466
1758
  // src/commands/te-kb/ask-shared.ts
@@ -1479,12 +1771,12 @@ function isTransientAskPollError(error) {
1479
1771
  error.message
1480
1772
  );
1481
1773
  }
1482
- async function pollUntilSettled(getStatus, executionId, options2 = {}) {
1483
- const intervalMs = options2.intervalMs ?? ASK_POLL_INTERVAL_MS;
1484
- const timeoutMs = options2.timeoutMs ?? ASK_POLL_TIMEOUT_MS;
1485
- const maxTransientFailures = options2.maxTransientFailures ?? ASK_MAX_TRANSIENT_POLL_FAILURES;
1486
- const now = options2.now ?? Date.now;
1487
- const sleep = options2.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
1774
+ async function pollUntilSettled(getStatus, executionId, options3 = {}) {
1775
+ const intervalMs = options3.intervalMs ?? ASK_POLL_INTERVAL_MS;
1776
+ const timeoutMs = options3.timeoutMs ?? ASK_POLL_TIMEOUT_MS;
1777
+ const maxTransientFailures = options3.maxTransientFailures ?? ASK_MAX_TRANSIENT_POLL_FAILURES;
1778
+ const now = options3.now ?? Date.now;
1779
+ const sleep = options3.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
1488
1780
  const startTime = now();
1489
1781
  let transientFailures = 0;
1490
1782
  while (true) {
@@ -1636,8 +1928,15 @@ function executionIdFrom(ctx) {
1636
1928
  var askStatus = {
1637
1929
  service: "kb",
1638
1930
  command: "+ask-status",
1639
- description: "Query the status of an in-progress or completed knowledge base ask execution (GET /agent/api/external/knowledge-bases/ask?executionId=<id>). Does not poll; returns the current state.",
1931
+ description: "Query an Ask execution. With --source-index, revisit that saved citation at its original version using current permissions; never selects the latest version. Does not poll.",
1640
1932
  flags: [
1933
+ {
1934
+ name: "source-index",
1935
+ type: "number",
1936
+ required: false,
1937
+ min: 0,
1938
+ desc: "Zero-based sourceIndex from a completed Ask source reference. Unversioned historical sources cannot be revisited."
1939
+ },
1641
1940
  {
1642
1941
  name: "execution-id",
1643
1942
  type: "string",
@@ -1649,6 +1948,10 @@ var askStatus = {
1649
1948
  ],
1650
1949
  risk: "read",
1651
1950
  validate: (ctx) => {
1951
+ const index = ctx.optionalNum("source-index");
1952
+ if (index !== void 0 && (!Number.isSafeInteger(index) || index < 0 || index > 999999999)) {
1953
+ throw new CliValidationError("--source-index must be a non-negative integer below 1000000000.");
1954
+ }
1652
1955
  const executionId = executionIdFrom(ctx);
1653
1956
  if (!executionId) {
1654
1957
  throw new Error("Invalid --execution-id: must be non-empty.");
@@ -1661,16 +1964,26 @@ var askStatus = {
1661
1964
  },
1662
1965
  dryRun: (ctx) => ({
1663
1966
  method: "GET",
1664
- url: `${ctx.host().replace(/\/$/, "")}${ASK_API_PATH}?executionId=${encodeURIComponent(executionIdFrom(ctx))}`
1967
+ url: `${ctx.host().replace(/\/$/, "")}${ASK_API_PATH}?executionId=${encodeURIComponent(executionIdFrom(ctx))}${ctx.optionalNum("source-index") !== void 0 ? `&sourceIndex=${ctx.optionalNum("source-index")}` : ""}`
1665
1968
  }),
1666
1969
  execute: async (ctx) => {
1667
1970
  const executionId = executionIdFrom(ctx);
1668
- return await kbApi(ctx, "GET", ASK_API_PATH, { executionId });
1971
+ const sourceIndex = ctx.optionalNum("source-index");
1972
+ if (sourceIndex !== void 0 && kbExecutionContextRequired()) {
1973
+ throw new CliValidationError(
1974
+ "Historical references cannot be read inside a pinned KB execution. Use this command outside that execution with your current user credentials.",
1975
+ { code: "KB_READ_CONTEXT_REFERENCE_FORBIDDEN" }
1976
+ );
1977
+ }
1978
+ return kbApi(ctx, "GET", ASK_API_PATH, {
1979
+ executionId,
1980
+ ...sourceIndex !== void 0 ? { sourceIndex } : {}
1981
+ });
1669
1982
  }
1670
1983
  };
1671
1984
 
1672
1985
  // src/commands/te-kb/url.ts
1673
- var API_PATH16 = "/agent/api/external/knowledge-bases/sources/url";
1986
+ var API_PATH17 = "/agent/api/external/knowledge-bases/sources/url";
1674
1987
  function validateUrl(url2) {
1675
1988
  if (!/^https?:\/\//i.test(url2)) {
1676
1989
  throw new Error(`Invalid --url: ${url2}. Must be an http(s) URL`);
@@ -1707,16 +2020,16 @@ var url = {
1707
2020
  },
1708
2021
  dryRun: (ctx) => ({
1709
2022
  method: "POST",
1710
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH16}`,
2023
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH17}`,
1711
2024
  body: buildBody12(ctx)
1712
2025
  }),
1713
- execute: async (ctx) => kbApi(ctx, "POST", API_PATH16, {}, buildBody12(ctx))
2026
+ execute: async (ctx) => kbApi(ctx, "POST", API_PATH17, {}, buildBody12(ctx))
1714
2027
  };
1715
2028
 
1716
2029
  // src/commands/te-kb/import.ts
1717
2030
  import { promises as fs6 } from "fs";
1718
2031
  import path6 from "path";
1719
- var API_PATH17 = "/agent/api/external/knowledge-bases/import";
2032
+ var API_PATH18 = "/agent/api/external/knowledge-bases/import";
1720
2033
  var MAX_SNAPSHOT_ARCHIVE_BYTES = 50 * 1024 * 1024;
1721
2034
  var VALID_SCOPES2 = /* @__PURE__ */ new Set(["personal", "company"]);
1722
2035
  function getScope2(ctx) {
@@ -1846,7 +2159,7 @@ var importSnapshot = {
1846
2159
  try {
1847
2160
  return await kbUpload(
1848
2161
  ctx,
1849
- API_PATH17,
2162
+ API_PATH18,
1850
2163
  form,
1851
2164
  { scope: getScope2(ctx) },
1852
2165
  { preserveErrorMetadata: true, retryUnauthorized: true }
@@ -1875,7 +2188,7 @@ var importSnapshot = {
1875
2188
  };
1876
2189
 
1877
2190
  // src/commands/te-kb/import-status.ts
1878
- var API_PATH18 = "/agent/api/external/knowledge-bases/import";
2191
+ var API_PATH19 = "/agent/api/external/knowledge-bases/import";
1879
2192
  var MAX_REQUEST_ID_LENGTH = 191;
1880
2193
  function requestIdFrom(ctx) {
1881
2194
  return ctx.str("request-id").trim();
@@ -1906,7 +2219,7 @@ var importStatus = {
1906
2219
  },
1907
2220
  dryRun: (ctx) => ({
1908
2221
  method: "GET",
1909
- url: `${ctx.host().replace(/\/$/, "")}${API_PATH18}?requestId=${encodeURIComponent(requestIdFrom(ctx))}`
2222
+ url: `${ctx.host().replace(/\/$/, "")}${API_PATH19}?requestId=${encodeURIComponent(requestIdFrom(ctx))}`
1910
2223
  }),
1911
2224
  execute: async (ctx) => {
1912
2225
  const hint = "Verify the request ID and that the server supports kb +import-status. Do not retry the import until its status is known.";
@@ -1914,7 +2227,7 @@ var importStatus = {
1914
2227
  return await kbApi(
1915
2228
  ctx,
1916
2229
  "GET",
1917
- API_PATH18,
2230
+ API_PATH19,
1918
2231
  { requestId: requestIdFrom(ctx) },
1919
2232
  void 0,
1920
2233
  { preserveErrorMetadata: true, retryUnauthorized: true }
@@ -2311,6 +2624,8 @@ var rollbackStatus = {
2311
2624
 
2312
2625
  // src/commands/te-kb/index.ts
2313
2626
  var commands = [
2627
+ projectTargetGet,
2628
+ ...publicationCommands,
2314
2629
  usageList,
2315
2630
  ...schemaImportCommands,
2316
2631
  sourceCheckUpdates,
@@ -2358,6 +2673,10 @@ export {
2358
2673
  add,
2359
2674
  ask,
2360
2675
  askStatus,
2676
+ candidateChanges,
2677
+ candidateDiscard,
2678
+ candidateGet,
2679
+ candidateRead,
2361
2680
  compile,
2362
2681
  create,
2363
2682
  te_kb_default as default,
@@ -2369,6 +2688,11 @@ export {
2369
2688
  kbList,
2370
2689
  kbRead,
2371
2690
  listSources,
2691
+ projectTargetGet,
2692
+ publicationCommands,
2693
+ publicationGet,
2694
+ readContextCreate,
2695
+ readContextRelease,
2372
2696
  remove,
2373
2697
  rmSource,
2374
2698
  rollback,