@tiangong-ai/cli 0.0.21 → 0.0.23

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 (36) hide show
  1. package/AGENTS.md +3 -2
  2. package/README.md +110 -10
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +25 -3
  5. package/dist/cli.js.map +1 -1
  6. package/dist/research/orchestration.js +117 -4
  7. package/dist/research/orchestration.js.map +1 -1
  8. package/dist/research/workspace/broker.js +38 -46
  9. package/dist/research/workspace/broker.js.map +1 -1
  10. package/dist/research/workspace/capabilities.d.ts +2 -0
  11. package/dist/research/workspace/capabilities.js +246 -7
  12. package/dist/research/workspace/capabilities.js.map +1 -1
  13. package/dist/research/workspace/constants.d.ts +2 -2
  14. package/dist/research/workspace/constants.js +6 -0
  15. package/dist/research/workspace/constants.js.map +1 -1
  16. package/dist/research/workspace/credentials.d.ts +19 -0
  17. package/dist/research/workspace/credentials.js +111 -0
  18. package/dist/research/workspace/credentials.js.map +1 -0
  19. package/dist/research/workspace/executor.d.ts +1 -0
  20. package/dist/research/workspace/executor.js +7 -3
  21. package/dist/research/workspace/executor.js.map +1 -1
  22. package/dist/research/workspace/external-skills.d.ts +458 -0
  23. package/dist/research/workspace/external-skills.js +1000 -0
  24. package/dist/research/workspace/external-skills.js.map +1 -0
  25. package/dist/research/workspace/preflight.d.ts +2 -0
  26. package/dist/research/workspace/preflight.js +11 -4
  27. package/dist/research/workspace/preflight.js.map +1 -1
  28. package/dist/research/workspace/runtime.js +63 -20
  29. package/dist/research/workspace/runtime.js.map +1 -1
  30. package/dist/research/workspace/storage.js +37 -2
  31. package/dist/research/workspace/storage.js.map +1 -1
  32. package/dist/research/workspace/types.d.ts +29 -0
  33. package/dist/research/workspace/workspace.d.ts +2 -0
  34. package/dist/research/workspace/workspace.js +98 -45
  35. package/dist/research/workspace/workspace.js.map +1 -1
  36. package/package.json +4 -4
package/AGENTS.md CHANGED
@@ -15,8 +15,8 @@ checkPaths:
15
15
  - .docpact/config.yaml
