@tiangong-ai/cli 0.0.19 → 0.0.21

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 (58) hide show
  1. package/AGENTS.md +8 -2
  2. package/README.md +209 -4
  3. package/dist/cli.js +2 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/research/commands.js +6 -0
  6. package/dist/research/commands.js.map +1 -1
  7. package/dist/research/orchestration.d.ts +3 -0
  8. package/dist/research/orchestration.js +391 -0
  9. package/dist/research/orchestration.js.map +1 -0
  10. package/dist/research/workspace/broker.d.ts +5 -0
  11. package/dist/research/workspace/broker.js +729 -0
  12. package/dist/research/workspace/broker.js.map +1 -0
  13. package/dist/research/workspace/capabilities.d.ts +10 -0
  14. package/dist/research/workspace/capabilities.js +356 -0
  15. package/dist/research/workspace/capabilities.js.map +1 -0
  16. package/dist/research/workspace/constants.d.ts +8 -0
  17. package/dist/research/workspace/constants.js +41 -0
  18. package/dist/research/workspace/constants.js.map +1 -0
  19. package/dist/research/workspace/context.d.ts +3 -0
  20. package/dist/research/workspace/context.js +77 -0
  21. package/dist/research/workspace/context.js.map +1 -0
  22. package/dist/research/workspace/evidence.d.ts +32 -0
  23. package/dist/research/workspace/evidence.js +235 -0
  24. package/dist/research/workspace/evidence.js.map +1 -0
  25. package/dist/research/workspace/executor.d.ts +22 -0
  26. package/dist/research/workspace/executor.js +926 -0
  27. package/dist/research/workspace/executor.js.map +1 -0
  28. package/dist/research/workspace/input-plan.d.ts +5 -0
  29. package/dist/research/workspace/input-plan.js +319 -0
  30. package/dist/research/workspace/input-plan.js.map +1 -0
  31. package/dist/research/workspace/journal.d.ts +7 -0
  32. package/dist/research/workspace/journal.js +105 -0
  33. package/dist/research/workspace/journal.js.map +1 -0
  34. package/dist/research/workspace/preflight.d.ts +108 -0
  35. package/dist/research/workspace/preflight.js +261 -0
  36. package/dist/research/workspace/preflight.js.map +1 -0
  37. package/dist/research/workspace/projects.d.ts +12 -0
  38. package/dist/research/workspace/projects.js +514 -0
  39. package/dist/research/workspace/projects.js.map +1 -0
  40. package/dist/research/workspace/runtime.d.ts +31 -0
  41. package/dist/research/workspace/runtime.js +1637 -0
  42. package/dist/research/workspace/runtime.js.map +1 -0
  43. package/dist/research/workspace/sanitization.d.ts +5 -0
  44. package/dist/research/workspace/sanitization.js +72 -0
  45. package/dist/research/workspace/sanitization.js.map +1 -0
  46. package/dist/research/workspace/schemas.d.ts +17 -0
  47. package/dist/research/workspace/schemas.js +342 -0
  48. package/dist/research/workspace/schemas.js.map +1 -0
  49. package/dist/research/workspace/storage.d.ts +25 -0
  50. package/dist/research/workspace/storage.js +222 -0
  51. package/dist/research/workspace/storage.js.map +1 -0
  52. package/dist/research/workspace/types.d.ts +341 -0
  53. package/dist/research/workspace/types.js +2 -0
  54. package/dist/research/workspace/types.js.map +1 -0
  55. package/dist/research/workspace/workspace.d.ts +23 -0
  56. package/dist/research/workspace/workspace.js +702 -0
  57. package/dist/research/workspace/workspace.js.map +1 -0
  58. package/package.json +4 -2
package/AGENTS.md CHANGED
@@ -15,8 +15,8 @@ checkPaths:
15
15
  - .docpact/config.yaml
