@wayai/cli 0.3.353 → 0.3.354

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -15613,17 +15613,17 @@ function isShortNameAlias(segment2) {
15613
15613
  function isCaseInstructions(segments) {
15614
15614
  return segments.length > 2 && segments[0] === "instructions" && segments[1] === "case";
15615
15615
  }
15616
- function contentArea(segments, phaseFolders) {
15616
+ function contentArea(segments, phaseFolders2) {
15617
15617
  if (segments.length < 2) return null;
15618
15618
  if (segments[0] === "analysis") return "analysis";
15619
- return phaseFolders.includes(segments[0]) ? "phase" : null;
15619
+ return phaseFolders2.includes(segments[0]) ? "phase" : null;
15620
15620
  }
15621
- function allowedArea(segments, phaseFolders) {
15622
- if (segments[0] === "conf") return contentArea(segments.slice(1), phaseFolders);
15621
+ function allowedArea(segments, phaseFolders2) {
15622
+ if (segments[0] === "conf") return contentArea(segments.slice(1), phaseFolders2);
15623
15623
  if (isCaseInstructions(segments)) return "case_instructions";
15624
- return contentArea(segments, phaseFolders);
15624
+ return contentArea(segments, phaseFolders2);
15625
15625
  }
15626
- function checkCaseFilePathUnder(rules, entry, phaseFolders) {
15626
+ function checkCaseFilePathUnder(rules, entry, phaseFolders2) {
15627
15627
  const entryRules = rules.filter((rule) => rule.on === "entry");
15628
15628
  for (const rule of entryRules) if (rule.refuses(entry)) return { ok: false, reason: rule.reason, segment: null };
15629
15629
  const segments = entry.path.split("/");
@@ -15633,7 +15633,7 @@ function checkCaseFilePathUnder(rules, entry, phaseFolders) {
15633
15633
  if (index >= 0) return { ok: false, reason: rule.reason, segment: index };
15634
15634
  }
15635
15635
  const confidential = segments[0] === "conf";
15636
- const area = allowedArea(segments, phaseFolders);
15636
+ const area = allowedArea(segments, phaseFolders2);
15637
15637
  if (area === null) return { ok: false, reason: "not_allowed", segment: confidential && segments.length > 1 ? 1 : 0 };
15638
15638
  const folded = segments.map(fold);
15639
15639
  return {
@@ -15646,8 +15646,8 @@ function checkCaseFilePathUnder(rules, entry, phaseFolders) {
15646
15646
  fold_key: folded.join("/")
15647
15647
  };
15648
15648
  }
15649
- function checkCaseFilePath(entry, phaseFolders) {
15650
- return checkCaseFilePathUnder(CASE_FILE_PATH_RULES, entry, phaseFolders);
15649
+ function checkCaseFilePath(entry, phaseFolders2) {
15650
+ return checkCaseFilePathUnder(CASE_FILE_PATH_RULES, entry, phaseFolders2);
15651
15651
  }
15652
15652
  var CASE_FILE_ENTRY_TYPES, CASE_FILE_PATH_MAX_BYTES, CASE_FILE_SEGMENT_MAX_BYTES, CONTROL, INVISIBLE, PERCENT_ESCAPE, WINDOWS_RESERVED_CHARACTER, WINDOWS_DEVICE_NAME, AGENT_INSTRUCTION_FILE, isLast, CASE_FILE_PATH_RULES;
15653
15653
  var init_chunk_KWRHZBGU = __esm({
@@ -17121,7 +17121,7 @@ function casePassageLines(text5) {
17121
17121
  if (lines2.at(-1) === "") lines2.pop();
17122
17122
  return lines2;
17123
17123
  }
17124
- var CASE_COMMENT_TEXT_MAX_LENGTH, CASE_COMMENTS_PAGE_MAX, CASE_COMMENT_LINE_MAX, casePassageLineSchema, lineNumber, addCaseCommentShape, CASE_COMMENT_REVERSED_REASON, addCaseCommentBody, caseCommentsQuery, CASE_COMMENT_OUT_OF_RANGE_REASON;
17124
+ var CASE_COMMENT_TEXT_MAX_LENGTH, CASE_COMMENTS_PAGE_MAX, CASE_COMMENT_LINE_MAX, casePassageLineSchema, lineNumber, addCaseCommentShape, CASE_COMMENT_REVERSED_REASON, addCaseCommentBody, caseCommentsQuery, CASE_COMMENT_OUT_OF_RANGE_REASON, CASE_COMMENT_NOT_TEXT_REASON, CASE_COMMENT_DOCUMENT_TOO_LARGE_REASON;
17125
17125
  var init_chunk_S7UAXLHJ = __esm({
17126
17126
  "../../packages/core/dist/chunk-S7UAXLHJ.js"() {
17127
17127
  "use strict";
@@ -17159,11 +17159,13 @@ var init_chunk_S7UAXLHJ = __esm({
17159
17159
  limit: external_exports.coerce.number().int().min(1).max(CASE_COMMENTS_PAGE_MAX).optional()
17160
17160
  });
17161
17161
  CASE_COMMENT_OUT_OF_RANGE_REASON = "passage_out_of_range";
17162
+ CASE_COMMENT_NOT_TEXT_REASON = "not_text";
17163
+ CASE_COMMENT_DOCUMENT_TOO_LARGE_REASON = "document_too_large";
17162
17164
  }
17163
17165
  });
17164
17166
 
17165
17167
  // ../../packages/core/dist/chunk-U3L6QR6F.js
17166
- var CASE_VERSION_DECISION_REASON_MAX_LENGTH, CASE_VERSION_DECISIONS, caseVersionDecisionReason, reason, lineNumber2, recordCaseReferenceBody, CASE_PASSAGE_REVERSED_REASON, citeCasePassageBody, decideCaseVersionBody, CASE_PASSAGE_LINK_CHANGED_REASON, CASE_PASSAGE_NO_TEXT_REASON, CASE_PASSAGE_OUT_OF_RANGE_REASON;
17168
+ var CASE_VERSION_DECISION_REASON_MAX_LENGTH, CASE_VERSION_DECISIONS, caseVersionDecisionReason, reason, lineNumber2, recordCaseReferenceBody, CASE_PASSAGE_REVERSED_REASON, citeCasePassageBody, decideCaseVersionBody, CASE_PASSAGE_LINK_REQUIRED_REASON, CASE_PASSAGE_LINK_CHANGED_REASON, CASE_PASSAGE_NO_TEXT_REASON, CASE_PASSAGE_TEXT_TOO_LARGE_REASON, CASE_PASSAGE_NOT_TEXT_REASON, CASE_PASSAGE_OUT_OF_RANGE_REASON;
17167
17169
  var init_chunk_U3L6QR6F = __esm({
17168
17170
  "../../packages/core/dist/chunk-U3L6QR6F.js"() {
17169
17171
  "use strict";
@@ -17197,8 +17199,11 @@ var init_chunk_U3L6QR6F = __esm({
17197
17199
  }).strict().superRefine((body, ctx) => {
17198
17200
  if (body.decision === "keep" && body.reason === null) ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message: "A version kept needs its reason", path: ["reason"] });
17199
17201
  });
17202
+ CASE_PASSAGE_LINK_REQUIRED_REASON = "link_required";
17200
17203
  CASE_PASSAGE_LINK_CHANGED_REASON = "link_changed";
17201
17204
  CASE_PASSAGE_NO_TEXT_REASON = "version_no_text";
17205
+ CASE_PASSAGE_TEXT_TOO_LARGE_REASON = CASE_COMMENT_DOCUMENT_TOO_LARGE_REASON;
17206
+ CASE_PASSAGE_NOT_TEXT_REASON = CASE_COMMENT_NOT_TEXT_REASON;
17202
17207
  CASE_PASSAGE_OUT_OF_RANGE_REASON = CASE_COMMENT_OUT_OF_RANGE_REASON;
17203
17208
  }
17204
17209
  });
@@ -20567,7 +20572,7 @@ function dataErrorMessage(err) {
20567
20572
  const message = parsed?.error?.message;
20568
20573
  return typeof message === "string" && message ? message : null;
20569
20574
  }
20570
- var RETRYABLE_BACKOFF_MS, delay, accessDimensions, courseAuthoring, caseTypePath, casePath, ApiError, ApiClient;
20575
+ var RETRYABLE_BACKOFF_MS, delay, accessDimensions, courseAuthoring, caseTypePath, casePath, etagSha, ApiError, ApiClient;
20571
20576
  var init_api_client = __esm({
20572
20577
  "src/lib/api-client.ts"() {
20573
20578
  "use strict";
@@ -20584,6 +20589,7 @@ var init_api_client = __esm({
20584
20589
  courseAuthoring = (communityId, courseId) => `/api/communities/${encodeURIComponent(communityId)}/authoring/courses${courseId === void 0 ? "" : `/${encodeURIComponent(courseId)}`}`;
20585
20590
  caseTypePath = (ref) => `/api/cases/${encodeURIComponent(ref.org_id)}/${encodeURIComponent(ref.space_id)}/types/${encodeURIComponent(ref.type_id)}`;
20586
20591
  casePath = (ref) => `/api/cases/${encodeURIComponent(ref.org_id)}/${encodeURIComponent(ref.space_id)}/cases/${encodeURIComponent(ref.code)}`;
20592
+ etagSha = (etag) => etag === null ? null : /^(?:W\/)?"([0-9a-f]{64})"$/.exec(etag)?.[1] ?? null;
20587
20593
  ApiError = class extends Error {
20588
20594
  status;
20589
20595
  body;
@@ -20802,6 +20808,19 @@ var init_api_client = __esm({
20802
20808
  async getCaseInputSourceLink(ref, inputId) {
20803
20809
  return this.request("GET", `${casePath(ref)}/inputs/${encodeURIComponent(inputId)}/source-link`);
20804
20810
  }
20811
+ /**
20812
+ * The text of the case's own source an input links, named as a passage's body names it: the bytes a passage's lines
20813
+ * number, with their SHA-256 as the server computed it from them (the answer's `ETag`); `sha` is null when no such tag is answered.
20814
+ */
20815
+ async getCaseInputSourceContent(ref, inputId, source) {
20816
+ const params = new URLSearchParams(source);
20817
+ const { bytes, etag } = await this.download(`${casePath(ref)}/inputs/${encodeURIComponent(inputId)}/source-link/content?${params}`);
20818
+ return { bytes, sha: etagSha(etag) };
20819
+ }
20820
+ /** The official versions an input of origin `previous_output` may link: the current one of each output of an earlier phase it depends on, that the reader reads. */
20821
+ async listCaseInputOfficialVersions(ref, inputId) {
20822
+ return this.request("GET", `${casePath(ref)}/inputs/${encodeURIComponent(inputId)}/official-versions`);
20823
+ }
20805
20824
  /** Link an input: to a collection document's version, an earlier phase's official version, or a received document, by the body's fields. */
20806
20825
  async linkCaseInput(ref, inputId, body) {
20807
20826
  return this.request("PUT", `${casePath(ref)}/inputs/${encodeURIComponent(inputId)}/link`, body);
@@ -20818,7 +20837,7 @@ var init_api_client = __esm({
20818
20837
  const params = new URLSearchParams({ part: query.part });
20819
20838
  if (query.version_id !== void 0) params.set("version_id", query.version_id);
20820
20839
  const { bytes, etag } = await this.download(`${casePath(ref)}/collection/${encodeURIComponent(documentId)}/content?${params}`);
20821
- return { bytes, sha: etag === null ? null : /^(?:W\/)?"([0-9a-f]{64})"$/.exec(etag)?.[1] ?? null };
20840
+ return { bytes, sha: etagSha(etag) };
20822
20841
  }
20823
20842
  /**
20824
20843
  * The case's package (`get_case_package`): the revision of the type version it opened on that reaches it, its files listed by path, SHA-256 and size;
@@ -32073,8 +32092,8 @@ import * as path33 from "path";
32073
32092
  function isClonePath(rel) {
32074
32093
  return isCasePath(rel, rel.split("/").filter((segment2) => CASE_PHASE_FOLDER_PATTERN.test(segment2)));
32075
32094
  }
32076
- function assertClonePaths(root, record, phaseFolders) {
32077
- if (!Object.keys(record.files).every((rel) => isCasePath(rel, phaseFolders))) throw notAMarker(path33.join(root, CASE_CLONE_RECORD_FILE));
32095
+ function assertClonePaths(root, record, phaseFolders2) {
32096
+ if (!Object.keys(record.files).every((rel) => isCasePath(rel, phaseFolders2))) throw notAMarker(path33.join(root, CASE_CLONE_RECORD_FILE));
32078
32097
  }
32079
32098
  function isCloneRecord(value) {
32080
32099
  if (typeof value !== "object" || value === null) return false;
@@ -32167,7 +32186,7 @@ var init_case_clone_record = __esm({
32167
32186
  init_case_types();
32168
32187
  init_case_local_files();
32169
32188
  CASE_CLONE_RECORD_FILE = ".wayai-case.json";
32170
- isCasePath = (rel, phaseFolders) => checkCaseFilePath({ path: rel, type: "file" }, phaseFolders).ok;
32189
+ isCasePath = (rel, phaseFolders2) => checkCaseFilePath({ path: rel, type: "file" }, phaseFolders2).ok;
32171
32190
  notAMarker = (file) => expected(`${sanitizeTerminalText(file)} is not a marker \`wayai cases clone\` wrote. Move it aside and clone the case again.`);
32172
32191
  sameCase = (a, b) => a.org_id === b.org_id && a.space_id === b.space_id && a.code === b.code;
32173
32192
  }
@@ -41824,6 +41843,58 @@ var init_case_comments = __esm({
41824
41843
  }
41825
41844
  });
41826
41845
 
41846
+ // ../../packages/core/dist/contracts/case-collection-citations.js
41847
+ var init_case_collection_citations = __esm({
41848
+ "../../packages/core/dist/contracts/case-collection-citations.js"() {
41849
+ "use strict";
41850
+ init_chunk_U3L6QR6F();
41851
+ init_chunk_S7UAXLHJ();
41852
+ init_chunk_7TQYAKCB();
41853
+ init_chunk_VROZDNLV();
41854
+ init_chunk_733K4J4G();
41855
+ init_chunk_PFPADFUC();
41856
+ init_chunk_KWRHZBGU();
41857
+ init_chunk_3T3D7LTE();
41858
+ init_chunk_M2T55BV6();
41859
+ init_chunk_VYINA6YP();
41860
+ init_chunk_ZVXO3XL6();
41861
+ init_chunk_FBV7NLKO();
41862
+ init_chunk_WEXVYJ5H();
41863
+ init_chunk_HZ6CADSY();
41864
+ init_chunk_ICYO56QW();
41865
+ init_chunk_WFQDSQJK();
41866
+ init_chunk_ZTNFLGW5();
41867
+ }
41868
+ });
41869
+
41870
+ // ../../packages/core/dist/contracts/case-collection-links.js
41871
+ var init_case_collection_links = __esm({
41872
+ "../../packages/core/dist/contracts/case-collection-links.js"() {
41873
+ "use strict";
41874
+ init_chunk_J7LBOXQK();
41875
+ init_chunk_6CHDJVQ6();
41876
+ init_chunk_U3X3BIQH();
41877
+ init_chunk_EYOBPUDN();
41878
+ init_chunk_U3L6QR6F();
41879
+ init_chunk_S7UAXLHJ();
41880
+ init_chunk_7TQYAKCB();
41881
+ init_chunk_VROZDNLV();
41882
+ init_chunk_733K4J4G();
41883
+ init_chunk_PFPADFUC();
41884
+ init_chunk_KWRHZBGU();
41885
+ init_chunk_3T3D7LTE();
41886
+ init_chunk_M2T55BV6();
41887
+ init_chunk_VYINA6YP();
41888
+ init_chunk_ZVXO3XL6();
41889
+ init_chunk_FBV7NLKO();
41890
+ init_chunk_WEXVYJ5H();
41891
+ init_chunk_HZ6CADSY();
41892
+ init_chunk_ICYO56QW();
41893
+ init_chunk_WFQDSQJK();
41894
+ init_chunk_ZTNFLGW5();
41895
+ }
41896
+ });
41897
+
41827
41898
  // src/cases/case-package.ts
41828
41899
  import * as fs37 from "fs";
41829
41900
  import * as path49 from "path";
@@ -42117,8 +42188,9 @@ async function readInputTexts(calls, folder, work, folders, listed3) {
42117
42188
  if (!view?.readable) return null;
42118
42189
  if (view.kind === "official_version") {
42119
42190
  const base2 = { ...named, origin: "previous_output", official_version_id: view.official_version_id, version: view.version };
42120
- const checked = checkedText(base2, file, null, view.passages.filter((p) => "official_version_id" in p && p.official_version_id === view.official_version_id));
42121
- return view.has_text ? { text: { ...checked.text, status: "no_read" }, data: null } : checked;
42191
+ const cited2 = view.passages.filter((p) => "official_version_id" in p && p.official_version_id === view.official_version_id);
42192
+ const answered = view.has_text ? await calls.run(() => sourceTextRefused(api.getCaseInputSourceContent(connection, input.id, { official_version_id: view.official_version_id }))) : null;
42193
+ return checkedText(base2, file, answered, cited2);
42122
42194
  }
42123
42195
  const base = { ...named, origin: "received", received_id: view.received_id };
42124
42196
  const cited = view.passages.filter((p) => "received_id" in p && p.received_id === view.received_id);
@@ -42240,11 +42312,11 @@ function unwrittenLines(work) {
42240
42312
  return (work?.phases ?? []).flatMap((p) => p.texts.flatMap(({ text: text5 }) => {
42241
42313
  const name = `${one(p.folder)}, input ${one(text5.key)} (${one(text5.name)})`;
42242
42314
  if (text5.status === "hash_mismatch") {
42243
- return [`${name}: not written, its bytes do not hash to the SHA-256 the space registered for it${text5.sha === null ? " (none was answered)" : ""}.`];
42315
+ const whose = text5.origin === "previous_output" ? "the space answered for them" : "the space registered for it";
42316
+ return [`${name}: not written, its bytes do not hash to the SHA-256 ${whose}${text5.sha === null ? " (none was answered)" : ""}.`];
42244
42317
  }
42245
- if (text5.status === "no_read") return [`${name}: not written, this CLI does not read the text of an earlier phase's official version yet.`];
42246
42318
  if (text5.status !== "no_text") return [];
42247
- return [text5.origin === "collection" ? `${name}: the version it links holds no registered text, or is no longer readable here.` : `${name}: the source it links holds no text, or it is no longer readable here.`];
42319
+ return [text5.origin === "collection" ? `${name}: the version it links holds no registered text, or is no longer readable here.` : `${name}: the source it links holds no text it can be read from (none, past its size limit, or not text), or it is no longer readable here.`];
42248
42320
  }));
42249
42321
  }
42250
42322
  function packageReadme(pkg2) {
@@ -42274,8 +42346,9 @@ function readme(detail, at, withheld, confidential, unwritten, pkg2) {
42274
42346
  " and its cited passages (lines and hash, and whether they match the text here).",
42275
42347
  `- \`${INPUTS_DIR}/<phase folder>/<input key>.md\`: each such input's registered text, of the version or source its`,
42276
42348
  " link names, byte for byte and checked against the SHA-256 the space registered for it: line N here is the line N a",
42277
- " citation names (each line ends at a line break). An earlier phase's official version's text is not here: this",
42278
- " CLI does not read it yet.",
42349
+ " citation names (each line ends at a line break). An earlier phase's official version's text is its frozen piece",
42350
+ " (one Markdown file, or a document of chapters composed as WayAI composes it), checked against the SHA-256 WayAI",
42351
+ " computed for the bytes it served.",
42279
42352
  ...unwritten.length ? ["", "Linked inputs' texts not written:", ...unwritten.map((line) => `- ${line}`)] : []
42280
42353
  ];
42281
42354
  return [
@@ -42513,7 +42586,7 @@ Session-start hook: ${safe6(script)} refreshes the mirror (never with --confiden
42513
42586
  console.log(` ${safe6(settings)}`);
42514
42587
  console.log(`For another agent, run at the start of each session: ${safe6(command2)}`);
42515
42588
  }
42516
- var CASE_MIRROR_DIR, CASE_MIRROR_HOOK_FILE, RECORD_FILE2, SUMMARY_FILE, INPUTS_FILE, INPUTS_DIR, LOCK_FILE, LOCK_WAIT_MS, LOCK_STALE_MS, LOCK_POLL_MS, AGENDA_PAGES_READ, SUMMARY_REVISION_PAGES, MIRROR_CONFIDENTIAL_NOTICE, safe6, one, words, isConfPath, isObject2, isStringMap, isDeliveries, notFound, segment, NO_REVISIONS, within, HOOK_SCRIPT, json;
42589
+ var CASE_MIRROR_DIR, CASE_MIRROR_HOOK_FILE, RECORD_FILE2, SUMMARY_FILE, INPUTS_FILE, INPUTS_DIR, LOCK_FILE, LOCK_WAIT_MS, LOCK_STALE_MS, LOCK_POLL_MS, AGENDA_PAGES_READ, SUMMARY_REVISION_PAGES, MIRROR_CONFIDENTIAL_NOTICE, safe6, one, words, isConfPath, isObject2, isStringMap, isDeliveries, notFound, SOURCE_TEXT_REFUSALS, sourceTextRefused, segment, NO_REVISIONS, within, HOOK_SCRIPT, json;
42517
42590
  var init_case_mirror = __esm({
42518
42591
  "src/cases/case-mirror.ts"() {
42519
42592
  "use strict";
@@ -42521,7 +42594,10 @@ var init_case_mirror = __esm({
42521
42594
  init_case_files();
42522
42595
  init_case_comments();
42523
42596
  init_case_types();
42597
+ init_case_collection_citations();
42598
+ init_case_collection_links();
42524
42599
  init_api_client();
42600
+ init_errors3();
42525
42601
  init_resource_files();
42526
42602
  init_utils();
42527
42603
  init_expected();
@@ -42550,6 +42626,17 @@ var init_case_mirror = __esm({
42550
42626
  isStringMap = (v) => isObject2(v) && Object.values(v).every((x) => typeof x === "string");
42551
42627
  isDeliveries = (v) => isObject2(v) && Object.values(v).every((d) => d === null || isObject2(d) && typeof d.submission_id === "string" && typeof d.state === "string");
42552
42628
  notFound = (call4) => call4.catch((err) => err instanceof ApiError && err.status === 404 ? null : Promise.reject(err));
42629
+ SOURCE_TEXT_REFUSALS = {
42630
+ 400: [
42631
+ CASE_PASSAGE_NO_TEXT_REASON,
42632
+ CASE_PASSAGE_TEXT_TOO_LARGE_REASON,
42633
+ CASE_PASSAGE_NOT_TEXT_REASON,
42634
+ CASE_PASSAGE_LINK_REQUIRED_REASON,
42635
+ CASE_LINK_OFFICIAL_VERSION_UNKNOWN_REASON
42636
+ ],
42637
+ 409: [CASE_PASSAGE_LINK_CHANGED_REASON]
42638
+ };
42639
+ sourceTextRefused = (call4) => notFound(call4).catch((err) => err instanceof ApiError && (err.status === 403 || SOURCE_TEXT_REFUSALS[err.status]?.includes(extractApiErrorReason(err) ?? "")) ? null : Promise.reject(err));
42553
42640
  segment = (name, pattern, id) => pattern.test(name) ? name : UUID_RE3.test(id) ? id : computeHash(Buffer.from(id, "utf-8"));
42554
42641
  NO_REVISIONS = { revisions: [], more: false, newest_at: null };
42555
42642
  within = (prev, now) => Object.fromEntries(Object.entries(prev).filter(([key]) => key in now));
@@ -43085,58 +43172,6 @@ var init_case_skeleton = __esm({
43085
43172
  }
43086
43173
  });
43087
43174
 
43088
- // ../../packages/core/dist/contracts/case-collection-links.js
43089
- var init_case_collection_links = __esm({
43090
- "../../packages/core/dist/contracts/case-collection-links.js"() {
43091
- "use strict";
43092
- init_chunk_J7LBOXQK();
43093
- init_chunk_6CHDJVQ6();
43094
- init_chunk_U3X3BIQH();
43095
- init_chunk_EYOBPUDN();
43096
- init_chunk_U3L6QR6F();
43097
- init_chunk_S7UAXLHJ();
43098
- init_chunk_7TQYAKCB();
43099
- init_chunk_VROZDNLV();
43100
- init_chunk_733K4J4G();
43101
- init_chunk_PFPADFUC();
43102
- init_chunk_KWRHZBGU();
43103
- init_chunk_3T3D7LTE();
43104
- init_chunk_M2T55BV6();
43105
- init_chunk_VYINA6YP();
43106
- init_chunk_ZVXO3XL6();
43107
- init_chunk_FBV7NLKO();
43108
- init_chunk_WEXVYJ5H();
43109
- init_chunk_HZ6CADSY();
43110
- init_chunk_ICYO56QW();
43111
- init_chunk_WFQDSQJK();
43112
- init_chunk_ZTNFLGW5();
43113
- }
43114
- });
43115
-
43116
- // ../../packages/core/dist/contracts/case-collection-citations.js
43117
- var init_case_collection_citations = __esm({
43118
- "../../packages/core/dist/contracts/case-collection-citations.js"() {
43119
- "use strict";
43120
- init_chunk_U3L6QR6F();
43121
- init_chunk_S7UAXLHJ();
43122
- init_chunk_7TQYAKCB();
43123
- init_chunk_VROZDNLV();
43124
- init_chunk_733K4J4G();
43125
- init_chunk_PFPADFUC();
43126
- init_chunk_KWRHZBGU();
43127
- init_chunk_3T3D7LTE();
43128
- init_chunk_M2T55BV6();
43129
- init_chunk_VYINA6YP();
43130
- init_chunk_ZVXO3XL6();
43131
- init_chunk_FBV7NLKO();
43132
- init_chunk_WEXVYJ5H();
43133
- init_chunk_HZ6CADSY();
43134
- init_chunk_ICYO56QW();
43135
- init_chunk_WFQDSQJK();
43136
- init_chunk_ZTNFLGW5();
43137
- }
43138
- });
43139
-
43140
43175
  // src/cases/case-inputs.ts
43141
43176
  function inputLinkState(input) {
43142
43177
  const unlinked = input.dispensation ? { state: "dispensed" } : { state: "unlinked" };
@@ -43175,14 +43210,30 @@ function inputLinkState(input) {
43175
43210
  }
43176
43211
  function linkCommand(key, folder, origin, id) {
43177
43212
  const [flag, placeholder] = origin === "previous_output" ? ["--official-version", "<official_version_id>"] : ["--received", "<received_id>"];
43178
- return `wayai cases link ${one2(key)} --phase ${one2(folder)} ${flag} ${id ?? placeholder}`;
43213
+ return `${linkPrefix(key, folder)} ${flag} ${id ?? placeholder}`;
43214
+ }
43215
+ function candidateLine(version, key, folder, folders) {
43216
+ const { output } = version;
43217
+ const traits = [
43218
+ `phase ${one2(folders.get(version.phase_id) ?? version.phase_id)}`,
43219
+ `published ${one2(version.published_at)}`,
43220
+ ...output.format === "file" ? ["a file: no text to cite"] : [],
43221
+ ...version.confidential ? ["confidential"] : []
43222
+ ];
43223
+ return `version ${version.version} of output ${one2(output.code)} (${one2(output.document_type)}), ${traits.join(", ")}: \`${linkCommand(key, folder, "previous_output", version.official_version_id)}\``;
43179
43224
  }
43180
- function linkHint(key, folder, origin) {
43225
+ function linkHint(key, folder, origin, linkable, folders = /* @__PURE__ */ new Map(), indent = " ") {
43181
43226
  if (origin === "collection") return "a person links it, in the web app";
43182
43227
  if (origin === "received") {
43183
43228
  return `link it to a received document of the case: \`${linkCommand(key, folder, origin)}\` (the id is in its files' names under a phase's received/)`;
43184
43229
  }
43185
- return `link it to the current official version of an earlier phase's output: \`${linkCommand(key, folder, origin)}\` (no wayai cases command lists those: a person gives you the id, or links it in the web app)`;
43230
+ const current = "link it to the current official version of an earlier phase's output:";
43231
+ if (linkable === null) {
43232
+ return `${current} \`${linkCommand(key, folder, origin)}\` (this server lists none of them: a person gives you the id, or links it in the web app)`;
43233
+ }
43234
+ if (linkable === void 0) return `${current} \`${linkPrefix(key, folder)} --list\` lists those it may link`;
43235
+ if (linkable.length === 0) return NONE_LINKABLE;
43236
+ return `link it to one of the official versions it may link ${WHICH_LINKABLE}:${candidateBlock(linkable, key, folder, folders, indent)}`;
43186
43237
  }
43187
43238
  function undecidedWords(input, folder, link, folders) {
43188
43239
  const linked = sourceWords(link.source, folders);
@@ -43197,7 +43248,7 @@ function undecidedWords(input, folder, link, folders) {
43197
43248
  agent: true
43198
43249
  };
43199
43250
  }
43200
- function inputLine(input, folder, folders) {
43251
+ function inputLine(input, folder, folders, linkable) {
43201
43252
  const head = `${one2(input.key)} (${one2(input.name)}), ${input.origin.replaceAll("_", " ")}${input.required ? ", required" : ""}`;
43202
43253
  const state = inputLinkState(input);
43203
43254
  switch (state.state) {
@@ -43212,7 +43263,7 @@ function inputLine(input, folder, folders) {
43212
43263
  case "unknown":
43213
43264
  return `${head}: this server does not say whether it is linked`;
43214
43265
  case "unlinked":
43215
- return `${head}: not linked; ${linkHint(input.key, folder, input.origin)}`;
43266
+ return `${head}: not linked; ${linkHint(input.key, folder, input.origin, linkable, folders, " ")}`;
43216
43267
  }
43217
43268
  }
43218
43269
  function findInput(work, phase, name) {
@@ -43221,21 +43272,37 @@ function findInput(work, phase, name) {
43221
43272
  throw expected(`Phase ${phase.folder} has no input ${JSON.stringify(sanitizeTerminalText(name))} you may read. Its inputs: ${work.inputs.map((i) => one2(i.key)).join(", ") || "none"}.`);
43222
43273
  }
43223
43274
  function linkTarget(opts) {
43224
- if (opts.officialVersion === void 0 === (opts.received === void 0)) {
43225
- throw expected("link takes one of --official-version <id> (an input of origin previous_output) or --received <id> (an input of origin received).");
43275
+ if ([opts.officialVersion !== void 0, opts.received !== void 0, opts.list === true].filter(Boolean).length !== 1) {
43276
+ throw expected("link takes one of --official-version <id or output code> (an input of origin previous_output), --received <id> (an input of origin received) or --list (the official versions an input of origin previous_output may link).");
43226
43277
  }
43278
+ if (opts.list === true) return { kind: "list" };
43227
43279
  if (opts.officialVersion !== void 0) {
43228
- if (!UUID_RE3.test(opts.officialVersion)) throw expected("--official-version takes an official version's id (a UUID).");
43229
- return { official_version_id: opts.officialVersion };
43280
+ if (UUID_RE3.test(opts.officialVersion)) return { kind: "source", ref: { official_version_id: opts.officialVersion } };
43281
+ if (CASE_CODE_PATTERN.test(opts.officialVersion)) return { kind: "output", code: opts.officialVersion };
43282
+ throw expected("--official-version takes an official version's id (a UUID) or the code of the output it is of (as memo).");
43230
43283
  }
43231
43284
  if (!UUID_RE3.test(opts.received)) throw expected("--received takes a received document's id (a UUID).");
43232
- return { received_id: opts.received };
43285
+ return { kind: "source", ref: { received_id: opts.received } };
43233
43286
  }
43234
43287
  function linkMismatch(input, label3, target) {
43235
43288
  if (input.origin === "collection") return `The ${label3} links a collection document: a person links it, in the web app.`;
43236
- const wants = "official_version_id" in target ? "previous_output" : "received";
43289
+ const wants = target.kind !== "source" || "official_version_id" in target.ref ? "previous_output" : "received";
43237
43290
  if (input.origin === wants) return null;
43238
- return input.origin === "previous_output" ? `The ${label3} links an earlier phase's official version: pass --official-version <id>.` : `The ${label3} links a received document of the case: pass --received <id>.`;
43291
+ if (input.origin === "previous_output") return `The ${label3} links an earlier phase's official version: pass --official-version <id or output code>, or --list.`;
43292
+ return target.kind === "list" ? `The ${label3} links a received document of the case, which no read lists here: pass --received <id> (the id is in its files' names under a phase's received/).` : `The ${label3} links a received document of the case: pass --received <id>.`;
43293
+ }
43294
+ function chooseByOutput(linkable, code2, named, folders) {
43295
+ const chosen = linkable.filter((v) => v.output.code === code2);
43296
+ if (chosen.length === 1) return chosen[0];
43297
+ if (chosen.length > 1) {
43298
+ throw expected(`Several outputs of code ${code2} have an official version the ${named.label} may link, one per phase: name it by its id.` + candidateBlock(chosen, named.key, named.folder, folders, " "));
43299
+ }
43300
+ if (linkable.length === 0) throw expected(noneLinkable(named.label));
43301
+ throw expected(`No output of code ${code2} has an official version the ${named.label} may link. Those it may link:` + candidateBlock(linkable, named.key, named.folder, folders, " "));
43302
+ }
43303
+ function linkableLines(linkable, named, folders) {
43304
+ if (linkable.length === 0) return [noneLinkable(named.label)];
43305
+ return [`Official versions the ${named.label} may link ${WHICH_LINKABLE}:`, ...candidateLines(linkable, named.key, named.folder, folders, " ")];
43239
43306
  }
43240
43307
  function detailOf(err, field) {
43241
43308
  try {
@@ -43309,12 +43376,13 @@ function citeFailure(err, session, named) {
43309
43376
  if (err.status === 403) return expected(`Your access to case ${session.connection.code} does not cite passages: that takes Edit level.`);
43310
43377
  return caseCallFailure(err, session.connection, `The ${named.label} was not found`);
43311
43378
  }
43312
- var one2, sourceWords;
43379
+ var one2, linkPrefix, candidateLines, candidateBlock, NONE_LINKABLE, noneLinkable, WHICH_LINKABLE, agentLinks, sourceWords;
43313
43380
  var init_case_inputs = __esm({
43314
43381
  "src/cases/case-inputs.ts"() {
43315
43382
  "use strict";
43316
43383
  init_case_records();
43317
43384
  init_case_collection_links();
43385
+ init_case_types();
43318
43386
  init_case_collection_citations();
43319
43387
  init_api_client();
43320
43388
  init_errors3();
@@ -43323,6 +43391,14 @@ var init_case_inputs = __esm({
43323
43391
  init_utils();
43324
43392
  init_case_session();
43325
43393
  one2 = (value) => sanitizeTerminalText(value).replace(/\s*\n\s*/g, " ");
43394
+ linkPrefix = (key, folder) => `wayai cases link ${one2(key)} --phase ${one2(folder)}`;
43395
+ candidateLines = (linkable, key, folder, folders, indent) => linkable.map((v) => `${indent}- ${candidateLine(v, key, folder, folders)}`);
43396
+ candidateBlock = (...args2) => candidateLines(...args2).map((line) => `
43397
+ ${line}`).join("");
43398
+ NONE_LINKABLE = "no earlier phase it depends on has a current official version of its type this authorization reads yet: it waits for one to be published";
43399
+ noneLinkable = (label3) => `The ${label3} may link no official version here: ${NONE_LINKABLE}.`;
43400
+ WHICH_LINKABLE = "(the current one of each output of an earlier phase it depends on)";
43401
+ agentLinks = (origin, linkable) => origin !== "collection" && !(origin === "previous_output" && Array.isArray(linkable) && linkable.length === 0);
43326
43402
  sourceWords = (source, folders) => {
43327
43403
  const folder = (phaseId) => one2(folders.get(phaseId) ?? phaseId);
43328
43404
  switch (source.kind) {
@@ -43403,6 +43479,14 @@ async function call2(session, run, notFound2) {
43403
43479
  throw caseCallFailure(err, session.connection, notFound2);
43404
43480
  }
43405
43481
  }
43482
+ async function readLinkable(s, inputId) {
43483
+ try {
43484
+ return (await s.api.listCaseInputOfficialVersions(s.connection, inputId)).data.versions;
43485
+ } catch (err) {
43486
+ if (err instanceof ApiError && (err.status === 403 || err.status === 404)) return null;
43487
+ throw caseCallFailure(err, s.connection);
43488
+ }
43489
+ }
43406
43490
  function findPhase(detail, name) {
43407
43491
  const phase = detail.phases.find((p) => p.folder === name) ?? detail.phases.find((p) => p.code === name);
43408
43492
  if (phase) return phase;
@@ -43432,7 +43516,7 @@ function blockerLine(b, names) {
43432
43516
  }
43433
43517
  async function namesFor(session, detail, phaseIds, opts = {}) {
43434
43518
  const names = new CaseNames(session, detail);
43435
- if (readsWork(detail)) for (const id of phaseIds) await names.readPhase(id, opts.agenda ?? true);
43519
+ if (readsWork(detail)) for (const id of phaseIds) await names.readPhase(id, opts.agenda ?? true, opts.linkableFor);
43436
43520
  return names;
43437
43521
  }
43438
43522
  function printPhasesView(detail, state) {
@@ -43505,8 +43589,9 @@ async function caseExplain(session, opts) {
43505
43589
  return;
43506
43590
  }
43507
43591
  if (opts.json) {
43508
- const inputs2 = asked && readsWork(detail) ? (await namesFor(session, detail, [asked.phase_id], { agenda: false })).phaseInputs.get(asked.phase_id) ?? [] : null;
43509
- console.log(JSON.stringify({ case: detail, state, ...inputs2 ? { inputs: inputs2.map(inputJson) } : {} }, null, 2));
43592
+ const names2 = asked && readsWork(detail) ? await namesFor(session, detail, [asked.phase_id], { agenda: false }) : null;
43593
+ const inputs2 = names2 ? (names2.phaseInputs.get(asked.phase_id) ?? []).map((i) => inputJson(i, names2)) : null;
43594
+ console.log(JSON.stringify({ case: detail, state, ...inputs2 ? { inputs: inputs2 } : {} }, null, 2));
43510
43595
  return;
43511
43596
  }
43512
43597
  const phases = asked ? state.phases.filter((p) => p.phase_id === asked.phase_id) : state.phases;
@@ -43520,7 +43605,7 @@ async function caseExplain(session, opts) {
43520
43605
  console.log(`Phase ${phaseLabel(asked)}: ${st ? statusWords(st.status) : "not shown"}. Nothing holds it.`);
43521
43606
  return;
43522
43607
  }
43523
- const names = await namesFor(session, detail, named);
43608
+ const names = await namesFor(session, detail, named, asked ? {} : { linkableFor: pendingInputs([...phases, ...state.tasks]) });
43524
43609
  if (phases.length === 0) console.log(`Every phase of ${detail.code} is delivered or dispensed.`);
43525
43610
  const fullyNamed = new Set(named);
43526
43611
  for (const p of phases) {
@@ -43541,7 +43626,7 @@ async function caseExplain(session, opts) {
43541
43626
  if (inputs.length) {
43542
43627
  console.log(`Inputs of ${asked.folder}:`);
43543
43628
  const folders = names.folders();
43544
- for (const i of inputs) console.log(` ${inputLine(i, asked.folder, folders)}`);
43629
+ for (const i of inputs) console.log(` ${inputLine(i, asked.folder, folders, names.linkable(i.id))}`);
43545
43630
  }
43546
43631
  }
43547
43632
  function agentWork(b, names) {
@@ -43549,7 +43634,7 @@ function agentWork(b, names) {
43549
43634
  case "output_pending":
43550
43635
  return b.submission === null;
43551
43636
  case "input_pending":
43552
- return names.inputOrigin(b.input_id) !== "collection";
43637
+ return names.agentLinks(b.input_id);
43553
43638
  case "task_pending":
43554
43639
  case "publication_pending":
43555
43640
  return true;
@@ -43573,7 +43658,8 @@ async function caseNext(session, opts) {
43573
43658
  const underWay = state.phases.filter((p) => p.status === "in_progress");
43574
43659
  const [notes, names] = await Promise.all([
43575
43660
  readsWork(detail) ? openNotes(session) : [],
43576
- namesFor(session, detail, underWay.map((p) => p.phase_id), { agenda: !opts.json })
43661
+ // The text names the pending inputs' links alone; --json carries every unlinked one's.
43662
+ namesFor(session, detail, underWay.map((p) => p.phase_id), { agenda: !opts.json, ...opts.json ? {} : { linkableFor: pendingInputs(underWay) } })
43577
43663
  ]);
43578
43664
  const yours = [];
43579
43665
  const others = [];
@@ -43594,8 +43680,18 @@ async function caseNext(session, opts) {
43594
43680
  return [{ phase_id: p.phase_id, input, ...undecidedWords(input, folder, link, folders) }];
43595
43681
  }));
43596
43682
  if (opts.json) {
43597
- const undecidedJson = undecided.map((u) => ({ phase_id: u.phase_id, ...inputJson(u.input), agent: u.agent }));
43598
- console.log(JSON.stringify({ to_do: yours, waiting_on_others: others, undecided_inputs: undecidedJson, open_notes: notes }, null, 2));
43683
+ const undecidedJson = undecided.map((u) => ({ phase_id: u.phase_id, ...inputJson(u.input, names), agent: u.agent }));
43684
+ const linkableJson = underWay.flatMap((p) => (names.phaseInputs.get(p.phase_id) ?? []).flatMap((i) => {
43685
+ const linkable = names.linkable(i.id);
43686
+ return linkable === void 0 ? [] : [{ phase_id: p.phase_id, input_id: i.id, key: i.key, linkable }];
43687
+ }));
43688
+ console.log(JSON.stringify({
43689
+ to_do: yours,
43690
+ waiting_on_others: others,
43691
+ undecided_inputs: undecidedJson,
43692
+ linkable_official_versions: linkableJson,
43693
+ open_notes: notes
43694
+ }, null, 2));
43599
43695
  return;
43600
43696
  }
43601
43697
  const undecidedLine = (u) => ` ${folders.get(u.phase_id) ?? ""}: ${names.input(u.input.id)} ${u.text}`;
@@ -43748,20 +43844,35 @@ async function caseReceivedAdd(session, file, opts) {
43748
43844
  if (received.text_origin === "agent") console.log("Its text is marked as converted by an agent, for whoever reviews it.");
43749
43845
  }
43750
43846
  async function locateInput(session, inputName, phaseName) {
43751
- const phase = findPhase(await loadCase(session), phaseName);
43847
+ const detail = await loadCase(session);
43848
+ const phase = findPhase(detail, phaseName);
43752
43849
  const work = (await call2(session, () => session.api.getCasePhaseWork(session.connection, phase.phase_id))).data;
43753
43850
  const input = findInput(work, phase, inputName);
43754
- return { phase, input, label: `input ${one3(input.key)} of ${phase.folder}` };
43851
+ return { detail, phase, input, label: `input ${one3(input.key)} of ${phase.folder}` };
43755
43852
  }
43756
43853
  async function caseLink(session, inputName, opts) {
43757
43854
  const target = linkTarget(opts);
43758
- const { phase, input, label: label3 } = await locateInput(session, inputName, opts.phase);
43855
+ const { detail, phase, input, label: label3 } = await locateInput(session, inputName, opts.phase);
43759
43856
  const mismatch = linkMismatch(input, label3, target);
43760
43857
  if (mismatch) throw expected(mismatch);
43761
- const [kind, id] = "official_version_id" in target ? ["official version", target.official_version_id] : ["received document", target.received_id];
43858
+ let ref;
43859
+ if (target.kind === "source") {
43860
+ ref = target.ref;
43861
+ } else {
43862
+ const listed3 = await readLinkable(session, input.id);
43863
+ if (listed3 === null) throw expected("This server lists no official version an input may link: name the one to link by its id (--official-version <id>).");
43864
+ const folders = phaseFolders(detail);
43865
+ const named = { label: label3, key: input.key, folder: phase.folder };
43866
+ if (target.kind === "list") {
43867
+ for (const line of linkableLines(listed3, named, folders)) console.log(line);
43868
+ return;
43869
+ }
43870
+ ref = { official_version_id: chooseByOutput(listed3, target.code, named, folders).official_version_id };
43871
+ }
43872
+ const [kind, id] = "official_version_id" in ref ? ["official version", ref.official_version_id] : ["received document", ref.received_id];
43762
43873
  let linked;
43763
43874
  try {
43764
- linked = (await session.api.linkCaseInput(session.connection, input.id, target)).data;
43875
+ linked = (await session.api.linkCaseInput(session.connection, input.id, ref)).data;
43765
43876
  } catch (err) {
43766
43877
  throw linkFailure(err, session, { label: label3, key: input.key, folder: phase.folder, origin: input.origin, id });
43767
43878
  }
@@ -43804,8 +43915,8 @@ async function caseSkeleton(session, clone, opts) {
43804
43915
  }
43805
43916
  const mirror = mirrorFolder(clone.root);
43806
43917
  if (!mirror) throw undelivered();
43807
- const phaseFolders = detail.phases.map((p) => p.folder);
43808
- assertClonePaths(clone.root, clone.record, phaseFolders);
43918
+ const phaseFolders2 = detail.phases.map((p) => p.folder);
43919
+ assertClonePaths(clone.root, clone.record, phaseFolders2);
43809
43920
  const phase = findPhase(detail, opts.phase);
43810
43921
  const work = (await call2(session, () => session.api.getCasePhaseWork(session.connection, phase.phase_id))).data;
43811
43922
  if (!opts.confidential && holdsRight && !markedThroughout(work)) throw expected(SKELETON_CONFIDENTIAL_REQUIRED);
@@ -43896,7 +44007,7 @@ async function caseSkeleton(session, clone, opts) {
43896
44007
  if (!opts.confidential) console.log(`
43897
44008
  ${SKELETON_CONFIDENTIAL_NOTICE}`);
43898
44009
  }
43899
- var NOTE_PAGES_READ, NOTES_PAGE, AGENDA_PAGES_READ2, one3, loadCase, loadState, phaseLabel, statusWords, CaseNames, AWAITING, readsWork, PHASES_VIEW_NOTE, noteLine, inputJson, blockerKey, SKELETON_CONFIDENTIAL_REQUIRED, SKELETON_CONFIDENTIAL_NOTICE;
44010
+ var NOTE_PAGES_READ, NOTES_PAGE, AGENDA_PAGES_READ2, one3, loadCase, loadState, phaseFolders, phaseLabel, statusWords, CaseNames, AWAITING, pendingInputs, readsWork, PHASES_VIEW_NOTE, noteLine, inputJson, blockerKey, SKELETON_CONFIDENTIAL_REQUIRED, SKELETON_CONFIDENTIAL_NOTICE;
43900
44011
  var init_case_work = __esm({
43901
44012
  "src/cases/case-work.ts"() {
43902
44013
  "use strict";
@@ -43910,6 +44021,7 @@ var init_case_work = __esm({
43910
44021
  init_case_package();
43911
44022
  init_case_skeleton();
43912
44023
  init_case_inputs();
44024
+ init_api_client();
43913
44025
  init_case_input_sources();
43914
44026
  init_case_item_reader();
43915
44027
  init_case_file_paths();
@@ -43923,12 +44035,14 @@ var init_case_work = __esm({
43923
44035
  one3 = (value) => sanitizeTerminalText(value).replace(/\s*\n\s*/g, " ");
43924
44036
  loadCase = async (s) => (await call2(s, () => s.api.getCase(s.connection))).data;
43925
44037
  loadState = async (s) => (await call2(s, () => s.api.getCaseState(s.connection))).data;
44038
+ phaseFolders = (detail) => new Map(detail.phases.map((p) => [p.phase_id, p.folder]));
43926
44039
  phaseLabel = (p) => `${one3(p.folder)} (${one3(p.name)})`;
43927
44040
  statusWords = (status) => status.replaceAll("_", " ");
43928
44041
  CaseNames = class {
43929
44042
  constructor(session, detail) {
43930
44043
  this.session = session;
43931
44044
  this.phases = new Map(detail.phases.map((p) => [p.phase_id, p]));
44045
+ this.folderOf = phaseFolders(detail);
43932
44046
  this.tasks = new Map((detail.tasks ?? []).map((t) => [t.case_task_id, one3(t.name)]));
43933
44047
  }
43934
44048
  phases;
@@ -43936,23 +44050,35 @@ var init_case_work = __esm({
43936
44050
  outputs = /* @__PURE__ */ new Map();
43937
44051
  inputs = /* @__PURE__ */ new Map();
43938
44052
  groups = /* @__PURE__ */ new Map();
44053
+ /** The official versions each unlinked input of origin `previous_output` read may link (`./case-inputs.ts` `Linkable`). */
44054
+ linkableOf = /* @__PURE__ */ new Map();
44055
+ folderOf;
43939
44056
  /** Each phase read's inputs, in their order. */
43940
44057
  phaseInputs = /* @__PURE__ */ new Map();
43941
- /** Read one phase's outputs and inputs, and (unless `agenda` is false) its agenda groups, to name them. */
43942
- async readPhase(phaseId, agenda = true) {
44058
+ /**
44059
+ * Read one phase's outputs and inputs, and (unless `agenda` is false) its agenda groups, to name them; and what each
44060
+ * unlinked input of origin `previous_output` may link, of those `linkableFor` holds (all of them when it is undefined).
44061
+ */
44062
+ async readPhase(phaseId, agenda = true, linkableFor) {
43943
44063
  const s = this.session;
43944
44064
  const work = (await call2(s, () => s.api.getCasePhaseWork(s.connection, phaseId))).data;
43945
44065
  for (const o of work.outputs) this.outputs.set(o.id, `${one3(o.code)} (${one3(o.document_type)})`);
43946
44066
  const folder = this.phases.get(phaseId)?.folder ?? "";
43947
44067
  for (const i of work.inputs) this.inputs.set(i.id, { label: `${one3(i.key)} (${one3(i.name)})`, input: i, folder });
43948
44068
  this.phaseInputs.set(phaseId, work.inputs);
43949
- let cursor;
43950
- for (let page = 0; agenda && page < AGENDA_PAGES_READ2; page++) {
43951
- const { groups, next_cursor } = (await call2(s, () => s.api.getCaseAgenda(s.connection, phaseId, cursor))).data;
43952
- for (const g of groups) this.groups.set(g.agenda_group_id, `${one3(g.code)} (${one3(g.name)})`);
43953
- if (!next_cursor) break;
43954
- cursor = next_cursor;
43955
- }
44069
+ const unlinked = work.inputs.filter((i) => i.origin === "previous_output" && inputLinkState(i).state === "unlinked" && (linkableFor === void 0 || linkableFor.has(i.id)));
44070
+ const groups = async () => {
44071
+ let cursor;
44072
+ for (let page = 0; agenda && page < AGENDA_PAGES_READ2; page++) {
44073
+ const { groups: got, next_cursor } = (await call2(s, () => s.api.getCaseAgenda(s.connection, phaseId, cursor))).data;
44074
+ for (const g of got) this.groups.set(g.agenda_group_id, `${one3(g.code)} (${one3(g.name)})`);
44075
+ if (!next_cursor) break;
44076
+ cursor = next_cursor;
44077
+ }
44078
+ };
44079
+ await Promise.all([groups(), ...unlinked.map(async (i) => {
44080
+ this.linkableOf.set(i.id, await readLinkable(s, i.id));
44081
+ })]);
43956
44082
  }
43957
44083
  // Each name with its noun: `output memo (Technical memo)`, or `an output` for one not read.
43958
44084
  phase(id) {
@@ -43977,15 +44103,20 @@ var init_case_work = __esm({
43977
44103
  /** How an unlinked input is linked (`./case-inputs.ts` `linkHint`), after a colon; nothing for one not read. */
43978
44104
  inputHint(id) {
43979
44105
  const named = this.inputs.get(id);
43980
- return named ? `: ${linkHint(named.input.key, named.folder, named.input.origin)}` : "";
44106
+ return named ? `: ${linkHint(named.input.key, named.folder, named.input.origin, this.linkable(id), this.folderOf)}` : "";
44107
+ }
44108
+ /** Whether an unlinked input is the agent's to link (`./case-inputs.ts` `agentLinks`); not for one not read. */
44109
+ agentLinks(id) {
44110
+ const named = this.inputs.get(id);
44111
+ return named !== void 0 && agentLinks(named.input.origin, this.linkable(id));
43981
44112
  }
43982
- /** An input's origin, or undefined for one not read. */
43983
- inputOrigin(id) {
43984
- return this.inputs.get(id)?.input.origin;
44113
+ /** The official versions an unlinked input of origin `previous_output` may link, as read (`./case-inputs.ts` `Linkable`). */
44114
+ linkable(id) {
44115
+ return this.linkableOf.get(id);
43985
44116
  }
43986
44117
  /** Each phase's folder, by phase id. */
43987
44118
  folders() {
43988
- return new Map([...this.phases].map(([id, p]) => [id, p.folder]));
44119
+ return this.folderOf;
43989
44120
  }
43990
44121
  group(id) {
43991
44122
  return this.groups.has(id) ? `agenda group ${this.groups.get(id)}` : "an agenda group";
@@ -43997,10 +44128,14 @@ var init_case_work = __esm({
43997
44128
  approval: "approval",
43998
44129
  publication: "publication"
43999
44130
  };
44131
+ pendingInputs = (held) => new Set(held.flatMap((p) => p.blockers.flatMap((b) => b.reason === "input_pending" ? [b.input_id] : [])));
44000
44132
  readsWork = (detail) => detail.access.capabilities.includes("view_work");
44001
44133
  PHASES_VIEW_NOTE = "You see only the phases' status of this case: its work is not yours to read here.";
44002
44134
  noteLine = (n) => `${n.kind === "pending" ? "pending" : "next step"}: ${one3(n.text)} [${n.note_id}]`;
44003
- inputJson = (i) => ({ input_id: i.id, key: i.key, origin: i.origin, required: i.required, link: inputLinkState(i) });
44135
+ inputJson = (i, names) => {
44136
+ const linkable = names.linkable(i.id);
44137
+ return { input_id: i.id, key: i.key, origin: i.origin, required: i.required, link: inputLinkState(i), ...linkable !== void 0 ? { linkable } : {} };
44138
+ };
44004
44139
  blockerKey = (b) => {
44005
44140
  switch (b.reason) {
44006
44141
  case "output_pending":
@@ -44027,13 +44162,13 @@ function casesRequestsPerMinute() {
44027
44162
  const budget = getEndpointConfig("/api/cases/org/space/cases/code/files")?.userLimit;
44028
44163
  return budget ? Math.max(1, Math.floor(budget * 4 / 5)) : 48;
44029
44164
  }
44030
- function assertWritableCasePaths(paths, phaseFolders) {
44165
+ function assertWritableCasePaths(paths, phaseFolders2) {
44031
44166
  const problems2 = [];
44032
44167
  const spelled = /* @__PURE__ */ new Map();
44033
44168
  const keys = /* @__PURE__ */ new Set();
44034
44169
  const checked = [];
44035
44170
  for (const rel of paths) {
44036
- const check = checkCaseFilePath({ path: rel, type: "file" }, phaseFolders);
44171
+ const check = checkCaseFilePath({ path: rel, type: "file" }, phaseFolders2);
44037
44172
  if (!check.ok) {
44038
44173
  problems2.push(`${JSON.stringify(safe7(rel))}: a case path cannot be that (${check.reason})`);
44039
44174
  continue;
@@ -44073,7 +44208,7 @@ function linkRefusal2(rel) {
44073
44208
  `${safe7(rel)} is a symlink, or not a regular file or folder. The CLI never follows one in a clone: replace it with the file or folder itself, or move it out of the clone.`
44074
44209
  );
44075
44210
  }
44076
- function scanClone(root, phaseFolders, confidential = true) {
44211
+ function scanClone(root, phaseFolders2, confidential = true) {
44077
44212
  const out = /* @__PURE__ */ new Map();
44078
44213
  const walk = (abs, rel) => {
44079
44214
  for (const name of fs40.readdirSync(abs).sort()) {
@@ -44098,7 +44233,7 @@ function scanClone(root, phaseFolders, confidential = true) {
44098
44233
  };
44099
44234
  requireOwn(root);
44100
44235
  const top = new Set(fs40.readdirSync(root));
44101
- const areas = [.../* @__PURE__ */ new Set([...phaseFolders, "analysis", ...confidential ? ["conf"] : []])].filter((area) => top.has(area));
44236
+ const areas = [.../* @__PURE__ */ new Set([...phaseFolders2, "analysis", ...confidential ? ["conf"] : []])].filter((area) => top.has(area));
44102
44237
  if (top.has("instructions")) {
44103
44238
  if (!fs40.lstatSync(path52.join(root, "instructions")).isDirectory()) throw linkRefusal2("instructions");
44104
44239
  if (fs40.readdirSync(path52.join(root, "instructions")).includes("case")) areas.push("instructions/case");
@@ -44147,13 +44282,13 @@ function requireFiles(detail, confidential) {
44147
44282
  }
44148
44283
  }
44149
44284
  async function pullInto(calls, detail, record, opts) {
44150
- const phaseFolders = phaseFoldersOf(detail);
44285
+ const phaseFolders2 = phaseFoldersOf(detail);
44151
44286
  const files = await calls.files();
44152
- assertWritableCasePaths([...sidesOf(record, /* @__PURE__ */ new Map(), files, opts.confidential).listed.keys()], phaseFolders);
44287
+ assertWritableCasePaths([...sidesOf(record, /* @__PURE__ */ new Map(), files, opts.confidential).listed.keys()], phaseFolders2);
44153
44288
  const root = opts.root();
44154
- assertClonePaths(root, record, phaseFolders);
44289
+ assertClonePaths(root, record, phaseFolders2);
44155
44290
  mirrorFolder(root);
44156
- const local = scanClone(root, phaseFolders, opts.confidential);
44291
+ const local = scanClone(root, phaseFolders2, opts.confidential);
44157
44292
  const { synced: synced2, local: localIn, remote, listed: listed3, theirsListed } = sidesOf(record, local, files, opts.confidential);
44158
44293
  const plan = planPull({ synced: synced2, local: localIn, remote, overwrite: opts.overwrite });
44159
44294
  const outside = outsideRun(record, files, opts.confidential);
@@ -44329,8 +44464,8 @@ async function casePullMirror(opts) {
44329
44464
  });
44330
44465
  });
44331
44466
  }
44332
- function leftOutReason(rel, phaseFolders, detail) {
44333
- const check = checkCaseFilePath({ path: rel, type: "file" }, phaseFolders);
44467
+ function leftOutReason(rel, phaseFolders2, detail) {
44468
+ const check = checkCaseFilePath({ path: rel, type: "file" }, phaseFolders2);
44334
44469
  if (!check.ok) return `the case takes no such path (${check.reason})`;
44335
44470
  if (check.received) return "a received document, which is never replaced or removed: register a new one with `wayai cases received add`";
44336
44471
  if (check.level === "conduct" && detail.access.level !== "conduct") return "the case's own instructions, which need Conduct level";
@@ -44398,9 +44533,9 @@ async function casePush(opts) {
44398
44533
  if (!detail.access.capabilities.includes("upload_document")) {
44399
44534
  throw expected(`Your access to case ${safe7(detail.code)} does not write its files: that takes Edit level, on an open case.`);
44400
44535
  }
44401
- const phaseFolders = phaseFoldersOf(detail);
44402
- assertClonePaths(root, record, phaseFolders);
44403
- const scanned = scanClone(root, phaseFolders, opts.confidential);
44536
+ const phaseFolders2 = phaseFoldersOf(detail);
44537
+ assertClonePaths(root, record, phaseFolders2);
44538
+ const scanned = scanClone(root, phaseFolders2, opts.confidential);
44404
44539
  const listing = await calls.files();
44405
44540
  const outside = outsideRun(record, listing, opts.confidential);
44406
44541
  const theirs = [...scanned.keys()].filter((rel) => isTheirs(rel) && !outside(rel.slice(0, -THEIRS_SUFFIX.length)));
@@ -44418,7 +44553,7 @@ Nothing was pushed.`
44418
44553
  for (const rel of changedPaths) {
44419
44554
  if (outside(rel) || isTheirs(rel)) continue;
44420
44555
  const file = scanned.get(rel);
44421
- const reason3 = record.files[rel]?.sha === file?.content_sha256 ? null : leftOutReason(rel, phaseFolders, detail);
44556
+ const reason3 = record.files[rel]?.sha === file?.content_sha256 ? null : leftOutReason(rel, phaseFolders2, detail);
44422
44557
  if (reason3) {
44423
44558
  leftOut.push(`${safe7(rel)}: ${reason3}`);
44424
44559
  leftOutPaths.add(rel);
@@ -45006,11 +45141,12 @@ async function casesCommand(args2) {
45006
45141
  case "link": {
45007
45142
  if (operands.length !== 1) throw usageError4("link takes one <input>: its key, as `wayai cases explain --phase <folder>` names it.");
45008
45143
  if (values.phase === void 0) throw usageError4("link takes --phase <folder>.");
45009
- linkTarget({ officialVersion: values["official-version"], received: values.received });
45144
+ linkTarget({ officialVersion: values["official-version"], received: values.received, list: values.list });
45010
45145
  return caseLink(await openCaseSession(selector), operands[0], {
45011
45146
  phase: values.phase,
45012
45147
  officialVersion: values["official-version"],
45013
- received: values.received
45148
+ received: values.received,
45149
+ list: values.list
45014
45150
  });
45015
45151
  }
45016
45152
  case "cite": {
@@ -45248,7 +45384,8 @@ Usage:
45248
45384
  wayai cases received add <file> --text <markdown file> --phase <folder> --type <type>
45249
45385
  [--title <title>] [--confidential]
45250
45386
  wayai cases link <input> --phase <folder>
45251
- --official-version <official_version_id> | --received <received_id>
45387
+ --official-version <official_version_id | output code> | --received <received_id>
45388
+ | --list
45252
45389
  wayai cases cite <input> <start>[-<end>] --phase <folder>
45253
45390
 
45254
45391
  connect Ask to connect this machine to the case, wait while you approve it
@@ -45279,7 +45416,7 @@ pull Bring the clone up to date, keeping your local changes. A file
45279
45416
  Clone and every pull then rewrite the clone's read-only mirror,
45280
45417
  ${CASE_MIRROR_DIR}/: the case, its status, evidence, agenda and
45281
45418
  deliveries of the phases under way, their linked inputs'
45282
- registered texts (each checked against its registered hash),
45419
+ texts (each checked against the hash WayAI gives for it),
45283
45420
  what changed since the last pull, and the case's package
45284
45421
  (its instructions, templates, tools and sources, each checked
45285
45422
  against the published manifest, read-only; confidential
@@ -45349,10 +45486,13 @@ received add Register a document a party sent, in one phase, with its
45349
45486
  confidential, if the case lets you write one.
45350
45487
  link Link an input of one phase (its key, as explain --phase names it):
45351
45488
  one of origin previous_output to an earlier phase's current
45352
- official version (--official-version), one of origin received to
45353
- a received document of the case (--received; its id is in its
45354
- files' names under a phase's received/). A collection input is
45355
- linked in the web app.
45489
+ official version (--official-version: its id, or the code of its
45490
+ output, as memo), one of origin received to a received document
45491
+ of the case (--received; its id is in its files' names under a
45492
+ phase's received/). --list lists the official versions an input
45493
+ of origin previous_output may link, each with the command that
45494
+ links it, and links nothing. A collection input is linked in the
45495
+ web app.
45356
45496
  cite Cite a passage of what an input links now, by its lines (as
45357
45497
  12-18, numbered as the mirror's inputs/ texts number them): the
45358
45498
  case hashes them. Any origin.
@@ -45423,7 +45563,8 @@ need it.
45423
45563
  "mark-confidential": { type: "boolean" },
45424
45564
  "mirror-only": { type: "boolean" },
45425
45565
  "official-version": { type: "string" },
45426
- received: { type: "string" }
45566
+ received: { type: "string" },
45567
+ list: { type: "boolean" }
45427
45568
  };
45428
45569
  SELECT = ["case", "org", "space"];
45429
45570
  ADMITS = {
@@ -45439,7 +45580,7 @@ need it.
45439
45580
  note: [...SELECT, "kind", "phase", "task", "origin"],
45440
45581
  "note done": SELECT,
45441
45582
  "received add": [...SELECT, "text", "phase", "type", "title", "confidential"],
45442
- link: [...SELECT, "phase", "official-version", "received"],
45583
+ link: [...SELECT, "phase", "official-version", "received", "list"],
45443
45584
  cite: [...SELECT, "phase"],
45444
45585
  clone: [...SELECT, "dir", "confidential"],
45445
45586
  // A clone names its case: pull and push take the clone (--dir), never a case.