16
16
  - docs/agents/**
17
17
  - src/**
18
- lastReviewedAt: 2026-08-06
19
- lastReviewedCommit: f5d031588a8eb2694573b8c3c83ff07c6ecd2b6f
18
+ lastReviewedAt: 2026-08-08
19
+ lastReviewedCommit: c55eab450de73bed783c7417c43db20ef56c0c43
20
20
  ---
21
21
 
22
22
  # Tiangong AI CLI Contract
@@ -36,6 +36,7 @@ This repository owns the Tiangong AI command-line interface.
36
36
 
37
37
  ## Current Command Surface
38
38
 
39
+ - `tiangong-ai --version`
39
40
  - `tiangong-ai doctor`
40
41
  - `tiangong-ai kb ingest`
41
42
  - `tiangong-ai kb ingest bulk`
package/README.md CHANGED
@@ -12,8 +12,8 @@ checkPaths:
12
12
  - package.json
13
13
  - bin/**
14
14
  - src/**
15
- lastReviewedAt: 2026-08-04
16
- lastReviewedCommit: 7429c2ab92509920a2728dc38685ad5c4f2c8f13
15
+ lastReviewedAt: 2026-08-07
16
+ lastReviewedCommit: 5d942d487a7c4592de80e0ac64ac6741c6836942
17
17
  ---
18
18
 
19
19
  # Tiangong AI CLI
@@ -26,11 +26,19 @@ Package: `@tiangong-ai/cli` Executable: `tiangong-ai` Node: `>=24`
26
26
  npm install
27
27
  npm run build
28
28
  node ./bin/tiangong-ai.js --help
29
+ node ./bin/tiangong-ai.js --version
29
30
  ```
30
31
 
31
32
  Use Node `24.x`; this package declares `>=24 <25` and includes `.nvmrc` for
32
33
  compatible version managers.
33
34
 
35
+ After installation, print the package version with either top-level flag:
36
+
37
+ ```bash
38
+ tiangong-ai --version
39
+ tiangong-ai -v
40
+ ```
41
+
34
42
  ## KB Ingest
35
43
 
36
44
  Required environment:
@@ -195,6 +203,18 @@ file, and budget confirmation when `maxCostUsd` exceeds
195
203
  ```bash
196
204
  tiangong-ai research workspace init /absolute/path/to/workspace \
197
205
  --mode production-research
206
+ tiangong-ai research capability catalog \
207
+ --path /absolute/path/to/workspace \
208
+ --workspace /absolute/path/to/workspace --json
209
+ # Run the returned pinned project installation plan outside the research runtime.
210
+ tiangong-ai research capability configure \
211
+ --profile internet-research \
212
+ --workspace /absolute/path/to/workspace --json
213
+ tiangong-ai research capability credential set \
214
+ --id brave.search.api-key --from-env BRAVE_SEARCH_API_KEY \
215
+ --workspace /absolute/path/to/workspace --json
216
+ tiangong-ai research capability doctor --live \
217
+ --workspace /absolute/path/to/workspace --json
198
218
  tiangong-ai research project preflight \
199
219
  --workspace /absolute/path/to/workspace \
200
220
  --question "How do advanced GPU process nodes change environmental resource burdens?" \
@@ -206,6 +226,27 @@ tiangong-ai research project init gpu-resource-impact \
206
226
  --confirm-budget --json
207
227
  ```
208
228
 
229
+ Production admission requires at least one locked external capability with
230
+ `brokered-network` and `discoveryScopes: ["public-internet"]`; an input plan or
231
+ local files alone cannot represent internet coverage. The machine-readable
232
+ catalog contains only external Skills and reports every required, enhanced,
233
+ and conditional recommendation; exact source commit and whole-tree hash; a
234
+ pinned installer version and checkout/install plan; credential requirements;
235
+ and installed, configured, locked, and live provider status. Installation is
236
+ never performed by the research runtime. It also reports the other Skills
237
+ evaluated from the pinned upstream package and why each is not selected:
238
+ custom question-specific admission, query assistance without evidence, or an
239
+ execution model that the bounded GET broker does not authorize.
240
+
241
+ The default `internet-research` profile selects Brave Web Search and News
242
+ Search. `internet-research-with-context` additionally selects the
243
+ subscription-dependent LLM Context endpoint, while
244
+ `internet-research-with-media` also selects image and video discovery. A
245
+ provider-plan or authentication failure blocks the selected profile instead of
246
+ silently dropping a Skill. `credential set` reads the value only from the
247
+ explicit owner environment name and stores it under the declared logical ID;
248
+ the value is never returned or journaled.
249
+
209
250
  The requirements object declares `dimensions`, `sourceTypes`, `minSources`,
210
251
  `minFullTextSources`, `minDatedSources`, and optional inclusive
211
252
  `publicationDateFrom` / `publicationDateTo` boundaries (`YYYY-MM-DD` or
@@ -226,7 +267,11 @@ routes use the same agent family.
226
267
 
227
268
  Research execution requires `/usr/bin/sandbox-exec` on macOS or Bubblewrap
228
269
  (`bwrap`) on Linux. Windows can inspect and configure workspaces but does not
229
- execute research packages.
270
+ execute research packages. That outer platform sandbox is the execution
271
+ boundary. Codex is therefore started with its nested sandbox disabled: nesting
272
+ Seatbelt on macOS can cancel MCP calls even though the process is already
273
+ confined. Shell and unified-exec tools remain disabled, as do undeclared Codex
274
+ integrations.
230
275
 
231
276
  Add immutable local evidence, verify the workspace, and execute ready work:
232
277
 
@@ -237,7 +282,7 @@ tiangong-ai research project input add gpu-resource-impact \
237
282
  --role primary
238
283
  tiangong-ai research workspace doctor --workspace /absolute/path/to/workspace
239
284
  tiangong-ai research workspace doctor --workspace /absolute/path/to/workspace \
240
- --agent-smoke
285
+ --agent-smoke --capability-smoke
241
286
  tiangong-ai research run --workspace /absolute/path/to/workspace \
242
287
  --project gpu-resource-impact --progress-jsonl
243
288
  tiangong-ai research status --workspace /absolute/path/to/workspace --json
@@ -279,9 +324,15 @@ facts.
279
324
  Total, per-package, output, repair, broker-response bytes, estimated broker
280
325
  context tokens, context items, wall-time, output-count, output-size, and attempt
281
326
  limits live in `.tiangong-research/config.json`.
327
+ New workspaces reserve 500,000 total tokens by default, including 200,000 for
328
+ discovery; the remaining package defaults are 55,000 for analysis, 60,000 for
329
+ synthesis, and 120,000 for review. These are admission ceilings rather than a
330
+ target spend and can be lowered only when the resulting pre-call reservations
331
+ still fit.
282
332
  Before an agent starts, the runtime reserves the package token and conservative
283
333
  price budget. The call-level check accounts for prompt and schema bytes at
284
334
  three bytes per token, repeats input allowance for every permitted API turn,
335
+ adds the maximum bounded broker context for every permitted discovery turn,
285
336
  and adds primary output plus a potential isolated repair's input and output;
286
337
  insufficient package or remaining project budget prevents invocation. The
287
338
  provider cost cap is the current package reservation, not the remaining
@@ -292,7 +343,9 @@ schema tool, uses one plain-JSON turn, and remains subject to the CLI schema and
292
343
  semantic validators. Current Codex and Claude CLI adapters report
293
344
  output usage only after execution, so preflight identifies
294
345
  `outputTokenLimitEnforcement` as `post-execution`; captured bytes provide a
295
- separate process bound, and over-limit output fails without promotion.
346
+ separate process bound. Discovery capture allowance includes the bounded MCP
347
+ tool contexts as well as the requested model output, and over-limit output fails
348
+ without promotion.
296
349
  Preflight also reports per-stage `maxTurns` and `turnLimitEnforcement`: Claude
297
350
  receives a provider-side turn cap, while the current Codex CLI exposes no such
298
351
  flag, so its turn allowance is reservation guidance plus post-execution
@@ -315,7 +368,12 @@ context, broker objects, and registered local input hashes before recording
315
368
  their safe locators. Capsule deletion therefore does not delete the durable
316
369
  review chain.
317
370
 
318
- Discovery alone may use the capability broker and workspace-read tools.
371
+ Discovery receives only the capability broker as an execution tool. The CLI
372
+ embeds the exact staged capability manifest and each external Skill's top-level
373
+ `SKILL.md` in the prompt, so the producer does not need filesystem or shell
374
+ access and cannot execute provider examples directly. Broker responses include
375
+ the exact bounded context inline with the hash-bound receipt; raw objects remain
376
+ in the permanent evidence store for audit.
319
377
  Analyze and synthesize receive bounded, hash-verified prior-stage artifacts in
320
378
  their prompt with tools disabled. Review is also tool-free and limited to the
321
379
  two turns required by the structured-output protocol:
@@ -329,8 +387,31 @@ dimension is usable but incomplete; a missing dimension or unmet declared
329
387
  minimum blocks downstream work. Qualitative gaps remain visible without
330
388
  silently changing those mechanical fields.
331
389
 
332
- Method skills are declared in `.tiangong-research/capabilities.json` with
333
- absolute skill paths and explicit permissions, then frozen before execution:
390
+ Method Skills are external to this project. Recommended evidence Skills are
391
+ selected through `research capability configure`; an owner-selected database,
392
+ domain index, or other external method is admitted from an absolute reviewed
393
+ definition:
394
+
395
+ ```bash
396
+ tiangong-ai research capability import \
397
+ --definition /absolute/path/to/external-capability.json \
398
+ --workspace /absolute/path/to/workspace --json
399
+ ```
400
+
401
+ `research capability catalog --json` returns the authoritative custom
402
+ definition template. Its source must identify an external git, registry, or
403
+ local artifact with an immutable reference, explicit `expectedTreeSha256`, and
404
+ license. Git references must be full 40-character commits; registry references
405
+ must be exact versions; local references must equal
406
+ `sha256:<expectedTreeSha256>`. Every source type must match the installed whole
407
+ tree before a lock can be written. Skill trees reject symlinks and excessive
408
+ file counts/sizes. Project-owned Tiangong Skills are rejected as imported
409
+ evidence providers. Configure/import refuses to rewrite the lock if any
410
+ existing capability has drifted; restore it or explicitly update its source
411
+ identity and expected hash first.
412
+
413
+ External Skills use absolute paths and explicit permissions, then freeze
414
+ before execution:
334
415
 
335
416
  ```bash
336
417
  tiangong-ai research capability lock --workspace /absolute/path/to/workspace
@@ -341,7 +422,14 @@ A capability using `brokered-network` must declare exact `allowedHosts` and may
341
422
  declare an `http` policy with one exact `accept` value,
342
423
  `allowedContentTypes`, `maxResponseBytes`, and `maxItems`. Its optional
343
424
  `coverage` block declares dimensions, source types, full-text availability,
344
- and publication-date availability for the preflight gap report.
425
+ publication-date availability, and named discovery scopes for the preflight gap
426
+ report. Mark `requiredForDiscovery: true` for every public index or
427
+ owner-whitelisted database the question must exercise. Downstream work is
428
+ blocked unless each such capability produces its own verified broker receipt;
429
+ another local file cannot substitute for it. The current evidence broker
430
+ authorizes bounded GET endpoints only. A non-network external method-guidance
431
+ Skill stages reviewed instructions but does not grant an undeclared tool or
432
+ service call.
345
433
  Optional credentials declare logical IDs, exact host scopes, header names, and
346
434
  prefixes. Put only the logical value map in `.tiangong-research/.env`:
347
435
 
@@ -349,9 +437,21 @@ prefixes. Put only the logical value map in `.tiangong-research/.env`:
349
437
  TIANGONG_RESEARCH_CAPABILITY_CREDENTIALS_JSON={"source.example.api":"owner-provided-value"}
350
438
  ```
351
439
 
440
+ Prefer the non-echoing configuration command over hand editing:
441
+
442
+ ```bash
443
+ tiangong-ai research capability credential set \
444
+ --id source.example.api --from-env OWNER_DATABASE_API_KEY \
445
+ --workspace /absolute/path/to/workspace --json
446
+ ```
447
+
352
448
  The broker injects declared credentials only for admitted HTTPS hosts. Agent
353
449
  processes do not receive this variable. Keep the file owner-only (`chmod 600`)
354
- and use `research workspace doctor` before a run. The broker preserves a
450
+ and run `research capability doctor --live` plus production
451
+ `research workspace doctor --agent-smoke --capability-smoke` before a run.
452
+ Capability doctor retries only one 429 response with bounded `Retry-After`
453
+ backoff; deterministic 4xx, missing subscription, authentication, drift, and
454
+ content-type failures stop explicitly. The broker preserves a
355
455
  sanitized non-2xx excerpt, safe request ID, and `Retry-After`; it supports JSON
356
456
  Pointer extraction, bounded item and estimated-token views, and an explicit
357
457
  public-response cache. For a JSON collection, use the returned
package/dist/cli.d.ts CHANGED
@@ -3,6 +3,7 @@ export type { CliIO, Output } from "./io.js";
3
3
  export { parseArgs } from "./args.js";
4
4
  export { DEFAULT_API_BASE_URL, DEFAULT_API_PATH_PREFIX } from "./kb/config.js";
5
5
  export { resolveCollectionSelector } from "./kb/selector.js";
6
+ export declare const CLI_VERSION: string;
6
7
  export declare const DEFAULT_BULK_POLL_INTERVAL_SECONDS = 30;
7
8
  export declare const DEFAULT_BULK_PIPELINE_HEALTH_POLL_INTERVAL_SECONDS = 60;
8
9
  export declare function runCli(argv: string[], io: CliIO): Promise<number>;
package/dist/cli.js CHANGED
@@ -6,10 +6,11 @@ import { basename, dirname, extname, isAbsolute, join, posix as pathPosix, relat
6
6
  import { setTimeout as sleep } from "node:timers/promises";
7
7
  import { deflateRawSync, inflateRawSync } from "node:zlib";
8
8
  import sharp from "sharp";
9
+ import packageMetadata from "../package.json" with { type: "json" };
9
10
  import { getBoolean, getNonNegativeInteger, getPositiveInteger, getString, nonNegativeIntegerValue, parseArgs, positiveIntegerValue, positiveNumberValue, } from "./args.js";
10
11
  import { isObject, responseData, stringField } from "./data.js";
11
12
  import { firstEnv, loadDotenv } from "./env.js";
12
- import { CliError, HttpError } from "./errors.js";
13
+ import { CliError, HttpError, toErrorPayload } from "./errors.js";
13
14
  import { jsonRequest } from "./http.js";
14
15
  import { runEducationCommand } from "./education/commands.js";
15
16
  import { collectionKey, collectionPath, listCollections, resolveCollection, resolveSelectorFields, } from "./kb/client.js";
@@ -18,11 +19,13 @@ import { runCourseFulltextCommand } from "./kb/course-fulltext.js";
18
19
  import { readBulkPipelineHealth } from "./kb/pipeline-health.js";
19
20
  import { resolveCollectionSelector } from "./kb/selector.js";
20
21
  import { batchDocumentStatuses, getDocumentStatus } from "./kb/status.js";
21
- import { write } from "./io.js";
22
+ import { stringifyJson, write } from "./io.js";
22
23
  import { runResearchCommand } from "./research/commands.js";
24
+ import { configuredResearchSecrets, sanitizeResearchText, sanitizeResearchValue, } from "./research/workspace/sanitization.js";
23
25
  export { parseArgs } from "./args.js";
24
26
  export { DEFAULT_API_BASE_URL, DEFAULT_API_PATH_PREFIX } from "./kb/config.js";
25
27
  export { resolveCollectionSelector } from "./kb/selector.js";
28
+ export const CLI_VERSION = packageMetadata.version;
26
29
  const DEFAULT_RETRIES = 3;
27
30
  const DEFAULT_BULK_WINDOW_SIZE = 100;
28
31
  const DEFAULT_BULK_TOP_UP_MAX = 50;
@@ -55,6 +58,10 @@ const BULK_SUPPORTED_EXTENSIONS = new Set([
55
58
  ]);
56
59
  export async function runCli(argv, io) {
57
60
  try {
61
+ if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
62
+ write(io.stdout, `${CLI_VERSION}\n`);
63
+ return 0;
64
+ }
58
65
  loadDotenv(io.env);
59
66
  if (argv.length === 0 || argv[0] === "--help" || argv[0] === "-h") {
60
67
  write(io.stdout, topHelp());
@@ -132,7 +139,18 @@ export async function runCli(argv, io) {
132
139
  }
133
140
  catch (error) {
134
141
  if (error instanceof CliError) {
135
- write(io.stderr, `${error.message}\n`);
142
+ if (argv[0] === "research") {
143
+ const secrets = configuredResearchSecrets(io.env);
144
+ if (argv.includes("--json")) {
145
+ write(io.stderr, stringifyJson(sanitizeResearchValue(toErrorPayload(error), secrets), true));
146
+ }
147
+ else {
148
+ write(io.stderr, `${sanitizeResearchText(error.message, secrets)}\n`);
149
+ }
150
+ }
151
+ else {
152
+ write(io.stderr, `${error.message}\n`);
153
+ }
136
154
  return error.exitCode;
137
155
  }
138
156
  throw error;
@@ -2699,6 +2717,10 @@ Usage:
2699
2717
  tiangong-ai research search --input <request.json>|--query <query> [--sources default|all|sci|report|patent|esg]
2700
2718
  tiangong-ai education search --input <request.json>|--query <query> [--sources default|all|course|edu|textbook]
2701
2719
 
2720
+ Options:
2721
+ -h, --help Show this help.
2722
+ -v, --version Show the CLI version.
2723
+
2702
2724
  Run "tiangong-ai kb --help" for KB options.
2703
2725
  Run "tiangong-ai research --help" for research options.
2704
2726
  Run "tiangong-ai education --help" for education options.