16
16
  - docs/agents/**
17
17
  - src/**
18
- lastReviewedAt: 2026-07-22
19
- lastReviewedCommit: 2a1945321c66b1a2215b515e4d2b477572a3d6ac
18
+ lastReviewedAt: 2026-08-06
19
+ lastReviewedCommit: f5d031588a8eb2694573b8c3c83ff07c6ecd2b6f
20
20
  ---
21
21
 
22
22
  # Tiangong AI CLI Contract
@@ -44,6 +44,12 @@ This repository owns the Tiangong AI command-line interface.
44
44
  - `tiangong-ai kb ingest export`
45
45
  - `tiangong-ai kb collections`
46
46
  - `tiangong-ai kb status`
47
+ - `tiangong-ai research context`
48
+ - `tiangong-ai research workspace`
49
+ - `tiangong-ai research capability`
50
+ - `tiangong-ai research project`
51
+ - `tiangong-ai research status`
52
+ - `tiangong-ai research run`
47
53
  - `tiangong-ai research search`
48
54
  - `tiangong-ai education search`
49
55
 
package/README.md CHANGED
@@ -12,8 +12,8 @@ checkPaths:
12
12
  - package.json
13
13
  - bin/**
14
14
  - src/**
15
- lastReviewedAt: 2026-06-01
16
- lastReviewedCommit: 09572bea5a50c07a5a8e023a2b7e180cbd037d75
15
+ lastReviewedAt: 2026-08-04
16
+ lastReviewedCommit: 7429c2ab92509920a2728dc38685ad5c4f2c8f13
17
17
  ---
18
18
 
19
19
  # Tiangong AI CLI
@@ -175,6 +175,206 @@ region are resolved by the AWS SDK, including `AWS_ACCESS_KEY_ID`,
175
175
  `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, `AWS_PROFILE`, `AWS_REGION`, and
176
176
  `AWS_DEFAULT_REGION`.
177
177
 
178
+ ## Research Workspaces
179
+
180
+ Create a bounded smoke-test workspace and register a question:
181
+
182
+ ```bash
183
+ tiangong-ai research workspace init /absolute/path/to/workspace
184
+ tiangong-ai research project init gpu-resource-impact \
185
+ --workspace /absolute/path/to/workspace \
186
+ --question "How do advanced GPU process nodes change environmental resource burdens?"
187
+ ```
188
+
189
+ `smoke-test` is the default and is intended for deterministic fixtures and
190
+ low-cost canaries. Formal work must use `--mode production-research`, explicit
191
+ producer/reviewer model IDs and pricing in `config.json`, a requirements JSON
192
+ file, and budget confirmation when `maxCostUsd` exceeds
193
+ `confirmationCostUsd`:
194
+
195
+ ```bash
196
+ tiangong-ai research workspace init /absolute/path/to/workspace \
197
+ --mode production-research
198
+ tiangong-ai research project preflight \
199
+ --workspace /absolute/path/to/workspace \
200
+ --question "How do advanced GPU process nodes change environmental resource burdens?" \
201
+ --requirements /absolute/path/to/evidence-requirements.json --json
202
+ tiangong-ai research project init gpu-resource-impact \
203
+ --workspace /absolute/path/to/workspace \
204
+ --question "How do advanced GPU process nodes change environmental resource burdens?" \
205
+ --requirements /absolute/path/to/evidence-requirements.json \
206
+ --confirm-budget --json
207
+ ```
208
+
209
+ The requirements object declares `dimensions`, `sourceTypes`, `minSources`,
210
+ `minFullTextSources`, `minDatedSources`, and optional inclusive
211
+ `publicationDateFrom` / `publicationDateTo` boundaries (`YYYY-MM-DD` or
212
+ `null`). After discovery, a mechanical coverage gate verifies the declared
213
+ source, full-text, publication-date, and dimension summary before analysis.
214
+ For large local sources, pass an immutable `--input-plan` to both preflight and
215
+ project initialization. Each plan entry may expose either a separate
216
+ `contextPath` or non-overlapping, one-based `contextRanges`; the producer sees
217
+ only that bounded context, while independent review receives the hash-verified
218
+ full source. Symlinks, duplicate content, changed hashes, and context above
219
+ `maxInputContextTokens` are rejected.
220
+
221
+ The workspace stores its current protocol state under `.tiangong-research/`.
222
+ Each project follows five ordered stages: evidence discovery, analysis,
223
+ synthesis, independent review, and mechanical closure. Producer work defaults
224
+ to Codex, independent review defaults to Claude, and a run is blocked when both
225
+ routes use the same agent family.
226
+
227
+ Research execution requires `/usr/bin/sandbox-exec` on macOS or Bubblewrap
228
+ (`bwrap`) on Linux. Windows can inspect and configure workspaces but does not
229
+ execute research packages.
230
+
231
+ Add immutable local evidence, verify the workspace, and execute ready work:
232
+
233
+ ```bash
234
+ tiangong-ai research project input add gpu-resource-impact \
235
+ --workspace /absolute/path/to/workspace \
236
+ --path /absolute/path/to/inventory.csv \
237
+ --role primary
238
+ tiangong-ai research workspace doctor --workspace /absolute/path/to/workspace
239
+ tiangong-ai research workspace doctor --workspace /absolute/path/to/workspace \
240
+ --agent-smoke
241
+ tiangong-ai research run --workspace /absolute/path/to/workspace \
242
+ --project gpu-resource-impact --progress-jsonl
243
+ tiangong-ai research status --workspace /absolute/path/to/workspace --json
244
+ ```
245
+
246
+ Use `research run --project <id>` for an auditable project-scoped run: only
247
+ that project is checked, scheduled, summarized, and bound to the top-level
248
+ JSON/JSONL `projectId`, so historical blocked siblings do not alter its exit
249
+ status. Omit `--project` and use `--max-parallel` only for an intentional
250
+ workspace-wide run.
251
+
252
+ Inputs are admitted by SHA-256. Agent work runs with a dedicated capsule HOME
253
+ in an ephemeral platform sandbox. Only the minimal supported agent auth file is
254
+ copied into that HOME. For Claude, an owner-only user `settings.json` is never
255
+ copied; only the whitelisted API key/token and HTTPS base URL fields from its
256
+ `env` object are injected in memory. Permissions, hooks, additional directories,
257
+ and unrelated settings are not admitted. The workspace credential file and the
258
+ rest of the host home are not admitted. Production doctor is blocked until
259
+ `--agent-smoke` actually starts both routes inside this boundary. A successful
260
+ smoke creates a 24-hour attestation bound to workspace config, capability lock,
261
+ output schema, and the resolved agent binary/wrapper fingerprints. Production
262
+ execution stops before invocation if the attestation expires or any bound value
263
+ drifts.
264
+ Use the exact `codex` / `claude` route by default. A custom wrapper must use an
265
+ absolute `binary` plus an absolute `wrapperTargetBinary`; the runtime injects
266
+ the resolved target path and independently hashes the target executable, route
267
+ launcher/wrapper, and internal adapter. A wrapper that performs an unpinned
268
+ PATH lookup is not a reproducible route.
269
+
270
+ The CLI owns the authoritative JSON Schemas for discovery, analysis,
271
+ synthesis, and review. Inspect one with `research schema show <stage> --json`.
272
+ Codex and Claude receive the schema through their structured-output options;
273
+ the CLI materializes the validated final object. A syntax/schema failure gets
274
+ at most one separately budgeted formatting repair, never a full blind retry.
275
+ The same isolated repair may correct mechanically diagnosed provenance or
276
+ finding/source bindings; it has no broker or research tools and cannot add new
277
+ facts.
278
+
279
+ Total, per-package, output, repair, broker-response bytes, estimated broker
280
+ context tokens, context items, wall-time, output-count, output-size, and attempt
281
+ limits live in `.tiangong-research/config.json`.
282
+ Before an agent starts, the runtime reserves the package token and conservative
283
+ price budget. The call-level check accounts for prompt and schema bytes at
284
+ three bytes per token, repeats input allowance for every permitted API turn,
285
+ and adds primary output plus a potential isolated repair's input and output;
286
+ insufficient package or remaining project budget prevents invocation. The
287
+ provider cost cap is the current package reservation, not the remaining
288
+ workspace allowance. Tool-free primary stages allow two protocol turns because
289
+ Claude structured output uses a `StructuredOutput` call plus its follow-up
290
+ result; external tools remain disabled. Formatting repair omits the provider
291
+ schema tool, uses one plain-JSON turn, and remains subject to the CLI schema and
292
+ semantic validators. Current Codex and Claude CLI adapters report
293
+ output usage only after execution, so preflight identifies
294
+ `outputTokenLimitEnforcement` as `post-execution`; captured bytes provide a
295
+ separate process bound, and over-limit output fails without promotion.
296
+ Preflight also reports per-stage `maxTurns` and `turnLimitEnforcement`: Claude
297
+ receives a provider-side turn cap, while the current Codex CLI exposes no such
298
+ flag, so its turn allowance is reservation guidance plus post-execution
299
+ accounting and rejection. Usage records separate input, cached-input, and output
300
+ tokens; `inputTokens` excludes
301
+ the separately reported cached portion. Configured pricing fills cost when the
302
+ provider does not report it. Run records and JSONL progress also preserve
303
+ sanitized event/item counts, provider turns, tool calls, reasoning tokens, and
304
+ bounded provider errors.
305
+
306
+ Every evidence source must resolve to an admitted input or a completed broker
307
+ receipt. Successful broker bodies are immutable content-addressed objects under
308
+ `.tiangong-research/evidence/objects`; receipts are project-scoped and verified
309
+ for existence, size, and SHA-256 before every capsule stages them. Independent
310
+ review binds the requirements, receipts, permanent evidence objects, inputs,
311
+ and artifact hashes. Its exact packet and merged bounded evidence context are
312
+ also content-addressed under the project `review/packets/` and
313
+ `review/contexts/` directories. Mechanical closure re-verifies the packet,
314
+ context, broker objects, and registered local input hashes before recording
315
+ their safe locators. Capsule deletion therefore does not delete the durable
316
+ review chain.
317
+
318
+ Discovery alone may use the capability broker and workspace-read tools.
319
+ Analyze and synthesize receive bounded, hash-verified prior-stage artifacts in
320
+ their prompt with tools disabled. Review is also tool-free and limited to the
321
+ two turns required by the structured-output protocol:
322
+ its prompt embeds the complete generated artifacts, persistent packet, local
323
+ bounded contexts, and each cited broker receipt's exact bounded view. Full
324
+ local files and raw broker objects are hash-bound for durable human/mechanical
325
+ audit, but the model must not claim to have read beyond those embedded views.
326
+ The CLI mechanically derives local full-text availability, source types,
327
+ counts, date coverage, source IDs, and the coverage decision. A `partial`
328
+ dimension is usable but incomplete; a missing dimension or unmet declared
329
+ minimum blocks downstream work. Qualitative gaps remain visible without
330
+ silently changing those mechanical fields.
331
+
332
+ Method skills are declared in `.tiangong-research/capabilities.json` with
333
+ absolute skill paths and explicit permissions, then frozen before execution:
334
+
335
+ ```bash
336
+ tiangong-ai research capability lock --workspace /absolute/path/to/workspace
337
+ tiangong-ai research capability verify --workspace /absolute/path/to/workspace
338
+ ```
339
+
340
+ A capability using `brokered-network` must declare exact `allowedHosts` and may
341
+ declare an `http` policy with one exact `accept` value,
342
+ `allowedContentTypes`, `maxResponseBytes`, and `maxItems`. Its optional
343
+ `coverage` block declares dimensions, source types, full-text availability,
344
+ and publication-date availability for the preflight gap report.
345
+ Optional credentials declare logical IDs, exact host scopes, header names, and
346
+ prefixes. Put only the logical value map in `.tiangong-research/.env`:
347
+
348
+ ```bash
349
+ TIANGONG_RESEARCH_CAPABILITY_CREDENTIALS_JSON={"source.example.api":"owner-provided-value"}
350
+ ```
351
+
352
+ The broker injects declared credentials only for admitted HTTPS hosts. Agent
353
+ 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
355
+ sanitized non-2xx excerpt, safe request ID, and `Retry-After`; it supports JSON
356
+ Pointer extraction, bounded item and estimated-token views, and an explicit
357
+ public-response cache. For a JSON collection, use the returned
358
+ `contextNextOffset` as the next `item_offset`; this creates a distinct bounded
359
+ context receipt while reusing the same verified raw object instead of
360
+ refetching it. Follow upstream pagination with its next admitted HTTPS URL.
361
+ The recorded estimate is `ceil(contextBytes / 3)`. Use `cache_mode=bypass` for
362
+ a fresh public request and always for credentialed requests. Raw URLs and
363
+ credential values are never journaled.
364
+
365
+ Retry policy is classified: deterministic configuration/4xx/output failures
366
+ stop, schema failures use the formatting repair path, and rate limits or
367
+ transient server failures alone may schedule another attempt. Explicit recovery
368
+ uses append-only management events:
369
+
370
+ ```bash
371
+ tiangong-ai research project retry gpu-resource-impact --package analyze \
372
+ --workspace /absolute/path/to/workspace
373
+ tiangong-ai research project fork gpu-resource-impact \
374
+ --to gpu-resource-impact-v2 --resume-through analyze \
375
+ --workspace /absolute/path/to/workspace
376
+ ```
377
+
178
378
  ## Research Search
179
379
 
180
380
  Forward research-oriented search requests to SCI, report, patent, and ESG edge
@@ -235,8 +435,13 @@ appends `course_search`, `edu_search`, or `textbook_search`.
235
435
 
236
436
  ## Boundary
237
437
 
238
- The CLI is a thin local client. It sends bearer-token requests to the Tiangong
239
- KB ingest API and records SQLite checkpoints for batch recovery. Ingest uses
438
+ The CLI owns local operator workflows. Research workspaces keep bounded local
439
+ state, capability locks, isolated agent runs, usage accounting, provenance,
440
+ independent review, and deterministic closure. Research capability credentials
441
+ remain in the workspace broker and are not forwarded to agent processes.
442
+
443
+ For KB operations, the CLI sends bearer-token requests to the Tiangong KB
444
+ ingest API and records SQLite checkpoints for batch recovery. Ingest uses
240
445
  the bulk runner and releases sliding-window capacity only when document status
241
446
  is `completed` and both `opensearchIndexed` and `pineconeIndexed` are true. If
242
447
  the status API does not return those index flags yet, the file remains in
package/dist/cli.js CHANGED
@@ -2694,6 +2694,8 @@ Usage:
2694
2694
  tiangong-ai kb ingest status <document-id>
2695
2695
  tiangong-ai kb collections list [--capability upload]
2696
2696
  tiangong-ai kb course fulltext --document-id <id> --tags <tag>
2697
+ tiangong-ai research workspace init <absolute-path>
2698
+ tiangong-ai research run [--workspace <absolute-path>] [--project <project-id>] [--max-parallel 1]
2697
2699
  tiangong-ai research search --input <request.json>|--query <query> [--sources default|all|sci|report|patent|esg]
2698
2700
  tiangong-ai education search --input <request.json>|--query <query> [--sources default|all|course|edu|textbook]
2699
2701