@wayai/cli 0.3.341 → 0.3.342
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 +1658 -1399
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -447,11 +447,11 @@ function captureException2(error, context) {
|
|
|
447
447
|
Sentry.captureException(error);
|
|
448
448
|
});
|
|
449
449
|
}
|
|
450
|
-
function addApiBreadcrumb(method,
|
|
450
|
+
function addApiBreadcrumb(method, path54) {
|
|
451
451
|
if (!initialized) return;
|
|
452
452
|
Sentry.addBreadcrumb({
|
|
453
453
|
category: "http",
|
|
454
|
-
message: `${method} ${
|
|
454
|
+
message: `${method} ${path54}`,
|
|
455
455
|
level: "info"
|
|
456
456
|
});
|
|
457
457
|
}
|
|
@@ -1121,8 +1121,8 @@ var init_parseUtil = __esm({
|
|
|
1121
1121
|
init_errors2();
|
|
1122
1122
|
init_en();
|
|
1123
1123
|
makeIssue = (params) => {
|
|
1124
|
-
const { data, path:
|
|
1125
|
-
const fullPath = [...
|
|
1124
|
+
const { data, path: path54, errorMaps, issueData } = params;
|
|
1125
|
+
const fullPath = [...path54, ...issueData.path || []];
|
|
1126
1126
|
const fullIssue = {
|
|
1127
1127
|
...issueData,
|
|
1128
1128
|
path: fullPath
|
|
@@ -1433,11 +1433,11 @@ var init_types = __esm({
|
|
|
1433
1433
|
init_parseUtil();
|
|
1434
1434
|
init_util();
|
|
1435
1435
|
ParseInputLazyPath = class {
|
|
1436
|
-
constructor(parent, value,
|
|
1436
|
+
constructor(parent, value, path54, key) {
|
|
1437
1437
|
this._cachedPath = [];
|
|
1438
1438
|
this.parent = parent;
|
|
1439
1439
|
this.data = value;
|
|
1440
|
-
this._path =
|
|
1440
|
+
this._path = path54;
|
|
1441
1441
|
this._key = key;
|
|
1442
1442
|
}
|
|
1443
1443
|
get path() {
|
|
@@ -6537,8 +6537,8 @@ var init_chunk_5FO3GNKP = __esm({
|
|
|
6537
6537
|
});
|
|
6538
6538
|
|
|
6539
6539
|
// ../../packages/core/dist/chunk-7LULTR3U.js
|
|
6540
|
-
function matchPath(pattern,
|
|
6541
|
-
const pathSegments2 =
|
|
6540
|
+
function matchPath(pattern, path54) {
|
|
6541
|
+
const pathSegments2 = path54.replace(/\/$/, "").split("/");
|
|
6542
6542
|
const isPrefix = pattern.endsWith("/*");
|
|
6543
6543
|
const patternSegments = (isPrefix ? pattern.slice(0, -2) : pattern).split("/");
|
|
6544
6544
|
if (isPrefix ? pathSegments2.length < patternSegments.length : pathSegments2.length !== patternSegments.length) {
|
|
@@ -6546,19 +6546,19 @@ function matchPath(pattern, path53) {
|
|
|
6546
6546
|
}
|
|
6547
6547
|
return patternSegments.every((segment2, i) => segment2 === "*" ? pathSegments2[i] !== "" : segment2 === pathSegments2[i]);
|
|
6548
6548
|
}
|
|
6549
|
-
function getEndpointConfig(
|
|
6549
|
+
function getEndpointConfig(path54) {
|
|
6550
6550
|
for (const excluded of EXCLUDED_PATHS) {
|
|
6551
|
-
if (matchPath(excluded,
|
|
6551
|
+
if (matchPath(excluded, path54)) {
|
|
6552
6552
|
return null;
|
|
6553
6553
|
}
|
|
6554
6554
|
}
|
|
6555
|
-
const normalizedPath =
|
|
6555
|
+
const normalizedPath = path54.replace(/\/$/, "");
|
|
6556
6556
|
if (!normalizedPath.endsWith("/*") && Object.prototype.hasOwnProperty.call(ENDPOINT_CONFIGS, normalizedPath)) {
|
|
6557
6557
|
return ENDPOINT_CONFIGS[normalizedPath];
|
|
6558
6558
|
}
|
|
6559
6559
|
const sortedPatterns = Object.keys(ENDPOINT_CONFIGS).sort((a, b) => b.length - a.length);
|
|
6560
6560
|
for (const pattern of sortedPatterns) {
|
|
6561
|
-
if (matchPath(pattern,
|
|
6561
|
+
if (matchPath(pattern, path54)) {
|
|
6562
6562
|
return ENDPOINT_CONFIGS[pattern];
|
|
6563
6563
|
}
|
|
6564
6564
|
}
|
|
@@ -7500,12 +7500,12 @@ function typeMatches(typeField, allowed) {
|
|
|
7500
7500
|
if (Array.isArray(typeField)) return typeField.every((t) => typeof t === "string" && allowed.has(t));
|
|
7501
7501
|
return false;
|
|
7502
7502
|
}
|
|
7503
|
-
function validateSchema(schema,
|
|
7503
|
+
function validateSchema(schema, path54, errors, opts = {}) {
|
|
7504
7504
|
if (typeof schema === "boolean") return;
|
|
7505
7505
|
const depth = opts.depth ?? 0;
|
|
7506
7506
|
if (depth > MAX_SCHEMA_DEPTH) {
|
|
7507
7507
|
errors.push({
|
|
7508
|
-
path:
|
|
7508
|
+
path: path54 || "<root>",
|
|
7509
7509
|
message: `schema nesting exceeds ${MAX_SCHEMA_DEPTH} levels`,
|
|
7510
7510
|
suggestion: "Flatten the schema; LLM providers reject deeply nested tool input_schemas."
|
|
7511
7511
|
});
|
|
@@ -7513,7 +7513,7 @@ function validateSchema(schema, path53, errors, opts = {}) {
|
|
|
7513
7513
|
}
|
|
7514
7514
|
if (!isRecord(schema)) {
|
|
7515
7515
|
errors.push({
|
|
7516
|
-
path:
|
|
7516
|
+
path: path54,
|
|
7517
7517
|
message: `expected object, got ${schema === null ? "null" : typeof schema}`
|
|
7518
7518
|
});
|
|
7519
7519
|
return;
|
|
@@ -7521,14 +7521,14 @@ function validateSchema(schema, path53, errors, opts = {}) {
|
|
|
7521
7521
|
if (opts.isRoot) {
|
|
7522
7522
|
if ("type" in schema && schema.type !== "object") {
|
|
7523
7523
|
errors.push({
|
|
7524
|
-
path:
|
|
7524
|
+
path: path54 ? `${path54}.type` : "type",
|
|
7525
7525
|
message: `root type must be 'object', got ${JSON.stringify(schema.type)}`,
|
|
7526
7526
|
suggestion: "Tool parameters at the root must be an object: `{ type: 'object', properties: { ... } }`."
|
|
7527
7527
|
});
|
|
7528
7528
|
}
|
|
7529
7529
|
} else if ("type" in schema && !typeMatches(schema.type, ALLOWED_TYPES)) {
|
|
7530
7530
|
errors.push({
|
|
7531
|
-
path: `${
|
|
7531
|
+
path: `${path54}.type`,
|
|
7532
7532
|
message: `type must be one of ${[...ALLOWED_TYPES].join("/")} or an array of those, got ${JSON.stringify(schema.type)}`
|
|
7533
7533
|
});
|
|
7534
7534
|
}
|
|
@@ -7538,25 +7538,25 @@ function validateSchema(schema, path53, errors, opts = {}) {
|
|
|
7538
7538
|
const isPlaceholder = PLACEHOLDER_TOKENS.includes(e);
|
|
7539
7539
|
const isOutcomePlaceholder = e === "[KANBAN_OUTCOME_VALUES]";
|
|
7540
7540
|
errors.push({
|
|
7541
|
-
path: `${
|
|
7541
|
+
path: `${path54}.enum`,
|
|
7542
7542
|
message: `enum must be a non-empty array of primitives, got string ${JSON.stringify(e)}`,
|
|
7543
7543
|
suggestion: isOutcomePlaceholder ? "Declare `outcomes` on the hub's terminal kanban status so the platform can render the placeholder into a valid array; with none configured the platform drops the parameter instead." : isPlaceholder ? "Set `operation: 'update_kanban_status'` on the tool and ensure at least one hub.kanban_status has `allowsAgentUpdate: true` so the platform can render the placeholder into a valid array." : 'Wrap the value in an array: `enum: ["value"]`.'
|
|
7544
7544
|
});
|
|
7545
7545
|
} else if (!Array.isArray(e)) {
|
|
7546
7546
|
errors.push({
|
|
7547
|
-
path: `${
|
|
7547
|
+
path: `${path54}.enum`,
|
|
7548
7548
|
message: `enum must be a non-empty array of primitives, got ${typeof e}`
|
|
7549
7549
|
});
|
|
7550
7550
|
} else if (e.length === 0) {
|
|
7551
7551
|
errors.push({
|
|
7552
|
-
path: `${
|
|
7552
|
+
path: `${path54}.enum`,
|
|
7553
7553
|
message: "enum must not be empty"
|
|
7554
7554
|
});
|
|
7555
7555
|
} else {
|
|
7556
7556
|
for (let i = 0; i < e.length; i++) {
|
|
7557
7557
|
if (!isPrimitive(e[i])) {
|
|
7558
7558
|
errors.push({
|
|
7559
|
-
path: `${
|
|
7559
|
+
path: `${path54}.enum[${i}]`,
|
|
7560
7560
|
message: `enum entry must be a primitive (string/number/boolean/null), got ${typeof e[i]}`
|
|
7561
7561
|
});
|
|
7562
7562
|
}
|
|
@@ -7566,7 +7566,7 @@ function validateSchema(schema, path53, errors, opts = {}) {
|
|
|
7566
7566
|
for (const key of ["exclusiveMinimum", "exclusiveMaximum"]) {
|
|
7567
7567
|
if (key in schema && typeof schema[key] === "boolean") {
|
|
7568
7568
|
errors.push({
|
|
7569
|
-
path: `${
|
|
7569
|
+
path: `${path54}.${key}`,
|
|
7570
7570
|
message: `${key} as boolean is draft-04 syntax; draft 2020-12 requires a numeric value`,
|
|
7571
7571
|
suggestion: `Replace with the numeric bound, e.g. \`${key}: 0\`.`
|
|
7572
7572
|
});
|
|
@@ -7575,45 +7575,45 @@ function validateSchema(schema, path53, errors, opts = {}) {
|
|
|
7575
7575
|
if ("properties" in schema) {
|
|
7576
7576
|
if (!isRecord(schema.properties)) {
|
|
7577
7577
|
errors.push({
|
|
7578
|
-
path: `${
|
|
7578
|
+
path: `${path54}.properties`,
|
|
7579
7579
|
message: `properties must be an object, got ${Array.isArray(schema.properties) ? "array" : typeof schema.properties}`
|
|
7580
7580
|
});
|
|
7581
7581
|
} else {
|
|
7582
7582
|
for (const [propName, propSchema] of Object.entries(schema.properties)) {
|
|
7583
|
-
validateSchema(propSchema, `${
|
|
7583
|
+
validateSchema(propSchema, `${path54}.properties.${propName}`, errors, { depth: depth + 1 });
|
|
7584
7584
|
}
|
|
7585
7585
|
}
|
|
7586
7586
|
}
|
|
7587
7587
|
if (schemaTypeIncludes(schema, "array") && "items" in schema) {
|
|
7588
7588
|
if (Array.isArray(schema.items)) {
|
|
7589
|
-
schema.items.forEach((sub, i) => validateSchema(sub, `${
|
|
7589
|
+
schema.items.forEach((sub, i) => validateSchema(sub, `${path54}.items[${i}]`, errors, { depth: depth + 1 }));
|
|
7590
7590
|
} else {
|
|
7591
|
-
validateSchema(schema.items, `${
|
|
7591
|
+
validateSchema(schema.items, `${path54}.items`, errors, { depth: depth + 1 });
|
|
7592
7592
|
}
|
|
7593
7593
|
}
|
|
7594
7594
|
for (const key of SUBSCHEMA_OBJECT_KEYWORDS) {
|
|
7595
7595
|
if (key in schema && isRecord(schema[key])) {
|
|
7596
|
-
validateSchema(schema[key], `${
|
|
7596
|
+
validateSchema(schema[key], `${path54}.${key}`, errors, { depth: depth + 1 });
|
|
7597
7597
|
}
|
|
7598
7598
|
}
|
|
7599
7599
|
for (const key of SUBSCHEMA_LIST_KEYWORDS) {
|
|
7600
7600
|
const list2 = schema[key];
|
|
7601
7601
|
if (Array.isArray(list2)) {
|
|
7602
|
-
list2.forEach((sub, i) => validateSchema(sub, `${
|
|
7602
|
+
list2.forEach((sub, i) => validateSchema(sub, `${path54}.${key}[${i}]`, errors, { depth: depth + 1 }));
|
|
7603
7603
|
}
|
|
7604
7604
|
}
|
|
7605
7605
|
for (const key of SUBSCHEMA_MAP_KEYWORDS) {
|
|
7606
7606
|
const map = schema[key];
|
|
7607
7607
|
if (isRecord(map)) {
|
|
7608
7608
|
for (const [name, sub] of Object.entries(map)) {
|
|
7609
|
-
validateSchema(sub, `${
|
|
7609
|
+
validateSchema(sub, `${path54}.${key}.${name}`, errors, { depth: depth + 1 });
|
|
7610
7610
|
}
|
|
7611
7611
|
}
|
|
7612
7612
|
}
|
|
7613
7613
|
const reportedPaths = new Set(errors.map((e) => e.path));
|
|
7614
7614
|
for (const [k, v] of Object.entries(schema)) {
|
|
7615
7615
|
if (typeof v !== "string") continue;
|
|
7616
|
-
const fieldPath = `${
|
|
7616
|
+
const fieldPath = `${path54}.${k}`;
|
|
7617
7617
|
if (reportedPaths.has(fieldPath)) continue;
|
|
7618
7618
|
for (const token of PLACEHOLDER_TOKENS) {
|
|
7619
7619
|
if (v === token) {
|
|
@@ -8508,16 +8508,16 @@ function parseCommunityLessonVideoUrl(url) {
|
|
|
8508
8508
|
const parts = /^https?:\/\/([^/?#]+)([^?#]*)(?:\?([^#]*))?(?:#.*)?$/i.exec(url.trim());
|
|
8509
8509
|
if (!parts) return null;
|
|
8510
8510
|
const host = parts[1].toLowerCase();
|
|
8511
|
-
const
|
|
8511
|
+
const path54 = parts[2] ?? "";
|
|
8512
8512
|
const query = parts[3] ?? "";
|
|
8513
8513
|
let id;
|
|
8514
8514
|
if (host === YOUTU_BE) {
|
|
8515
|
-
id = /^\/([A-Za-z0-9_-]{11})\/?$/.exec(
|
|
8515
|
+
id = /^\/([A-Za-z0-9_-]{11})\/?$/.exec(path54)?.[1];
|
|
8516
8516
|
} else if (YOUTUBE_HOSTS.has(host)) {
|
|
8517
|
-
if (
|
|
8517
|
+
if (path54 === "/watch" || path54 === "/watch/") {
|
|
8518
8518
|
id = query.split("&").find((param) => param.startsWith("v="))?.slice(2);
|
|
8519
8519
|
} else {
|
|
8520
|
-
id = YOUTUBE_ID_PATH.exec(
|
|
8520
|
+
id = YOUTUBE_ID_PATH.exec(path54)?.[1];
|
|
8521
8521
|
}
|
|
8522
8522
|
}
|
|
8523
8523
|
return id !== void 0 && YOUTUBE_ID.test(id) ? { provider: "youtube", id } : null;
|
|
@@ -11664,9 +11664,9 @@ function monitorRuleActions(monitorConfig) {
|
|
|
11664
11664
|
if (!monitorConfig || typeof monitorConfig !== "object") return [];
|
|
11665
11665
|
const config = monitorConfig;
|
|
11666
11666
|
const found = [];
|
|
11667
|
-
const visit = (action,
|
|
11667
|
+
const visit = (action, path54) => {
|
|
11668
11668
|
if (!action || typeof action !== "object" || Array.isArray(action)) return;
|
|
11669
|
-
found.push({ action, path:
|
|
11669
|
+
found.push({ action, path: path54 });
|
|
11670
11670
|
};
|
|
11671
11671
|
if (Array.isArray(config.rules)) {
|
|
11672
11672
|
config.rules.forEach((rule, index) => {
|
|
@@ -11698,25 +11698,25 @@ function collectMonitorRuleIssues(monitorConfig) {
|
|
|
11698
11698
|
const trigger = resolveMonitorTrigger(monitorConfig);
|
|
11699
11699
|
const kinds = monitorRuleActionKinds(trigger);
|
|
11700
11700
|
const issues = [...callUtteranceRuleIssues(monitorConfig), ...automationGateIssues(monitorConfig)];
|
|
11701
|
-
for (const { action, path:
|
|
11702
|
-
if (trigger === "call_utterance" &&
|
|
11701
|
+
for (const { action, path: path54 } of monitorRuleActions(monitorConfig)) {
|
|
11702
|
+
if (trigger === "call_utterance" && path54[0] === "fallback") continue;
|
|
11703
11703
|
const kind = action.kind;
|
|
11704
11704
|
if (typeof kind === "string" && !kinds.includes(kind)) {
|
|
11705
|
-
issues.push({ path: [...
|
|
11705
|
+
issues.push({ path: [...path54, "kind"], message: monitorActionKindMessage(kind, trigger) });
|
|
11706
11706
|
}
|
|
11707
11707
|
const toolName = action.tool_name;
|
|
11708
11708
|
if (kind === "call_tool" && typeof toolName === "string" && isRefusedNativeToolName(toolName, trigger)) {
|
|
11709
|
-
issues.push({ path: [...
|
|
11709
|
+
issues.push({ path: [...path54, "tool_name"], message: monitorRuleToolNotAllowedMessage(toolName, trigger) });
|
|
11710
11710
|
continue;
|
|
11711
11711
|
}
|
|
11712
11712
|
if (kind === "call_tool" && toolName === INSERT_NOTE_TOOL_NAME) {
|
|
11713
|
-
issues.push(...insertNoteArgumentIssues(action,
|
|
11713
|
+
issues.push(...insertNoteArgumentIssues(action, path54));
|
|
11714
11714
|
}
|
|
11715
11715
|
if (kind === "call_tool" && toolName === RUN_MONITOR_TOOL_NAME) {
|
|
11716
11716
|
const callee = readRunMonitorCallee(action);
|
|
11717
11717
|
if (!callee.ok) {
|
|
11718
11718
|
issues.push({
|
|
11719
|
-
path: [...
|
|
11719
|
+
path: [...path54, "args", "monitor_name"],
|
|
11720
11720
|
message: runMonitorCalleeMessage(callee.reason)
|
|
11721
11721
|
});
|
|
11722
11722
|
}
|
|
@@ -11776,11 +11776,11 @@ function insertNoteTemplateMessage(reason3) {
|
|
|
11776
11776
|
return `insert_note's template is longer than the ${MONITOR_NOTE_TEMPLATE_MAX}-character limit.`;
|
|
11777
11777
|
}
|
|
11778
11778
|
}
|
|
11779
|
-
function insertNoteArgumentIssues(action,
|
|
11779
|
+
function insertNoteArgumentIssues(action, path54) {
|
|
11780
11780
|
const result = readInsertNoteTemplate(action);
|
|
11781
11781
|
if (result.ok) return [];
|
|
11782
11782
|
return [{
|
|
11783
|
-
path: [...
|
|
11783
|
+
path: [...path54, "args", "template"],
|
|
11784
11784
|
message: insertNoteTemplateMessage(result.reason)
|
|
11785
11785
|
}];
|
|
11786
11786
|
}
|
|
@@ -13334,8 +13334,8 @@ function evalInitialStateError(input) {
|
|
|
13334
13334
|
const parsed = evalInitialStateEntry.safeParse(entries[i]);
|
|
13335
13335
|
if (!parsed.success) {
|
|
13336
13336
|
const issue = parsed.error.issues[0];
|
|
13337
|
-
const
|
|
13338
|
-
return `initial_state[${i}].${
|
|
13337
|
+
const path54 = issue?.path.join(".") || "?";
|
|
13338
|
+
return `initial_state[${i}].${path54} is invalid: ${issue?.message ?? "malformed"}`;
|
|
13339
13339
|
}
|
|
13340
13340
|
if (seenSlugs.has(parsed.data.slug)) {
|
|
13341
13341
|
return `initial_state[${i}].slug "${parsed.data.slug}" is declared more than once`;
|
|
@@ -13810,12 +13810,12 @@ function validateFollowupLinks(followups, label3, ctx) {
|
|
|
13810
13810
|
const linkTargets = /* @__PURE__ */ new Set();
|
|
13811
13811
|
followups.forEach((followup, i) => {
|
|
13812
13812
|
const ref = followup?.after_followup_id;
|
|
13813
|
-
const
|
|
13813
|
+
const path54 = ["followups", i, "after_followup_id"];
|
|
13814
13814
|
if (followup?.type !== "inactivity_after_before_event") {
|
|
13815
13815
|
if (ref !== void 0) {
|
|
13816
13816
|
ctx.addIssue({
|
|
13817
13817
|
code: external_exports.ZodIssueCode.custom,
|
|
13818
|
-
path:
|
|
13818
|
+
path: path54,
|
|
13819
13819
|
message: `kanban status ${label3}: after_followup_id is only valid on inactivity_after_before_event followups (this one is ${followup?.type})`
|
|
13820
13820
|
});
|
|
13821
13821
|
}
|
|
@@ -13824,7 +13824,7 @@ function validateFollowupLinks(followups, label3, ctx) {
|
|
|
13824
13824
|
if (ref === void 0) {
|
|
13825
13825
|
ctx.addIssue({
|
|
13826
13826
|
code: external_exports.ZodIssueCode.custom,
|
|
13827
|
-
path:
|
|
13827
|
+
path: path54,
|
|
13828
13828
|
message: `kanban status ${label3}: inactivity_after_before_event requires after_followup_id naming the id of a before_event followup in the same status`
|
|
13829
13829
|
});
|
|
13830
13830
|
return;
|
|
@@ -13834,7 +13834,7 @@ function validateFollowupLinks(followups, label3, ctx) {
|
|
|
13834
13834
|
if (matches.length > 1) {
|
|
13835
13835
|
ctx.addIssue({
|
|
13836
13836
|
code: external_exports.ZodIssueCode.custom,
|
|
13837
|
-
path:
|
|
13837
|
+
path: path54,
|
|
13838
13838
|
message: `kanban status ${label3}: after_followup_id "${ref}" matches ${matches.length} followups \u2014 a link must name exactly one`
|
|
13839
13839
|
});
|
|
13840
13840
|
return;
|
|
@@ -13846,7 +13846,7 @@ function validateFollowupLinks(followups, label3, ctx) {
|
|
|
13846
13846
|
);
|
|
13847
13847
|
ctx.addIssue({
|
|
13848
13848
|
code: external_exports.ZodIssueCode.custom,
|
|
13849
|
-
path:
|
|
13849
|
+
path: path54,
|
|
13850
13850
|
message: hasIdlessBeforeEvent ? `kanban status ${label3}: after_followup_id "${ref}" matches no followup \u2014 a link target must declare an explicit id, and this status has before_event followups without one` : `kanban status ${label3}: after_followup_id "${ref}" matches no followup in this status`
|
|
13851
13851
|
});
|
|
13852
13852
|
return;
|
|
@@ -13854,7 +13854,7 @@ function validateFollowupLinks(followups, label3, ctx) {
|
|
|
13854
13854
|
if (target.type !== "before_event") {
|
|
13855
13855
|
ctx.addIssue({
|
|
13856
13856
|
code: external_exports.ZodIssueCode.custom,
|
|
13857
|
-
path:
|
|
13857
|
+
path: path54,
|
|
13858
13858
|
message: `kanban status ${label3}: after_followup_id "${ref}" points at a ${target.type} followup \u2014 only before_event followups can anchor a chain`
|
|
13859
13859
|
});
|
|
13860
13860
|
}
|
|
@@ -14698,10 +14698,10 @@ function refineHubAsCodePersons(config, ctx) {
|
|
|
14698
14698
|
function refineHubAsCodeEvalAttachments(config, ctx) {
|
|
14699
14699
|
const cfg = config;
|
|
14700
14700
|
const referencedHashes = /* @__PURE__ */ new Set();
|
|
14701
|
-
const addTurnIssue = (
|
|
14701
|
+
const addTurnIssue = (path54, turn, name) => {
|
|
14702
14702
|
const error = evalTurnAttachmentsError(turn);
|
|
14703
14703
|
if (error) {
|
|
14704
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path:
|
|
14704
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: path54, message: `${name}: ${error}` });
|
|
14705
14705
|
return;
|
|
14706
14706
|
}
|
|
14707
14707
|
for (const hash2 of collectTurnAttachmentHashes(turn)) referencedHashes.add(hash2);
|
|
@@ -14802,17 +14802,17 @@ function refineHubAsCodeCallOpenings(config, ctx) {
|
|
|
14802
14802
|
const agent = entry;
|
|
14803
14803
|
const openings = agent?.call_openings;
|
|
14804
14804
|
if (openings === void 0 || openings === null) return;
|
|
14805
|
-
const
|
|
14805
|
+
const path54 = ["agents", a, "call_openings"];
|
|
14806
14806
|
const name = `agent "${typeof agent?.name === "string" ? agent.name : "<unnamed>"}"`;
|
|
14807
14807
|
if (typeof openings !== "object" || Array.isArray(openings)) {
|
|
14808
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path:
|
|
14808
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: path54, message: `${name}: call_openings must map a language to an opening` });
|
|
14809
14809
|
return;
|
|
14810
14810
|
}
|
|
14811
14811
|
if (agent?.role !== "pilot_voice" && Object.keys(openings).length > 0) {
|
|
14812
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path:
|
|
14812
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: path54, message: `${name}: only a pilot_voice agent has call_openings` });
|
|
14813
14813
|
}
|
|
14814
14814
|
for (const [language, raw] of Object.entries(openings)) {
|
|
14815
|
-
const at = [...
|
|
14815
|
+
const at = [...path54, language];
|
|
14816
14816
|
if (!callOpeningLanguage.safeParse(language).success) {
|
|
14817
14817
|
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: at, message: `${name}: call_openings language must be one of ${CALL_OPENING_LANGUAGES.join(", ")}` });
|
|
14818
14818
|
continue;
|
|
@@ -14948,11 +14948,11 @@ function refineHubAsCodeDelegation(config, ctx) {
|
|
|
14948
14948
|
}
|
|
14949
14949
|
}
|
|
14950
14950
|
if (del.context_boundary === void 0) return;
|
|
14951
|
-
const
|
|
14951
|
+
const path54 = ["agents", agentIndex, "tools", "delegation", delIndex, "context_boundary"];
|
|
14952
14952
|
if (del.type !== "hub") {
|
|
14953
14953
|
ctx.addIssue({
|
|
14954
14954
|
code: external_exports.ZodIssueCode.custom,
|
|
14955
|
-
path:
|
|
14955
|
+
path: path54,
|
|
14956
14956
|
message: `context_boundary applies only to \`type: hub\` delegations (got type "${got(del.type)}")`
|
|
14957
14957
|
});
|
|
14958
14958
|
return;
|
|
@@ -14960,18 +14960,18 @@ function refineHubAsCodeDelegation(config, ctx) {
|
|
|
14960
14960
|
if (!CONTEXT_BOUNDARIES.includes(del.context_boundary)) {
|
|
14961
14961
|
ctx.addIssue({
|
|
14962
14962
|
code: external_exports.ZodIssueCode.custom,
|
|
14963
|
-
path:
|
|
14963
|
+
path: path54,
|
|
14964
14964
|
message: `context_boundary must be one of: ${CONTEXT_BOUNDARIES.join(", ")}`
|
|
14965
14965
|
});
|
|
14966
14966
|
}
|
|
14967
14967
|
});
|
|
14968
14968
|
});
|
|
14969
14969
|
}
|
|
14970
|
-
function refuseNonBooleanFlag(ctx, subject, entry, key,
|
|
14970
|
+
function refuseNonBooleanFlag(ctx, subject, entry, key, path54) {
|
|
14971
14971
|
const value = entry[key];
|
|
14972
14972
|
if (value === void 0 || typeof value === "boolean") return;
|
|
14973
14973
|
const shown3 = value === null || typeof value !== "object" ? JSON.stringify(value).slice(0, 40) : Array.isArray(value) ? "a list" : "an object";
|
|
14974
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: [...
|
|
14974
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: [...path54, key], message: `${subject}: ${key} must be true or false, got ${shown3}` });
|
|
14975
14975
|
}
|
|
14976
14976
|
function refineHubAsCodeFlags(config, ctx) {
|
|
14977
14977
|
const { agents, connections, evals, journeys, teams } = config;
|
|
@@ -15162,11 +15162,11 @@ function pathPastDepth(root, levels) {
|
|
|
15162
15162
|
function refusedNesting(value, at, ctx) {
|
|
15163
15163
|
const past = pathPastDepth(value, MAX_HUB_AS_CODE_DEPTH - at.length);
|
|
15164
15164
|
if (!past) return false;
|
|
15165
|
-
const
|
|
15165
|
+
const path54 = [...at, ...past].slice(0, NAMED_DEPTH_SEGMENTS).map((key) => typeof key === "string" ? key.slice(0, NAMED_DEPTH_KEY_CHARS) : key);
|
|
15166
15166
|
ctx.addIssue({
|
|
15167
15167
|
code: external_exports.ZodIssueCode.custom,
|
|
15168
|
-
path:
|
|
15169
|
-
message: `${fieldName(
|
|
15168
|
+
path: path54,
|
|
15169
|
+
message: `${fieldName(path54)}\u2026 nests deeper than ${MAX_HUB_AS_CODE_DEPTH} levels of arrays and objects`,
|
|
15170
15170
|
fatal: true
|
|
15171
15171
|
});
|
|
15172
15172
|
return true;
|
|
@@ -15183,15 +15183,15 @@ function refusedStringConfigNesting(config, ctx) {
|
|
|
15183
15183
|
}
|
|
15184
15184
|
function refusedUnreadableSection(config, ctx) {
|
|
15185
15185
|
if (!isPlainObject(config)) return false;
|
|
15186
|
-
const refused = (
|
|
15187
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path:
|
|
15186
|
+
const refused = (path54, must) => {
|
|
15187
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, path: path54, message: `${fieldName(path54)} must ${must}`, fatal: true });
|
|
15188
15188
|
return true;
|
|
15189
15189
|
};
|
|
15190
|
-
const badList = (value,
|
|
15190
|
+
const badList = (value, path54, reads = {}) => {
|
|
15191
15191
|
if (value === void 0 || value === null && reads.nullSection !== false) return false;
|
|
15192
|
-
if (!Array.isArray(value)) return refused(
|
|
15192
|
+
if (!Array.isArray(value)) return refused(path54, "be an array");
|
|
15193
15193
|
const nullAt = reads.nullEntries ? -1 : value.indexOf(null);
|
|
15194
|
-
return nullAt !== -1 && refused([...
|
|
15194
|
+
return nullAt !== -1 && refused([...path54, nullAt], "not be null");
|
|
15195
15195
|
};
|
|
15196
15196
|
const entries = (section) => Array.isArray(section) ? section : [];
|
|
15197
15197
|
return ["connections", "teams", "evals", "journeys", "agents", "eval_attachment_files", "call_opening_files"].some((section) => badList(config[section], [section])) || isPlainObject(config.hub) && badList(config.hub.tags, ["hub", "tags"], { nullEntries: true }) || [["evals", "history"], ["journeys", "transcript"]].some(([section, turns]) => entries(config[section]).some((entry, index) => isPlainObject(entry) && badList(entry[turns], [section, index, turns], { nullEntries: true }))) || entries(config.agents).some((agent, index) => {
|
|
@@ -15367,7 +15367,7 @@ var init_chunk_NQ23GOXL = __esm({
|
|
|
15367
15367
|
MAX_HUB_AS_CODE_DEPTH = 128;
|
|
15368
15368
|
NAMED_DEPTH_SEGMENTS = 12;
|
|
15369
15369
|
NAMED_DEPTH_KEY_CHARS = 64;
|
|
15370
|
-
fieldName = (
|
|
15370
|
+
fieldName = (path54) => path54.reduce(
|
|
15371
15371
|
(name, key) => typeof key === "number" ? `${name}[${key}]` : name ? `${name}.${key}` : key,
|
|
15372
15372
|
""
|
|
15373
15373
|
);
|
|
@@ -15826,8 +15826,8 @@ var init_chunk_VROZDNLV = __esm({
|
|
|
15826
15826
|
CASE_UPLOADS_BUSY_REASON = "case_uploads_busy";
|
|
15827
15827
|
isBlob = (value) => typeof Blob !== "undefined" && value instanceof Blob;
|
|
15828
15828
|
caseUploadForm = external_exports.record(external_exports.string(), external_exports.unknown()).transform((form2, ctx) => {
|
|
15829
|
-
const refuse2 = (message,
|
|
15830
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [
|
|
15829
|
+
const refuse2 = (message, path54) => {
|
|
15830
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [path54] });
|
|
15831
15831
|
return external_exports.NEVER;
|
|
15832
15832
|
};
|
|
15833
15833
|
const text5 = form2[CASE_UPLOAD_REVISION_FIELD];
|
|
@@ -16036,17 +16036,17 @@ function fixedTextProblem(text5) {
|
|
|
16036
16036
|
}
|
|
16037
16037
|
return null;
|
|
16038
16038
|
}
|
|
16039
|
-
function casePieceSidecar(
|
|
16040
|
-
if (/\.yaml$/i.test(
|
|
16041
|
-
const sidecar =
|
|
16042
|
-
return sidecar ===
|
|
16039
|
+
function casePieceSidecar(path54) {
|
|
16040
|
+
if (/\.yaml$/i.test(path54)) return null;
|
|
16041
|
+
const sidecar = path54.replace(/\.[^./]+$/, ".yaml");
|
|
16042
|
+
return sidecar === path54 ? null : sidecar;
|
|
16043
16043
|
}
|
|
16044
16044
|
function pathsOverlap(a, b) {
|
|
16045
16045
|
return a === b || a.endsWith("/") && b.startsWith(a) || b.endsWith("/") && a.startsWith(b);
|
|
16046
16046
|
}
|
|
16047
|
-
function boundPathKey(
|
|
16048
|
-
const folder =
|
|
16049
|
-
const checked = checkCaseFilePath({ path: folder ? `${
|
|
16047
|
+
function boundPathKey(path54, folders) {
|
|
16048
|
+
const folder = path54.endsWith("/");
|
|
16049
|
+
const checked = checkCaseFilePath({ path: folder ? `${path54}${CHAPTER_PROBE}` : path54, type: "file" }, folders);
|
|
16050
16050
|
if (!checked.ok || checked.received) return null;
|
|
16051
16051
|
return folder ? checked.fold_key.slice(0, -CHAPTER_PROBE.length) : checked.fold_key;
|
|
16052
16052
|
}
|
|
@@ -16099,11 +16099,11 @@ function caseTypeDefinitionProblem(definition) {
|
|
|
16099
16099
|
if (output.format === "file" && output.output_items.length > 0) return problem("file_output_with_items", outputAt);
|
|
16100
16100
|
if (output.format === "file" && output.case_items_allowed) return problem("file_output_with_case_items", outputAt);
|
|
16101
16101
|
if (caseValuesRepeated(output.approving_team_ids)) return problem("approving_team_repeated", outputAt);
|
|
16102
|
-
for (const
|
|
16103
|
-
if (!
|
|
16104
|
-
const key = boundPathKey(
|
|
16102
|
+
for (const path54 of output.file_paths) {
|
|
16103
|
+
if (!path54.startsWith(`${phase.folder}/`)) return problem("file_path_outside_phase", outputAt);
|
|
16104
|
+
const key = boundPathKey(path54, folders);
|
|
16105
16105
|
if (key === null) return problem("file_path_not_writable", outputAt);
|
|
16106
|
-
if (output.format === "file" &&
|
|
16106
|
+
if (output.format === "file" && path54.endsWith("/")) return problem("file_path_folder_for_file", outputAt);
|
|
16107
16107
|
if (paths.some((held) => pathsOverlap(held, key))) return problem("file_path_overlaps", outputAt);
|
|
16108
16108
|
paths.push(key);
|
|
16109
16109
|
}
|
|
@@ -16230,8 +16230,8 @@ var init_chunk_PFPADFUC = __esm({
|
|
|
16230
16230
|
const { folder, code: targetCode } = resolveItemLink("", target);
|
|
16231
16231
|
return (!target.includes("/") || CASE_PHASE_FOLDER_PATTERN.test(folder)) && CASE_CODE_PATTERN.test(targetCode);
|
|
16232
16232
|
}, "An item is named by its code, or by its phase folder and code");
|
|
16233
|
-
filePath = external_exports.string().min(1).max(CASE_FILE_PATH_MAX_LENGTH).refine((
|
|
16234
|
-
const segments = (
|
|
16233
|
+
filePath = external_exports.string().min(1).max(CASE_FILE_PATH_MAX_LENGTH).refine((path54) => {
|
|
16234
|
+
const segments = (path54.endsWith("/") ? path54.slice(0, -1) : path54).split("/");
|
|
16235
16235
|
return segments.length >= 2 && segments.length <= 8 && CASE_PHASE_FOLDER_PATTERN.test(segments[0]) && segments.slice(1).every((segment2) => FILE_PATH_SEGMENT_PATTERN.test(segment2));
|
|
16236
16236
|
}, "A file path is the phase folder, then letters, digits, dots, dashes and underscores");
|
|
16237
16237
|
caseTypePartyRoleSchema = external_exports.object({
|
|
@@ -16784,8 +16784,8 @@ var init_chunk_EYOBPUDN = __esm({
|
|
|
16784
16784
|
// ../../packages/core/dist/chunk-6CHDJVQ6.js
|
|
16785
16785
|
function collectionUploadForm(field, shape) {
|
|
16786
16786
|
return external_exports.record(external_exports.string(), external_exports.unknown()).transform((form2, ctx) => {
|
|
16787
|
-
const refuse2 = (message,
|
|
16788
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [
|
|
16787
|
+
const refuse2 = (message, path54) => {
|
|
16788
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [path54] });
|
|
16789
16789
|
return external_exports.NEVER;
|
|
16790
16790
|
};
|
|
16791
16791
|
const text5 = form2[field];
|
|
@@ -16936,8 +16936,8 @@ var init_chunk_WYCUCSD5 = __esm({
|
|
|
16936
16936
|
confidential: external_exports.boolean().default(false)
|
|
16937
16937
|
}).strict();
|
|
16938
16938
|
caseReceivedUploadForm = external_exports.record(external_exports.string(), external_exports.unknown()).transform((form2, ctx) => {
|
|
16939
|
-
const refuse2 = (message,
|
|
16940
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [
|
|
16939
|
+
const refuse2 = (message, path54) => {
|
|
16940
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [path54] });
|
|
16941
16941
|
return external_exports.NEVER;
|
|
16942
16942
|
};
|
|
16943
16943
|
const text5 = form2[CASE_RECEIVED_DOCUMENT_FIELD];
|
|
@@ -20343,7 +20343,7 @@ var init_resource_files = __esm({
|
|
|
20343
20343
|
});
|
|
20344
20344
|
|
|
20345
20345
|
// ../../packages/core/dist/contracts/case-type-drafts.js
|
|
20346
|
-
var caseTypeSourceQuery, caseTypePackageParam, caseTypeDraftParam, CASE_TYPE_DRAFT_FIELD, CASE_TYPE_PACKAGE_FIELD, caseTypeDraftFields, CASE_TYPE_DRAFT_BODY_MAX_BYTES, caseTypeDraftForm, CASE_PACKAGE_INVALID_REASON, CASE_TYPE_DRAFT_UPLOAD_EXPIRED_REASON, CASE_TYPE_DRAFT_UPLOADS_BUSY_REASON, CASE_TYPE_DRAFTS_FULL_REASON;
|
|
20346
|
+
var caseTypeSourceQuery, caseTypePackageParam, caseTypeDraftParam, CASE_TYPE_DRAFT_FIELD, CASE_TYPE_PACKAGE_FIELD, caseTypeDraftFields, CASE_TYPE_DRAFT_BODY_MAX_BYTES, caseTypeDraftForm, CASE_PACKAGE_INVALID_REASON, CASE_TYPE_DRAFT_UPLOAD_EXPIRED_REASON, CASE_TYPE_DRAFT_UPLOADS_BUSY_REASON, CASE_TYPE_DRAFTS_FULL_REASON, caseRecordPackageQuery, CASE_PACKAGE_PATH_MAX_CHARS, caseRecordPackageFileQuery;
|
|
20347
20347
|
var init_case_type_drafts = __esm({
|
|
20348
20348
|
"../../packages/core/dist/contracts/case-type-drafts.js"() {
|
|
20349
20349
|
"use strict";
|
|
@@ -20375,8 +20375,8 @@ var init_case_type_drafts = __esm({
|
|
|
20375
20375
|
}).strict();
|
|
20376
20376
|
CASE_TYPE_DRAFT_BODY_MAX_BYTES = 22 * 1024 * 1024;
|
|
20377
20377
|
caseTypeDraftForm = external_exports.record(external_exports.string(), external_exports.unknown()).transform((form2, ctx) => {
|
|
20378
|
-
const refuse2 = (message,
|
|
20379
|
-
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [
|
|
20378
|
+
const refuse2 = (message, path54) => {
|
|
20379
|
+
ctx.addIssue({ code: external_exports.ZodIssueCode.custom, message, path: [path54] });
|
|
20380
20380
|
return external_exports.NEVER;
|
|
20381
20381
|
};
|
|
20382
20382
|
const text5 = form2[CASE_TYPE_DRAFT_FIELD];
|
|
@@ -20399,6 +20399,13 @@ var init_case_type_drafts = __esm({
|
|
|
20399
20399
|
CASE_TYPE_DRAFT_UPLOAD_EXPIRED_REASON = "case_type_draft_upload_expired";
|
|
20400
20400
|
CASE_TYPE_DRAFT_UPLOADS_BUSY_REASON = "case_type_draft_uploads_busy";
|
|
20401
20401
|
CASE_TYPE_DRAFTS_FULL_REASON = "case_type_drafts_full";
|
|
20402
|
+
caseRecordPackageQuery = external_exports.object({
|
|
20403
|
+
confidential: external_exports.enum(["true", "false"]).optional().transform((value) => value === "true")
|
|
20404
|
+
});
|
|
20405
|
+
CASE_PACKAGE_PATH_MAX_CHARS = 200;
|
|
20406
|
+
caseRecordPackageFileQuery = caseRecordPackageQuery.extend({
|
|
20407
|
+
path: external_exports.string().min(1).max(CASE_PACKAGE_PATH_MAX_CHARS)
|
|
20408
|
+
});
|
|
20402
20409
|
}
|
|
20403
20410
|
});
|
|
20404
20411
|
|
|
@@ -20467,10 +20474,10 @@ function toDataProxyPath(v1Path) {
|
|
|
20467
20474
|
}
|
|
20468
20475
|
return `${DATA_PROXY_PREFIX}${v1Path.slice(REKOR_V1_PREFIX.length)}`;
|
|
20469
20476
|
}
|
|
20470
|
-
function withOrgSelector(
|
|
20471
|
-
if (!orgId) return
|
|
20472
|
-
const separator =
|
|
20473
|
-
return `${
|
|
20477
|
+
function withOrgSelector(path54, orgId) {
|
|
20478
|
+
if (!orgId) return path54;
|
|
20479
|
+
const separator = path54.includes("?") ? "&" : "?";
|
|
20480
|
+
return `${path54}${separator}${DATA_PROXY_ORG_QUERY_PARAM}=${encodeURIComponent(orgId)}`;
|
|
20474
20481
|
}
|
|
20475
20482
|
function dataErrorMessage(err) {
|
|
20476
20483
|
if (!(err instanceof ApiError)) return null;
|
|
@@ -20512,13 +20519,13 @@ var init_api_client = __esm({
|
|
|
20512
20519
|
* telling them apart by body shape misreads one for the other.
|
|
20513
20520
|
*/
|
|
20514
20521
|
path;
|
|
20515
|
-
constructor(method,
|
|
20522
|
+
constructor(method, path54, status, body) {
|
|
20516
20523
|
const safeBody = maskSecretsInMessage(body);
|
|
20517
|
-
super(`API request failed: ${method} ${
|
|
20524
|
+
super(`API request failed: ${method} ${path54} (${status}): ${safeBody}`);
|
|
20518
20525
|
this.name = "ApiError";
|
|
20519
20526
|
this.status = status;
|
|
20520
20527
|
this.body = safeBody;
|
|
20521
|
-
this.path =
|
|
20528
|
+
this.path = path54;
|
|
20522
20529
|
}
|
|
20523
20530
|
/** True when the status code is a 4xx client error (expected user-facing condition, not a bug). */
|
|
20524
20531
|
get isExpected() {
|
|
@@ -20727,6 +20734,19 @@ var init_api_client = __esm({
|
|
|
20727
20734
|
const { bytes, etag } = await this.download(`${casePath(ref)}/collection/${encodeURIComponent(documentId)}/content?${params}`);
|
|
20728
20735
|
return { bytes, sha: etag === null ? null : /^(?:W\/)?"([0-9a-f]{64})"$/.exec(etag)?.[1] ?? null };
|
|
20729
20736
|
}
|
|
20737
|
+
/**
|
|
20738
|
+
* The case's package (`get_case_package`): the type version's it opened on, its files listed by path, SHA-256 and size;
|
|
20739
|
+
* a marked one only with `confidential`, which needs the Confidential right on the case. Null for a version with none.
|
|
20740
|
+
*/
|
|
20741
|
+
async getCasePackage(ref, confidential) {
|
|
20742
|
+
return this.request("GET", `${casePath(ref)}/package${confidential ? "?confidential=true" : ""}`);
|
|
20743
|
+
}
|
|
20744
|
+
/** One file of the case's package, by its path in the package: its bytes. */
|
|
20745
|
+
async getCasePackageContent(ref, path54, confidential) {
|
|
20746
|
+
const params = new URLSearchParams({ path: path54 });
|
|
20747
|
+
if (confidential) params.set("confidential", "true");
|
|
20748
|
+
return (await this.download(`${casePath(ref)}/package/content?${params}`)).bytes;
|
|
20749
|
+
}
|
|
20730
20750
|
/** A page of the files the case holds now, by path. */
|
|
20731
20751
|
async listCaseFiles(ref, query = {}) {
|
|
20732
20752
|
const params = new URLSearchParams();
|
|
@@ -20736,8 +20756,8 @@ var init_api_client = __esm({
|
|
|
20736
20756
|
return this.request("GET", `${casePath(ref)}/files${qs ? `?${qs}` : ""}`);
|
|
20737
20757
|
}
|
|
20738
20758
|
/** A case file's bytes as the case holds them now. */
|
|
20739
|
-
async getCaseFileContent(ref,
|
|
20740
|
-
return (await this.download(`${casePath(ref)}/files/content?${new URLSearchParams({ path:
|
|
20759
|
+
async getCaseFileContent(ref, path54) {
|
|
20760
|
+
return (await this.download(`${casePath(ref)}/files/content?${new URLSearchParams({ path: path54 })}`)).bytes;
|
|
20741
20761
|
}
|
|
20742
20762
|
/**
|
|
20743
20763
|
* One revision of the case's files, in one multipart request: the revision's JSON, and each content it sends as a
|
|
@@ -20962,8 +20982,8 @@ var init_api_client = __esm({
|
|
|
20962
20982
|
...opts?.check && { check: true }
|
|
20963
20983
|
});
|
|
20964
20984
|
}
|
|
20965
|
-
async lookup(
|
|
20966
|
-
const params = new URLSearchParams({ path:
|
|
20985
|
+
async lookup(path54, opts) {
|
|
20986
|
+
const params = new URLSearchParams({ path: path54 });
|
|
20967
20987
|
if (opts?.organizationId) params.set("organization_id", opts.organizationId);
|
|
20968
20988
|
return this.request("GET", `/api/ci/lookup?${params.toString()}`);
|
|
20969
20989
|
}
|
|
@@ -21503,9 +21523,9 @@ var init_api_client = __esm({
|
|
|
21503
21523
|
`/api/admin/data-explorer/debug/observability/${encodeURIComponent(hubId)}/conversations/${encodeURIComponent(conversationId)}${qs}`
|
|
21504
21524
|
);
|
|
21505
21525
|
}
|
|
21506
|
-
async request(method,
|
|
21507
|
-
addApiBreadcrumb(method,
|
|
21508
|
-
const url = `${this.apiUrl}${
|
|
21526
|
+
async request(method, path54, body, extraHeaders, contentType) {
|
|
21527
|
+
addApiBreadcrumb(method, path54);
|
|
21528
|
+
const url = `${this.apiUrl}${path54}`;
|
|
21509
21529
|
let refreshedOn401 = false;
|
|
21510
21530
|
for (let retry = 0; ; retry++) {
|
|
21511
21531
|
let response = await this.send(url, method, body, extraHeaders, contentType);
|
|
@@ -21530,7 +21550,7 @@ var init_api_client = __esm({
|
|
|
21530
21550
|
await delay(RETRYABLE_BACKOFF_MS[retry]);
|
|
21531
21551
|
continue;
|
|
21532
21552
|
}
|
|
21533
|
-
throw new ApiError(method,
|
|
21553
|
+
throw new ApiError(method, path54, response.status, errorBody);
|
|
21534
21554
|
}
|
|
21535
21555
|
}
|
|
21536
21556
|
/**
|
|
@@ -21600,9 +21620,9 @@ var init_api_client = __esm({
|
|
|
21600
21620
|
return this.download(withOrgSelector(toDataProxyPath(v1Path), orgId));
|
|
21601
21621
|
}
|
|
21602
21622
|
/** A backend path's raw bytes (`dataDownload`'s read, for any path). */
|
|
21603
|
-
async download(
|
|
21604
|
-
addApiBreadcrumb("GET",
|
|
21605
|
-
const url = `${this.apiUrl}${
|
|
21623
|
+
async download(path54) {
|
|
21624
|
+
addApiBreadcrumb("GET", path54);
|
|
21625
|
+
const url = `${this.apiUrl}${path54}`;
|
|
21606
21626
|
let response = await this.send(url, "GET");
|
|
21607
21627
|
if (response.status === 401 && this.onUnauthorized) {
|
|
21608
21628
|
let refreshed;
|
|
@@ -21616,7 +21636,7 @@ var init_api_client = __esm({
|
|
|
21616
21636
|
}
|
|
21617
21637
|
}
|
|
21618
21638
|
if (!response.ok) {
|
|
21619
|
-
throw new ApiError("GET",
|
|
21639
|
+
throw new ApiError("GET", path54, response.status, await response.text());
|
|
21620
21640
|
}
|
|
21621
21641
|
return {
|
|
21622
21642
|
bytes: new Uint8Array(await response.arrayBuffer()),
|
|
@@ -22060,9 +22080,9 @@ function getVersionCachePath(filename = CLI_CACHE_FILE) {
|
|
|
22060
22080
|
}
|
|
22061
22081
|
function readVersionCache(filename = CLI_CACHE_FILE) {
|
|
22062
22082
|
try {
|
|
22063
|
-
const
|
|
22064
|
-
if (!existsSync4(
|
|
22065
|
-
const parsed = JSON.parse(readFileSync6(
|
|
22083
|
+
const path54 = getVersionCachePath(filename);
|
|
22084
|
+
if (!existsSync4(path54)) return null;
|
|
22085
|
+
const parsed = JSON.parse(readFileSync6(path54, "utf-8"));
|
|
22066
22086
|
if (typeof parsed.lastCheck !== "number") return null;
|
|
22067
22087
|
if (parsed.latest !== null && typeof parsed.latest !== "string") return null;
|
|
22068
22088
|
return parsed;
|
|
@@ -22082,10 +22102,10 @@ function isVersionCacheStale(filename = CLI_CACHE_FILE, maxAgeMs = MAX_AGE_24H_M
|
|
|
22082
22102
|
return Date.now() - cache.lastCheck > maxAgeMs;
|
|
22083
22103
|
}
|
|
22084
22104
|
function writeVersionCache(filename, cache) {
|
|
22085
|
-
const
|
|
22086
|
-
const dir = dirname6(
|
|
22105
|
+
const path54 = getVersionCachePath(filename);
|
|
22106
|
+
const dir = dirname6(path54);
|
|
22087
22107
|
if (!existsSync4(dir)) mkdirSync2(dir, { recursive: true });
|
|
22088
|
-
writeFileSync2(
|
|
22108
|
+
writeFileSync2(path54, JSON.stringify(cache));
|
|
22089
22109
|
}
|
|
22090
22110
|
function touchVersionCache(filename) {
|
|
22091
22111
|
writeVersionCache(filename, { lastCheck: Date.now(), latest: readVersionCache(filename)?.latest ?? null });
|
|
@@ -22124,14 +22144,14 @@ function parseFrontmatterVersion(content) {
|
|
|
22124
22144
|
function findInstalledSkills(projectRoot, paths = SKILL_INSTALL_PATHS) {
|
|
22125
22145
|
const found = [];
|
|
22126
22146
|
for (const rel of paths) {
|
|
22127
|
-
const
|
|
22128
|
-
if (!existsSync5(
|
|
22147
|
+
const path54 = join9(projectRoot, rel);
|
|
22148
|
+
if (!existsSync5(path54)) continue;
|
|
22129
22149
|
let version = null;
|
|
22130
22150
|
try {
|
|
22131
|
-
version = parseFrontmatterVersion(readFileSync7(
|
|
22151
|
+
version = parseFrontmatterVersion(readFileSync7(path54, "utf-8"));
|
|
22132
22152
|
} catch {
|
|
22133
22153
|
}
|
|
22134
|
-
found.push({ path:
|
|
22154
|
+
found.push({ path: path54, version });
|
|
22135
22155
|
}
|
|
22136
22156
|
return found;
|
|
22137
22157
|
}
|
|
@@ -26077,12 +26097,12 @@ async function createDataClient(orgId, opts = {}) {
|
|
|
26077
26097
|
return orgId2;
|
|
26078
26098
|
}
|
|
26079
26099
|
return {
|
|
26080
|
-
async request(method,
|
|
26081
|
-
const envelope = await api.dataRequest(method,
|
|
26100
|
+
async request(method, path54, body, headers) {
|
|
26101
|
+
const envelope = await api.dataRequest(method, path54, body, org, headers);
|
|
26082
26102
|
return envelope.data;
|
|
26083
26103
|
},
|
|
26084
|
-
async requestRaw(method,
|
|
26085
|
-
const body_ = await api.dataRequest(method,
|
|
26104
|
+
async requestRaw(method, path54, body) {
|
|
26105
|
+
const body_ = await api.dataRequest(method, path54, body, org);
|
|
26086
26106
|
return body_;
|
|
26087
26107
|
},
|
|
26088
26108
|
async collectPages(makePath) {
|
|
@@ -27264,7 +27284,7 @@ async function communitiesClient() {
|
|
|
27264
27284
|
const { config, accessToken } = await requireAuth();
|
|
27265
27285
|
return new ApiClient({ apiUrl: config.api_url, accessToken, onUnauthorized: () => getAccessToken(config) });
|
|
27266
27286
|
}
|
|
27267
|
-
function communitiesFailure(err,
|
|
27287
|
+
function communitiesFailure(err, notFound2) {
|
|
27268
27288
|
if (!(err instanceof ApiError)) return err;
|
|
27269
27289
|
if (err.status === 403 && extractApiErrorCode(err) === "AUTHORIZATION_ERROR") {
|
|
27270
27290
|
const override2 = envTokenOverride() ? " WAYAI_TOKEN is set in this shell and is sent instead of your sign-in: unset it first." : "";
|
|
@@ -27272,7 +27292,7 @@ function communitiesFailure(err, notFound) {
|
|
|
27272
27292
|
`Communities are managed from a browser sign-in only, and this login is an API token. Run \`wayai login\` (without --token).${override2}`
|
|
27273
27293
|
);
|
|
27274
27294
|
}
|
|
27275
|
-
if (err.status === 404) return expected(
|
|
27295
|
+
if (err.status === 404) return expected(notFound2);
|
|
27276
27296
|
if (err.status === 429) {
|
|
27277
27297
|
const seconds2 = retryAfterSeconds(err);
|
|
27278
27298
|
return expected(
|
|
@@ -27281,11 +27301,11 @@ function communitiesFailure(err, notFound) {
|
|
|
27281
27301
|
}
|
|
27282
27302
|
return err;
|
|
27283
27303
|
}
|
|
27284
|
-
async function callCommunities(request,
|
|
27304
|
+
async function callCommunities(request, notFound2) {
|
|
27285
27305
|
try {
|
|
27286
27306
|
return await request;
|
|
27287
27307
|
} catch (err) {
|
|
27288
|
-
throw communitiesFailure(err,
|
|
27308
|
+
throw communitiesFailure(err, notFound2);
|
|
27289
27309
|
}
|
|
27290
27310
|
}
|
|
27291
27311
|
var communityNotFound, orgNotFound;
|
|
@@ -30061,8 +30081,8 @@ var init_sync2 = __esm({
|
|
|
30061
30081
|
this.pacer = pacer;
|
|
30062
30082
|
this.communityId = communityId;
|
|
30063
30083
|
}
|
|
30064
|
-
async send(request,
|
|
30065
|
-
return (await callCommunities(this.pacer.run(request),
|
|
30084
|
+
async send(request, notFound2 = communityNotFound(this.communityId)) {
|
|
30085
|
+
return (await callCommunities(this.pacer.run(request), notFound2)).data;
|
|
30066
30086
|
}
|
|
30067
30087
|
/**
|
|
30068
30088
|
* gh #5003 Decision 8's bounded read: the org's list, settings, rooms, the join link and the
|
|
@@ -34424,15 +34444,15 @@ var init_caller_audio = __esm({
|
|
|
34424
34444
|
}
|
|
34425
34445
|
describe;
|
|
34426
34446
|
async clipFor(line) {
|
|
34427
|
-
const
|
|
34428
|
-
if (!
|
|
34447
|
+
const path54 = line.clip ? isAbsolute2(line.clip) ? line.clip : resolve10(this.planDir, line.clip) : this.dir ? join33(this.dir, `${line.n}.wav`) : null;
|
|
34448
|
+
if (!path54) throw new Error(`Line ${line.n} has no clip: give --clips <dir>, or a "clip" for it in the plan.`);
|
|
34429
34449
|
let buf;
|
|
34430
34450
|
try {
|
|
34431
|
-
buf = readFileSync17(
|
|
34451
|
+
buf = readFileSync17(path54);
|
|
34432
34452
|
} catch {
|
|
34433
|
-
throw new Error(`Line ${line.n}'s clip ${
|
|
34453
|
+
throw new Error(`Line ${line.n}'s clip ${path54} cannot be read.`);
|
|
34434
34454
|
}
|
|
34435
|
-
return parseWav(buf,
|
|
34455
|
+
return parseWav(buf, path54);
|
|
34436
34456
|
}
|
|
34437
34457
|
};
|
|
34438
34458
|
OPENAI_PCM_SAMPLE_RATE = 24e3;
|
|
@@ -34462,17 +34482,17 @@ ${text5}`).digest("hex");
|
|
|
34462
34482
|
return join33(this.cacheDir, `${key}.pcm`);
|
|
34463
34483
|
}
|
|
34464
34484
|
clipFor(line) {
|
|
34465
|
-
const
|
|
34466
|
-
let pending = this.inFlight.get(
|
|
34485
|
+
const path54 = this.cachePath(line.say);
|
|
34486
|
+
let pending = this.inFlight.get(path54);
|
|
34467
34487
|
if (!pending) {
|
|
34468
|
-
pending = this.readOrSynthesize(line,
|
|
34469
|
-
this.inFlight.set(
|
|
34488
|
+
pending = this.readOrSynthesize(line, path54);
|
|
34489
|
+
this.inFlight.set(path54, pending);
|
|
34470
34490
|
}
|
|
34471
34491
|
return pending;
|
|
34472
34492
|
}
|
|
34473
|
-
async readOrSynthesize(line,
|
|
34493
|
+
async readOrSynthesize(line, path54) {
|
|
34474
34494
|
try {
|
|
34475
|
-
return pcmClip(readFileSync17(
|
|
34495
|
+
return pcmClip(readFileSync17(path54));
|
|
34476
34496
|
} catch {
|
|
34477
34497
|
}
|
|
34478
34498
|
const res = await this.doFetch("https://api.openai.com/v1/audio/speech", {
|
|
@@ -34486,10 +34506,10 @@ ${text5}`).digest("hex");
|
|
|
34486
34506
|
}
|
|
34487
34507
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
34488
34508
|
if (buf.length < 2) throw new Error(`OpenAI speech synthesis returned no audio for line ${line.n}.`);
|
|
34489
|
-
mkdirSync12(dirname12(
|
|
34490
|
-
const tmp = `${
|
|
34509
|
+
mkdirSync12(dirname12(path54), { recursive: true });
|
|
34510
|
+
const tmp = `${path54}.${process.pid}.tmp`;
|
|
34491
34511
|
writeFileSync7(tmp, buf);
|
|
34492
|
-
renameSync5(tmp,
|
|
34512
|
+
renameSync5(tmp, path54);
|
|
34493
34513
|
return pcmClip(buf);
|
|
34494
34514
|
}
|
|
34495
34515
|
};
|
|
@@ -36054,15 +36074,15 @@ function parseEvalCallArgs(args2) {
|
|
|
36054
36074
|
if (parsed.jsonPath) checkReportPath(parsed.jsonPath);
|
|
36055
36075
|
return parsed;
|
|
36056
36076
|
}
|
|
36057
|
-
function checkReportPath(
|
|
36058
|
-
const target = resolve11(
|
|
36077
|
+
function checkReportPath(path54) {
|
|
36078
|
+
const target = resolve11(path54);
|
|
36059
36079
|
const dir = dirname13(target);
|
|
36060
|
-
if (!existsSync17(dir) || !statSync8(dir).isDirectory()) fail(`--json ${
|
|
36061
|
-
if (existsSync17(target) && statSync8(target).isDirectory()) fail(`--json ${
|
|
36080
|
+
if (!existsSync17(dir) || !statSync8(dir).isDirectory()) fail(`--json ${path54}: the folder ${dir} does not exist.`);
|
|
36081
|
+
if (existsSync17(target) && statSync8(target).isDirectory()) fail(`--json ${path54} is a folder; name a file.`);
|
|
36062
36082
|
try {
|
|
36063
36083
|
accessSync(existsSync17(target) ? target : dir, fsConstants.W_OK);
|
|
36064
36084
|
} catch {
|
|
36065
|
-
fail(`--json ${
|
|
36085
|
+
fail(`--json ${path54} cannot be written here.`);
|
|
36066
36086
|
}
|
|
36067
36087
|
}
|
|
36068
36088
|
function suiteExitCode(report2, runs, reportWritten) {
|
|
@@ -36862,15 +36882,15 @@ async function analyticsSummaryCommand(args2) {
|
|
|
36862
36882
|
}
|
|
36863
36883
|
let selectedVariables = [];
|
|
36864
36884
|
if (metricNames && metricNames.length > 0 && allVars) {
|
|
36865
|
-
const
|
|
36885
|
+
const notFound2 = [];
|
|
36866
36886
|
for (const name of metricNames) {
|
|
36867
36887
|
const match = allVars.find((v) => v.variable_name === name);
|
|
36868
36888
|
if (match) selectedVariables.push(match.variable_id);
|
|
36869
|
-
else
|
|
36889
|
+
else notFound2.push(name);
|
|
36870
36890
|
}
|
|
36871
|
-
if (
|
|
36891
|
+
if (notFound2.length > 0) {
|
|
36872
36892
|
const available = allVars.map((v) => v.variable_name).sort();
|
|
36873
|
-
console.error(`Unknown metric(s): ${
|
|
36893
|
+
console.error(`Unknown metric(s): ${notFound2.join(", ")}`);
|
|
36874
36894
|
console.error(`
|
|
36875
36895
|
Available metrics:
|
|
36876
36896
|
${available.join("\n ")}`);
|
|
@@ -38377,9 +38397,9 @@ async function runList(orgId, json2) {
|
|
|
38377
38397
|
async function runJoinLink(action, target, { json: json2, yes }) {
|
|
38378
38398
|
const api = await communitiesClient();
|
|
38379
38399
|
const { id, label: label3 } = await resolveCommunity(api, target);
|
|
38380
|
-
const
|
|
38400
|
+
const notFound2 = communityNotFound(label3);
|
|
38381
38401
|
if (action === "get") {
|
|
38382
|
-
const { data: data2 } = await callCommunities(api.getCommunityJoinLink(id),
|
|
38402
|
+
const { data: data2 } = await callCommunities(api.getCommunityJoinLink(id), notFound2);
|
|
38383
38403
|
printLink(data2, label3, json2);
|
|
38384
38404
|
return;
|
|
38385
38405
|
}
|
|
@@ -38393,7 +38413,7 @@ async function runJoinLink(action, target, { json: json2, yes }) {
|
|
|
38393
38413
|
);
|
|
38394
38414
|
const { data } = await callCommunities(
|
|
38395
38415
|
action === "rotate" ? api.replaceCommunityJoinLink(id) : api.disableCommunityJoinLink(id),
|
|
38396
|
-
|
|
38416
|
+
notFound2
|
|
38397
38417
|
);
|
|
38398
38418
|
printLink(data, label3, json2);
|
|
38399
38419
|
}
|
|
@@ -38473,9 +38493,9 @@ function accessEmails(raw) {
|
|
|
38473
38493
|
}
|
|
38474
38494
|
return [...emails];
|
|
38475
38495
|
}
|
|
38476
|
-
async function callAccess(request,
|
|
38496
|
+
async function callAccess(request, notFound2, label3) {
|
|
38477
38497
|
try {
|
|
38478
|
-
return await callCommunities(request,
|
|
38498
|
+
return await callCommunities(request, notFound2);
|
|
38479
38499
|
} catch (err) {
|
|
38480
38500
|
if (err instanceof ApiError && err.status === 409) {
|
|
38481
38501
|
const reason3 = extractApiErrorReason(err);
|
|
@@ -38489,10 +38509,10 @@ async function callAccess(request, notFound, label3) {
|
|
|
38489
38509
|
throw err;
|
|
38490
38510
|
}
|
|
38491
38511
|
}
|
|
38492
|
-
async function* accessPages(api, id,
|
|
38512
|
+
async function* accessPages(api, id, notFound2) {
|
|
38493
38513
|
let cursor;
|
|
38494
38514
|
do {
|
|
38495
|
-
const { data } = await callCommunities(api.listCommunityAccess(id, cursor),
|
|
38515
|
+
const { data } = await callCommunities(api.listCommunityAccess(id, cursor), notFound2);
|
|
38496
38516
|
yield data.entries;
|
|
38497
38517
|
cursor = data.next_cursor ?? void 0;
|
|
38498
38518
|
} while (cursor !== void 0);
|
|
@@ -39198,13 +39218,13 @@ async function openCaseSession(selector, now = Date.now(), cwd = process.cwd())
|
|
|
39198
39218
|
if (!token) throw expected(`This machine's keyring holds no token for case ${connection.code}. Connect again: ${connectCommand(connection)}`);
|
|
39199
39219
|
return { connection, api: new ApiClient({ apiUrl: connection.api_url, accessToken: token }) };
|
|
39200
39220
|
}
|
|
39201
|
-
function caseCallFailure(err, connection,
|
|
39221
|
+
function caseCallFailure(err, connection, notFound2 = `Case ${connection.code} was not found`) {
|
|
39202
39222
|
if (!(err instanceof ApiError)) return err;
|
|
39203
39223
|
if (err.status === 401) {
|
|
39204
39224
|
return expected(`The case token was refused: its authorization was revoked, expired or replaced. Connect again: ${connectCommand(connection)}`);
|
|
39205
39225
|
}
|
|
39206
39226
|
if (err.status === 404) {
|
|
39207
|
-
return expected(`${
|
|
39227
|
+
return expected(`${notFound2}, or this machine's authorization on case ${connection.code} is no longer live.`);
|
|
39208
39228
|
}
|
|
39209
39229
|
if (err.status === 429) {
|
|
39210
39230
|
const seconds2 = retryAfterSeconds(err);
|
|
@@ -39335,6 +39355,1206 @@ var init_case_local_files = __esm({
|
|
|
39335
39355
|
}
|
|
39336
39356
|
});
|
|
39337
39357
|
|
|
39358
|
+
// ../../packages/core/dist/contracts/case-comments.js
|
|
39359
|
+
var init_case_comments = __esm({
|
|
39360
|
+
"../../packages/core/dist/contracts/case-comments.js"() {
|
|
39361
|
+
"use strict";
|
|
39362
|
+
init_chunk_S7UAXLHJ();
|
|
39363
|
+
init_chunk_7TQYAKCB();
|
|
39364
|
+
init_chunk_VROZDNLV();
|
|
39365
|
+
init_chunk_733K4J4G();
|
|
39366
|
+
init_chunk_PFPADFUC();
|
|
39367
|
+
init_chunk_KWRHZBGU();
|
|
39368
|
+
init_chunk_3T3D7LTE();
|
|
39369
|
+
init_chunk_M2T55BV6();
|
|
39370
|
+
init_chunk_VYINA6YP();
|
|
39371
|
+
init_chunk_ZVXO3XL6();
|
|
39372
|
+
init_chunk_FBV7NLKO();
|
|
39373
|
+
init_chunk_WEXVYJ5H();
|
|
39374
|
+
init_chunk_HZ6CADSY();
|
|
39375
|
+
init_chunk_ICYO56QW();
|
|
39376
|
+
init_chunk_WFQDSQJK();
|
|
39377
|
+
init_chunk_ZTNFLGW5();
|
|
39378
|
+
}
|
|
39379
|
+
});
|
|
39380
|
+
|
|
39381
|
+
// ../../packages/core/dist/contracts/case-type-packages.js
|
|
39382
|
+
function headerSum(header) {
|
|
39383
|
+
let sum = 0;
|
|
39384
|
+
for (let i = 0; i < BLOCK; i++) sum += i >= 148 && i < 156 ? 32 : header[i];
|
|
39385
|
+
return sum;
|
|
39386
|
+
}
|
|
39387
|
+
function splitPath(path54) {
|
|
39388
|
+
if (ascii().encode(path54).length !== path54.length) return null;
|
|
39389
|
+
if (path54.length <= 100) return { name: path54, prefix: "" };
|
|
39390
|
+
for (let i = path54.indexOf("/"); i >= 0; i = path54.indexOf("/", i + 1)) {
|
|
39391
|
+
if (i <= 155 && path54.length - i - 1 <= 100) return { name: path54.slice(i + 1), prefix: path54.slice(0, i) };
|
|
39392
|
+
}
|
|
39393
|
+
return null;
|
|
39394
|
+
}
|
|
39395
|
+
function writeCasePackage(files) {
|
|
39396
|
+
const blocks = [];
|
|
39397
|
+
for (const { path: path54, bytes } of byPath(files)) {
|
|
39398
|
+
const header = new Uint8Array(BLOCK);
|
|
39399
|
+
const encoder = ascii();
|
|
39400
|
+
const put = (text5, at2) => header.set(encoder.encode(text5), at2);
|
|
39401
|
+
const split = splitPath(path54);
|
|
39402
|
+
if (!split) throw new Error(`A package path its archive can't hold: ${path54}`);
|
|
39403
|
+
const { name, prefix } = split;
|
|
39404
|
+
put(name, 0);
|
|
39405
|
+
put("0000644\0", 100);
|
|
39406
|
+
put("0000000\0", 108);
|
|
39407
|
+
put("0000000\0", 116);
|
|
39408
|
+
put(`${bytes.length.toString(8).padStart(11, "0")}\0`, 124);
|
|
39409
|
+
put("00000000000\0", 136);
|
|
39410
|
+
put("0", 156);
|
|
39411
|
+
put("ustar\x0000", 257);
|
|
39412
|
+
put(prefix, 345);
|
|
39413
|
+
put(`${headerSum(header).toString(8).padStart(6, "0")}\0 `, 148);
|
|
39414
|
+
blocks.push(header, bytes);
|
|
39415
|
+
if (bytes.length % BLOCK) blocks.push(new Uint8Array(BLOCK - bytes.length % BLOCK));
|
|
39416
|
+
}
|
|
39417
|
+
blocks.push(new Uint8Array(BLOCK * 2));
|
|
39418
|
+
const out = new Uint8Array(blocks.reduce((n, block2) => n + block2.length, 0));
|
|
39419
|
+
let at = 0;
|
|
39420
|
+
for (const block2 of blocks) {
|
|
39421
|
+
out.set(block2, at);
|
|
39422
|
+
at += block2.length;
|
|
39423
|
+
}
|
|
39424
|
+
return out;
|
|
39425
|
+
}
|
|
39426
|
+
function textField(block2, start, length) {
|
|
39427
|
+
const end = block2.subarray(start, start + length).indexOf(0);
|
|
39428
|
+
return new TextDecoder().decode(block2.subarray(start, end < 0 ? start + length : start + end));
|
|
39429
|
+
}
|
|
39430
|
+
function octalField(block2, start, length) {
|
|
39431
|
+
const text5 = textField(block2, start, length).trim();
|
|
39432
|
+
return /^[0-7]+$/.test(text5) ? parseInt(text5, 8) : NaN;
|
|
39433
|
+
}
|
|
39434
|
+
function readCasePackage(data) {
|
|
39435
|
+
const entries = [];
|
|
39436
|
+
const others = [];
|
|
39437
|
+
const notTar = { problems: [{ path: null, reason: "package_not_tar" }] };
|
|
39438
|
+
let at = 0;
|
|
39439
|
+
for (; ; ) {
|
|
39440
|
+
if (at + BLOCK > data.length) return notTar;
|
|
39441
|
+
const block2 = data.subarray(at, at + BLOCK);
|
|
39442
|
+
if (block2.every((byte) => byte === 0)) {
|
|
39443
|
+
if (!data.subarray(at).every((byte) => byte === 0)) return notTar;
|
|
39444
|
+
break;
|
|
39445
|
+
}
|
|
39446
|
+
if (octalField(block2, 148, 8) !== headerSum(block2) || textField(block2, 257, 6) !== "ustar") return notTar;
|
|
39447
|
+
const prefix = textField(block2, 345, 155);
|
|
39448
|
+
const name = textField(block2, 0, 100);
|
|
39449
|
+
const path54 = prefix ? `${prefix}/${name}` : name;
|
|
39450
|
+
const size = octalField(block2, 124, 12);
|
|
39451
|
+
if (Number.isNaN(size) || at + BLOCK + size > data.length) return notTar;
|
|
39452
|
+
at += BLOCK;
|
|
39453
|
+
const type = String.fromCharCode(block2[156]);
|
|
39454
|
+
if (type === "0" || type === "\0") entries.push({ path: path54, bytes: data.subarray(at, at + size), offset: at });
|
|
39455
|
+
else others.push(path54);
|
|
39456
|
+
at += size + (BLOCK - size % BLOCK) % BLOCK;
|
|
39457
|
+
}
|
|
39458
|
+
return { entries, others };
|
|
39459
|
+
}
|
|
39460
|
+
function pathProblem(path54) {
|
|
39461
|
+
if (path54.length === 0 || path54.length > CASE_PACKAGE_LIMITS.path_chars) return "package_path_invalid";
|
|
39462
|
+
const segments = path54.split("/");
|
|
39463
|
+
if (segments.length > CASE_PACKAGE_LIMITS.depth || segments.some((segment2) => !SEGMENT.test(segment2)) || !splitPath(path54)) return "package_path_invalid";
|
|
39464
|
+
return CASE_PACKAGE_FOLDERS.includes(segments[0]) ? null : "package_path_unexpected";
|
|
39465
|
+
}
|
|
39466
|
+
function classify2(path54) {
|
|
39467
|
+
const p = path54.split("/");
|
|
39468
|
+
const markdown = path54.endsWith(".md");
|
|
39469
|
+
if (p[0] === "instructions" || p[0] === "templates") {
|
|
39470
|
+
if (p.length === 3 && p[1] === "figures") return isCasePackageImage(path54) ? { kind: "figure" } : null;
|
|
39471
|
+
if (p[0] === "templates") return p.length === 3 && PHASE_FOLDER.test(p[1]) && markdown ? { kind: "template", folder: p[1], code: p[2].slice(0, -3) } : null;
|
|
39472
|
+
if (p.length === 2 && p[1] === "case.md") return { kind: "case" };
|
|
39473
|
+
if (p.length === 3 && PHASE_FOLDER.test(p[1]) && p[2] === "phase.md") return { kind: "phase", folder: p[1] };
|
|
39474
|
+
const kind = INSTRUCTION_KINDS[p[2] ?? ""];
|
|
39475
|
+
if (p.length === 4 && PHASE_FOLDER.test(p[1]) && markdown && kind) return { kind, folder: p[1], code: p[3].slice(0, -3) };
|
|
39476
|
+
return null;
|
|
39477
|
+
}
|
|
39478
|
+
if (p.length < 2) return null;
|
|
39479
|
+
if (p[0] === "tools") return TOOL_EXTENSIONS.has(extensionOf(path54)) ? { kind: "tool" } : null;
|
|
39480
|
+
return SOURCE_EXTENSIONS.has(extensionOf(path54)) || isCasePackageImage(path54) ? { kind: "source" } : null;
|
|
39481
|
+
}
|
|
39482
|
+
function decodeText(bytes) {
|
|
39483
|
+
try {
|
|
39484
|
+
const text5 = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
39485
|
+
return text5.includes("\0") ? null : text5;
|
|
39486
|
+
} catch {
|
|
39487
|
+
return null;
|
|
39488
|
+
}
|
|
39489
|
+
}
|
|
39490
|
+
function headingOf(line) {
|
|
39491
|
+
let indent = 0;
|
|
39492
|
+
while (indent < 3 && line[indent] === " ") indent++;
|
|
39493
|
+
let level = 0;
|
|
39494
|
+
while (line[indent + level] === "#") level++;
|
|
39495
|
+
const after = line[indent + level];
|
|
39496
|
+
if (level < 1 || level > 6 || after !== void 0 && after.trim() !== "") return null;
|
|
39497
|
+
const body = line.slice(indent + level).trim();
|
|
39498
|
+
let end = body.length;
|
|
39499
|
+
while (end > 0 && body[end - 1] === "#") end--;
|
|
39500
|
+
return body.slice(0, end).trimEnd().toLowerCase() || null;
|
|
39501
|
+
}
|
|
39502
|
+
function headingsOf(text5) {
|
|
39503
|
+
const found = /* @__PURE__ */ new Set();
|
|
39504
|
+
let fenced = false;
|
|
39505
|
+
for (const line of text5.split(/\r?\n/)) {
|
|
39506
|
+
const trimmed = line.trimStart();
|
|
39507
|
+
if (trimmed.startsWith("```") || trimmed.startsWith("~~~")) {
|
|
39508
|
+
fenced = !fenced;
|
|
39509
|
+
continue;
|
|
39510
|
+
}
|
|
39511
|
+
const heading = fenced ? null : headingOf(line);
|
|
39512
|
+
if (heading) found.add(heading);
|
|
39513
|
+
}
|
|
39514
|
+
return found;
|
|
39515
|
+
}
|
|
39516
|
+
function frontMatterOf(text5) {
|
|
39517
|
+
const lines = text5.split(/\r?\n/);
|
|
39518
|
+
if (lines[0] !== "---") return {};
|
|
39519
|
+
const fields = {};
|
|
39520
|
+
for (const line of lines.slice(1)) {
|
|
39521
|
+
if (line === "---") return fields;
|
|
39522
|
+
const colon = line.indexOf(":");
|
|
39523
|
+
if (colon > 0) fields[line.slice(0, colon).trim()] = line.slice(colon + 1).trim();
|
|
39524
|
+
}
|
|
39525
|
+
return {};
|
|
39526
|
+
}
|
|
39527
|
+
function indexOf(definition) {
|
|
39528
|
+
return new Map(definition.type_phases.map((phase) => [phase.folder, {
|
|
39529
|
+
tasks: new Set(phase.type_tasks.map((task) => task.code)),
|
|
39530
|
+
items: new Map(phase.phase_outputs.flatMap((output) => output.output_items.map((item) => [item.code, item]))),
|
|
39531
|
+
outputs: new Set(phase.phase_outputs.map((output) => output.code)),
|
|
39532
|
+
inputs: new Set(phase.phase_inputs.map((input) => input.key)),
|
|
39533
|
+
agenda: new Set(phase.agenda_groups.map((group) => group.code))
|
|
39534
|
+
}]));
|
|
39535
|
+
}
|
|
39536
|
+
function casePackageProblems(read, archiveBytes, definition) {
|
|
39537
|
+
const { entries, others = [] } = read;
|
|
39538
|
+
const problems2 = [];
|
|
39539
|
+
if (archiveBytes > CASE_PACKAGE_LIMITS.bytes) problems2.push({ path: null, reason: "package_too_large" });
|
|
39540
|
+
if (entries.length + others.length > CASE_PACKAGE_LIMITS.files) return [{ path: null, reason: "package_too_many_files" }, ...problems2];
|
|
39541
|
+
problems2.push(...others.map((path54) => ({ path: path54, reason: "package_entry_not_file" })));
|
|
39542
|
+
const phases = indexOf(definition);
|
|
39543
|
+
const seen = /* @__PURE__ */ new Set();
|
|
39544
|
+
const itemInstructions = /* @__PURE__ */ new Set();
|
|
39545
|
+
let textBytes = 0;
|
|
39546
|
+
for (const { path: path54, bytes } of entries) {
|
|
39547
|
+
const bad = pathProblem(path54);
|
|
39548
|
+
if (bad) {
|
|
39549
|
+
problems2.push({ path: path54, reason: bad });
|
|
39550
|
+
continue;
|
|
39551
|
+
}
|
|
39552
|
+
const folded = path54.toLowerCase();
|
|
39553
|
+
if (seen.has(folded)) problems2.push({ path: path54, reason: "package_path_repeated" });
|
|
39554
|
+
seen.add(folded);
|
|
39555
|
+
const found = classify2(path54);
|
|
39556
|
+
if (!found) {
|
|
39557
|
+
problems2.push({ path: path54, reason: "package_path_unexpected" });
|
|
39558
|
+
continue;
|
|
39559
|
+
}
|
|
39560
|
+
if (isCasePackageImage(path54)) {
|
|
39561
|
+
if (bytes.length > CASE_PACKAGE_LIMITS.image_bytes) problems2.push({ path: path54, reason: "package_image_too_large" });
|
|
39562
|
+
if (!IMAGE_SIGNATURES[extensionOf(path54)].every((byte, i) => bytes[i] === byte)) problems2.push({ path: path54, reason: "package_image_invalid" });
|
|
39563
|
+
} else {
|
|
39564
|
+
textBytes += bytes.length;
|
|
39565
|
+
const text5 = decodeText(bytes);
|
|
39566
|
+
if (text5 === null) problems2.push({ path: path54, reason: "package_not_text" });
|
|
39567
|
+
else {
|
|
39568
|
+
if (path54.endsWith(".md") && text5.trim() === "") problems2.push({ path: path54, reason: "package_file_empty" });
|
|
39569
|
+
if (found.kind === "task" || found.kind === "item") {
|
|
39570
|
+
const held = headingsOf(text5);
|
|
39571
|
+
const missing = SECTIONS[found.kind].filter((section) => !held.has(section.toLowerCase()));
|
|
39572
|
+
if (missing.length) problems2.push({ path: path54, reason: "package_sections_missing", detail: missing.join(", ") });
|
|
39573
|
+
}
|
|
39574
|
+
if (found.kind === "task" && !EXECUTORS.includes(frontMatterOf(text5).executor ?? "")) problems2.push({ path: path54, reason: "package_executor_missing" });
|
|
39575
|
+
}
|
|
39576
|
+
}
|
|
39577
|
+
if (found.folder === void 0) continue;
|
|
39578
|
+
const phase = phases.get(found.folder);
|
|
39579
|
+
if (!phase) {
|
|
39580
|
+
problems2.push({ path: path54, reason: "package_phase_unknown" });
|
|
39581
|
+
continue;
|
|
39582
|
+
}
|
|
39583
|
+
if (found.kind === "template" || found.kind === "item") {
|
|
39584
|
+
const item = phase.items.get(found.code);
|
|
39585
|
+
if (!item) problems2.push({ path: path54, reason: "package_code_unknown" });
|
|
39586
|
+
else if (found.kind === "template" && item.template_mode === "fixed") problems2.push({ path: path54, reason: "package_template_fixed" });
|
|
39587
|
+
else if (found.kind === "item") itemInstructions.add(`${found.folder}/${found.code}`);
|
|
39588
|
+
continue;
|
|
39589
|
+
}
|
|
39590
|
+
const set = CODE_SETS[found.kind];
|
|
39591
|
+
if (set && !phase[set].has(found.code)) problems2.push({ path: path54, reason: "package_code_unknown" });
|
|
39592
|
+
}
|
|
39593
|
+
if (textBytes > CASE_PACKAGE_LIMITS.text_bytes) problems2.push({ path: null, reason: "package_text_too_large" });
|
|
39594
|
+
for (const [folder, phase] of phases) {
|
|
39595
|
+
for (const [code2, item] of phase.items) {
|
|
39596
|
+
if (item.required && !item.grouping && !itemInstructions.has(`${folder}/${code2}`)) {
|
|
39597
|
+
problems2.push({ path: `instructions/${folder}/items/${code2}.md`, reason: "package_item_instruction_missing" });
|
|
39598
|
+
}
|
|
39599
|
+
}
|
|
39600
|
+
}
|
|
39601
|
+
return problems2;
|
|
39602
|
+
}
|
|
39603
|
+
function casePackageConfidentialPaths(definition) {
|
|
39604
|
+
const paths = /* @__PURE__ */ new Set();
|
|
39605
|
+
for (const phase of definition.type_phases) {
|
|
39606
|
+
const groups = new Set(phase.agenda_groups.filter((group) => group.confidential).map((group) => group.code));
|
|
39607
|
+
const tasks = new Set(phase.type_tasks.filter((task) => task.agenda_group !== null && groups.has(task.agenda_group)).map((task) => task.code));
|
|
39608
|
+
for (const group of groups) paths.add(`instructions/${phase.folder}/agenda/${group}.md`);
|
|
39609
|
+
for (const task of tasks) paths.add(`instructions/${phase.folder}/tasks/${task}.md`);
|
|
39610
|
+
for (const item of phase.phase_outputs.flatMap((output) => output.output_items)) {
|
|
39611
|
+
if (item.task === null || !tasks.has(item.task)) continue;
|
|
39612
|
+
paths.add(`instructions/${phase.folder}/items/${item.code}.md`);
|
|
39613
|
+
paths.add(`templates/${phase.folder}/${item.code}.md`);
|
|
39614
|
+
}
|
|
39615
|
+
}
|
|
39616
|
+
return paths;
|
|
39617
|
+
}
|
|
39618
|
+
async function casePackageSha(bytes) {
|
|
39619
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
39620
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
39621
|
+
}
|
|
39622
|
+
function casePackageChanges(draft, base) {
|
|
39623
|
+
const before = new Map(base.map((file) => [file.path, file]));
|
|
39624
|
+
const after = new Map(draft.map((file) => [file.path, file]));
|
|
39625
|
+
return [.../* @__PURE__ */ new Set([...before.keys(), ...after.keys()])].sort().map((path54) => {
|
|
39626
|
+
const [was, now] = [before.get(path54), after.get(path54)];
|
|
39627
|
+
return {
|
|
39628
|
+
path: path54,
|
|
39629
|
+
status: !was ? "added" : !now ? "removed" : was.sha === now.sha ? "same" : "changed",
|
|
39630
|
+
size: now?.size ?? null,
|
|
39631
|
+
base_size: was?.size ?? null,
|
|
39632
|
+
image: isCasePackageImage(path54),
|
|
39633
|
+
confidential: Boolean(was?.confidential || now?.confidential)
|
|
39634
|
+
};
|
|
39635
|
+
});
|
|
39636
|
+
}
|
|
39637
|
+
var CASE_PACKAGE_LIMITS, CASE_PACKAGE_FOLDERS, BLOCK, SEGMENT, PHASE_FOLDER, TOOL_EXTENSIONS, SOURCE_EXTENSIONS, IMAGE_SIGNATURES, SECTIONS, EXECUTORS, extensionOf, isCasePackageImage, byPath, ascii, INSTRUCTION_KINDS, CODE_SETS;
|
|
39638
|
+
var init_case_type_packages = __esm({
|
|
39639
|
+
"../../packages/core/dist/contracts/case-type-packages.js"() {
|
|
39640
|
+
"use strict";
|
|
39641
|
+
CASE_PACKAGE_LIMITS = {
|
|
39642
|
+
/** The archive, headers and end included. */
|
|
39643
|
+
bytes: 20 * 1024 * 1024,
|
|
39644
|
+
/** Every text file together: what a person reviews line by line before publishing. */
|
|
39645
|
+
text_bytes: 4 * 1024 * 1024,
|
|
39646
|
+
image_bytes: 1024 * 1024,
|
|
39647
|
+
files: 500,
|
|
39648
|
+
path_chars: 200,
|
|
39649
|
+
depth: 8
|
|
39650
|
+
};
|
|
39651
|
+
CASE_PACKAGE_FOLDERS = ["instructions", "templates", "tools", "sources"];
|
|
39652
|
+
BLOCK = 512;
|
|
39653
|
+
SEGMENT = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
39654
|
+
PHASE_FOLDER = /^[0-9]{2}-[a-z0-9-]+$/;
|
|
39655
|
+
TOOL_EXTENSIONS = /* @__PURE__ */ new Set(["py", "r", "sql", "js", "mjs", "sh", "json", "yaml", "yml", "csv", "txt", "md"]);
|
|
39656
|
+
SOURCE_EXTENSIONS = /* @__PURE__ */ new Set(["md", "txt", "csv", "json", "yaml", "yml"]);
|
|
39657
|
+
IMAGE_SIGNATURES = { png: [137, 80, 78, 71, 13, 10, 26, 10], jpg: [255, 216, 255], jpeg: [255, 216, 255] };
|
|
39658
|
+
SECTIONS = { task: ["Objective", "Inputs", "Steps", "Output", "Acceptance"], item: ["Content", "Steps", "Acceptance"] };
|
|
39659
|
+
EXECUTORS = ["agent", "person"];
|
|
39660
|
+
extensionOf = (path54) => path54.slice(path54.lastIndexOf(".") + 1).toLowerCase();
|
|
39661
|
+
isCasePackageImage = (path54) => Object.hasOwn(IMAGE_SIGNATURES, extensionOf(path54));
|
|
39662
|
+
byPath = (files) => [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
39663
|
+
ascii = () => new TextEncoder();
|
|
39664
|
+
INSTRUCTION_KINDS = { tasks: "task", items: "item", outputs: "output", inputs: "input", agenda: "agenda" };
|
|
39665
|
+
CODE_SETS = { task: "tasks", output: "outputs", input: "inputs", agenda: "agenda" };
|
|
39666
|
+
}
|
|
39667
|
+
});
|
|
39668
|
+
|
|
39669
|
+
// src/cases/case-type-folder.ts
|
|
39670
|
+
import * as fs33 from "fs";
|
|
39671
|
+
import * as path45 from "path";
|
|
39672
|
+
function isTypeFolderPath(rel) {
|
|
39673
|
+
return rel === TYPE_FILE || isCasePackagePath(rel);
|
|
39674
|
+
}
|
|
39675
|
+
function isCasePackagePath(rel) {
|
|
39676
|
+
if (caseLocalPathProblem(rel) !== null) return false;
|
|
39677
|
+
return !casePackageProblems({ entries: [{ path: rel, bytes: new Uint8Array(), offset: 0 }] }, 0, NO_PHASES).some((problem) => PACKAGE_PATH_REASONS.has(problem.reason));
|
|
39678
|
+
}
|
|
39679
|
+
function packagePathCollisions(paths) {
|
|
39680
|
+
const problems2 = [];
|
|
39681
|
+
const files = new Set(paths.map((rel) => rel.toLowerCase()));
|
|
39682
|
+
const spelled = /* @__PURE__ */ new Map();
|
|
39683
|
+
for (const rel of paths) {
|
|
39684
|
+
const segments = rel.split("/");
|
|
39685
|
+
for (let i = 1; i <= segments.length; i++) {
|
|
39686
|
+
const spelling = segments.slice(0, i).join("/");
|
|
39687
|
+
const key = spelling.toLowerCase();
|
|
39688
|
+
const known = spelled.get(key);
|
|
39689
|
+
if (known === void 0) spelled.set(key, spelling);
|
|
39690
|
+
else if (known !== spelling) {
|
|
39691
|
+
problems2.push(`${JSON.stringify(safe(known))} and ${JSON.stringify(safe(spelling))} differ only in case, so they would be one entry here`);
|
|
39692
|
+
break;
|
|
39693
|
+
}
|
|
39694
|
+
if (i < segments.length && files.has(key)) {
|
|
39695
|
+
problems2.push(`${JSON.stringify(safe(rel))}: lies in a folder that is also a file`);
|
|
39696
|
+
break;
|
|
39697
|
+
}
|
|
39698
|
+
}
|
|
39699
|
+
}
|
|
39700
|
+
return problems2;
|
|
39701
|
+
}
|
|
39702
|
+
function isRecord3(value) {
|
|
39703
|
+
if (typeof value !== "object" || value === null) return false;
|
|
39704
|
+
const v = value;
|
|
39705
|
+
if (!caseTypeParam.safeParse({ org_id: v.org_id, space_id: v.space_id, type_id: v.type_id }).success || typeof v.abbreviation !== "string") return false;
|
|
39706
|
+
if (typeof v.version !== "number" || !Number.isInteger(v.version) || v.version < 1) return false;
|
|
39707
|
+
if (typeof v.files !== "object" || v.files === null || Array.isArray(v.files)) return false;
|
|
39708
|
+
return Object.entries(v.files).every(([rel, sha]) => isTypeFolderPath(rel) && typeof sha === "string" && CASE_FILE_SHA_PATTERN.test(sha));
|
|
39709
|
+
}
|
|
39710
|
+
function readTypeFolderRecord(root) {
|
|
39711
|
+
const file = path45.join(root, TYPE_FOLDER_MARKER);
|
|
39712
|
+
let marker;
|
|
39713
|
+
try {
|
|
39714
|
+
marker = fs33.lstatSync(file);
|
|
39715
|
+
} catch {
|
|
39716
|
+
return null;
|
|
39717
|
+
}
|
|
39718
|
+
const problem = ownProblem(marker) ?? (() => {
|
|
39719
|
+
const folder = ownProblem(fs33.lstatSync(root));
|
|
39720
|
+
return folder ? `its folder: ${folder}` : null;
|
|
39721
|
+
})();
|
|
39722
|
+
if (problem) {
|
|
39723
|
+
throw expected(safe(
|
|
39724
|
+
`Refused the case type marker ${file}: ${problem}. A type folder counts only in a folder you own that not every user can write to: remove it, or pull the type into a folder of your own.`
|
|
39725
|
+
));
|
|
39726
|
+
}
|
|
39727
|
+
const text5 = readRealFileOrThrow(root, file);
|
|
39728
|
+
if (text5 === null) return null;
|
|
39729
|
+
let parsed;
|
|
39730
|
+
try {
|
|
39731
|
+
parsed = JSON.parse(text5);
|
|
39732
|
+
} catch {
|
|
39733
|
+
parsed = void 0;
|
|
39734
|
+
}
|
|
39735
|
+
if (!isRecord3(parsed)) throw expected(`${safe(file)} is not a marker \`wayai cases type pull\` wrote. Move it aside and pull the type again.`);
|
|
39736
|
+
return parsed;
|
|
39737
|
+
}
|
|
39738
|
+
function writeTypeFolderRecord(root, record) {
|
|
39739
|
+
const files = {};
|
|
39740
|
+
for (const rel of Object.keys(record.files).sort()) files[rel] = record.files[rel];
|
|
39741
|
+
const body = {
|
|
39742
|
+
org_id: record.org_id,
|
|
39743
|
+
space_id: record.space_id,
|
|
39744
|
+
type_id: record.type_id,
|
|
39745
|
+
abbreviation: record.abbreviation,
|
|
39746
|
+
version: record.version,
|
|
39747
|
+
files
|
|
39748
|
+
};
|
|
39749
|
+
const tmp = path45.join(root, `${TYPE_FOLDER_MARKER}.tmp`);
|
|
39750
|
+
if (!writeFileNoFollow(root, tmp, Buffer.from(`${JSON.stringify(body, null, 2)}
|
|
39751
|
+
`, "utf-8"))) throw symlinkRefusal(tmp, "file");
|
|
39752
|
+
fs33.chmodSync(tmp, 420);
|
|
39753
|
+
fs33.renameSync(tmp, path45.join(root, TYPE_FOLDER_MARKER));
|
|
39754
|
+
}
|
|
39755
|
+
function findTypeFolder(from) {
|
|
39756
|
+
let dir = path45.resolve(from);
|
|
39757
|
+
for (; ; ) {
|
|
39758
|
+
try {
|
|
39759
|
+
dir = fs33.realpathSync(dir);
|
|
39760
|
+
break;
|
|
39761
|
+
} catch {
|
|
39762
|
+
const parent = path45.dirname(dir);
|
|
39763
|
+
if (parent === dir) return null;
|
|
39764
|
+
dir = parent;
|
|
39765
|
+
}
|
|
39766
|
+
}
|
|
39767
|
+
for (; ; ) {
|
|
39768
|
+
const record = readTypeFolderRecord(dir);
|
|
39769
|
+
if (record) return { root: dir, record };
|
|
39770
|
+
const parent = path45.dirname(dir);
|
|
39771
|
+
if (parent === dir) return null;
|
|
39772
|
+
dir = parent;
|
|
39773
|
+
}
|
|
39774
|
+
}
|
|
39775
|
+
function linkRefusal(rel) {
|
|
39776
|
+
return expected(
|
|
39777
|
+
`${safe(rel)} is a symlink, or not a regular file or folder. The CLI never follows one in a type folder: replace it with the file or folder itself, or move it out of the folder.`
|
|
39778
|
+
);
|
|
39779
|
+
}
|
|
39780
|
+
function ownRefusal(rel, problem) {
|
|
39781
|
+
return expected(`Refused ${safe(rel)}: ${problem}. A type folder is read and written only in folders and files you own, never in one every user can write to.`);
|
|
39782
|
+
}
|
|
39783
|
+
function scanTypeFolder(root) {
|
|
39784
|
+
requireOwn(root);
|
|
39785
|
+
const files = /* @__PURE__ */ new Map();
|
|
39786
|
+
const read = (abs, rel) => {
|
|
39787
|
+
const bytes = readFileNoFollow(root, abs);
|
|
39788
|
+
if (!bytes) throw linkRefusal(rel);
|
|
39789
|
+
return bytes;
|
|
39790
|
+
};
|
|
39791
|
+
const walk = (abs, rel) => {
|
|
39792
|
+
for (const name of fs33.readdirSync(abs).sort()) {
|
|
39793
|
+
if (name.startsWith(".")) continue;
|
|
39794
|
+
const childAbs = path45.join(abs, name);
|
|
39795
|
+
const childRel = `${rel}/${name}`;
|
|
39796
|
+
const st = fs33.lstatSync(childAbs);
|
|
39797
|
+
if (!st.isDirectory() && !st.isFile()) throw linkRefusal(childRel);
|
|
39798
|
+
const problem = ownProblem(st);
|
|
39799
|
+
if (problem) throw ownRefusal(childRel, problem);
|
|
39800
|
+
if (st.isDirectory()) walk(childAbs, childRel);
|
|
39801
|
+
else files.set(childRel, read(childAbs, childRel));
|
|
39802
|
+
}
|
|
39803
|
+
};
|
|
39804
|
+
const top = new Set(fs33.readdirSync(root));
|
|
39805
|
+
let typeFile = null;
|
|
39806
|
+
if (top.has(TYPE_FILE)) {
|
|
39807
|
+
const st = fs33.lstatSync(path45.join(root, TYPE_FILE));
|
|
39808
|
+
if (!st.isFile()) throw linkRefusal(TYPE_FILE);
|
|
39809
|
+
const problem = ownProblem(st);
|
|
39810
|
+
if (problem) throw ownRefusal(TYPE_FILE, problem);
|
|
39811
|
+
typeFile = read(path45.join(root, TYPE_FILE), TYPE_FILE);
|
|
39812
|
+
}
|
|
39813
|
+
for (const folder of CASE_PACKAGE_FOLDERS) {
|
|
39814
|
+
if (!top.has(folder)) continue;
|
|
39815
|
+
const abs = path45.join(root, folder);
|
|
39816
|
+
const st = fs33.lstatSync(abs);
|
|
39817
|
+
if (!st.isDirectory()) throw linkRefusal(folder);
|
|
39818
|
+
const problem = ownProblem(st);
|
|
39819
|
+
if (problem) throw ownRefusal(folder, problem);
|
|
39820
|
+
walk(abs, folder);
|
|
39821
|
+
}
|
|
39822
|
+
return { typeFile, files: new Map([...files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) };
|
|
39823
|
+
}
|
|
39824
|
+
function scanShas(scan) {
|
|
39825
|
+
const out = /* @__PURE__ */ new Map();
|
|
39826
|
+
if (scan.typeFile) out.set(TYPE_FILE, computeHash(scan.typeFile));
|
|
39827
|
+
for (const [rel, bytes] of scan.files) out.set(rel, computeHash(bytes));
|
|
39828
|
+
return out;
|
|
39829
|
+
}
|
|
39830
|
+
function localChanges(record, scan) {
|
|
39831
|
+
const now = scanShas(scan);
|
|
39832
|
+
const paths = /* @__PURE__ */ new Set([...Object.keys(record.files), ...now.keys()]);
|
|
39833
|
+
return [...paths].filter((rel) => record.files[rel] !== now.get(rel)).sort();
|
|
39834
|
+
}
|
|
39835
|
+
var TYPE_FOLDER_MARKER, TYPE_FILE, safe, PACKAGE_PATH_REASONS, NO_PHASES;
|
|
39836
|
+
var init_case_type_folder = __esm({
|
|
39837
|
+
"src/cases/case-type-folder.ts"() {
|
|
39838
|
+
"use strict";
|
|
39839
|
+
init_case_type_packages();
|
|
39840
|
+
init_case_files();
|
|
39841
|
+
init_case_types();
|
|
39842
|
+
init_expected();
|
|
39843
|
+
init_fs_safety();
|
|
39844
|
+
init_resource_files();
|
|
39845
|
+
init_terminal_output();
|
|
39846
|
+
init_case_local_files();
|
|
39847
|
+
TYPE_FOLDER_MARKER = ".wayai-case-type.json";
|
|
39848
|
+
TYPE_FILE = "type.json";
|
|
39849
|
+
safe = (text5) => sanitizeTerminalText(text5);
|
|
39850
|
+
PACKAGE_PATH_REASONS = /* @__PURE__ */ new Set([
|
|
39851
|
+
"package_not_tar",
|
|
39852
|
+
"package_entry_not_file",
|
|
39853
|
+
"package_too_many_files",
|
|
39854
|
+
"package_path_invalid",
|
|
39855
|
+
"package_path_repeated",
|
|
39856
|
+
"package_path_unexpected"
|
|
39857
|
+
]);
|
|
39858
|
+
NO_PHASES = { type_party_roles: [], type_outcomes: [], type_phases: [], attributes: { type: "object" } };
|
|
39859
|
+
}
|
|
39860
|
+
});
|
|
39861
|
+
|
|
39862
|
+
// src/cases/case-package.ts
|
|
39863
|
+
import * as fs34 from "fs";
|
|
39864
|
+
import * as path46 from "path";
|
|
39865
|
+
function isManifestFile(v) {
|
|
39866
|
+
return isObject(v) && typeof v.path === "string" && isCasePackagePath(v.path) && typeof v.sha === "string" && CASE_FILE_SHA_PATTERN.test(v.sha) && typeof v.size === "number" && typeof v.image === "boolean" && typeof v.confidential === "boolean" && STATUSES.includes(v.status);
|
|
39867
|
+
}
|
|
39868
|
+
function isManifest(v) {
|
|
39869
|
+
return isObject(v) && typeof v.package_id === "string" && typeof v.version === "number" && typeof v.revision === "number" && typeof v.published_at === "string" && typeof v.confidential === "boolean" && Array.isArray(v.files) && v.files.every(isManifestFile);
|
|
39870
|
+
}
|
|
39871
|
+
function readManifest(root, mirror) {
|
|
39872
|
+
const file = path46.join(mirror, PACKAGE_MANIFEST_FILE);
|
|
39873
|
+
requireOwn(file);
|
|
39874
|
+
const text5 = readRealFileOrThrow(root, file);
|
|
39875
|
+
if (text5 === null) return void 0;
|
|
39876
|
+
let parsed;
|
|
39877
|
+
try {
|
|
39878
|
+
parsed = JSON.parse(text5);
|
|
39879
|
+
} catch {
|
|
39880
|
+
return void 0;
|
|
39881
|
+
}
|
|
39882
|
+
if (!isObject(parsed) || !(parsed.package === null || isManifest(parsed.package))) return void 0;
|
|
39883
|
+
return parsed.package;
|
|
39884
|
+
}
|
|
39885
|
+
function heldReader(root, mirror) {
|
|
39886
|
+
const cache = /* @__PURE__ */ new Map();
|
|
39887
|
+
return (rel) => {
|
|
39888
|
+
if (!cache.has(rel)) {
|
|
39889
|
+
const bytes = readFileNoFollow(root, path46.join(mirror, CASE_PACKAGE_DIR, ...rel.split("/")));
|
|
39890
|
+
cache.set(rel, bytes === null ? null : { bytes, sha: computeHash(bytes) });
|
|
39891
|
+
}
|
|
39892
|
+
return cache.get(rel);
|
|
39893
|
+
};
|
|
39894
|
+
}
|
|
39895
|
+
function assertDeliverablePackagePaths(paths) {
|
|
39896
|
+
if (paths.length > CASE_PACKAGE_LIMITS.files) {
|
|
39897
|
+
throw expected(`The case's package lists ${paths.length} files, more than a package holds (${CASE_PACKAGE_LIMITS.files}), so the mirror was not written.`);
|
|
39898
|
+
}
|
|
39899
|
+
const problems2 = [];
|
|
39900
|
+
const seen = /* @__PURE__ */ new Set();
|
|
39901
|
+
for (const rel of paths) {
|
|
39902
|
+
if (!isCasePackagePath(rel)) problems2.push(`${JSON.stringify(safe2(rel))}: a package holds no such path`);
|
|
39903
|
+
else if (seen.has(rel)) problems2.push(`${JSON.stringify(safe2(rel))}: listed twice`);
|
|
39904
|
+
seen.add(rel);
|
|
39905
|
+
}
|
|
39906
|
+
problems2.push(...packagePathCollisions([...seen].filter(isCasePackagePath)));
|
|
39907
|
+
if (problems2.length > 0) {
|
|
39908
|
+
throw expected(`The case's package lists paths this clone will not write, so the mirror was not written:
|
|
39909
|
+
${[...new Set(problems2)].join("\n ")}`);
|
|
39910
|
+
}
|
|
39911
|
+
}
|
|
39912
|
+
async function readPackageDelivery(reads, root, mirror, confidential) {
|
|
39913
|
+
const held = heldReader(root, mirror);
|
|
39914
|
+
const previous = readManifest(root, mirror);
|
|
39915
|
+
const changed = (previous?.files ?? []).filter((f) => f.status === "written" && (confidential || !f.confidential) && held(f.path)?.sha !== f.sha).map((f) => f.path).sort(toolsFirst);
|
|
39916
|
+
const listed3 = await reads.list();
|
|
39917
|
+
const files = listed3 ? confidential ? listed3.files : listed3.files.filter((f) => !f.confidential) : [];
|
|
39918
|
+
assertDeliverablePackagePaths(files.map((f) => f.path));
|
|
39919
|
+
const read = await Promise.all(files.map(async (f) => {
|
|
39920
|
+
const entry = { path: f.path, sha: f.sha, size: f.size, image: f.image, confidential: f.confidential };
|
|
39921
|
+
const here = held(f.path);
|
|
39922
|
+
if (here !== null && here.sha === f.sha && here.bytes.byteLength === f.size) return { file: { ...entry, status: "written" }, data: here.bytes };
|
|
39923
|
+
const bytes = await reads.content(f.path);
|
|
39924
|
+
if (bytes === null) return { file: { ...entry, status: "not_found" }, data: null };
|
|
39925
|
+
if (bytes.byteLength !== f.size || computeHash(bytes) !== f.sha) return { file: { ...entry, status: "hash_mismatch" }, data: null };
|
|
39926
|
+
return { file: { ...entry, status: "written" }, data: Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength) };
|
|
39927
|
+
}));
|
|
39928
|
+
const status = new Map(read.map(({ file }) => [file.path, file.status]));
|
|
39929
|
+
const changedHere = changed.map((rel) => {
|
|
39930
|
+
const what = status.get(rel) === "written" ? "rewritten as published" : status.has(rel) ? "removed, as this run did not write it (below)" : "removed: the package no longer holds it";
|
|
39931
|
+
return `${CASE_PACKAGE_DIR}/${safe2(rel)} was changed here since the last pull: ${what}.` + (isTool(rel) ? " It is a tool: anything it produced while changed is not the published tool's." : "");
|
|
39932
|
+
});
|
|
39933
|
+
const unwritten = read.map((r) => r.file).filter((f) => f.status !== "written").sort((a, b) => toolsFirst(a.path, b.path)).map((f) => f.status === "hash_mismatch" ? `${CASE_PACKAGE_DIR}/${safe2(f.path)}: not written, its bytes do not hash to the SHA-256 the package lists for it.` : `${CASE_PACKAGE_DIR}/${safe2(f.path)}: not written, the space no longer serves it to this authorization; pull again.`);
|
|
39934
|
+
return {
|
|
39935
|
+
manifest: listed3 && {
|
|
39936
|
+
package_id: listed3.package_id,
|
|
39937
|
+
version: listed3.version,
|
|
39938
|
+
revision: listed3.revision,
|
|
39939
|
+
published_at: listed3.published_at,
|
|
39940
|
+
confidential,
|
|
39941
|
+
files: read.map((r) => r.file)
|
|
39942
|
+
},
|
|
39943
|
+
files: read.flatMap(({ file, data }) => data === null ? [] : [{ name: `${CASE_PACKAGE_DIR}/${file.path}`, data, mode: PACKAGE_FILE_MODE }]),
|
|
39944
|
+
unwritten,
|
|
39945
|
+
changedHere
|
|
39946
|
+
};
|
|
39947
|
+
}
|
|
39948
|
+
function entriesUnder(dir) {
|
|
39949
|
+
const out = [];
|
|
39950
|
+
const walk = (abs, rel) => {
|
|
39951
|
+
let names;
|
|
39952
|
+
try {
|
|
39953
|
+
names = fs34.readdirSync(abs);
|
|
39954
|
+
} catch {
|
|
39955
|
+
return;
|
|
39956
|
+
}
|
|
39957
|
+
for (const name of names.sort()) {
|
|
39958
|
+
if (name.startsWith(".")) continue;
|
|
39959
|
+
const child = path46.join(abs, name);
|
|
39960
|
+
const childRel = rel === null ? name : `${rel}/${name}`;
|
|
39961
|
+
if (fs34.lstatSync(child).isDirectory()) walk(child, childRel);
|
|
39962
|
+
else out.push(childRel);
|
|
39963
|
+
}
|
|
39964
|
+
};
|
|
39965
|
+
try {
|
|
39966
|
+
if (fs34.lstatSync(dir).isDirectory()) walk(dir, null);
|
|
39967
|
+
} catch {
|
|
39968
|
+
}
|
|
39969
|
+
return out;
|
|
39970
|
+
}
|
|
39971
|
+
function checkPackageFolder(root, mirror) {
|
|
39972
|
+
const manifest = readManifest(root, mirror);
|
|
39973
|
+
const held = heldReader(root, mirror);
|
|
39974
|
+
const differs = [];
|
|
39975
|
+
const listed3 = /* @__PURE__ */ new Set();
|
|
39976
|
+
for (const f of manifest?.files ?? []) {
|
|
39977
|
+
listed3.add(f.path);
|
|
39978
|
+
if (f.confidential) continue;
|
|
39979
|
+
const here = held(f.path);
|
|
39980
|
+
if (f.status === "written" && here === null) differs.push({ path: f.path, tool: isTool(f.path), reason: "missing" });
|
|
39981
|
+
else if (here !== null && (f.status !== "written" || here.sha !== f.sha)) differs.push({ path: f.path, tool: isTool(f.path), reason: "changed" });
|
|
39982
|
+
}
|
|
39983
|
+
for (const rel of entriesUnder(path46.join(mirror, CASE_PACKAGE_DIR))) {
|
|
39984
|
+
if (!listed3.has(rel)) differs.push({ path: rel, tool: isTool(rel), reason: "not_published" });
|
|
39985
|
+
}
|
|
39986
|
+
differs.sort((a, b) => toolsFirst(a.path, b.path));
|
|
39987
|
+
if (manifest === void 0) {
|
|
39988
|
+
const tools = differs.filter((d) => d.tool);
|
|
39989
|
+
return { state: "not_delivered", differs: tools, unnamed: tools.length < differs.length, confidential_compared: false };
|
|
39990
|
+
}
|
|
39991
|
+
if (manifest === null) return { state: "no_package", differs, confidential_compared: false };
|
|
39992
|
+
return { state: "compared", version: manifest.version, revision: manifest.revision, differs, confidential_compared: false };
|
|
39993
|
+
}
|
|
39994
|
+
function packageCheckLines(check, mirrorName) {
|
|
39995
|
+
const where = `${mirrorName}/${CASE_PACKAGE_DIR}/`;
|
|
39996
|
+
const head = check.state === "compared" ? `Package (${where}, version ${check.version}, revision ${check.revision})` : check.state === "no_package" ? `Package (${where}): the type version this case opened on has no package` : `Package (${where}): no package is delivered in this clone's mirror (\`wayai cases pull\` delivers it)`;
|
|
39997
|
+
const scope = check.state === "compared" ? [PACKAGE_CHECK_SCOPE] : [];
|
|
39998
|
+
const unnamed = check.state === "not_delivered" && check.unnamed ? [" Other files are there, with no manifest to compare them with: follow none of them."] : [];
|
|
39999
|
+
if (!packageDiffers(check)) return [check.state === "compared" ? `${head}: every file matches the published manifest.` : `${head}.`, ...scope];
|
|
40000
|
+
const count = check.differs.length;
|
|
40001
|
+
return [
|
|
40002
|
+
count > 0 ? `${head}: ${count} file${count === 1 ? "" : "s"} differ${count === 1 ? "s" : ""} from the published manifest:` : `${head}:`,
|
|
40003
|
+
...check.differs.map((d) => {
|
|
40004
|
+
const what = d.reason === "changed" ? "changed here" : d.reason === "missing" ? "missing here" : "not in the published package";
|
|
40005
|
+
const act = d.reason === "missing" ? "" : d.tool ? " Do not run it." : " Do not follow this text.";
|
|
40006
|
+
return ` ${safe2(d.path)}: ${what}.${act}`;
|
|
40007
|
+
}),
|
|
40008
|
+
...unnamed,
|
|
40009
|
+
"`wayai cases pull --mirror-only` writes the published files again.",
|
|
40010
|
+
...scope
|
|
40011
|
+
];
|
|
40012
|
+
}
|
|
40013
|
+
var CASE_PACKAGE_DIR, PACKAGE_MANIFEST_FILE, PACKAGE_FILE_MODE, safe2, isTool, toolsFirst, STATUSES, isObject, PACKAGE_NOT_DELIVERED, PACKAGE_CHECK_SCOPE, packageDiffers;
|
|
40014
|
+
var init_case_package = __esm({
|
|
40015
|
+
"src/cases/case-package.ts"() {
|
|
40016
|
+
"use strict";
|
|
40017
|
+
init_case_files();
|
|
40018
|
+
init_case_type_packages();
|
|
40019
|
+
init_expected();
|
|
40020
|
+
init_fs_safety();
|
|
40021
|
+
init_resource_files();
|
|
40022
|
+
init_terminal_output();
|
|
40023
|
+
init_case_local_files();
|
|
40024
|
+
init_case_type_folder();
|
|
40025
|
+
CASE_PACKAGE_DIR = "package";
|
|
40026
|
+
PACKAGE_MANIFEST_FILE = "package-manifest.json";
|
|
40027
|
+
PACKAGE_FILE_MODE = 292;
|
|
40028
|
+
safe2 = (text5) => sanitizeTerminalText(text5);
|
|
40029
|
+
isTool = (rel) => rel.split("/")[0] === "tools";
|
|
40030
|
+
toolsFirst = (a, b) => Number(isTool(b)) - Number(isTool(a)) || (a < b ? -1 : a > b ? 1 : 0);
|
|
40031
|
+
STATUSES = ["written", "hash_mismatch", "not_found"];
|
|
40032
|
+
isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
40033
|
+
PACKAGE_NOT_DELIVERED = { state: "not_delivered", differs: [], unnamed: false, confidential_compared: false };
|
|
40034
|
+
PACKAGE_CHECK_SCOPE = "Confidential files are not compared.";
|
|
40035
|
+
packageDiffers = (check) => check.differs.length > 0 || check.state === "not_delivered" && check.unnamed;
|
|
40036
|
+
}
|
|
40037
|
+
});
|
|
40038
|
+
|
|
40039
|
+
// src/cases/case-mirror.ts
|
|
40040
|
+
import * as crypto4 from "crypto";
|
|
40041
|
+
import * as fs35 from "fs";
|
|
40042
|
+
import * as os4 from "os";
|
|
40043
|
+
import * as path47 from "path";
|
|
40044
|
+
function shownEntries(revision, confidential) {
|
|
40045
|
+
return confidential ? revision.entries : revision.entries.filter((e) => !e.confidential && !isConfPath(e.path));
|
|
40046
|
+
}
|
|
40047
|
+
function isBaseline(b) {
|
|
40048
|
+
return isObject2(b) && typeof b.at === "string" && typeof b.confidential === "boolean" && (b.revision_at === null || typeof b.revision_at === "string") && (b.status === null || typeof b.status === "string") && isStringMap(b.phases) && isStringMap(b.tasks) && isStringMap(b.groups) && isDeliveries(b.deliveries);
|
|
40049
|
+
}
|
|
40050
|
+
function isMirrorRecord(v) {
|
|
40051
|
+
return isObject2(v) && typeof v.org_id === "string" && typeof v.space_id === "string" && typeof v.code === "string" && (v.last_pull === null || isBaseline(v.last_pull));
|
|
40052
|
+
}
|
|
40053
|
+
function mirrorFolder(root) {
|
|
40054
|
+
const dir = path47.join(root, CASE_MIRROR_DIR);
|
|
40055
|
+
let st;
|
|
40056
|
+
try {
|
|
40057
|
+
st = fs35.lstatSync(dir);
|
|
40058
|
+
} catch {
|
|
40059
|
+
return null;
|
|
40060
|
+
}
|
|
40061
|
+
if (!st.isDirectory()) {
|
|
40062
|
+
throw expected(`${safe3(dir)} is a symlink or not a folder. It is the case's mirror, which the CLI writes: move it aside, then pull again.`);
|
|
40063
|
+
}
|
|
40064
|
+
requireOwn(dir);
|
|
40065
|
+
return dir;
|
|
40066
|
+
}
|
|
40067
|
+
function readBaseline(root, detail, record) {
|
|
40068
|
+
const dir = mirrorFolder(root);
|
|
40069
|
+
if (!dir) return null;
|
|
40070
|
+
const file = path47.join(dir, RECORD_FILE);
|
|
40071
|
+
requireOwn(file);
|
|
40072
|
+
const text5 = readRealFileOrThrow(root, file);
|
|
40073
|
+
if (text5 === null) return null;
|
|
40074
|
+
let parsed;
|
|
40075
|
+
try {
|
|
40076
|
+
parsed = JSON.parse(text5);
|
|
40077
|
+
} catch {
|
|
40078
|
+
return null;
|
|
40079
|
+
}
|
|
40080
|
+
if (!isMirrorRecord(parsed)) return null;
|
|
40081
|
+
if (parsed.org_id !== record.org_id || parsed.space_id !== record.space_id || parsed.code !== detail.code) return null;
|
|
40082
|
+
return parsed.last_pull;
|
|
40083
|
+
}
|
|
40084
|
+
async function readAgenda(calls, phaseId) {
|
|
40085
|
+
const { api, connection } = calls.session;
|
|
40086
|
+
const groups = [];
|
|
40087
|
+
let cursor;
|
|
40088
|
+
for (let page = 0; page < AGENDA_PAGES_READ; page++) {
|
|
40089
|
+
const { groups: got, next_cursor } = (await calls.run(() => api.getCaseAgenda(connection, phaseId, cursor))).data;
|
|
40090
|
+
groups.push(...got);
|
|
40091
|
+
if (!next_cursor) return { groups, more: false };
|
|
40092
|
+
cursor = next_cursor;
|
|
40093
|
+
}
|
|
40094
|
+
return { groups, more: true };
|
|
40095
|
+
}
|
|
40096
|
+
async function readInputTexts(calls, folder, work) {
|
|
40097
|
+
const { api, connection } = calls.session;
|
|
40098
|
+
const linked = work.inputs.filter((input) => input.link?.readable === true);
|
|
40099
|
+
const read = await Promise.all(linked.map(async (input) => {
|
|
40100
|
+
const view = (await calls.run(() => api.getCaseInputLink(connection, input.id))).data;
|
|
40101
|
+
if (!view?.readable) return null;
|
|
40102
|
+
const answered = await calls.run(() => notFound(api.getCaseCollectionContent(connection, view.document_id, { part: "text", version_id: view.version_id })));
|
|
40103
|
+
const passages = view.passages.filter((p) => p.version_id === view.version_id);
|
|
40104
|
+
const base = { input_id: input.id, key: input.key, name: input.name, document_id: view.document_id, version_id: view.version_id };
|
|
40105
|
+
const unmatched = passages.map((p) => ({ passage_id: p.passage_id, line_start: p.line_start, line_end: p.line_end, passage_sha: p.passage_sha, matches: false }));
|
|
40106
|
+
if (!answered) return { text: { ...base, status: "no_text", file: null, sha: null, passages: unmatched }, data: null };
|
|
40107
|
+
if (answered.sha === null || computeHash(answered.bytes) !== answered.sha) {
|
|
40108
|
+
return { text: { ...base, status: "hash_mismatch", file: null, sha: answered.sha, passages: unmatched }, data: null };
|
|
40109
|
+
}
|
|
40110
|
+
const lines = unmatched.length ? casePassageLines(new TextDecoder("utf-8").decode(answered.bytes)) : [];
|
|
40111
|
+
const file = `${INPUTS_DIR}/${folder}/${segment(input.key, CASE_INPUT_KEY_PATTERN, input.id)}.md`;
|
|
40112
|
+
return {
|
|
40113
|
+
text: {
|
|
40114
|
+
...base,
|
|
40115
|
+
status: "written",
|
|
40116
|
+
file,
|
|
40117
|
+
sha: answered.sha,
|
|
40118
|
+
passages: unmatched.map((p) => {
|
|
40119
|
+
const inRange = p.line_start >= 1 && p.line_end >= p.line_start && p.line_end <= lines.length;
|
|
40120
|
+
const cited = Buffer.from(lines.slice(p.line_start - 1, p.line_end).join("\n"), "utf-8");
|
|
40121
|
+
return { ...p, matches: inRange && computeHash(cited) === p.passage_sha };
|
|
40122
|
+
})
|
|
40123
|
+
},
|
|
40124
|
+
data: Buffer.from(answered.bytes.buffer, answered.bytes.byteOffset, answered.bytes.byteLength)
|
|
40125
|
+
};
|
|
40126
|
+
}));
|
|
40127
|
+
return read.filter((r) => r !== null);
|
|
40128
|
+
}
|
|
40129
|
+
async function readWork(calls, detail, confidential) {
|
|
40130
|
+
const { api, connection } = calls.session;
|
|
40131
|
+
const state = (await calls.run(() => api.getCaseState(connection))).data;
|
|
40132
|
+
if (state.view !== "work") return { state, phases: [], approved: [] };
|
|
40133
|
+
const folders = new Map(detail.phases.map((p) => [p.phase_id, p.folder]));
|
|
40134
|
+
const underWay = state.state.phases.filter((p) => p.status === "in_progress").map((p) => p.phase_id);
|
|
40135
|
+
const [phases, approved] = await Promise.all([
|
|
40136
|
+
Promise.all(underWay.map(async (phaseId) => {
|
|
40137
|
+
const folder = folders.get(phaseId) ?? "";
|
|
40138
|
+
const [{ work, texts }, agenda, delivery] = await Promise.all([
|
|
40139
|
+
calls.run(() => api.getCasePhaseWork(connection, phaseId)).then(async ({ data }) => ({
|
|
40140
|
+
work: data,
|
|
40141
|
+
texts: await readInputTexts(calls, segment(folder, CASE_PHASE_FOLDER_PATTERN, phaseId), data)
|
|
40142
|
+
})),
|
|
40143
|
+
readAgenda(calls, phaseId),
|
|
40144
|
+
calls.run(() => api.getCaseDelivery(connection, phaseId))
|
|
40145
|
+
]);
|
|
40146
|
+
return { phase_id: phaseId, folder, work, groups: agenda.groups, more_groups: agenda.more, delivery: delivery.data, texts };
|
|
40147
|
+
})),
|
|
40148
|
+
calls.run(() => api.listCaseApprovedDecisions(connection, confidential))
|
|
40149
|
+
]);
|
|
40150
|
+
return { state, phases, approved: approved.data };
|
|
40151
|
+
}
|
|
40152
|
+
async function revisionsSince(calls, after, confidential) {
|
|
40153
|
+
const { api, connection } = calls.session;
|
|
40154
|
+
const out = [];
|
|
40155
|
+
let newest = after ?? null;
|
|
40156
|
+
let cursor;
|
|
40157
|
+
const pages = after === void 0 ? 1 : SUMMARY_REVISION_PAGES;
|
|
40158
|
+
for (let page = 0; page < pages; page++) {
|
|
40159
|
+
const { revisions, next_cursor } = (await calls.run(() => api.listCaseRevisions(connection, { cursor, limit: CASE_REVISIONS_PAGE_MAX }))).data;
|
|
40160
|
+
for (const revision of revisions) {
|
|
40161
|
+
if (after !== void 0 && after !== null && revision.created_at <= after) return { revisions: out, more: false, newest_at: newest };
|
|
40162
|
+
const entries = shownEntries(revision, confidential);
|
|
40163
|
+
if (entries.length === 0) continue;
|
|
40164
|
+
if (newest === null || revision.created_at > newest) newest = revision.created_at;
|
|
40165
|
+
if (after !== void 0) out.push({ ...revision, entries });
|
|
40166
|
+
}
|
|
40167
|
+
if (!next_cursor) return { revisions: out, more: false, newest_at: newest };
|
|
40168
|
+
cursor = next_cursor;
|
|
40169
|
+
}
|
|
40170
|
+
return { revisions: out, more: after !== void 0, newest_at: newest };
|
|
40171
|
+
}
|
|
40172
|
+
function snapshotOf(work) {
|
|
40173
|
+
if (!work) return { status: null, phases: {}, tasks: {}, groups: {}, deliveries: {} };
|
|
40174
|
+
if (work.state.view === "phases") {
|
|
40175
|
+
return { status: work.state.status, phases: Object.fromEntries(work.state.phases.map((p) => [p.phase_id, p.status])), tasks: {}, groups: {}, deliveries: {} };
|
|
40176
|
+
}
|
|
40177
|
+
const { state } = work.state;
|
|
40178
|
+
return {
|
|
40179
|
+
status: state.status,
|
|
40180
|
+
phases: Object.fromEntries(state.phases.map((p) => [p.phase_id, p.status])),
|
|
40181
|
+
tasks: Object.fromEntries(state.tasks.map((t) => [t.case_task_id, t.status])),
|
|
40182
|
+
groups: Object.fromEntries(state.agenda_groups.map((g) => [g.agenda_group_id, g.status])),
|
|
40183
|
+
deliveries: Object.fromEntries(work.phases.map((p) => [p.phase_id, p.delivery ? { submission_id: p.delivery.submission_id, state: p.delivery.state } : null]))
|
|
40184
|
+
};
|
|
40185
|
+
}
|
|
40186
|
+
function statusSections(detail, work, before, now) {
|
|
40187
|
+
const phase = new Map(detail.phases.map((p) => [p.phase_id, `${one(p.folder)} (${one(p.name)})`]));
|
|
40188
|
+
const task = new Map((detail.tasks ?? []).map((t) => [t.case_task_id, `${one(t.name)} [${t.case_task_id}]`]));
|
|
40189
|
+
const group = new Map(work.phases.flatMap((p) => p.groups.map((g) => [g.agenda_group_id, `${one(g.code)} (${one(g.name)})`])));
|
|
40190
|
+
const changes = (prev, next, name, added) => Object.entries(next).flatMap(([id, status]) => {
|
|
40191
|
+
const was = prev[id];
|
|
40192
|
+
if (was === void 0) return added ? [`${name(id)}: new, ${words(status)}`] : [];
|
|
40193
|
+
return was === status ? [] : [`${name(id)}: ${words(was)} \u2192 ${words(status)}`];
|
|
40194
|
+
});
|
|
40195
|
+
const sections = [];
|
|
40196
|
+
if (before.status !== null && now.status !== null && before.status !== now.status) {
|
|
40197
|
+
sections.push({ title: "The case", lines: [`${words(before.status)} \u2192 ${words(now.status)}`] });
|
|
40198
|
+
}
|
|
40199
|
+
sections.push({ title: "Phases", lines: changes(before.phases, now.phases, (id) => phase.get(id) ?? "a phase", false) });
|
|
40200
|
+
sections.push({ title: "Tasks", lines: changes(before.tasks, now.tasks, (id) => task.get(id) ?? `a task [${id}]`, true) });
|
|
40201
|
+
sections.push({ title: "Agenda groups", lines: changes(before.groups, now.groups, (id) => group.get(id) ?? "an agenda group of a phase not under way", false) });
|
|
40202
|
+
const deliveries = work.phases.flatMap((p) => {
|
|
40203
|
+
if (!(p.phase_id in before.deliveries) || !p.delivery) return [];
|
|
40204
|
+
const was = before.deliveries[p.phase_id];
|
|
40205
|
+
if (was?.submission_id === p.delivery.submission_id && was.state === p.delivery.state) return [];
|
|
40206
|
+
const change = was?.submission_id === p.delivery.submission_id ? `its submission is now ${words(p.delivery.state)}` : `a new submission, ${words(p.delivery.state)}`;
|
|
40207
|
+
return [`${phase.get(p.phase_id) ?? "a phase"}: ${change}`];
|
|
40208
|
+
});
|
|
40209
|
+
sections.push({ title: "Deliveries", lines: deliveries });
|
|
40210
|
+
return sections;
|
|
40211
|
+
}
|
|
40212
|
+
function filesSection(input) {
|
|
40213
|
+
const now = new Map(input.files.filter((f) => input.inRun(f.path)).map((f) => [f.path, f.sha]));
|
|
40214
|
+
const before = new Map(Object.entries(input.record.files).filter(([rel]) => input.inRun(rel)).map(([rel, f]) => [rel, f.sha]));
|
|
40215
|
+
const lines = [];
|
|
40216
|
+
for (const [rel, sha] of now) {
|
|
40217
|
+
if (!before.has(rel)) lines.push(`+ ${safe3(rel)}`);
|
|
40218
|
+
else if (before.get(rel) !== sha) lines.push(`~ ${safe3(rel)}`);
|
|
40219
|
+
}
|
|
40220
|
+
for (const rel of before.keys()) if (!now.has(rel)) lines.push(`- ${safe3(rel)} (removed, or no longer readable here)`);
|
|
40221
|
+
return { title: "Files on the case that differ from what this clone last pulled", lines: lines.sort((a, b) => a.slice(2) < b.slice(2) ? -1 : 1) };
|
|
40222
|
+
}
|
|
40223
|
+
function revisionsSection(since, hideMessages) {
|
|
40224
|
+
const lines = since.revisions.flatMap((r) => {
|
|
40225
|
+
const author = r.author?.display_name ? one(r.author.display_name) : "a person no longer named";
|
|
40226
|
+
const message = r.message !== null && !hideMessages ? `: ${one(r.message)}` : "";
|
|
40227
|
+
return [`revision ${r.revision_id}, ${r.created_at}, ${author} (${r.channel})${message}`, ...r.entries.map((e) => ` ${safe3(e.path)}${e.sha === null ? " (removed)" : ""}`)];
|
|
40228
|
+
});
|
|
40229
|
+
if (since.more) lines.push("\u2026 and older ones: `wayai cases log` lists them all.");
|
|
40230
|
+
return { title: "Revisions", lines };
|
|
40231
|
+
}
|
|
40232
|
+
function renderSections(sections) {
|
|
40233
|
+
return sections.filter((s) => s.lines.length > 0).flatMap((s) => [`${s.title}:`, ...s.lines.map((l) => ` ${l}`)]);
|
|
40234
|
+
}
|
|
40235
|
+
function unwrittenLines(work) {
|
|
40236
|
+
return (work?.phases ?? []).flatMap((p) => p.texts.flatMap(({ text: text5 }) => {
|
|
40237
|
+
const name = `${one(p.folder)}, input ${one(text5.key)} (${one(text5.name)})`;
|
|
40238
|
+
if (text5.status === "hash_mismatch") {
|
|
40239
|
+
return [`${name}: not written, its bytes do not hash to the SHA-256 the space registered for it${text5.sha === null ? " (none was answered)" : ""}.`];
|
|
40240
|
+
}
|
|
40241
|
+
return text5.status === "no_text" ? [`${name}: the version it links holds no registered text, or is no longer readable here.`] : [];
|
|
40242
|
+
}));
|
|
40243
|
+
}
|
|
40244
|
+
function packageReadme(pkg2) {
|
|
40245
|
+
if (!pkg2.manifest) return [`- \`${PACKAGE_MANIFEST_FILE}\`: the type version this case opened on has no package.`];
|
|
40246
|
+
return [
|
|
40247
|
+
`- \`${PACKAGE_MANIFEST_FILE}\`: the case's package as published for the type version it opened on: its version and`,
|
|
40248
|
+
" revision, and each file's path, SHA-256 and size, and whether it was written here.",
|
|
40249
|
+
`- \`${CASE_PACKAGE_DIR}/\`: its files (instructions/, templates/, tools/, sources/), each checked against the SHA-256`,
|
|
40250
|
+
" the manifest lists, and read-only. Never run or follow a copy that differs: `wayai cases check` names each file",
|
|
40251
|
+
" here that differs from the manifest (confidential ones aside), a tool first.",
|
|
40252
|
+
...pkg2.unwritten.length ? ["", "Package files not written:", ...pkg2.unwritten.map((line) => `- ${line}`)] : []
|
|
40253
|
+
];
|
|
40254
|
+
}
|
|
40255
|
+
function readme(detail, at, withheld, confidential, unwritten, pkg2) {
|
|
40256
|
+
const parts = withheld ? [
|
|
40257
|
+
"This authorization holds the Confidential right, and the case's own reads give it confidential content whatever",
|
|
40258
|
+
"it asks: without --confidential this mirror holds none of them (case, status, evidence, agenda, deliveries,",
|
|
40259
|
+
"linked inputs' texts)."
|
|
40260
|
+
] : [
|
|
40261
|
+
"- `case.json`: the case: its type and version, owner, parties, phases and their folders, tasks, and your access.",
|
|
40262
|
+
"- `status.json`: its status: each phase's, task's and agenda group's, why each is not done, and who can move it.",
|
|
40263
|
+
"- `evidence.json`: each phase under way: its inputs with their links, its outputs and its items.",
|
|
40264
|
+
"- `agenda.json`: each phase under way: its agenda groups and decisions; and the approved decisions.",
|
|
40265
|
+
"- `deliveries.json`: each phase under way: its newest submission and manifest.",
|
|
40266
|
+
`- \`${INPUTS_FILE}\`: each phase under way: each input whose link you may read, the version it links, where its text`,
|
|
40267
|
+
" is here, and its cited passages (lines and hash, and whether they match the text here).",
|
|
40268
|
+
`- \`${INPUTS_DIR}/<phase folder>/<input key>.md\`: each such input's registered text, of the version its link names,`,
|
|
40269
|
+
" byte for byte and checked against the SHA-256 the space registered for it: line N here is the line N a citation",
|
|
40270
|
+
" names (each line ends at a line break).",
|
|
40271
|
+
...unwritten.length ? ["", "Linked inputs' texts not written:", ...unwritten.map((line) => `- ${line}`)] : []
|
|
40272
|
+
];
|
|
40273
|
+
return [
|
|
40274
|
+
`# Case ${safe3(detail.code)}: read-only mirror`,
|
|
40275
|
+
"",
|
|
40276
|
+
`Written ${at} by \`wayai cases clone\` or \`pull\`. Every pull rewrites this folder whole, and \`wayai cases push\` never sends`,
|
|
40277
|
+
"anything in it: an edit here is lost and never reaches the case.",
|
|
40278
|
+
"",
|
|
40279
|
+
`- \`${SUMMARY_FILE}\`: what changed on the case since your last pull.`,
|
|
40280
|
+
...parts,
|
|
40281
|
+
...packageReadme(pkg2),
|
|
40282
|
+
`- \`${CASE_MIRROR_HOOK_FILE}\`: the session-start hook. It refreshes this folder, never with --confidential.`,
|
|
40283
|
+
`- \`${RECORD_FILE}\`: what the next pull compares with.`,
|
|
40284
|
+
"",
|
|
40285
|
+
"Not here: the drafting checks (`wayai cases check --phase <folder>` reads them live).",
|
|
40286
|
+
...confidential ? [] : ["", MIRROR_CONFIDENTIAL_NOTICE],
|
|
40287
|
+
""
|
|
40288
|
+
].join("\n");
|
|
40289
|
+
}
|
|
40290
|
+
function lockOwnerStopped(text5) {
|
|
40291
|
+
const owner = text5 === null ? null : /^(\d+) (\S+) [0-9a-f]+$/.exec(text5) ?? null;
|
|
40292
|
+
if (!owner || owner[2] !== os4.hostname()) return false;
|
|
40293
|
+
try {
|
|
40294
|
+
process.kill(Number(owner[1]), 0);
|
|
40295
|
+
return false;
|
|
40296
|
+
} catch (err) {
|
|
40297
|
+
return err.code === "ESRCH";
|
|
40298
|
+
}
|
|
40299
|
+
}
|
|
40300
|
+
async function lockMirror(root) {
|
|
40301
|
+
const dir = path47.join(root, CASE_MIRROR_DIR);
|
|
40302
|
+
if (!mirrorFolder(root)) {
|
|
40303
|
+
try {
|
|
40304
|
+
fs35.mkdirSync(dir, { mode: CASE_FOLDER_MODE });
|
|
40305
|
+
fs35.chmodSync(dir, CASE_FOLDER_MODE);
|
|
40306
|
+
} catch (err) {
|
|
40307
|
+
if (err.code !== "EEXIST") throw err;
|
|
40308
|
+
}
|
|
40309
|
+
mirrorFolder(root);
|
|
40310
|
+
}
|
|
40311
|
+
const lock = path47.join(dir, LOCK_FILE);
|
|
40312
|
+
const mine = `${process.pid} ${os4.hostname()} ${crypto4.randomBytes(16).toString("hex")}`;
|
|
40313
|
+
const held = (file) => {
|
|
40314
|
+
try {
|
|
40315
|
+
return fs35.readFileSync(file, "utf-8");
|
|
40316
|
+
} catch {
|
|
40317
|
+
return null;
|
|
40318
|
+
}
|
|
40319
|
+
};
|
|
40320
|
+
const refusal2 = (err) => {
|
|
40321
|
+
const code2 = err.code;
|
|
40322
|
+
return code2 === "EACCES" || code2 === "EPERM" || code2 === "EROFS" ? expected(`The mirror's folder ${safe3(dir)} cannot be written (${code2}). Make it writable by you (it is the CLI's to write), then pull again.`) : err;
|
|
40323
|
+
};
|
|
40324
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
40325
|
+
for (; ; ) {
|
|
40326
|
+
try {
|
|
40327
|
+
const fd = fs35.openSync(lock, "wx", 420);
|
|
40328
|
+
try {
|
|
40329
|
+
fs35.writeFileSync(fd, mine);
|
|
40330
|
+
} finally {
|
|
40331
|
+
fs35.closeSync(fd);
|
|
40332
|
+
}
|
|
40333
|
+
return () => {
|
|
40334
|
+
if (held(lock) === mine) fs35.rmSync(lock, { force: true });
|
|
40335
|
+
};
|
|
40336
|
+
} catch (err) {
|
|
40337
|
+
if (err.code !== "EEXIST") throw refusal2(err);
|
|
40338
|
+
}
|
|
40339
|
+
const judged = held(lock);
|
|
40340
|
+
let age = 0;
|
|
40341
|
+
try {
|
|
40342
|
+
age = Date.now() - fs35.lstatSync(lock).mtimeMs;
|
|
40343
|
+
} catch (err) {
|
|
40344
|
+
if (err.code === "ENOENT") continue;
|
|
40345
|
+
throw refusal2(err);
|
|
40346
|
+
}
|
|
40347
|
+
if (judged !== null && (lockOwnerStopped(judged) || age > LOCK_STALE_MS)) {
|
|
40348
|
+
const aside = path47.join(dir, `${LOCK_FILE}.stale-${mine.split(" ")[2]}`);
|
|
40349
|
+
try {
|
|
40350
|
+
fs35.renameSync(lock, aside);
|
|
40351
|
+
} catch (err) {
|
|
40352
|
+
if (err.code === "ENOENT") continue;
|
|
40353
|
+
throw refusal2(err);
|
|
40354
|
+
}
|
|
40355
|
+
if (held(aside) !== judged) {
|
|
40356
|
+
try {
|
|
40357
|
+
fs35.linkSync(aside, lock);
|
|
40358
|
+
} catch {
|
|
40359
|
+
}
|
|
40360
|
+
}
|
|
40361
|
+
fs35.rmSync(aside, { force: true });
|
|
40362
|
+
continue;
|
|
40363
|
+
}
|
|
40364
|
+
if (Date.now() > deadline) {
|
|
40365
|
+
throw expected(`Another run has held the mirror at ${safe3(dir)} for ${Math.round(age / 1e3)} s. Pull again once it ends.`);
|
|
40366
|
+
}
|
|
40367
|
+
await new Promise((resolve18) => setTimeout(resolve18, LOCK_POLL_MS));
|
|
40368
|
+
}
|
|
40369
|
+
}
|
|
40370
|
+
function writeMirror(root, files) {
|
|
40371
|
+
const id = crypto4.randomBytes(8).toString("hex");
|
|
40372
|
+
const dir = path47.join(root, CASE_MIRROR_DIR);
|
|
40373
|
+
const at = (name) => path47.join(dir, ...name.split("/"));
|
|
40374
|
+
const temp = (name) => {
|
|
40375
|
+
const slash = name.lastIndexOf("/");
|
|
40376
|
+
return `${name.slice(0, slash + 1)}.tmp-${id}-${name.slice(slash + 1)}`;
|
|
40377
|
+
};
|
|
40378
|
+
const lstat = (target) => {
|
|
40379
|
+
try {
|
|
40380
|
+
return fs35.lstatSync(target);
|
|
40381
|
+
} catch {
|
|
40382
|
+
return void 0;
|
|
40383
|
+
}
|
|
40384
|
+
};
|
|
40385
|
+
const folders = new Set(files.flatMap((f) => f.name.split("/").slice(0, -1).map((_, i, all) => all.slice(0, i + 1).join("/"))));
|
|
40386
|
+
try {
|
|
40387
|
+
for (const folder of folders) {
|
|
40388
|
+
const st = lstat(at(folder));
|
|
40389
|
+
if (st && !st.isDirectory()) fs35.rmSync(at(folder), { force: true });
|
|
40390
|
+
}
|
|
40391
|
+
for (const f of files) {
|
|
40392
|
+
writeCaseLocalFile(root, `${CASE_MIRROR_DIR}/${temp(f.name)}`, f.data);
|
|
40393
|
+
if (f.mode !== void 0) fs35.chmodSync(at(temp(f.name)), f.mode);
|
|
40394
|
+
}
|
|
40395
|
+
for (const f of files) {
|
|
40396
|
+
const st = lstat(at(f.name));
|
|
40397
|
+
if (st?.isDirectory()) fs35.rmSync(at(f.name), { recursive: true, force: true });
|
|
40398
|
+
else if (st?.isFile() && (st.mode & 128) === 0) fs35.chmodSync(at(f.name), 420);
|
|
40399
|
+
fs35.renameSync(at(temp(f.name)), at(f.name));
|
|
40400
|
+
}
|
|
40401
|
+
const names = new Set(files.map((f) => f.name));
|
|
40402
|
+
const sweep = (folder) => {
|
|
40403
|
+
for (const name of fs35.readdirSync(folder === null ? dir : at(folder))) {
|
|
40404
|
+
const rel = folder === null ? name : `${folder}/${name}`;
|
|
40405
|
+
if (names.has(rel) || rel === LOCK_FILE) continue;
|
|
40406
|
+
if (folders.has(rel) && lstat(at(rel))?.isDirectory()) sweep(rel);
|
|
40407
|
+
else fs35.rmSync(at(rel), { recursive: true, force: true });
|
|
40408
|
+
}
|
|
40409
|
+
};
|
|
40410
|
+
sweep(null);
|
|
40411
|
+
} finally {
|
|
40412
|
+
for (const f of files) fs35.rmSync(at(temp(f.name)), { force: true });
|
|
40413
|
+
}
|
|
40414
|
+
}
|
|
40415
|
+
async function writeCaseMirror(calls, input) {
|
|
40416
|
+
const { root, detail, confidential, mode } = input;
|
|
40417
|
+
const before = mode === "clone" ? null : readBaseline(root, detail, input.record);
|
|
40418
|
+
const withheld = detail.access.capabilities.includes("read_confidential") && !confidential;
|
|
40419
|
+
const readsRevisions = before !== null || mode !== "mirror-only";
|
|
40420
|
+
const { api, connection } = calls.session;
|
|
40421
|
+
const [work, since, pkg2] = await Promise.all([
|
|
40422
|
+
withheld ? null : readWork(calls, detail, confidential),
|
|
40423
|
+
readsRevisions ? revisionsSince(calls, before ? before.revision_at : void 0, confidential) : NO_REVISIONS,
|
|
40424
|
+
// Asked with --confidential alone: unasked, the space leaves its marked files out, whatever right the reader holds.
|
|
40425
|
+
readPackageDelivery({
|
|
40426
|
+
list: async () => (await calls.run(() => api.getCasePackage(connection, confidential))).data,
|
|
40427
|
+
content: (rel) => calls.run(() => notFound(api.getCasePackageContent(connection, rel, confidential)))
|
|
40428
|
+
}, root, path47.join(root, CASE_MIRROR_DIR), confidential)
|
|
40429
|
+
]);
|
|
40430
|
+
const now = snapshotOf(work);
|
|
40431
|
+
const at = nowIso();
|
|
40432
|
+
let baseline;
|
|
40433
|
+
if (mode !== "mirror-only") {
|
|
40434
|
+
baseline = { at, confidential, revision_at: since.newest_at, ...now };
|
|
40435
|
+
} else if (before && before.confidential && !confidential) {
|
|
40436
|
+
baseline = {
|
|
40437
|
+
...before,
|
|
40438
|
+
confidential: false,
|
|
40439
|
+
status: now.status === null ? null : before.status,
|
|
40440
|
+
phases: within(before.phases, now.phases),
|
|
40441
|
+
tasks: within(before.tasks, now.tasks),
|
|
40442
|
+
groups: within(before.groups, now.groups),
|
|
40443
|
+
deliveries: within(before.deliveries, now.deliveries)
|
|
40444
|
+
};
|
|
40445
|
+
} else {
|
|
40446
|
+
baseline = before;
|
|
40447
|
+
}
|
|
40448
|
+
const sections = [];
|
|
40449
|
+
if (before) sections.push(revisionsSection(since, withheld));
|
|
40450
|
+
if (mode !== "clone") sections.push(filesSection(input));
|
|
40451
|
+
if (before && work) sections.push(...statusSections(detail, work, before, now));
|
|
40452
|
+
const lines = renderSections(sections);
|
|
40453
|
+
const heading = mode === "clone" ? "This is the clone's first pull: there is nothing earlier to compare with." : before ? `Since the last pull (${before.at}):` : "No record of an earlier pull is in this clone's mirror: only its files are compared.";
|
|
40454
|
+
const summary = [heading, ...lines.length ? lines : before ? ["Nothing changed."] : []];
|
|
40455
|
+
const notice = confidential ? [] : ["", MIRROR_CONFIDENTIAL_NOTICE];
|
|
40456
|
+
const unwritten = unwrittenLines(work);
|
|
40457
|
+
const files = [
|
|
40458
|
+
{ name: "README.md", data: Buffer.from(readme(detail, at, withheld, confidential, unwritten, pkg2), "utf-8") },
|
|
40459
|
+
{ name: SUMMARY_FILE, data: Buffer.from(`# Case ${safe3(detail.code)}: since the last pull
|
|
40460
|
+
|
|
40461
|
+
${[...summary, ...notice].join("\n")}
|
|
40462
|
+
`, "utf-8") },
|
|
40463
|
+
{ name: CASE_MIRROR_HOOK_FILE, data: Buffer.from(HOOK_SCRIPT, "utf-8"), mode: 493 },
|
|
40464
|
+
{ name: RECORD_FILE, data: json({ org_id: input.record.org_id, space_id: input.record.space_id, code: detail.code, last_pull: baseline }) },
|
|
40465
|
+
{ name: PACKAGE_MANIFEST_FILE, data: json({ package: pkg2.manifest }) },
|
|
40466
|
+
...pkg2.files
|
|
40467
|
+
];
|
|
40468
|
+
if (work) {
|
|
40469
|
+
files.push(
|
|
40470
|
+
{ name: "case.json", data: json(detail) },
|
|
40471
|
+
{ name: "status.json", data: json(work.state) },
|
|
40472
|
+
{ name: "evidence.json", data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, work: p.work })) }) },
|
|
40473
|
+
{ name: "agenda.json", data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, groups: p.groups, more_groups: p.more_groups })), approved: work.approved }) },
|
|
40474
|
+
{ name: "deliveries.json", data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, delivery: p.delivery })) }) },
|
|
40475
|
+
{ name: INPUTS_FILE, data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, inputs: p.texts.map((t) => t.text) })) }) },
|
|
40476
|
+
...work.phases.flatMap((p) => p.texts.flatMap(({ text: text5, data }) => text5.file !== null && data !== null ? [{ name: text5.file, data }] : []))
|
|
40477
|
+
);
|
|
40478
|
+
}
|
|
40479
|
+
writeMirror(root, files);
|
|
40480
|
+
console.log(`
|
|
40481
|
+
Mirror of case ${safe3(detail.code)} written to ${safe3(path47.join(root, CASE_MIRROR_DIR))} (read-only: every pull rewrites it).`);
|
|
40482
|
+
for (const line of unwritten) console.log(`Linked input's text: ${line}`);
|
|
40483
|
+
for (const line of [...pkg2.changedHere, ...pkg2.unwritten]) console.log(`Package: ${line}`);
|
|
40484
|
+
for (const line of mode === "mirror-only" ? [...summary, ...notice] : summary) console.log(line);
|
|
40485
|
+
}
|
|
40486
|
+
function checkMirrorPackage(root) {
|
|
40487
|
+
const dir = mirrorFolder(root);
|
|
40488
|
+
return dir ? checkPackageFolder(root, dir) : PACKAGE_NOT_DELIVERED;
|
|
40489
|
+
}
|
|
40490
|
+
async function withMirrorLock(root, step) {
|
|
40491
|
+
const unlock = await lockMirror(root);
|
|
40492
|
+
try {
|
|
40493
|
+
return await step();
|
|
40494
|
+
} finally {
|
|
40495
|
+
unlock();
|
|
40496
|
+
}
|
|
40497
|
+
}
|
|
40498
|
+
function printHookSetup(root) {
|
|
40499
|
+
const script = path47.join(root, CASE_MIRROR_DIR, CASE_MIRROR_HOOK_FILE);
|
|
40500
|
+
const command2 = `sh '${script.replaceAll("'", "'\\''")}'`;
|
|
40501
|
+
const settings = JSON.stringify({ hooks: { SessionStart: [{ hooks: [{ type: "command", command: command2 }] }] } });
|
|
40502
|
+
console.log(`
|
|
40503
|
+
Session-start hook: ${safe3(script)} refreshes the mirror (never with --confidential).`);
|
|
40504
|
+
console.log(`For Claude Code, add it to ${safe3(path47.join(root, ".claude", "settings.json"))}:`);
|
|
40505
|
+
console.log(` ${safe3(settings)}`);
|
|
40506
|
+
console.log(`For another agent, run at the start of each session: ${safe3(command2)}`);
|
|
40507
|
+
}
|
|
40508
|
+
var CASE_MIRROR_DIR, CASE_MIRROR_HOOK_FILE, RECORD_FILE, 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, safe3, one, words, isConfPath, isObject2, isStringMap, isDeliveries, notFound, segment, NO_REVISIONS, within, HOOK_SCRIPT, json;
|
|
40509
|
+
var init_case_mirror = __esm({
|
|
40510
|
+
"src/cases/case-mirror.ts"() {
|
|
40511
|
+
"use strict";
|
|
40512
|
+
init_dist();
|
|
40513
|
+
init_case_files();
|
|
40514
|
+
init_case_comments();
|
|
40515
|
+
init_case_types();
|
|
40516
|
+
init_api_client();
|
|
40517
|
+
init_resource_files();
|
|
40518
|
+
init_utils();
|
|
40519
|
+
init_expected();
|
|
40520
|
+
init_fs_safety();
|
|
40521
|
+
init_terminal_output();
|
|
40522
|
+
init_case_local_files();
|
|
40523
|
+
init_case_package();
|
|
40524
|
+
CASE_MIRROR_DIR = ".wayai-mirror";
|
|
40525
|
+
CASE_MIRROR_HOOK_FILE = "session-start.sh";
|
|
40526
|
+
RECORD_FILE = "record.json";
|
|
40527
|
+
SUMMARY_FILE = "since-last-pull.md";
|
|
40528
|
+
INPUTS_FILE = "inputs.json";
|
|
40529
|
+
INPUTS_DIR = "inputs";
|
|
40530
|
+
LOCK_FILE = ".lock";
|
|
40531
|
+
LOCK_WAIT_MS = 12e4;
|
|
40532
|
+
LOCK_STALE_MS = 10 * 6e4;
|
|
40533
|
+
LOCK_POLL_MS = 50;
|
|
40534
|
+
AGENDA_PAGES_READ = 5;
|
|
40535
|
+
SUMMARY_REVISION_PAGES = 2;
|
|
40536
|
+
MIRROR_CONFIDENTIAL_NOTICE = "Confidential content is left out unless you pass --confidential.";
|
|
40537
|
+
safe3 = (text5) => sanitizeTerminalText(text5);
|
|
40538
|
+
one = (text5) => sanitizeTerminalText(text5).replace(/\s*\n\s*/g, " ");
|
|
40539
|
+
words = (status) => status.replaceAll("_", " ");
|
|
40540
|
+
isConfPath = (rel) => rel.split("/")[0] === "conf";
|
|
40541
|
+
isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
40542
|
+
isStringMap = (v) => isObject2(v) && Object.values(v).every((x) => typeof x === "string");
|
|
40543
|
+
isDeliveries = (v) => isObject2(v) && Object.values(v).every((d) => d === null || isObject2(d) && typeof d.submission_id === "string" && typeof d.state === "string");
|
|
40544
|
+
notFound = (call4) => call4.catch((err) => err instanceof ApiError && err.status === 404 ? null : Promise.reject(err));
|
|
40545
|
+
segment = (name, pattern, id) => pattern.test(name) ? name : UUID_RE3.test(id) ? id : computeHash(Buffer.from(id, "utf-8"));
|
|
40546
|
+
NO_REVISIONS = { revisions: [], more: false, newest_at: null };
|
|
40547
|
+
within = (prev, now) => Object.fromEntries(Object.entries(prev).filter(([key]) => key in now));
|
|
40548
|
+
HOOK_SCRIPT = `#!/bin/sh
|
|
40549
|
+
# Written by \`wayai cases clone\` and every \`wayai cases pull\` (this folder is rewritten whole: do not edit it).
|
|
40550
|
+
# The session-start hook: refreshes this clone's read-only mirror of its case. It never passes --confidential.
|
|
40551
|
+
exec wayai cases pull --mirror-only --dir "$(dirname "$0")/.."
|
|
40552
|
+
`;
|
|
40553
|
+
json = (value) => Buffer.from(`${JSON.stringify(value, null, 2)}
|
|
40554
|
+
`, "utf-8");
|
|
40555
|
+
}
|
|
40556
|
+
});
|
|
40557
|
+
|
|
39338
40558
|
// ../../packages/core/dist/contracts/case-notes.js
|
|
39339
40559
|
var init_case_notes = __esm({
|
|
39340
40560
|
"../../packages/core/dist/contracts/case-notes.js"() {
|
|
@@ -39367,13 +40587,13 @@ var init_case_checks = __esm({
|
|
|
39367
40587
|
});
|
|
39368
40588
|
|
|
39369
40589
|
// src/cases/case-work.ts
|
|
39370
|
-
import * as
|
|
39371
|
-
import * as
|
|
39372
|
-
async function call(session, run,
|
|
40590
|
+
import * as fs36 from "fs";
|
|
40591
|
+
import * as path48 from "path";
|
|
40592
|
+
async function call(session, run, notFound2) {
|
|
39373
40593
|
try {
|
|
39374
40594
|
return await run();
|
|
39375
40595
|
} catch (err) {
|
|
39376
|
-
throw caseCallFailure(err, session.connection,
|
|
40596
|
+
throw caseCallFailure(err, session.connection, notFound2);
|
|
39377
40597
|
}
|
|
39378
40598
|
}
|
|
39379
40599
|
function findPhase(detail, name) {
|
|
@@ -39435,13 +40655,13 @@ async function caseBrief(session, opts) {
|
|
|
39435
40655
|
console.log(JSON.stringify({ case: detail, state, open_notes: notes }, null, 2));
|
|
39436
40656
|
return;
|
|
39437
40657
|
}
|
|
39438
|
-
const head = `${detail.code}, ${
|
|
40658
|
+
const head = `${detail.code}, ${one2(detail.type_name)} (version ${detail.version})${detail.confidential ? ", confidential" : ""}`;
|
|
39439
40659
|
console.log(head);
|
|
39440
40660
|
if (detail.closure) {
|
|
39441
|
-
console.log(`Closed on ${detail.closure.closed_at}${detail.closure.outcome_name ? `: ${
|
|
40661
|
+
console.log(`Closed on ${detail.closure.closed_at}${detail.closure.outcome_name ? `: ${one2(detail.closure.outcome_name)}` : ""}.`);
|
|
39442
40662
|
}
|
|
39443
|
-
if (detail.owner?.display_name) console.log(`Owner: ${
|
|
39444
|
-
if (detail.parties?.length) console.log(`Parties: ${detail.parties.map((p) => `${
|
|
40663
|
+
if (detail.owner?.display_name) console.log(`Owner: ${one2(detail.owner.display_name)}.`);
|
|
40664
|
+
if (detail.parties?.length) console.log(`Parties: ${detail.parties.map((p) => `${one2(p.role)}: ${one2(p.name)}`).join("; ")}.`);
|
|
39445
40665
|
if (state.view === "phases") {
|
|
39446
40666
|
printPhasesView(detail, state);
|
|
39447
40667
|
return;
|
|
@@ -39461,7 +40681,7 @@ async function caseBrief(session, opts) {
|
|
|
39461
40681
|
console.log(`Open tasks (${open.length}):`);
|
|
39462
40682
|
for (const t of open) {
|
|
39463
40683
|
const st = taskState.get(t.case_task_id);
|
|
39464
|
-
console.log(` ${byId.get(t.phase_id)?.folder ?? ""}: ${
|
|
40684
|
+
console.log(` ${byId.get(t.phase_id)?.folder ?? ""}: ${one2(t.name)}${t.required ? " (required)" : ""}${st?.status === "waiting" ? ", waits for another task" : ""}${st?.late ? ", late" : ""} [${t.case_task_id}]`);
|
|
39465
40685
|
}
|
|
39466
40686
|
}
|
|
39467
40687
|
if (notes.length) {
|
|
@@ -39501,7 +40721,7 @@ async function caseExplain(session, opts) {
|
|
|
39501
40721
|
const shown3 = fullyNamed.has(p.phase_id) ? p.blockers : p.blockers.filter((b) => b.reason === "phase_dependency_pending" || b.reason === "phase_not_activated");
|
|
39502
40722
|
for (const b of shown3) console.log(` - ${blockerLine(b, names)}`);
|
|
39503
40723
|
const rest = p.blockers.length - shown3.length;
|
|
39504
|
-
if (rest > 0) console.log(` - and ${rest} requirement${rest === 1 ? "" : "s"} of its own (\`wayai cases explain --phase ${
|
|
40724
|
+
if (rest > 0) console.log(` - and ${rest} requirement${rest === 1 ? "" : "s"} of its own (\`wayai cases explain --phase ${one2(names.phaseRow(p.phase_id)?.folder ?? "")}\`)`);
|
|
39505
40725
|
}
|
|
39506
40726
|
const taskPhase = new Map((detail.tasks ?? []).map((t) => [t.case_task_id, t.phase_id]));
|
|
39507
40727
|
const tasks = state.tasks.filter((t) => fullyNamed.has(taskPhase.get(t.case_task_id) ?? ""));
|
|
@@ -39568,7 +40788,19 @@ async function caseNext(session, opts) {
|
|
|
39568
40788
|
}
|
|
39569
40789
|
if (underWay.length && !yours.length && !notes.length && !others.length) console.log("Nothing is pending on the phases under way.");
|
|
39570
40790
|
}
|
|
40791
|
+
function clonePackageCheck(session) {
|
|
40792
|
+
const clone = findCaseClone(process.cwd());
|
|
40793
|
+
return clone && sameCase(clone.record, session.connection) ? checkMirrorPackage(clone.root) : null;
|
|
40794
|
+
}
|
|
39571
40795
|
async function caseCheck(session, opts) {
|
|
40796
|
+
if (opts.phase === void 0) {
|
|
40797
|
+
const pkg3 = clonePackageCheck(session);
|
|
40798
|
+
if (!pkg3) throw expected(`check without --phase compares a clone's delivered package with its manifest: run it inside a clone of case ${session.connection.code}.`);
|
|
40799
|
+
if (packageDiffers(pkg3)) process.exitCode = 1;
|
|
40800
|
+
if (opts.json) console.log(JSON.stringify({ delivered_package: pkg3 }, null, 2));
|
|
40801
|
+
else for (const line of packageCheckLines(pkg3, CASE_MIRROR_DIR)) console.log(line);
|
|
40802
|
+
return;
|
|
40803
|
+
}
|
|
39572
40804
|
const detail = await loadCase(session);
|
|
39573
40805
|
const phase = findPhase(detail, opts.phase);
|
|
39574
40806
|
let outputId;
|
|
@@ -39576,28 +40808,31 @@ async function caseCheck(session, opts) {
|
|
|
39576
40808
|
const work = (await call(session, () => session.api.getCasePhaseWork(session.connection, phase.phase_id))).data;
|
|
39577
40809
|
const output = work.outputs.find((o) => o.code === opts.output);
|
|
39578
40810
|
if (!output) {
|
|
39579
|
-
throw expected(`Phase ${phase.folder} has no output ${JSON.stringify(sanitizeTerminalText(opts.output))}. Its outputs: ${work.outputs.map((o) =>
|
|
40811
|
+
throw expected(`Phase ${phase.folder} has no output ${JSON.stringify(sanitizeTerminalText(opts.output))}. Its outputs: ${work.outputs.map((o) => one2(o.code)).join(", ") || "none"}.`);
|
|
39580
40812
|
}
|
|
39581
40813
|
outputId = output.id;
|
|
39582
40814
|
}
|
|
39583
40815
|
const checks = (await call(session, () => session.api.getCasePhaseChecks(session.connection, phase.phase_id, outputId))).data;
|
|
39584
40816
|
if (checks.refused) process.exitCode = 1;
|
|
40817
|
+
const pkg2 = clonePackageCheck(session);
|
|
40818
|
+
if (pkg2 && packageDiffers(pkg2)) process.exitCode = 1;
|
|
39585
40819
|
if (opts.json) {
|
|
39586
|
-
console.log(JSON.stringify(checks, null, 2));
|
|
40820
|
+
console.log(JSON.stringify({ ...checks, delivered_package: pkg2 }, null, 2));
|
|
39587
40821
|
return;
|
|
39588
40822
|
}
|
|
39589
40823
|
const errors = checks.problems.filter((p) => p.severity === "error").length;
|
|
39590
40824
|
const warnings = checks.problems.length - errors;
|
|
39591
40825
|
console.log(`Checks of ${phase.folder}${opts.output ? `, output ${opts.output}` : ""}, over the case's files as WayAI holds them: ${errors} error${errors === 1 ? "" : "s"}, ${warnings} warning${warnings === 1 ? "" : "s"}. A submit now would be ${checks.refused ? "refused" : "accepted by the checks"}.`);
|
|
39592
40826
|
for (const p of checks.problems) {
|
|
39593
|
-
const where = [p.output_code &&
|
|
39594
|
-
const what = p.confidential ? "about something confidential" : [p.subject &&
|
|
40827
|
+
const where = [p.output_code && one2(p.output_code), p.path && `${one2(p.path)}${p.line ? `:${p.line}` : ""}`].filter(Boolean).join(" ");
|
|
40828
|
+
const what = p.confidential ? "about something confidential" : [p.subject && one2(p.subject), p.expected !== null && `expected ${one2(p.expected)}`, p.found !== null && `found ${one2(p.found)}`, p.count !== null && `${p.count}\xD7`].filter(Boolean).join(", ");
|
|
39595
40829
|
console.log(` ${p.severity} ${p.code}${where ? ` [${where}]` : ""}${what ? `: ${what}` : ""}`);
|
|
39596
40830
|
}
|
|
39597
40831
|
if (checks.truncated) console.log(" (more problems were found than one answer carries)");
|
|
39598
40832
|
for (const c of checks.coverage) {
|
|
39599
|
-
console.log(`Coverage of ${
|
|
40833
|
+
console.log(`Coverage of ${one2(c.output_code)}: ${c.ready} of ${c.total} items ready${c.dispensed ? `, ${c.dispensed} dispensed` : ""}.`);
|
|
39600
40834
|
}
|
|
40835
|
+
if (pkg2) for (const line of packageCheckLines(pkg2, CASE_MIRROR_DIR)) console.log(line);
|
|
39601
40836
|
}
|
|
39602
40837
|
function decisionCsvValue(d) {
|
|
39603
40838
|
const value = d.type === "percent" && typeof d.value === "number" ? Number((d.value / 100).toPrecision(15)) : d.value;
|
|
@@ -39617,7 +40852,7 @@ async function caseDecisions(session, opts) {
|
|
|
39617
40852
|
const results = [{ rel: CASE_DECISIONS_CSV_PATH, rows: open, outcome: writeCaseLocalFile(root, CASE_DECISIONS_CSV_PATH, Buffer.from(decisionsCsv(open))) }];
|
|
39618
40853
|
if (opts.confidential) {
|
|
39619
40854
|
const sealed = decisions.filter((d) => d.confidential);
|
|
39620
|
-
const exists =
|
|
40855
|
+
const exists = fs36.existsSync(path48.join(root, ...CASE_CONFIDENTIAL_DECISIONS_CSV_PATH.split("/")));
|
|
39621
40856
|
if (sealed.length || exists) {
|
|
39622
40857
|
results.push({
|
|
39623
40858
|
rel: CASE_CONFIDENTIAL_DECISIONS_CSV_PATH,
|
|
@@ -39627,7 +40862,7 @@ async function caseDecisions(session, opts) {
|
|
|
39627
40862
|
}
|
|
39628
40863
|
}
|
|
39629
40864
|
for (const r of results) {
|
|
39630
|
-
const listed3 = r.rows.length ? `: ${r.rows.map((d) =>
|
|
40865
|
+
const listed3 = r.rows.length ? `: ${r.rows.map((d) => one2(d.code)).join(", ")}` : ", with its header alone: no decision is approved yet";
|
|
39631
40866
|
console.log(`${r.rel} ${r.outcome === "written" ? "written" : "already up to date"}${listed3}.`);
|
|
39632
40867
|
}
|
|
39633
40868
|
}
|
|
@@ -39646,24 +40881,24 @@ async function caseNote(session, text5, opts) {
|
|
|
39646
40881
|
async function caseNoteDone(session, noteId) {
|
|
39647
40882
|
if (!UUID_RE3.test(noteId)) throw expected("note done takes a note's id, as `wayai cases next` shows it.");
|
|
39648
40883
|
const note = (await call(session, () => session.api.completeCaseNote(session.connection, noteId), `Note ${noteId} was not found`)).data;
|
|
39649
|
-
console.log(`Done: ${
|
|
40884
|
+
console.log(`Done: ${one2(note.text)}`);
|
|
39650
40885
|
}
|
|
39651
40886
|
function sizeOf(file) {
|
|
39652
40887
|
try {
|
|
39653
|
-
return
|
|
40888
|
+
return fs36.statSync(file).size;
|
|
39654
40889
|
} catch {
|
|
39655
40890
|
throw expected(`Cannot read ${sanitizeTerminalText(file)}.`);
|
|
39656
40891
|
}
|
|
39657
40892
|
}
|
|
39658
40893
|
function readLocal(file) {
|
|
39659
40894
|
try {
|
|
39660
|
-
return
|
|
40895
|
+
return fs36.readFileSync(file);
|
|
39661
40896
|
} catch {
|
|
39662
40897
|
throw expected(`Cannot read ${sanitizeTerminalText(file)}.`);
|
|
39663
40898
|
}
|
|
39664
40899
|
}
|
|
39665
40900
|
async function caseReceivedAdd(session, file, opts) {
|
|
39666
|
-
const name = caseReceivedFileName(
|
|
40901
|
+
const name = caseReceivedFileName(path48.basename(file));
|
|
39667
40902
|
const format = caseReceivedFormat(name);
|
|
39668
40903
|
if (!format) throw expected(`${sanitizeTerminalText(name)} is in no format a received document takes: ${Object.keys(CASE_RECEIVED_FORMATS).join(", ")}.`);
|
|
39669
40904
|
const tooLarge2 = () => expected(`The file and its text together pass ${CASE_RECEIVED_UPLOAD_BODY_MAX_BYTES / (1024 * 1024)} MiB, the most one registration takes.`);
|
|
@@ -39672,7 +40907,7 @@ async function caseReceivedAdd(session, file, opts) {
|
|
|
39672
40907
|
const text5 = readLocal(opts.text);
|
|
39673
40908
|
if (bytes.byteLength + text5.byteLength > CASE_RECEIVED_UPLOAD_BODY_MAX_BYTES) throw tooLarge2();
|
|
39674
40909
|
const phase = findPhase(await loadCase(session), opts.phase);
|
|
39675
|
-
const title2 = opts.title ??
|
|
40910
|
+
const title2 = opts.title ?? path48.parse(name).name;
|
|
39676
40911
|
const document = registerCaseReceivedDocumentShape.safeParse({ phase_id: phase.phase_id, title: title2, type: opts.type, confidential: opts.confidential });
|
|
39677
40912
|
if (!document.success) throw expected(`The document is refused: ${document.error.issues[0]?.message ?? "not of its shape"}.`);
|
|
39678
40913
|
const received = (await call(session, () => session.api.registerCaseReceivedDocument(
|
|
@@ -39681,10 +40916,10 @@ async function caseReceivedAdd(session, file, opts) {
|
|
|
39681
40916
|
{ name, bytes },
|
|
39682
40917
|
text5
|
|
39683
40918
|
))).data;
|
|
39684
|
-
console.log(`${
|
|
40919
|
+
console.log(`${one2(received.title)} registered in ${phase.folder}/received/ of ${session.connection.code}: ${received.received_id}`);
|
|
39685
40920
|
if (received.text_origin === "agent") console.log("Its text is marked as converted by an agent, for whoever reviews it.");
|
|
39686
40921
|
}
|
|
39687
|
-
var NOTE_PAGES_READ, NOTES_PAGE,
|
|
40922
|
+
var NOTE_PAGES_READ, NOTES_PAGE, AGENDA_PAGES_READ2, one2, loadCase, loadState, phaseLabel, statusWords, CaseNames, AWAITING, readsWork, PHASES_VIEW_NOTE, noteLine, blockerKey;
|
|
39688
40923
|
var init_case_work = __esm({
|
|
39689
40924
|
"src/cases/case-work.ts"() {
|
|
39690
40925
|
"use strict";
|
|
@@ -39693,22 +40928,25 @@ var init_case_work = __esm({
|
|
|
39693
40928
|
init_terminal_output();
|
|
39694
40929
|
init_case_session();
|
|
39695
40930
|
init_case_local_files();
|
|
40931
|
+
init_case_clone_record();
|
|
40932
|
+
init_case_mirror();
|
|
40933
|
+
init_case_package();
|
|
39696
40934
|
init_case_notes();
|
|
39697
40935
|
init_case_checks();
|
|
39698
40936
|
init_case_received_documents();
|
|
39699
40937
|
NOTE_PAGES_READ = 3;
|
|
39700
40938
|
NOTES_PAGE = CASE_NOTES_PAGE_MAX;
|
|
39701
|
-
|
|
39702
|
-
|
|
40939
|
+
AGENDA_PAGES_READ2 = 5;
|
|
40940
|
+
one2 = (value) => sanitizeTerminalText(value).replace(/\s*\n\s*/g, " ");
|
|
39703
40941
|
loadCase = async (s) => (await call(s, () => s.api.getCase(s.connection))).data;
|
|
39704
40942
|
loadState = async (s) => (await call(s, () => s.api.getCaseState(s.connection))).data;
|
|
39705
|
-
phaseLabel = (p) => `${
|
|
40943
|
+
phaseLabel = (p) => `${one2(p.folder)} (${one2(p.name)})`;
|
|
39706
40944
|
statusWords = (status) => status.replaceAll("_", " ");
|
|
39707
40945
|
CaseNames = class {
|
|
39708
40946
|
constructor(session, detail) {
|
|
39709
40947
|
this.session = session;
|
|
39710
40948
|
this.phases = new Map(detail.phases.map((p) => [p.phase_id, p]));
|
|
39711
|
-
this.tasks = new Map((detail.tasks ?? []).map((t) => [t.case_task_id,
|
|
40949
|
+
this.tasks = new Map((detail.tasks ?? []).map((t) => [t.case_task_id, one2(t.name)]));
|
|
39712
40950
|
}
|
|
39713
40951
|
phases;
|
|
39714
40952
|
tasks;
|
|
@@ -39719,12 +40957,12 @@ var init_case_work = __esm({
|
|
|
39719
40957
|
async readPhase(phaseId) {
|
|
39720
40958
|
const s = this.session;
|
|
39721
40959
|
const work = (await call(s, () => s.api.getCasePhaseWork(s.connection, phaseId))).data;
|
|
39722
|
-
for (const o of work.outputs) this.outputs.set(o.id, `${
|
|
39723
|
-
for (const i of work.inputs) this.inputs.set(i.id, `${
|
|
40960
|
+
for (const o of work.outputs) this.outputs.set(o.id, `${one2(o.code)} (${one2(o.document_type)})`);
|
|
40961
|
+
for (const i of work.inputs) this.inputs.set(i.id, `${one2(i.key)} (${one2(i.name)})`);
|
|
39724
40962
|
let cursor;
|
|
39725
|
-
for (let page = 0; page <
|
|
40963
|
+
for (let page = 0; page < AGENDA_PAGES_READ2; page++) {
|
|
39726
40964
|
const { groups, next_cursor } = (await call(s, () => s.api.getCaseAgenda(s.connection, phaseId, cursor))).data;
|
|
39727
|
-
for (const g of groups) this.groups.set(g.agenda_group_id, `${
|
|
40965
|
+
for (const g of groups) this.groups.set(g.agenda_group_id, `${one2(g.code)} (${one2(g.name)})`);
|
|
39728
40966
|
if (!next_cursor) break;
|
|
39729
40967
|
cursor = next_cursor;
|
|
39730
40968
|
}
|
|
@@ -39761,7 +40999,7 @@ var init_case_work = __esm({
|
|
|
39761
40999
|
};
|
|
39762
41000
|
readsWork = (detail) => detail.access.capabilities.includes("view_work");
|
|
39763
41001
|
PHASES_VIEW_NOTE = "You see only the phases' status of this case: its work is not yours to read here.";
|
|
39764
|
-
noteLine = (n) => `${n.kind === "pending" ? "pending" : "next step"}: ${
|
|
41002
|
+
noteLine = (n) => `${n.kind === "pending" ? "pending" : "next step"}: ${one2(n.text)} [${n.note_id}]`;
|
|
39765
41003
|
blockerKey = (b) => {
|
|
39766
41004
|
switch (b.reason) {
|
|
39767
41005
|
case "output_pending":
|
|
@@ -39780,8 +41018,8 @@ var init_case_work = __esm({
|
|
|
39780
41018
|
});
|
|
39781
41019
|
|
|
39782
41020
|
// src/data/files-sync/local.ts
|
|
39783
|
-
import * as
|
|
39784
|
-
import * as
|
|
41021
|
+
import * as fs37 from "fs";
|
|
41022
|
+
import * as path49 from "path";
|
|
39785
41023
|
function foldSegment(segment2) {
|
|
39786
41024
|
return segment2.normalize("NFC").toLowerCase().replace(/[. ]+$/, "");
|
|
39787
41025
|
}
|
|
@@ -39809,7 +41047,7 @@ function remotePath(folder, rel) {
|
|
|
39809
41047
|
return folder ? `${folder}/${rel}` : rel;
|
|
39810
41048
|
}
|
|
39811
41049
|
function defaultDir(fileType, folder) {
|
|
39812
|
-
return
|
|
41050
|
+
return path49.join(fileType, ...folder ? folder.split("/") : []);
|
|
39813
41051
|
}
|
|
39814
41052
|
function describeSync(r) {
|
|
39815
41053
|
const where = r.folder ? `folder "${r.folder}"` : "the whole file type";
|
|
@@ -39872,7 +41110,7 @@ function assertPushable(folder, rels, platform2 = process.platform) {
|
|
|
39872
41110
|
}
|
|
39873
41111
|
function syncDirExists(dir) {
|
|
39874
41112
|
try {
|
|
39875
|
-
|
|
41113
|
+
fs37.lstatSync(dir);
|
|
39876
41114
|
return true;
|
|
39877
41115
|
} catch {
|
|
39878
41116
|
return false;
|
|
@@ -39880,13 +41118,13 @@ function syncDirExists(dir) {
|
|
|
39880
41118
|
}
|
|
39881
41119
|
function ensureSyncDir(dir) {
|
|
39882
41120
|
if (!syncDirExists(dir)) {
|
|
39883
|
-
|
|
41121
|
+
fs37.mkdirSync(dir, { recursive: true });
|
|
39884
41122
|
return;
|
|
39885
41123
|
}
|
|
39886
|
-
if (!
|
|
41124
|
+
if (!fs37.lstatSync(dir).isDirectory()) throw symlinkRefusal(dir, "directory");
|
|
39887
41125
|
}
|
|
39888
41126
|
function readRecord(dir) {
|
|
39889
|
-
const text5 = readRealFileOrThrow(dir,
|
|
41127
|
+
const text5 = readRealFileOrThrow(dir, path49.join(dir, RECORD_FILE2));
|
|
39890
41128
|
if (text5 === null) return null;
|
|
39891
41129
|
let parsed;
|
|
39892
41130
|
try {
|
|
@@ -39894,14 +41132,14 @@ function readRecord(dir) {
|
|
|
39894
41132
|
} catch {
|
|
39895
41133
|
parsed = void 0;
|
|
39896
41134
|
}
|
|
39897
|
-
if (!
|
|
41135
|
+
if (!isRecord4(parsed)) {
|
|
39898
41136
|
throw expected(
|
|
39899
|
-
`${
|
|
41137
|
+
`${path49.join(dir, RECORD_FILE2)} is not a record \`wayai files pull\` wrote. Restore it from version control, or move the folder aside and pull again.`
|
|
39900
41138
|
);
|
|
39901
41139
|
}
|
|
39902
41140
|
return parsed;
|
|
39903
41141
|
}
|
|
39904
|
-
function
|
|
41142
|
+
function isRecord4(v) {
|
|
39905
41143
|
if (typeof v !== "object" || v === null) return false;
|
|
39906
41144
|
const r = v;
|
|
39907
41145
|
if (typeof r.base !== "string" || typeof r.file_type !== "string" || typeof r.folder !== "string") return false;
|
|
@@ -39916,16 +41154,16 @@ function writeRecord(dir, record) {
|
|
|
39916
41154
|
for (const rel of Object.keys(record.files).sort()) files[rel] = syncedFile(record.files[rel]);
|
|
39917
41155
|
const body = `${JSON.stringify({ base: record.base, file_type: record.file_type, folder: record.folder, files }, null, 2)}
|
|
39918
41156
|
`;
|
|
39919
|
-
const tmp =
|
|
41157
|
+
const tmp = path49.join(dir, `${RECORD_FILE2}.tmp`);
|
|
39920
41158
|
if (!writeFileNoFollow(dir, tmp, Buffer.from(body, "utf-8"))) throw symlinkRefusal(tmp, "file");
|
|
39921
|
-
|
|
41159
|
+
fs37.renameSync(tmp, path49.join(dir, RECORD_FILE2));
|
|
39922
41160
|
}
|
|
39923
41161
|
function syncedFile(f) {
|
|
39924
41162
|
return { version: f.version, content_sha256: f.content_sha256 };
|
|
39925
41163
|
}
|
|
39926
41164
|
function readLocal2(dir, rel) {
|
|
39927
|
-
const bytes = readFileNoFollow(dir,
|
|
39928
|
-
if (!bytes) throw symlinkRefusal(
|
|
41165
|
+
const bytes = readFileNoFollow(dir, path49.join(dir, ...rel.split("/")));
|
|
41166
|
+
if (!bytes) throw symlinkRefusal(path49.join(dir, rel), "file");
|
|
39929
41167
|
return bytes;
|
|
39930
41168
|
}
|
|
39931
41169
|
function scanLocal(dir) {
|
|
@@ -39933,22 +41171,22 @@ function scanLocal(dir) {
|
|
|
39933
41171
|
if (!syncDirExists(dir)) return out;
|
|
39934
41172
|
ensureSyncDir(dir);
|
|
39935
41173
|
const walk = (absDir, relDir) => {
|
|
39936
|
-
for (const name of
|
|
41174
|
+
for (const name of fs37.readdirSync(absDir).sort()) {
|
|
39937
41175
|
const rel = relDir ? `${relDir}/${name}` : name;
|
|
39938
41176
|
if (foldSegment(name) === ".git") {
|
|
39939
41177
|
throw expected(
|
|
39940
|
-
`${sanitizeTerminalText(
|
|
41178
|
+
`${sanitizeTerminalText(path49.join(dir, rel))} is a git repository inside the synced folder, which files pull and push do not sync into. Sync into a folder of its own \u2014 a folder inside a repository is fine; a repository's root, or a folder holding one, is not.`
|
|
39941
41179
|
);
|
|
39942
41180
|
}
|
|
39943
41181
|
if (isOutsideSync(rel)) continue;
|
|
39944
|
-
const st =
|
|
41182
|
+
const st = fs37.lstatSync(path49.join(absDir, name));
|
|
39945
41183
|
if (st.isDirectory()) {
|
|
39946
|
-
walk(
|
|
41184
|
+
walk(path49.join(absDir, name), rel);
|
|
39947
41185
|
} else if (st.isFile()) {
|
|
39948
41186
|
const bytes = readLocal2(dir, rel);
|
|
39949
41187
|
out.set(rel, { rel, content_sha256: computeHash(bytes), size: bytes.length });
|
|
39950
41188
|
} else {
|
|
39951
|
-
throw symlinkRefusal(
|
|
41189
|
+
throw symlinkRefusal(path49.join(dir, rel), "file or folder");
|
|
39952
41190
|
}
|
|
39953
41191
|
}
|
|
39954
41192
|
};
|
|
@@ -39956,7 +41194,7 @@ function scanLocal(dir) {
|
|
|
39956
41194
|
return out;
|
|
39957
41195
|
}
|
|
39958
41196
|
function matchesScan(dir, rel, scanned) {
|
|
39959
|
-
const abs =
|
|
41197
|
+
const abs = path49.join(dir, ...rel.split("/"));
|
|
39960
41198
|
if (!syncDirExists(abs)) return scanned === void 0;
|
|
39961
41199
|
if (scanned === void 0) return false;
|
|
39962
41200
|
const bytes = readFileNoFollow(dir, abs);
|
|
@@ -39964,27 +41202,27 @@ function matchesScan(dir, rel, scanned) {
|
|
|
39964
41202
|
}
|
|
39965
41203
|
function writeLocal(dir, rel, bytes) {
|
|
39966
41204
|
const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
39967
|
-
if (!writeFileNoFollow(dir,
|
|
39968
|
-
throw symlinkRefusal(
|
|
41205
|
+
if (!writeFileNoFollow(dir, path49.join(dir, ...rel.split("/")), data)) {
|
|
41206
|
+
throw symlinkRefusal(path49.join(dir, rel), "file");
|
|
39969
41207
|
}
|
|
39970
41208
|
}
|
|
39971
41209
|
function removeLocal(dir, rel) {
|
|
39972
|
-
const abs =
|
|
39973
|
-
requireRealSubdirNoSymlink(dir,
|
|
41210
|
+
const abs = path49.join(dir, ...rel.split("/"));
|
|
41211
|
+
requireRealSubdirNoSymlink(dir, path49.dirname(abs), false);
|
|
39974
41212
|
let st;
|
|
39975
41213
|
try {
|
|
39976
|
-
st =
|
|
41214
|
+
st = fs37.lstatSync(abs);
|
|
39977
41215
|
} catch {
|
|
39978
41216
|
return;
|
|
39979
41217
|
}
|
|
39980
|
-
if (!st.isFile()) throw symlinkRefusal(
|
|
39981
|
-
|
|
39982
|
-
const root =
|
|
39983
|
-
for (let parent =
|
|
39984
|
-
const names =
|
|
41218
|
+
if (!st.isFile()) throw symlinkRefusal(path49.join(dir, rel), "file");
|
|
41219
|
+
fs37.rmSync(abs);
|
|
41220
|
+
const root = path49.resolve(dir);
|
|
41221
|
+
for (let parent = path49.dirname(path49.resolve(abs)); parent !== root && isUnder(root, parent); parent = path49.dirname(parent)) {
|
|
41222
|
+
const names = fs37.readdirSync(parent);
|
|
39985
41223
|
if (names.some((n) => n !== ".DS_Store")) break;
|
|
39986
|
-
for (const n of names)
|
|
39987
|
-
|
|
41224
|
+
for (const n of names) fs37.rmSync(path49.join(parent, n));
|
|
41225
|
+
fs37.rmdirSync(parent);
|
|
39988
41226
|
}
|
|
39989
41227
|
}
|
|
39990
41228
|
function diskClash(dir, rel) {
|
|
@@ -39993,7 +41231,7 @@ function diskClash(dir, rel) {
|
|
|
39993
41231
|
for (let i = 0; i < segments.length; i++) {
|
|
39994
41232
|
let names;
|
|
39995
41233
|
try {
|
|
39996
|
-
names =
|
|
41234
|
+
names = fs37.readdirSync(abs);
|
|
39997
41235
|
} catch {
|
|
39998
41236
|
return void 0;
|
|
39999
41237
|
}
|
|
@@ -40001,15 +41239,15 @@ function diskClash(dir, rel) {
|
|
|
40001
41239
|
const twin = names.find((n) => n !== segments[i] && foldSegment(n) === want);
|
|
40002
41240
|
if (twin !== void 0) return { reason: "case_twin", other: [...segments.slice(0, i), twin].join("/") };
|
|
40003
41241
|
if (!names.includes(segments[i])) return void 0;
|
|
40004
|
-
abs =
|
|
40005
|
-
const isDir =
|
|
41242
|
+
abs = path49.join(abs, segments[i]);
|
|
41243
|
+
const isDir = fs37.lstatSync(abs).isDirectory();
|
|
40006
41244
|
const here = segments.slice(0, i + 1).join("/");
|
|
40007
41245
|
if (i < segments.length - 1 && !isDir) return { reason: "file_folder", other: here };
|
|
40008
41246
|
if (i === segments.length - 1 && isDir) return { reason: "file_folder", other: `${here}/` };
|
|
40009
41247
|
}
|
|
40010
41248
|
return void 0;
|
|
40011
41249
|
}
|
|
40012
|
-
var
|
|
41250
|
+
var RECORD_FILE2, OUTSIDE_SYNC, OUTSIDE_SYNC_FOLDED, CaseIndex, MAX_REMOTE_PATH;
|
|
40013
41251
|
var init_local = __esm({
|
|
40014
41252
|
"src/data/files-sync/local.ts"() {
|
|
40015
41253
|
"use strict";
|
|
@@ -40017,8 +41255,8 @@ var init_local = __esm({
|
|
|
40017
41255
|
init_resource_files();
|
|
40018
41256
|
init_fs_safety();
|
|
40019
41257
|
init_terminal_output();
|
|
40020
|
-
|
|
40021
|
-
OUTSIDE_SYNC = [
|
|
41258
|
+
RECORD_FILE2 = ".wayai-files.json";
|
|
41259
|
+
OUTSIDE_SYNC = [RECORD_FILE2, `${RECORD_FILE2}.tmp`, ".git", ".DS_Store"];
|
|
40022
41260
|
OUTSIDE_SYNC_FOLDED = new Set(OUTSIDE_SYNC.map((n) => foldSegment(n)));
|
|
40023
41261
|
CaseIndex = class {
|
|
40024
41262
|
bySpelling = /* @__PURE__ */ new Map();
|
|
@@ -40191,25 +41429,25 @@ var init_plan = __esm({
|
|
|
40191
41429
|
constructor(paths = []) {
|
|
40192
41430
|
for (const p of paths) this.add(p);
|
|
40193
41431
|
}
|
|
40194
|
-
add(
|
|
40195
|
-
this.cases.add(
|
|
40196
|
-
this.files.add(
|
|
40197
|
-
const segments =
|
|
41432
|
+
add(path54) {
|
|
41433
|
+
this.cases.add(path54);
|
|
41434
|
+
this.files.add(path54);
|
|
41435
|
+
const segments = path54.split("/");
|
|
40198
41436
|
for (let i = 1; i < segments.length; i++) {
|
|
40199
41437
|
const folder = segments.slice(0, i).join("/");
|
|
40200
|
-
if (!this.folders.has(folder)) this.folders.set(folder,
|
|
41438
|
+
if (!this.folders.has(folder)) this.folders.set(folder, path54);
|
|
40201
41439
|
}
|
|
40202
41440
|
}
|
|
40203
41441
|
/** The path `path` would collide with, and how; undefined when it collides with none. */
|
|
40204
|
-
clash(
|
|
40205
|
-
const twin = this.cases.twinOf(
|
|
41442
|
+
clash(path54) {
|
|
41443
|
+
const twin = this.cases.twinOf(path54);
|
|
40206
41444
|
if (twin !== void 0) return { reason: "case_twin", other: twin };
|
|
40207
|
-
const segments =
|
|
41445
|
+
const segments = path54.split("/");
|
|
40208
41446
|
for (let i = 1; i < segments.length; i++) {
|
|
40209
41447
|
const folder = segments.slice(0, i).join("/");
|
|
40210
41448
|
if (this.files.has(folder)) return { reason: "file_folder", other: folder };
|
|
40211
41449
|
}
|
|
40212
|
-
const inside = this.folders.get(
|
|
41450
|
+
const inside = this.folders.get(path54);
|
|
40213
41451
|
return inside === void 0 ? void 0 : { reason: "file_folder", other: inside };
|
|
40214
41452
|
}
|
|
40215
41453
|
};
|
|
@@ -40273,9 +41511,9 @@ async function openRemote2() {
|
|
|
40273
41511
|
)
|
|
40274
41512
|
});
|
|
40275
41513
|
return {
|
|
40276
|
-
request: (method,
|
|
40277
|
-
upload: (
|
|
40278
|
-
download: (
|
|
41514
|
+
request: (method, path54, body, headers) => pacer.run(() => client.request(method, path54, body, headers)),
|
|
41515
|
+
upload: (path54, bytes, contentType, headers) => pacer.run(() => client.upload(path54, bytes, contentType, headers)),
|
|
41516
|
+
download: (path54) => pacer.run(() => client.download(path54))
|
|
40279
41517
|
};
|
|
40280
41518
|
}
|
|
40281
41519
|
function filesRoot(t) {
|
|
@@ -40358,7 +41596,7 @@ function isConflict(err) {
|
|
|
40358
41596
|
return err instanceof ApiError && (err.status === 409 || err.status === 412);
|
|
40359
41597
|
}
|
|
40360
41598
|
function conflictLine(c, texts) {
|
|
40361
|
-
return `${
|
|
41599
|
+
return `${safe4(c.rel)}: ${texts[c.reason]}${c.other === void 0 ? "" : ` "${safe4(c.other)}"`}`;
|
|
40362
41600
|
}
|
|
40363
41601
|
function remedy(conflicts, overwriteCommand) {
|
|
40364
41602
|
const isClash = (c) => c.reason === "case_twin" || c.reason === "file_folder";
|
|
@@ -40379,7 +41617,7 @@ async function pullFiles(opts) {
|
|
|
40379
41617
|
const plan = planPull({ synced: existing?.files ?? {}, local, remote, overwrite: opts.overwrite });
|
|
40380
41618
|
if (plan.replacedLocal.length > 0) {
|
|
40381
41619
|
console.log("These local changes would be replaced with the base's copies:");
|
|
40382
|
-
for (const rel of plan.replacedLocal) console.log(` ${
|
|
41620
|
+
for (const rel of plan.replacedLocal) console.log(` ${safe4(rel)}`);
|
|
40383
41621
|
if (!await agree(`Replace ${plan.replacedLocal.length} locally changed file(s)?`, opts.yes)) {
|
|
40384
41622
|
console.log("Cancelled.");
|
|
40385
41623
|
return;
|
|
@@ -40400,7 +41638,7 @@ async function pullFiles(opts) {
|
|
|
40400
41638
|
}
|
|
40401
41639
|
removeLocal(dir, rel);
|
|
40402
41640
|
delete record.files[rel];
|
|
40403
|
-
changes.push(`${MARK.delete} ${
|
|
41641
|
+
changes.push(`${MARK.delete} ${safe4(rel)}`);
|
|
40404
41642
|
}
|
|
40405
41643
|
for (const w of plan.writes) {
|
|
40406
41644
|
const clash = diskClash(dir, w.rel);
|
|
@@ -40408,13 +41646,13 @@ async function pullFiles(opts) {
|
|
|
40408
41646
|
conflicts.push({ rel: w.rel, ...clash });
|
|
40409
41647
|
continue;
|
|
40410
41648
|
}
|
|
40411
|
-
const
|
|
41649
|
+
const path54 = filePath2(target, w.rel);
|
|
40412
41650
|
let bytes;
|
|
40413
41651
|
let version = w.remote.version;
|
|
40414
41652
|
try {
|
|
40415
|
-
bytes = (await client.download(
|
|
41653
|
+
bytes = (await client.download(path54)).bytes;
|
|
40416
41654
|
if (computeHash(bytes) !== w.remote.content_sha256) {
|
|
40417
|
-
const meta = await client.request("GET", `${
|
|
41655
|
+
const meta = await client.request("GET", `${path54}?meta=1`);
|
|
40418
41656
|
if (meta?.content_sha256 !== computeHash(bytes)) {
|
|
40419
41657
|
changedWhilePulling.push(w.rel);
|
|
40420
41658
|
continue;
|
|
@@ -40433,7 +41671,7 @@ async function pullFiles(opts) {
|
|
|
40433
41671
|
const hash2 = computeHash(bytes);
|
|
40434
41672
|
writeLocal(dir, w.rel, bytes);
|
|
40435
41673
|
record.files[w.rel] = { version, content_sha256: hash2 };
|
|
40436
|
-
changes.push(`${local.has(w.rel) ? MARK.update : MARK.create} ${
|
|
41674
|
+
changes.push(`${local.has(w.rel) ? MARK.update : MARK.create} ${safe4(w.rel)}`);
|
|
40437
41675
|
}
|
|
40438
41676
|
} finally {
|
|
40439
41677
|
writeRecord(dir, record);
|
|
@@ -40441,13 +41679,13 @@ async function pullFiles(opts) {
|
|
|
40441
41679
|
const count = Object.keys(record.files).length;
|
|
40442
41680
|
console.log(sanitizeTerminalText(`Pulled ${describeSync(target)} \u2192 ${dir} (${count} file${count === 1 ? "" : "s"}).`));
|
|
40443
41681
|
printSection("Changes:", changes);
|
|
40444
|
-
printSection("Kept \u2014 your local changes:", plan.kept.map((k) => `${
|
|
41682
|
+
printSection("Kept \u2014 your local changes:", plan.kept.map((k) => `${safe4(k.rel)}: ${PULL_KEPT[k.reason]}`));
|
|
40445
41683
|
printSection(
|
|
40446
41684
|
`Conflicts \u2014 your copy is kept; to settle them, ${remedy(conflicts, pullCommand2(target, opts.dir, true))}:`,
|
|
40447
41685
|
conflicts.map((c) => conflictLine(c, PULL_CONFLICT))
|
|
40448
41686
|
);
|
|
40449
|
-
printSection("Changed or deleted on the base while pulling \u2014 left as is; pull again to take it:", changedWhilePulling.map(
|
|
40450
|
-
printSection(`Not synced \u2014 names a synced folder leaves out (${OUTSIDE_SYNC.join(", ")}):`, excluded.map(
|
|
41687
|
+
printSection("Changed or deleted on the base while pulling \u2014 left as is; pull again to take it:", changedWhilePulling.map(safe4));
|
|
41688
|
+
printSection(`Not synced \u2014 names a synced folder leaves out (${OUTSIDE_SYNC.join(", ")}):`, excluded.map(safe4));
|
|
40451
41689
|
}
|
|
40452
41690
|
function isTextType(contentType) {
|
|
40453
41691
|
const ct = contentType.split(";")[0].trim().toLowerCase();
|
|
@@ -40465,7 +41703,7 @@ function changedLines(before, after) {
|
|
|
40465
41703
|
async function describeSteps(client, t, dir, steps) {
|
|
40466
41704
|
const lines = [];
|
|
40467
41705
|
for (const step of steps) {
|
|
40468
|
-
const rel =
|
|
41706
|
+
const rel = safe4(step.rel);
|
|
40469
41707
|
if (step.op === "create") {
|
|
40470
41708
|
lines.push(`${MARK.create} ${rel} (new, ${step.local.size} bytes)`);
|
|
40471
41709
|
} else if (step.op === "delete") {
|
|
@@ -40492,17 +41730,17 @@ async function describeSteps(client, t, dir, steps) {
|
|
|
40492
41730
|
return lines;
|
|
40493
41731
|
}
|
|
40494
41732
|
function printPushNotes(plan) {
|
|
40495
|
-
printSection("Changed on the base since your last pull \u2014 left as is; pull to take it:", plan.changedOnBase.map(
|
|
40496
|
-
printSection("Deleted on the base since your last pull \u2014 left as is; pull to remove your copy:", plan.deletedOnBase.map(
|
|
40497
|
-
printSection("On the base, not in your files \u2014 left as is; pull to fetch it:", plan.onlyOnBase.map(
|
|
40498
|
-
printSection("Deleted in your files \u2014 kept on the base; push with --prune to delete it:", plan.keptOnBase.map(
|
|
41733
|
+
printSection("Changed on the base since your last pull \u2014 left as is; pull to take it:", plan.changedOnBase.map(safe4));
|
|
41734
|
+
printSection("Deleted on the base since your last pull \u2014 left as is; pull to remove your copy:", plan.deletedOnBase.map(safe4));
|
|
41735
|
+
printSection("On the base, not in your files \u2014 left as is; pull to fetch it:", plan.onlyOnBase.map(safe4));
|
|
41736
|
+
printSection("Deleted in your files \u2014 kept on the base; push with --prune to delete it:", plan.keptOnBase.map(safe4));
|
|
40499
41737
|
}
|
|
40500
41738
|
async function pushFiles(opts) {
|
|
40501
41739
|
const label3 = opts.label === void 0 ? void 0 : labelValue(opts.label);
|
|
40502
41740
|
const { target, dir, existing } = resolveSync(opts);
|
|
40503
41741
|
if (!existing) {
|
|
40504
41742
|
throw expected(
|
|
40505
|
-
`${sanitizeTerminalText(dir)} has no record of a pull (${
|
|
41743
|
+
`${sanitizeTerminalText(dir)} has no record of a pull (${RECORD_FILE2}), so there is nothing to check a push against. Run \`${pullCommand2(target, opts.dir)}\` first; a file type with no files pulls an empty record.`
|
|
40506
41744
|
);
|
|
40507
41745
|
}
|
|
40508
41746
|
const local = scanLocal(dir);
|
|
@@ -40543,7 +41781,7 @@ Push ${n} change${n === 1 ? "" : "s"} to ${describeSync(target)}?`, opts.yes)) {
|
|
|
40543
41781
|
let pushed = 0;
|
|
40544
41782
|
const refusedDeletes = /* @__PURE__ */ new Set();
|
|
40545
41783
|
for (const step of plan.steps) {
|
|
40546
|
-
const
|
|
41784
|
+
const path54 = filePath2(target, step.rel);
|
|
40547
41785
|
const blockedBy = step.op === "create" ? step.after?.find((d) => refusedDeletes.has(d.rel)) : void 0;
|
|
40548
41786
|
if (blockedBy !== void 0) {
|
|
40549
41787
|
const conflict = { rel: step.rel, reason: blockedBy.reason, other: blockedBy.rel };
|
|
@@ -40553,16 +41791,16 @@ Push ${n} change${n === 1 ? "" : "s"} to ${describeSync(target)}?`, opts.yes)) {
|
|
|
40553
41791
|
}
|
|
40554
41792
|
try {
|
|
40555
41793
|
if (step.op === "delete") {
|
|
40556
|
-
await client.request("DELETE",
|
|
41794
|
+
await client.request("DELETE", path54, void 0, fileWriteHeaders({ ifMatch: step.ifMatch }));
|
|
40557
41795
|
delete record.files[step.rel];
|
|
40558
41796
|
} else {
|
|
40559
41797
|
const bytes = readLocal2(dir, step.rel);
|
|
40560
41798
|
if (computeHash(bytes) !== step.local.content_sha256) {
|
|
40561
|
-
throw expected(`${
|
|
41799
|
+
throw expected(`${safe4(step.rel)} changed while the push ran. Nothing more was pushed; run the push again.`);
|
|
40562
41800
|
}
|
|
40563
41801
|
const contentType = step.op === "update" ? step.remote.content_type : guessMimeType(step.rel) ?? "application/octet-stream";
|
|
40564
41802
|
const row = await client.upload(
|
|
40565
|
-
|
|
41803
|
+
path54,
|
|
40566
41804
|
bytes,
|
|
40567
41805
|
contentType,
|
|
40568
41806
|
fileWriteHeaders({ ...step.op === "update" ? { ifMatch: step.ifMatch } : { createOnly: true }, label: label3 })
|
|
@@ -40573,7 +41811,7 @@ Push ${n} change${n === 1 ? "" : "s"} to ${describeSync(target)}?`, opts.yes)) {
|
|
|
40573
41811
|
};
|
|
40574
41812
|
}
|
|
40575
41813
|
pushed++;
|
|
40576
|
-
console.log(` ${MARK[step.op]} ${
|
|
41814
|
+
console.log(` ${MARK[step.op]} ${safe4(step.rel)}`);
|
|
40577
41815
|
} catch (err) {
|
|
40578
41816
|
if (step.op === "delete" && err instanceof ApiError && err.status === 404) {
|
|
40579
41817
|
delete record.files[step.rel];
|
|
@@ -40601,7 +41839,7 @@ function finishWithConflicts(t, dir, conflicts) {
|
|
|
40601
41839
|
`${count} conflict${count === 1 ? "" : "s"} not pushed \u2014 the base's copies of those files were left as they are. To settle them, ${remedy(conflicts, pullCommand2(t, dir, true))}, then push again.`
|
|
40602
41840
|
);
|
|
40603
41841
|
}
|
|
40604
|
-
var LIST_PAGE, MAX_LIST_PAGES, MAX_DIFF_BYTES, MARK,
|
|
41842
|
+
var LIST_PAGE, MAX_LIST_PAGES, MAX_DIFF_BYTES, MARK, safe4, PULL_KEPT, PULL_CONFLICT, PUSH_CONFLICT;
|
|
40605
41843
|
var init_sync3 = __esm({
|
|
40606
41844
|
"src/data/files-sync/sync.ts"() {
|
|
40607
41845
|
"use strict";
|
|
@@ -40623,7 +41861,7 @@ var init_sync3 = __esm({
|
|
|
40623
41861
|
MAX_LIST_PAGES = 1e3;
|
|
40624
41862
|
MAX_DIFF_BYTES = 256 * 1024;
|
|
40625
41863
|
MARK = { create: "+", update: "~", delete: "-" };
|
|
40626
|
-
|
|
41864
|
+
safe4 = (rel) => sanitizeTerminalText(rel);
|
|
40627
41865
|
PULL_KEPT = {
|
|
40628
41866
|
edited: "edited in your files, not pushed yet",
|
|
40629
41867
|
deleted: "deleted in your files, not pushed yet (push --prune deletes it from the base)"
|
|
@@ -40649,523 +41887,9 @@ var init_sync3 = __esm({
|
|
|
40649
41887
|
}
|
|
40650
41888
|
});
|
|
40651
41889
|
|
|
40652
|
-
// ../../packages/core/dist/contracts/case-comments.js
|
|
40653
|
-
var init_case_comments = __esm({
|
|
40654
|
-
"../../packages/core/dist/contracts/case-comments.js"() {
|
|
40655
|
-
"use strict";
|
|
40656
|
-
init_chunk_S7UAXLHJ();
|
|
40657
|
-
init_chunk_7TQYAKCB();
|
|
40658
|
-
init_chunk_VROZDNLV();
|
|
40659
|
-
init_chunk_733K4J4G();
|
|
40660
|
-
init_chunk_PFPADFUC();
|
|
40661
|
-
init_chunk_KWRHZBGU();
|
|
40662
|
-
init_chunk_3T3D7LTE();
|
|
40663
|
-
init_chunk_M2T55BV6();
|
|
40664
|
-
init_chunk_VYINA6YP();
|
|
40665
|
-
init_chunk_ZVXO3XL6();
|
|
40666
|
-
init_chunk_FBV7NLKO();
|
|
40667
|
-
init_chunk_WEXVYJ5H();
|
|
40668
|
-
init_chunk_HZ6CADSY();
|
|
40669
|
-
init_chunk_ICYO56QW();
|
|
40670
|
-
init_chunk_WFQDSQJK();
|
|
40671
|
-
init_chunk_ZTNFLGW5();
|
|
40672
|
-
}
|
|
40673
|
-
});
|
|
40674
|
-
|
|
40675
|
-
// src/cases/case-mirror.ts
|
|
40676
|
-
import * as crypto4 from "crypto";
|
|
40677
|
-
import * as fs35 from "fs";
|
|
40678
|
-
import * as os4 from "os";
|
|
40679
|
-
import * as path47 from "path";
|
|
40680
|
-
function shownEntries(revision, confidential) {
|
|
40681
|
-
return confidential ? revision.entries : revision.entries.filter((e) => !e.confidential && !isConfPath(e.path));
|
|
40682
|
-
}
|
|
40683
|
-
function isBaseline(b) {
|
|
40684
|
-
return isObject(b) && typeof b.at === "string" && typeof b.confidential === "boolean" && (b.revision_at === null || typeof b.revision_at === "string") && (b.status === null || typeof b.status === "string") && isStringMap(b.phases) && isStringMap(b.tasks) && isStringMap(b.groups) && isDeliveries(b.deliveries);
|
|
40685
|
-
}
|
|
40686
|
-
function isMirrorRecord(v) {
|
|
40687
|
-
return isObject(v) && typeof v.org_id === "string" && typeof v.space_id === "string" && typeof v.code === "string" && (v.last_pull === null || isBaseline(v.last_pull));
|
|
40688
|
-
}
|
|
40689
|
-
function mirrorFolder(root) {
|
|
40690
|
-
const dir = path47.join(root, CASE_MIRROR_DIR);
|
|
40691
|
-
let st;
|
|
40692
|
-
try {
|
|
40693
|
-
st = fs35.lstatSync(dir);
|
|
40694
|
-
} catch {
|
|
40695
|
-
return null;
|
|
40696
|
-
}
|
|
40697
|
-
if (!st.isDirectory()) {
|
|
40698
|
-
throw expected(`${safe2(dir)} is a symlink or not a folder. It is the case's mirror, which the CLI writes: move it aside, then pull again.`);
|
|
40699
|
-
}
|
|
40700
|
-
requireOwn(dir);
|
|
40701
|
-
return dir;
|
|
40702
|
-
}
|
|
40703
|
-
function readBaseline(root, detail, record) {
|
|
40704
|
-
const dir = mirrorFolder(root);
|
|
40705
|
-
if (!dir) return null;
|
|
40706
|
-
const file = path47.join(dir, RECORD_FILE2);
|
|
40707
|
-
requireOwn(file);
|
|
40708
|
-
const text5 = readRealFileOrThrow(root, file);
|
|
40709
|
-
if (text5 === null) return null;
|
|
40710
|
-
let parsed;
|
|
40711
|
-
try {
|
|
40712
|
-
parsed = JSON.parse(text5);
|
|
40713
|
-
} catch {
|
|
40714
|
-
return null;
|
|
40715
|
-
}
|
|
40716
|
-
if (!isMirrorRecord(parsed)) return null;
|
|
40717
|
-
if (parsed.org_id !== record.org_id || parsed.space_id !== record.space_id || parsed.code !== detail.code) return null;
|
|
40718
|
-
return parsed.last_pull;
|
|
40719
|
-
}
|
|
40720
|
-
async function readAgenda(calls, phaseId) {
|
|
40721
|
-
const { api, connection } = calls.session;
|
|
40722
|
-
const groups = [];
|
|
40723
|
-
let cursor;
|
|
40724
|
-
for (let page = 0; page < AGENDA_PAGES_READ2; page++) {
|
|
40725
|
-
const { groups: got, next_cursor } = (await calls.run(() => api.getCaseAgenda(connection, phaseId, cursor))).data;
|
|
40726
|
-
groups.push(...got);
|
|
40727
|
-
if (!next_cursor) return { groups, more: false };
|
|
40728
|
-
cursor = next_cursor;
|
|
40729
|
-
}
|
|
40730
|
-
return { groups, more: true };
|
|
40731
|
-
}
|
|
40732
|
-
async function readInputTexts(calls, folder, work) {
|
|
40733
|
-
const { api, connection } = calls.session;
|
|
40734
|
-
const notFound = (call4) => call4.catch((err) => err instanceof ApiError && err.status === 404 ? null : Promise.reject(err));
|
|
40735
|
-
const linked = work.inputs.filter((input) => input.link?.readable === true);
|
|
40736
|
-
const read = await Promise.all(linked.map(async (input) => {
|
|
40737
|
-
const view = (await calls.run(() => api.getCaseInputLink(connection, input.id))).data;
|
|
40738
|
-
if (!view?.readable) return null;
|
|
40739
|
-
const answered = await calls.run(() => notFound(api.getCaseCollectionContent(connection, view.document_id, { part: "text", version_id: view.version_id })));
|
|
40740
|
-
const passages = view.passages.filter((p) => p.version_id === view.version_id);
|
|
40741
|
-
const base = { input_id: input.id, key: input.key, name: input.name, document_id: view.document_id, version_id: view.version_id };
|
|
40742
|
-
const unmatched = passages.map((p) => ({ passage_id: p.passage_id, line_start: p.line_start, line_end: p.line_end, passage_sha: p.passage_sha, matches: false }));
|
|
40743
|
-
if (!answered) return { text: { ...base, status: "no_text", file: null, sha: null, passages: unmatched }, data: null };
|
|
40744
|
-
if (answered.sha === null || computeHash(answered.bytes) !== answered.sha) {
|
|
40745
|
-
return { text: { ...base, status: "hash_mismatch", file: null, sha: answered.sha, passages: unmatched }, data: null };
|
|
40746
|
-
}
|
|
40747
|
-
const lines = unmatched.length ? casePassageLines(new TextDecoder("utf-8").decode(answered.bytes)) : [];
|
|
40748
|
-
const file = `${INPUTS_DIR}/${folder}/${segment(input.key, CASE_INPUT_KEY_PATTERN, input.id)}.md`;
|
|
40749
|
-
return {
|
|
40750
|
-
text: {
|
|
40751
|
-
...base,
|
|
40752
|
-
status: "written",
|
|
40753
|
-
file,
|
|
40754
|
-
sha: answered.sha,
|
|
40755
|
-
passages: unmatched.map((p) => {
|
|
40756
|
-
const inRange = p.line_start >= 1 && p.line_end >= p.line_start && p.line_end <= lines.length;
|
|
40757
|
-
const cited = Buffer.from(lines.slice(p.line_start - 1, p.line_end).join("\n"), "utf-8");
|
|
40758
|
-
return { ...p, matches: inRange && computeHash(cited) === p.passage_sha };
|
|
40759
|
-
})
|
|
40760
|
-
},
|
|
40761
|
-
data: Buffer.from(answered.bytes.buffer, answered.bytes.byteOffset, answered.bytes.byteLength)
|
|
40762
|
-
};
|
|
40763
|
-
}));
|
|
40764
|
-
return read.filter((r) => r !== null);
|
|
40765
|
-
}
|
|
40766
|
-
async function readWork(calls, detail, confidential) {
|
|
40767
|
-
const { api, connection } = calls.session;
|
|
40768
|
-
const state = (await calls.run(() => api.getCaseState(connection))).data;
|
|
40769
|
-
if (state.view !== "work") return { state, phases: [], approved: [] };
|
|
40770
|
-
const folders = new Map(detail.phases.map((p) => [p.phase_id, p.folder]));
|
|
40771
|
-
const underWay = state.state.phases.filter((p) => p.status === "in_progress").map((p) => p.phase_id);
|
|
40772
|
-
const [phases, approved] = await Promise.all([
|
|
40773
|
-
Promise.all(underWay.map(async (phaseId) => {
|
|
40774
|
-
const folder = folders.get(phaseId) ?? "";
|
|
40775
|
-
const [{ work, texts }, agenda, delivery] = await Promise.all([
|
|
40776
|
-
calls.run(() => api.getCasePhaseWork(connection, phaseId)).then(async ({ data }) => ({
|
|
40777
|
-
work: data,
|
|
40778
|
-
texts: await readInputTexts(calls, segment(folder, CASE_PHASE_FOLDER_PATTERN, phaseId), data)
|
|
40779
|
-
})),
|
|
40780
|
-
readAgenda(calls, phaseId),
|
|
40781
|
-
calls.run(() => api.getCaseDelivery(connection, phaseId))
|
|
40782
|
-
]);
|
|
40783
|
-
return { phase_id: phaseId, folder, work, groups: agenda.groups, more_groups: agenda.more, delivery: delivery.data, texts };
|
|
40784
|
-
})),
|
|
40785
|
-
calls.run(() => api.listCaseApprovedDecisions(connection, confidential))
|
|
40786
|
-
]);
|
|
40787
|
-
return { state, phases, approved: approved.data };
|
|
40788
|
-
}
|
|
40789
|
-
async function revisionsSince(calls, after, confidential) {
|
|
40790
|
-
const { api, connection } = calls.session;
|
|
40791
|
-
const out = [];
|
|
40792
|
-
let newest = after ?? null;
|
|
40793
|
-
let cursor;
|
|
40794
|
-
const pages = after === void 0 ? 1 : SUMMARY_REVISION_PAGES;
|
|
40795
|
-
for (let page = 0; page < pages; page++) {
|
|
40796
|
-
const { revisions, next_cursor } = (await calls.run(() => api.listCaseRevisions(connection, { cursor, limit: CASE_REVISIONS_PAGE_MAX }))).data;
|
|
40797
|
-
for (const revision of revisions) {
|
|
40798
|
-
if (after !== void 0 && after !== null && revision.created_at <= after) return { revisions: out, more: false, newest_at: newest };
|
|
40799
|
-
const entries = shownEntries(revision, confidential);
|
|
40800
|
-
if (entries.length === 0) continue;
|
|
40801
|
-
if (newest === null || revision.created_at > newest) newest = revision.created_at;
|
|
40802
|
-
if (after !== void 0) out.push({ ...revision, entries });
|
|
40803
|
-
}
|
|
40804
|
-
if (!next_cursor) return { revisions: out, more: false, newest_at: newest };
|
|
40805
|
-
cursor = next_cursor;
|
|
40806
|
-
}
|
|
40807
|
-
return { revisions: out, more: after !== void 0, newest_at: newest };
|
|
40808
|
-
}
|
|
40809
|
-
function snapshotOf(work) {
|
|
40810
|
-
if (!work) return { status: null, phases: {}, tasks: {}, groups: {}, deliveries: {} };
|
|
40811
|
-
if (work.state.view === "phases") {
|
|
40812
|
-
return { status: work.state.status, phases: Object.fromEntries(work.state.phases.map((p) => [p.phase_id, p.status])), tasks: {}, groups: {}, deliveries: {} };
|
|
40813
|
-
}
|
|
40814
|
-
const { state } = work.state;
|
|
40815
|
-
return {
|
|
40816
|
-
status: state.status,
|
|
40817
|
-
phases: Object.fromEntries(state.phases.map((p) => [p.phase_id, p.status])),
|
|
40818
|
-
tasks: Object.fromEntries(state.tasks.map((t) => [t.case_task_id, t.status])),
|
|
40819
|
-
groups: Object.fromEntries(state.agenda_groups.map((g) => [g.agenda_group_id, g.status])),
|
|
40820
|
-
deliveries: Object.fromEntries(work.phases.map((p) => [p.phase_id, p.delivery ? { submission_id: p.delivery.submission_id, state: p.delivery.state } : null]))
|
|
40821
|
-
};
|
|
40822
|
-
}
|
|
40823
|
-
function statusSections(detail, work, before, now) {
|
|
40824
|
-
const phase = new Map(detail.phases.map((p) => [p.phase_id, `${one2(p.folder)} (${one2(p.name)})`]));
|
|
40825
|
-
const task = new Map((detail.tasks ?? []).map((t) => [t.case_task_id, `${one2(t.name)} [${t.case_task_id}]`]));
|
|
40826
|
-
const group = new Map(work.phases.flatMap((p) => p.groups.map((g) => [g.agenda_group_id, `${one2(g.code)} (${one2(g.name)})`])));
|
|
40827
|
-
const changes = (prev, next, name, added) => Object.entries(next).flatMap(([id, status]) => {
|
|
40828
|
-
const was = prev[id];
|
|
40829
|
-
if (was === void 0) return added ? [`${name(id)}: new, ${words(status)}`] : [];
|
|
40830
|
-
return was === status ? [] : [`${name(id)}: ${words(was)} \u2192 ${words(status)}`];
|
|
40831
|
-
});
|
|
40832
|
-
const sections = [];
|
|
40833
|
-
if (before.status !== null && now.status !== null && before.status !== now.status) {
|
|
40834
|
-
sections.push({ title: "The case", lines: [`${words(before.status)} \u2192 ${words(now.status)}`] });
|
|
40835
|
-
}
|
|
40836
|
-
sections.push({ title: "Phases", lines: changes(before.phases, now.phases, (id) => phase.get(id) ?? "a phase", false) });
|
|
40837
|
-
sections.push({ title: "Tasks", lines: changes(before.tasks, now.tasks, (id) => task.get(id) ?? `a task [${id}]`, true) });
|
|
40838
|
-
sections.push({ title: "Agenda groups", lines: changes(before.groups, now.groups, (id) => group.get(id) ?? "an agenda group of a phase not under way", false) });
|
|
40839
|
-
const deliveries = work.phases.flatMap((p) => {
|
|
40840
|
-
if (!(p.phase_id in before.deliveries) || !p.delivery) return [];
|
|
40841
|
-
const was = before.deliveries[p.phase_id];
|
|
40842
|
-
if (was?.submission_id === p.delivery.submission_id && was.state === p.delivery.state) return [];
|
|
40843
|
-
const change = was?.submission_id === p.delivery.submission_id ? `its submission is now ${words(p.delivery.state)}` : `a new submission, ${words(p.delivery.state)}`;
|
|
40844
|
-
return [`${phase.get(p.phase_id) ?? "a phase"}: ${change}`];
|
|
40845
|
-
});
|
|
40846
|
-
sections.push({ title: "Deliveries", lines: deliveries });
|
|
40847
|
-
return sections;
|
|
40848
|
-
}
|
|
40849
|
-
function filesSection(input) {
|
|
40850
|
-
const now = new Map(input.files.filter((f) => input.inRun(f.path)).map((f) => [f.path, f.sha]));
|
|
40851
|
-
const before = new Map(Object.entries(input.record.files).filter(([rel]) => input.inRun(rel)).map(([rel, f]) => [rel, f.sha]));
|
|
40852
|
-
const lines = [];
|
|
40853
|
-
for (const [rel, sha] of now) {
|
|
40854
|
-
if (!before.has(rel)) lines.push(`+ ${safe2(rel)}`);
|
|
40855
|
-
else if (before.get(rel) !== sha) lines.push(`~ ${safe2(rel)}`);
|
|
40856
|
-
}
|
|
40857
|
-
for (const rel of before.keys()) if (!now.has(rel)) lines.push(`- ${safe2(rel)} (removed, or no longer readable here)`);
|
|
40858
|
-
return { title: "Files on the case that differ from what this clone last pulled", lines: lines.sort((a, b) => a.slice(2) < b.slice(2) ? -1 : 1) };
|
|
40859
|
-
}
|
|
40860
|
-
function revisionsSection(since, hideMessages) {
|
|
40861
|
-
const lines = since.revisions.flatMap((r) => {
|
|
40862
|
-
const author = r.author?.display_name ? one2(r.author.display_name) : "a person no longer named";
|
|
40863
|
-
const message = r.message !== null && !hideMessages ? `: ${one2(r.message)}` : "";
|
|
40864
|
-
return [`revision ${r.revision_id}, ${r.created_at}, ${author} (${r.channel})${message}`, ...r.entries.map((e) => ` ${safe2(e.path)}${e.sha === null ? " (removed)" : ""}`)];
|
|
40865
|
-
});
|
|
40866
|
-
if (since.more) lines.push("\u2026 and older ones: `wayai cases log` lists them all.");
|
|
40867
|
-
return { title: "Revisions", lines };
|
|
40868
|
-
}
|
|
40869
|
-
function renderSections(sections) {
|
|
40870
|
-
return sections.filter((s) => s.lines.length > 0).flatMap((s) => [`${s.title}:`, ...s.lines.map((l) => ` ${l}`)]);
|
|
40871
|
-
}
|
|
40872
|
-
function unwrittenLines(work) {
|
|
40873
|
-
return (work?.phases ?? []).flatMap((p) => p.texts.flatMap(({ text: text5 }) => {
|
|
40874
|
-
const name = `${one2(p.folder)}, input ${one2(text5.key)} (${one2(text5.name)})`;
|
|
40875
|
-
if (text5.status === "hash_mismatch") {
|
|
40876
|
-
return [`${name}: not written, its bytes do not hash to the SHA-256 the space registered for it${text5.sha === null ? " (none was answered)" : ""}.`];
|
|
40877
|
-
}
|
|
40878
|
-
return text5.status === "no_text" ? [`${name}: the version it links holds no registered text, or is no longer readable here.`] : [];
|
|
40879
|
-
}));
|
|
40880
|
-
}
|
|
40881
|
-
function readme(detail, at, withheld, confidential, unwritten) {
|
|
40882
|
-
const parts = withheld ? [
|
|
40883
|
-
"This authorization holds the Confidential right, and the case's own reads give it confidential content whatever",
|
|
40884
|
-
"it asks: without --confidential this mirror holds none of them (case, status, evidence, agenda, deliveries,",
|
|
40885
|
-
"linked inputs' texts)."
|
|
40886
|
-
] : [
|
|
40887
|
-
"- `case.json`: the case: its type and version, owner, parties, phases and their folders, tasks, and your access.",
|
|
40888
|
-
"- `status.json`: its status: each phase's, task's and agenda group's, why each is not done, and who can move it.",
|
|
40889
|
-
"- `evidence.json`: each phase under way: its inputs with their links, its outputs and its items.",
|
|
40890
|
-
"- `agenda.json`: each phase under way: its agenda groups and decisions; and the approved decisions.",
|
|
40891
|
-
"- `deliveries.json`: each phase under way: its newest submission and manifest.",
|
|
40892
|
-
`- \`${INPUTS_FILE}\`: each phase under way: each input whose link you may read, the version it links, where its text`,
|
|
40893
|
-
" is here, and its cited passages (lines and hash, and whether they match the text here).",
|
|
40894
|
-
`- \`${INPUTS_DIR}/<phase folder>/<input key>.md\`: each such input's registered text, of the version its link names,`,
|
|
40895
|
-
" byte for byte and checked against the SHA-256 the space registered for it: line N here is the line N a citation",
|
|
40896
|
-
" names (each line ends at a line break).",
|
|
40897
|
-
...unwritten.length ? ["", "Linked inputs' texts not written:", ...unwritten.map((line) => `- ${line}`)] : []
|
|
40898
|
-
];
|
|
40899
|
-
return [
|
|
40900
|
-
`# Case ${safe2(detail.code)}: read-only mirror`,
|
|
40901
|
-
"",
|
|
40902
|
-
`Written ${at} by \`wayai cases clone\` or \`pull\`. Every pull rewrites this folder whole, and \`wayai cases push\` never sends`,
|
|
40903
|
-
"anything in it: an edit here is lost and never reaches the case.",
|
|
40904
|
-
"",
|
|
40905
|
-
`- \`${SUMMARY_FILE}\`: what changed on the case since your last pull.`,
|
|
40906
|
-
...parts,
|
|
40907
|
-
`- \`${CASE_MIRROR_HOOK_FILE}\`: the session-start hook. It refreshes this folder, never with --confidential.`,
|
|
40908
|
-
`- \`${RECORD_FILE2}\`: what the next pull compares with.`,
|
|
40909
|
-
"",
|
|
40910
|
-
"Not here: the drafting checks (`wayai cases check --phase <folder>` reads them live).",
|
|
40911
|
-
...confidential ? [] : ["", MIRROR_CONFIDENTIAL_NOTICE],
|
|
40912
|
-
""
|
|
40913
|
-
].join("\n");
|
|
40914
|
-
}
|
|
40915
|
-
function lockOwnerStopped(text5) {
|
|
40916
|
-
const owner = text5 === null ? null : /^(\d+) (\S+) [0-9a-f]+$/.exec(text5) ?? null;
|
|
40917
|
-
if (!owner || owner[2] !== os4.hostname()) return false;
|
|
40918
|
-
try {
|
|
40919
|
-
process.kill(Number(owner[1]), 0);
|
|
40920
|
-
return false;
|
|
40921
|
-
} catch (err) {
|
|
40922
|
-
return err.code === "ESRCH";
|
|
40923
|
-
}
|
|
40924
|
-
}
|
|
40925
|
-
async function lockMirror(root) {
|
|
40926
|
-
const dir = path47.join(root, CASE_MIRROR_DIR);
|
|
40927
|
-
if (!mirrorFolder(root)) {
|
|
40928
|
-
try {
|
|
40929
|
-
fs35.mkdirSync(dir, { mode: CASE_FOLDER_MODE });
|
|
40930
|
-
fs35.chmodSync(dir, CASE_FOLDER_MODE);
|
|
40931
|
-
} catch (err) {
|
|
40932
|
-
if (err.code !== "EEXIST") throw err;
|
|
40933
|
-
}
|
|
40934
|
-
mirrorFolder(root);
|
|
40935
|
-
}
|
|
40936
|
-
const lock = path47.join(dir, LOCK_FILE);
|
|
40937
|
-
const mine = `${process.pid} ${os4.hostname()} ${crypto4.randomBytes(16).toString("hex")}`;
|
|
40938
|
-
const held = (file) => {
|
|
40939
|
-
try {
|
|
40940
|
-
return fs35.readFileSync(file, "utf-8");
|
|
40941
|
-
} catch {
|
|
40942
|
-
return null;
|
|
40943
|
-
}
|
|
40944
|
-
};
|
|
40945
|
-
const refusal2 = (err) => {
|
|
40946
|
-
const code2 = err.code;
|
|
40947
|
-
return code2 === "EACCES" || code2 === "EPERM" || code2 === "EROFS" ? expected(`The mirror's folder ${safe2(dir)} cannot be written (${code2}). Make it writable by you (it is the CLI's to write), then pull again.`) : err;
|
|
40948
|
-
};
|
|
40949
|
-
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
40950
|
-
for (; ; ) {
|
|
40951
|
-
try {
|
|
40952
|
-
const fd = fs35.openSync(lock, "wx", 420);
|
|
40953
|
-
try {
|
|
40954
|
-
fs35.writeFileSync(fd, mine);
|
|
40955
|
-
} finally {
|
|
40956
|
-
fs35.closeSync(fd);
|
|
40957
|
-
}
|
|
40958
|
-
return () => {
|
|
40959
|
-
if (held(lock) === mine) fs35.rmSync(lock, { force: true });
|
|
40960
|
-
};
|
|
40961
|
-
} catch (err) {
|
|
40962
|
-
if (err.code !== "EEXIST") throw refusal2(err);
|
|
40963
|
-
}
|
|
40964
|
-
const judged = held(lock);
|
|
40965
|
-
let age = 0;
|
|
40966
|
-
try {
|
|
40967
|
-
age = Date.now() - fs35.lstatSync(lock).mtimeMs;
|
|
40968
|
-
} catch (err) {
|
|
40969
|
-
if (err.code === "ENOENT") continue;
|
|
40970
|
-
throw refusal2(err);
|
|
40971
|
-
}
|
|
40972
|
-
if (judged !== null && (lockOwnerStopped(judged) || age > LOCK_STALE_MS)) {
|
|
40973
|
-
const aside = path47.join(dir, `${LOCK_FILE}.stale-${mine.split(" ")[2]}`);
|
|
40974
|
-
try {
|
|
40975
|
-
fs35.renameSync(lock, aside);
|
|
40976
|
-
} catch (err) {
|
|
40977
|
-
if (err.code === "ENOENT") continue;
|
|
40978
|
-
throw refusal2(err);
|
|
40979
|
-
}
|
|
40980
|
-
if (held(aside) !== judged) {
|
|
40981
|
-
try {
|
|
40982
|
-
fs35.linkSync(aside, lock);
|
|
40983
|
-
} catch {
|
|
40984
|
-
}
|
|
40985
|
-
}
|
|
40986
|
-
fs35.rmSync(aside, { force: true });
|
|
40987
|
-
continue;
|
|
40988
|
-
}
|
|
40989
|
-
if (Date.now() > deadline) {
|
|
40990
|
-
throw expected(`Another run has held the mirror at ${safe2(dir)} for ${Math.round(age / 1e3)} s. Pull again once it ends.`);
|
|
40991
|
-
}
|
|
40992
|
-
await new Promise((resolve18) => setTimeout(resolve18, LOCK_POLL_MS));
|
|
40993
|
-
}
|
|
40994
|
-
}
|
|
40995
|
-
function writeMirror(root, files) {
|
|
40996
|
-
const id = crypto4.randomBytes(8).toString("hex");
|
|
40997
|
-
const dir = path47.join(root, CASE_MIRROR_DIR);
|
|
40998
|
-
const at = (name) => path47.join(dir, ...name.split("/"));
|
|
40999
|
-
const temp = (name) => {
|
|
41000
|
-
const slash = name.lastIndexOf("/");
|
|
41001
|
-
return `${name.slice(0, slash + 1)}.tmp-${id}-${name.slice(slash + 1)}`;
|
|
41002
|
-
};
|
|
41003
|
-
const lstat = (target) => {
|
|
41004
|
-
try {
|
|
41005
|
-
return fs35.lstatSync(target);
|
|
41006
|
-
} catch {
|
|
41007
|
-
return void 0;
|
|
41008
|
-
}
|
|
41009
|
-
};
|
|
41010
|
-
const folders = new Set(files.flatMap((f) => f.name.split("/").slice(0, -1).map((_, i, all) => all.slice(0, i + 1).join("/"))));
|
|
41011
|
-
try {
|
|
41012
|
-
for (const folder of folders) {
|
|
41013
|
-
const st = lstat(at(folder));
|
|
41014
|
-
if (st && !st.isDirectory()) fs35.rmSync(at(folder), { force: true });
|
|
41015
|
-
}
|
|
41016
|
-
for (const f of files) {
|
|
41017
|
-
writeCaseLocalFile(root, `${CASE_MIRROR_DIR}/${temp(f.name)}`, f.data);
|
|
41018
|
-
if (f.mode !== void 0) fs35.chmodSync(at(temp(f.name)), f.mode);
|
|
41019
|
-
}
|
|
41020
|
-
for (const f of files) {
|
|
41021
|
-
if (lstat(at(f.name))?.isDirectory()) fs35.rmSync(at(f.name), { recursive: true, force: true });
|
|
41022
|
-
fs35.renameSync(at(temp(f.name)), at(f.name));
|
|
41023
|
-
}
|
|
41024
|
-
const names = new Set(files.map((f) => f.name));
|
|
41025
|
-
const sweep = (folder) => {
|
|
41026
|
-
for (const name of fs35.readdirSync(folder === null ? dir : at(folder))) {
|
|
41027
|
-
const rel = folder === null ? name : `${folder}/${name}`;
|
|
41028
|
-
if (names.has(rel) || rel === LOCK_FILE) continue;
|
|
41029
|
-
if (folders.has(rel) && lstat(at(rel))?.isDirectory()) sweep(rel);
|
|
41030
|
-
else fs35.rmSync(at(rel), { recursive: true, force: true });
|
|
41031
|
-
}
|
|
41032
|
-
};
|
|
41033
|
-
sweep(null);
|
|
41034
|
-
} finally {
|
|
41035
|
-
for (const f of files) fs35.rmSync(at(temp(f.name)), { force: true });
|
|
41036
|
-
}
|
|
41037
|
-
}
|
|
41038
|
-
async function writeCaseMirror(calls, input) {
|
|
41039
|
-
const { root, detail, confidential, mode } = input;
|
|
41040
|
-
const before = mode === "clone" ? null : readBaseline(root, detail, input.record);
|
|
41041
|
-
const withheld = detail.access.capabilities.includes("read_confidential") && !confidential;
|
|
41042
|
-
const readsRevisions = before !== null || mode !== "mirror-only";
|
|
41043
|
-
const [work, since] = await Promise.all([
|
|
41044
|
-
withheld ? null : readWork(calls, detail, confidential),
|
|
41045
|
-
readsRevisions ? revisionsSince(calls, before ? before.revision_at : void 0, confidential) : NO_REVISIONS
|
|
41046
|
-
]);
|
|
41047
|
-
const now = snapshotOf(work);
|
|
41048
|
-
const at = nowIso();
|
|
41049
|
-
let baseline;
|
|
41050
|
-
if (mode !== "mirror-only") {
|
|
41051
|
-
baseline = { at, confidential, revision_at: since.newest_at, ...now };
|
|
41052
|
-
} else if (before && before.confidential && !confidential) {
|
|
41053
|
-
baseline = {
|
|
41054
|
-
...before,
|
|
41055
|
-
confidential: false,
|
|
41056
|
-
status: now.status === null ? null : before.status,
|
|
41057
|
-
phases: within(before.phases, now.phases),
|
|
41058
|
-
tasks: within(before.tasks, now.tasks),
|
|
41059
|
-
groups: within(before.groups, now.groups),
|
|
41060
|
-
deliveries: within(before.deliveries, now.deliveries)
|
|
41061
|
-
};
|
|
41062
|
-
} else {
|
|
41063
|
-
baseline = before;
|
|
41064
|
-
}
|
|
41065
|
-
const sections = [];
|
|
41066
|
-
if (before) sections.push(revisionsSection(since, withheld));
|
|
41067
|
-
if (mode !== "clone") sections.push(filesSection(input));
|
|
41068
|
-
if (before && work) sections.push(...statusSections(detail, work, before, now));
|
|
41069
|
-
const lines = renderSections(sections);
|
|
41070
|
-
const heading = mode === "clone" ? "This is the clone's first pull: there is nothing earlier to compare with." : before ? `Since the last pull (${before.at}):` : "No record of an earlier pull is in this clone's mirror: only its files are compared.";
|
|
41071
|
-
const summary = [heading, ...lines.length ? lines : before ? ["Nothing changed."] : []];
|
|
41072
|
-
const notice = confidential ? [] : ["", MIRROR_CONFIDENTIAL_NOTICE];
|
|
41073
|
-
const unwritten = unwrittenLines(work);
|
|
41074
|
-
const files = [
|
|
41075
|
-
{ name: "README.md", data: Buffer.from(readme(detail, at, withheld, confidential, unwritten), "utf-8") },
|
|
41076
|
-
{ name: SUMMARY_FILE, data: Buffer.from(`# Case ${safe2(detail.code)}: since the last pull
|
|
41077
|
-
|
|
41078
|
-
${[...summary, ...notice].join("\n")}
|
|
41079
|
-
`, "utf-8") },
|
|
41080
|
-
{ name: CASE_MIRROR_HOOK_FILE, data: Buffer.from(HOOK_SCRIPT, "utf-8"), mode: 493 },
|
|
41081
|
-
{ name: RECORD_FILE2, data: json({ org_id: input.record.org_id, space_id: input.record.space_id, code: detail.code, last_pull: baseline }) }
|
|
41082
|
-
];
|
|
41083
|
-
if (work) {
|
|
41084
|
-
files.push(
|
|
41085
|
-
{ name: "case.json", data: json(detail) },
|
|
41086
|
-
{ name: "status.json", data: json(work.state) },
|
|
41087
|
-
{ name: "evidence.json", data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, work: p.work })) }) },
|
|
41088
|
-
{ name: "agenda.json", data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, groups: p.groups, more_groups: p.more_groups })), approved: work.approved }) },
|
|
41089
|
-
{ name: "deliveries.json", data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, delivery: p.delivery })) }) },
|
|
41090
|
-
{ name: INPUTS_FILE, data: json({ phases: work.phases.map((p) => ({ phase_id: p.phase_id, folder: p.folder, inputs: p.texts.map((t) => t.text) })) }) },
|
|
41091
|
-
...work.phases.flatMap((p) => p.texts.flatMap(({ text: text5, data }) => text5.file !== null && data !== null ? [{ name: text5.file, data }] : []))
|
|
41092
|
-
);
|
|
41093
|
-
}
|
|
41094
|
-
writeMirror(root, files);
|
|
41095
|
-
console.log(`
|
|
41096
|
-
Mirror of case ${safe2(detail.code)} written to ${safe2(path47.join(root, CASE_MIRROR_DIR))} (read-only: every pull rewrites it).`);
|
|
41097
|
-
for (const line of unwritten) console.log(`Linked input's text: ${line}`);
|
|
41098
|
-
for (const line of mode === "mirror-only" ? [...summary, ...notice] : summary) console.log(line);
|
|
41099
|
-
}
|
|
41100
|
-
async function withMirrorLock(root, step) {
|
|
41101
|
-
const unlock = await lockMirror(root);
|
|
41102
|
-
try {
|
|
41103
|
-
return await step();
|
|
41104
|
-
} finally {
|
|
41105
|
-
unlock();
|
|
41106
|
-
}
|
|
41107
|
-
}
|
|
41108
|
-
function printHookSetup(root) {
|
|
41109
|
-
const script = path47.join(root, CASE_MIRROR_DIR, CASE_MIRROR_HOOK_FILE);
|
|
41110
|
-
const command2 = `sh '${script.replaceAll("'", "'\\''")}'`;
|
|
41111
|
-
const settings = JSON.stringify({ hooks: { SessionStart: [{ hooks: [{ type: "command", command: command2 }] }] } });
|
|
41112
|
-
console.log(`
|
|
41113
|
-
Session-start hook: ${safe2(script)} refreshes the mirror (never with --confidential).`);
|
|
41114
|
-
console.log(`For Claude Code, add it to ${safe2(path47.join(root, ".claude", "settings.json"))}:`);
|
|
41115
|
-
console.log(` ${safe2(settings)}`);
|
|
41116
|
-
console.log(`For another agent, run at the start of each session: ${safe2(command2)}`);
|
|
41117
|
-
}
|
|
41118
|
-
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_READ2, SUMMARY_REVISION_PAGES, MIRROR_CONFIDENTIAL_NOTICE, safe2, one2, words, isConfPath, isObject, isStringMap, isDeliveries, segment, NO_REVISIONS, within, HOOK_SCRIPT, json;
|
|
41119
|
-
var init_case_mirror = __esm({
|
|
41120
|
-
"src/cases/case-mirror.ts"() {
|
|
41121
|
-
"use strict";
|
|
41122
|
-
init_dist();
|
|
41123
|
-
init_case_files();
|
|
41124
|
-
init_case_comments();
|
|
41125
|
-
init_case_types();
|
|
41126
|
-
init_api_client();
|
|
41127
|
-
init_resource_files();
|
|
41128
|
-
init_utils();
|
|
41129
|
-
init_expected();
|
|
41130
|
-
init_fs_safety();
|
|
41131
|
-
init_terminal_output();
|
|
41132
|
-
init_case_local_files();
|
|
41133
|
-
CASE_MIRROR_DIR = ".wayai-mirror";
|
|
41134
|
-
CASE_MIRROR_HOOK_FILE = "session-start.sh";
|
|
41135
|
-
RECORD_FILE2 = "record.json";
|
|
41136
|
-
SUMMARY_FILE = "since-last-pull.md";
|
|
41137
|
-
INPUTS_FILE = "inputs.json";
|
|
41138
|
-
INPUTS_DIR = "inputs";
|
|
41139
|
-
LOCK_FILE = ".lock";
|
|
41140
|
-
LOCK_WAIT_MS = 12e4;
|
|
41141
|
-
LOCK_STALE_MS = 10 * 6e4;
|
|
41142
|
-
LOCK_POLL_MS = 50;
|
|
41143
|
-
AGENDA_PAGES_READ2 = 5;
|
|
41144
|
-
SUMMARY_REVISION_PAGES = 2;
|
|
41145
|
-
MIRROR_CONFIDENTIAL_NOTICE = "Confidential content is left out unless you pass --confidential.";
|
|
41146
|
-
safe2 = (text5) => sanitizeTerminalText(text5);
|
|
41147
|
-
one2 = (text5) => sanitizeTerminalText(text5).replace(/\s*\n\s*/g, " ");
|
|
41148
|
-
words = (status) => status.replaceAll("_", " ");
|
|
41149
|
-
isConfPath = (rel) => rel.split("/")[0] === "conf";
|
|
41150
|
-
isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
41151
|
-
isStringMap = (v) => isObject(v) && Object.values(v).every((x) => typeof x === "string");
|
|
41152
|
-
isDeliveries = (v) => isObject(v) && Object.values(v).every((d) => d === null || isObject(d) && typeof d.submission_id === "string" && typeof d.state === "string");
|
|
41153
|
-
segment = (name, pattern, id) => pattern.test(name) ? name : UUID_RE3.test(id) ? id : computeHash(Buffer.from(id, "utf-8"));
|
|
41154
|
-
NO_REVISIONS = { revisions: [], more: false, newest_at: null };
|
|
41155
|
-
within = (prev, now) => Object.fromEntries(Object.entries(prev).filter(([key]) => key in now));
|
|
41156
|
-
HOOK_SCRIPT = `#!/bin/sh
|
|
41157
|
-
# Written by \`wayai cases clone\` and every \`wayai cases pull\` (this folder is rewritten whole: do not edit it).
|
|
41158
|
-
# The session-start hook: refreshes this clone's read-only mirror of its case. It never passes --confidential.
|
|
41159
|
-
exec wayai cases pull --mirror-only --dir "$(dirname "$0")/.."
|
|
41160
|
-
`;
|
|
41161
|
-
json = (value) => Buffer.from(`${JSON.stringify(value, null, 2)}
|
|
41162
|
-
`, "utf-8");
|
|
41163
|
-
}
|
|
41164
|
-
});
|
|
41165
|
-
|
|
41166
41890
|
// src/cases/case-files.ts
|
|
41167
|
-
import * as
|
|
41168
|
-
import * as
|
|
41891
|
+
import * as fs38 from "fs";
|
|
41892
|
+
import * as path50 from "path";
|
|
41169
41893
|
function casesRequestsPerMinute() {
|
|
41170
41894
|
const budget = getEndpointConfig("/api/cases/org/space/cases/code/files")?.userLimit;
|
|
41171
41895
|
return budget ? Math.max(1, Math.floor(budget * 4 / 5)) : 48;
|
|
@@ -41178,7 +41902,7 @@ function assertWritableCasePaths(paths, phaseFolders) {
|
|
|
41178
41902
|
for (const rel of paths) {
|
|
41179
41903
|
const check = checkCaseFilePath({ path: rel, type: "file" }, phaseFolders);
|
|
41180
41904
|
if (!check.ok) {
|
|
41181
|
-
problems2.push(`${JSON.stringify(
|
|
41905
|
+
problems2.push(`${JSON.stringify(safe5(rel))}: a case path cannot be that (${check.reason})`);
|
|
41182
41906
|
continue;
|
|
41183
41907
|
}
|
|
41184
41908
|
const folded = check.fold_key.split("/");
|
|
@@ -41190,7 +41914,7 @@ function assertWritableCasePaths(paths, phaseFolders) {
|
|
|
41190
41914
|
if (known === void 0) {
|
|
41191
41915
|
spelled.set(key, spelling);
|
|
41192
41916
|
} else if (known !== spelling) {
|
|
41193
|
-
problems2.push(`${JSON.stringify(
|
|
41917
|
+
problems2.push(`${JSON.stringify(safe5(known))} and ${JSON.stringify(safe5(spelling))} differ only in case, so they would be one entry here`);
|
|
41194
41918
|
break;
|
|
41195
41919
|
}
|
|
41196
41920
|
}
|
|
@@ -41201,7 +41925,7 @@ function assertWritableCasePaths(paths, phaseFolders) {
|
|
|
41201
41925
|
const segments = key.split("/");
|
|
41202
41926
|
for (let i = 1; i < segments.length; i++) {
|
|
41203
41927
|
if (keys.has(segments.slice(0, i).join("/"))) {
|
|
41204
|
-
problems2.push(`${JSON.stringify(
|
|
41928
|
+
problems2.push(`${JSON.stringify(safe5(rel))} lies in a folder that is also a file`);
|
|
41205
41929
|
break;
|
|
41206
41930
|
}
|
|
41207
41931
|
}
|
|
@@ -41211,45 +41935,45 @@ function assertWritableCasePaths(paths, phaseFolders) {
|
|
|
41211
41935
|
${problems2.join("\n ")}`);
|
|
41212
41936
|
}
|
|
41213
41937
|
}
|
|
41214
|
-
function
|
|
41938
|
+
function linkRefusal2(rel) {
|
|
41215
41939
|
return expected(
|
|
41216
|
-
`${
|
|
41940
|
+
`${safe5(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.`
|
|
41217
41941
|
);
|
|
41218
41942
|
}
|
|
41219
41943
|
function scanClone(root, phaseFolders, confidential = true) {
|
|
41220
41944
|
const out = /* @__PURE__ */ new Map();
|
|
41221
41945
|
const walk = (abs, rel) => {
|
|
41222
|
-
for (const name of
|
|
41946
|
+
for (const name of fs38.readdirSync(abs).sort()) {
|
|
41223
41947
|
if (name.startsWith(".")) continue;
|
|
41224
|
-
const childAbs =
|
|
41948
|
+
const childAbs = path50.join(abs, name);
|
|
41225
41949
|
const childRel = `${rel}/${name}`;
|
|
41226
|
-
const st =
|
|
41950
|
+
const st = fs38.lstatSync(childAbs);
|
|
41227
41951
|
if (st.isDirectory() || st.isFile()) {
|
|
41228
41952
|
const problem = ownProblem(st);
|
|
41229
|
-
if (problem) throw expected(`Refused ${
|
|
41953
|
+
if (problem) throw expected(`Refused ${safe5(childRel)}: ${problem}. A case is read and written only in folders and files you own, never in one every user can write to.`);
|
|
41230
41954
|
}
|
|
41231
41955
|
if (st.isDirectory()) {
|
|
41232
41956
|
walk(childAbs, childRel);
|
|
41233
41957
|
} else if (st.isFile()) {
|
|
41234
41958
|
const bytes = readFileNoFollow(root, childAbs);
|
|
41235
|
-
if (!bytes) throw
|
|
41959
|
+
if (!bytes) throw linkRefusal2(childRel);
|
|
41236
41960
|
out.set(childRel, { rel: childRel, content_sha256: computeHash(bytes), size: bytes.length });
|
|
41237
41961
|
} else {
|
|
41238
|
-
throw
|
|
41962
|
+
throw linkRefusal2(childRel);
|
|
41239
41963
|
}
|
|
41240
41964
|
}
|
|
41241
41965
|
};
|
|
41242
41966
|
requireOwn(root);
|
|
41243
|
-
const top = new Set(
|
|
41967
|
+
const top = new Set(fs38.readdirSync(root));
|
|
41244
41968
|
const areas = [.../* @__PURE__ */ new Set([...phaseFolders, "analysis", ...confidential ? ["conf"] : []])].filter((area) => top.has(area));
|
|
41245
41969
|
if (top.has("instructions")) {
|
|
41246
|
-
if (!
|
|
41247
|
-
if (
|
|
41970
|
+
if (!fs38.lstatSync(path50.join(root, "instructions")).isDirectory()) throw linkRefusal2("instructions");
|
|
41971
|
+
if (fs38.readdirSync(path50.join(root, "instructions")).includes("case")) areas.push("instructions/case");
|
|
41248
41972
|
}
|
|
41249
41973
|
for (const rel of areas) {
|
|
41250
|
-
const abs =
|
|
41251
|
-
if (!
|
|
41252
|
-
if (rel === "instructions/case") requireOwn(
|
|
41974
|
+
const abs = path50.join(root, ...rel.split("/"));
|
|
41975
|
+
if (!fs38.lstatSync(abs).isDirectory()) throw linkRefusal2(rel);
|
|
41976
|
+
if (rel === "instructions/case") requireOwn(path50.join(root, "instructions"));
|
|
41253
41977
|
requireOwn(abs);
|
|
41254
41978
|
walk(abs, rel);
|
|
41255
41979
|
}
|
|
@@ -41281,11 +42005,11 @@ function sidesOf(record, local, files, confidential) {
|
|
|
41281
42005
|
function requireFiles(detail, confidential) {
|
|
41282
42006
|
const can = detail.access.capabilities;
|
|
41283
42007
|
if (!can.includes("view_work")) {
|
|
41284
|
-
throw expected(`Your access to case ${
|
|
42008
|
+
throw expected(`Your access to case ${safe5(detail.code)} does not reach its files: no team of yours reads its work.`);
|
|
41285
42009
|
}
|
|
41286
42010
|
if (confidential && !can.includes("read_confidential")) {
|
|
41287
42011
|
throw expected(
|
|
41288
|
-
`This machine's authorization on case ${
|
|
42012
|
+
`This machine's authorization on case ${safe5(detail.code)} does not hold the Confidential right, so --confidential reads nothing more. Run it without --confidential.`
|
|
41289
42013
|
);
|
|
41290
42014
|
}
|
|
41291
42015
|
}
|
|
@@ -41304,7 +42028,7 @@ async function pullInto(calls, detail, record, opts) {
|
|
|
41304
42028
|
const replaced = [...plan.replacedLocal, ...opts.overwrite ? theirsLeft : []];
|
|
41305
42029
|
if (replaced.length > 0) {
|
|
41306
42030
|
console.log("These local changes would be replaced with the case's copies, or removed:");
|
|
41307
|
-
for (const rel of replaced) console.log(` ${
|
|
42031
|
+
for (const rel of replaced) console.log(` ${safe5(rel)}`);
|
|
41308
42032
|
if (!await agree(`Replace or remove ${replaced.length} local file(s)?`, opts.yes)) {
|
|
41309
42033
|
console.log("Cancelled.");
|
|
41310
42034
|
return;
|
|
@@ -41332,7 +42056,7 @@ async function pullInto(calls, detail, record, opts) {
|
|
|
41332
42056
|
conflicts.push({ rel, reason: "unresolved" });
|
|
41333
42057
|
} else if (matchesScan(root, rel, local.get(rel))) {
|
|
41334
42058
|
removeLocal(root, rel);
|
|
41335
|
-
changes.push(`${MARK.delete} ${
|
|
42059
|
+
changes.push(`${MARK.delete} ${safe5(rel)}`);
|
|
41336
42060
|
} else {
|
|
41337
42061
|
conflicts.push({ rel, reason: "edited_while_pulling" });
|
|
41338
42062
|
}
|
|
@@ -41344,7 +42068,7 @@ async function pullInto(calls, detail, record, opts) {
|
|
|
41344
42068
|
}
|
|
41345
42069
|
removeLocal(root, rel);
|
|
41346
42070
|
delete next.files[rel];
|
|
41347
|
-
changes.push(`${MARK.delete} ${
|
|
42071
|
+
changes.push(`${MARK.delete} ${safe5(rel)}`);
|
|
41348
42072
|
}
|
|
41349
42073
|
for (const w of plan.writes) {
|
|
41350
42074
|
const clash = diskClash(root, w.rel);
|
|
@@ -41360,7 +42084,7 @@ async function pullInto(calls, detail, record, opts) {
|
|
|
41360
42084
|
}
|
|
41361
42085
|
writeCaseLocalFile(root, w.rel, Buffer.from(bytes));
|
|
41362
42086
|
next.files[w.rel] = recordedFile(listed3.get(w.rel));
|
|
41363
|
-
changes.push(`${local.has(w.rel) ? MARK.update : MARK.create} ${
|
|
42087
|
+
changes.push(`${local.has(w.rel) ? MARK.update : MARK.create} ${safe5(w.rel)}`);
|
|
41364
42088
|
}
|
|
41365
42089
|
for (const c of plan.conflicts) {
|
|
41366
42090
|
if (c.reason === "both_changed" || c.reason === "exists_locally") {
|
|
@@ -41383,15 +42107,15 @@ async function pullInto(calls, detail, record, opts) {
|
|
|
41383
42107
|
}
|
|
41384
42108
|
const named = conflicts.filter((c) => !(c.reason === "unresolved" && rewritten.has(c.rel)));
|
|
41385
42109
|
const count = Object.keys(next.files).length;
|
|
41386
|
-
console.log(
|
|
42110
|
+
console.log(safe5(`${opts.verb} case ${record.code} into ${root} (${count} file${count === 1 ? "" : "s"} recorded).`));
|
|
41387
42111
|
printSection("Changes:", changes);
|
|
41388
|
-
printSection("Kept: your local changes, not pushed yet:", plan.kept.map((k) => `${
|
|
42112
|
+
printSection("Kept: your local changes, not pushed yet:", plan.kept.map((k) => `${safe5(k.rel)}: ${k.reason === "edited" ? "edited here" : "deleted here (push --prune removes it from the case)"}`));
|
|
41389
42113
|
printSection(
|
|
41390
42114
|
"Conflicts: your copy is kept. Resolve each, deleting any copy beside it, then push; or take the case's copies with `wayai cases pull --overwrite`:",
|
|
41391
42115
|
named.map((c) => conflictLine(c, PULL_CONFLICT2))
|
|
41392
42116
|
);
|
|
41393
|
-
printSection("Changed on the case while pulling: left as is; pull again to take it:", changedWhilePulling.map(
|
|
41394
|
-
printSection(`Not pulled: case paths ending in ${THEIRS_SUFFIX}, the name a conflict's copy takes here:`, theirsListed.map(
|
|
42117
|
+
printSection("Changed on the case while pulling: left as is; pull again to take it:", changedWhilePulling.map(safe5));
|
|
42118
|
+
printSection(`Not pulled: case paths ending in ${THEIRS_SUFFIX}, the name a conflict's copy takes here:`, theirsListed.map(safe5));
|
|
41395
42119
|
if (!opts.confidential) console.log(`
|
|
41396
42120
|
${CONFIDENTIAL_NOTICE}`);
|
|
41397
42121
|
if (named.length > 0) process.exitCode = 1;
|
|
@@ -41409,7 +42133,7 @@ function cloneAt(dir) {
|
|
|
41409
42133
|
if (dir !== void 0) {
|
|
41410
42134
|
const root = caseLocalRoot(dir);
|
|
41411
42135
|
const record = readCloneRecord(root);
|
|
41412
|
-
if (!record) throw expected(`${
|
|
42136
|
+
if (!record) throw expected(`${safe5(dir)} is not a case clone: it holds no ${CASE_CLONE_RECORD_FILE}. Clone the case with \`wayai cases clone\`.`);
|
|
41413
42137
|
return { root, record };
|
|
41414
42138
|
}
|
|
41415
42139
|
const clone = findCaseClone(process.cwd());
|
|
@@ -41424,30 +42148,30 @@ async function caseClone(selector, opts) {
|
|
|
41424
42148
|
const calls = new CaseCalls(session);
|
|
41425
42149
|
const detail = await calls.detail();
|
|
41426
42150
|
requireFiles(detail, opts.confidential);
|
|
41427
|
-
const dir =
|
|
42151
|
+
const dir = path50.resolve(opts.dir ?? session.connection.code);
|
|
41428
42152
|
let exists = true;
|
|
41429
42153
|
let st;
|
|
41430
42154
|
try {
|
|
41431
|
-
st =
|
|
42155
|
+
st = fs38.lstatSync(dir);
|
|
41432
42156
|
} catch {
|
|
41433
42157
|
exists = false;
|
|
41434
42158
|
}
|
|
41435
|
-
if (st && !st.isDirectory()) throw expected(`${
|
|
42159
|
+
if (st && !st.isDirectory()) throw expected(`${safe5(dir)} is a symlink or not a folder: clone into a folder of its own.`);
|
|
41436
42160
|
if (exists) {
|
|
41437
42161
|
const existing = readCloneRecord(caseLocalRoot(dir));
|
|
41438
42162
|
if (existing) {
|
|
41439
|
-
throw expected(sameCase(existing, session.connection) ? `${
|
|
42163
|
+
throw expected(sameCase(existing, session.connection) ? `${safe5(dir)} is a clone of case ${safe5(existing.code)} already: run \`wayai cases pull\` there.` : `${safe5(dir)} is a clone of case ${safe5(existing.code)}: clone into another folder.`);
|
|
41440
42164
|
}
|
|
41441
42165
|
}
|
|
41442
|
-
const outer = findCaseClone(
|
|
41443
|
-
if (outer) throw expected(`${
|
|
42166
|
+
const outer = findCaseClone(path50.dirname(dir));
|
|
42167
|
+
if (outer) throw expected(`${safe5(dir)} lies inside the clone of case ${safe5(outer.record.code)} at ${safe5(outer.root)}: clone outside it.`);
|
|
41444
42168
|
const record = { org_id: session.connection.org_id, space_id: session.connection.space_id, code: session.connection.code, files: {} };
|
|
41445
42169
|
await pullInto(calls, detail, record, {
|
|
41446
42170
|
confidential: opts.confidential,
|
|
41447
42171
|
overwrite: false,
|
|
41448
42172
|
yes: false,
|
|
41449
42173
|
root: () => {
|
|
41450
|
-
if (!exists)
|
|
42174
|
+
if (!exists) fs38.mkdirSync(dir, { recursive: true, mode: CASE_FOLDER_MODE });
|
|
41451
42175
|
return caseLocalRoot(dir);
|
|
41452
42176
|
},
|
|
41453
42177
|
verb: "Cloned"
|
|
@@ -41508,7 +42232,7 @@ function uploadRefusal(err, session, entries) {
|
|
|
41508
42232
|
const reason3 = extractApiErrorReason(err);
|
|
41509
42233
|
const { at, paths } = refusalDetails(err, sent);
|
|
41510
42234
|
const list2 = paths.map((p) => `
|
|
41511
|
-
${
|
|
42235
|
+
${safe5(p)}`).join("");
|
|
41512
42236
|
if (err.status === 409 && reason3 === CASE_FILE_CONFLICT_REASON) {
|
|
41513
42237
|
return expected(`These files changed on the case since your last pull:${list2}
|
|
41514
42238
|
${nothing} Run \`wayai cases pull\`, then push again.`);
|
|
@@ -41526,7 +42250,7 @@ ${nothing} Write those files under other paths.`
|
|
|
41526
42250
|
if (err.status === 400 && reason3) {
|
|
41527
42251
|
const index = at === null ? null : /^entries\.(\d+)/.exec(at);
|
|
41528
42252
|
const where = index ? entries[Number(index[1])]?.path : void 0;
|
|
41529
|
-
return expected(`The case refused the revision (${
|
|
42253
|
+
return expected(`The case refused the revision (${safe5(reason3)}${where ? `, at ${safe5(where)}` : ""}). ${nothing}`);
|
|
41530
42254
|
}
|
|
41531
42255
|
return caseCallFailure(err, session.connection);
|
|
41532
42256
|
}
|
|
@@ -41550,7 +42274,7 @@ async function casePush(opts) {
|
|
|
41550
42274
|
const detail = await calls.detail();
|
|
41551
42275
|
requireFiles(detail, opts.confidential);
|
|
41552
42276
|
if (!detail.access.capabilities.includes("upload_document")) {
|
|
41553
|
-
throw expected(`Your access to case ${
|
|
42277
|
+
throw expected(`Your access to case ${safe5(detail.code)} does not write its files: that takes Edit level, on an open case.`);
|
|
41554
42278
|
}
|
|
41555
42279
|
const phaseFolders = phaseFoldersOf(detail);
|
|
41556
42280
|
assertClonePaths(root, record, phaseFolders);
|
|
@@ -41561,7 +42285,7 @@ async function casePush(opts) {
|
|
|
41561
42285
|
if (theirs.length > 0) {
|
|
41562
42286
|
throw expected(
|
|
41563
42287
|
`Resolve these conflicts first: merge each into the file beside it, then delete the ${THEIRS_SUFFIX} copy.${theirs.map((t) => `
|
|
41564
|
-
${
|
|
42288
|
+
${safe5(t)}`).join("")}
|
|
41565
42289
|
Nothing was pushed.`
|
|
41566
42290
|
);
|
|
41567
42291
|
}
|
|
@@ -41574,7 +42298,7 @@ Nothing was pushed.`
|
|
|
41574
42298
|
const file = scanned.get(rel);
|
|
41575
42299
|
const reason3 = record.files[rel]?.sha === file?.content_sha256 ? null : leftOutReason(rel, phaseFolders, detail);
|
|
41576
42300
|
if (reason3) {
|
|
41577
|
-
leftOut.push(`${
|
|
42301
|
+
leftOut.push(`${safe5(rel)}: ${reason3}`);
|
|
41578
42302
|
leftOutPaths.add(rel);
|
|
41579
42303
|
} else if (file) {
|
|
41580
42304
|
local.set(rel, file);
|
|
@@ -41584,13 +42308,13 @@ Nothing was pushed.`
|
|
|
41584
42308
|
const recordIn = { ...record, files: Object.fromEntries(Object.entries(record.files).filter(([rel]) => !leftOutPaths.has(rel))) };
|
|
41585
42309
|
const { synced: synced2, local: localIn, remote, listed: listed3 } = sidesOf(recordIn, local, files, opts.confidential);
|
|
41586
42310
|
const plan = planPush({ synced: synced2, local: localIn, remote, prune: opts.prune });
|
|
41587
|
-
console.log(
|
|
41588
|
-
const steps = plan.steps.map((s) => `${MARK[s.op]} ${
|
|
42311
|
+
console.log(safe5(`Push ${root} \u2192 case ${record.code}`));
|
|
42312
|
+
const steps = plan.steps.map((s) => `${MARK[s.op]} ${safe5(s.rel)}${s.op === "create" ? ` (new, ${s.local.size} bytes)` : ""}`);
|
|
41589
42313
|
printSection("Changes:", steps);
|
|
41590
|
-
printSection("Changed on the case since your last pull: left as is; pull to take it:", plan.changedOnBase.map(
|
|
41591
|
-
printSection("Deleted on the case since your last pull, or no longer readable here: left as is; pull to remove your copy:", plan.deletedOnBase.map(
|
|
41592
|
-
printSection("On the case, not in your clone: left as is; pull to fetch it:", plan.onlyOnBase.map(
|
|
41593
|
-
printSection("Deleted in your clone: kept on the case; push with --prune to remove it:", plan.keptOnBase.map(
|
|
42314
|
+
printSection("Changed on the case since your last pull: left as is; pull to take it:", plan.changedOnBase.map(safe5));
|
|
42315
|
+
printSection("Deleted on the case since your last pull, or no longer readable here: left as is; pull to remove your copy:", plan.deletedOnBase.map(safe5));
|
|
42316
|
+
printSection("On the case, not in your clone: left as is; pull to fetch it:", plan.onlyOnBase.map(safe5));
|
|
42317
|
+
printSection("Deleted in your clone: kept on the case; push with --prune to remove it:", plan.keptOnBase.map(safe5));
|
|
41594
42318
|
printSection("Left out: not pushed from this clone:", leftOut);
|
|
41595
42319
|
printSection("Conflicts: not pushed:", plan.conflicts.map((c) => conflictLine(c, PUSH_CONFLICT2)));
|
|
41596
42320
|
if (!opts.confidential) console.log(`
|
|
@@ -41626,9 +42350,9 @@ ${CONFIDENTIAL_NOTICE}`);
|
|
|
41626
42350
|
entries.push({ path: step.rel, type: "file", expect_sha: step.ifMatch, sha: null });
|
|
41627
42351
|
continue;
|
|
41628
42352
|
}
|
|
41629
|
-
const bytes = readFileNoFollow(root,
|
|
42353
|
+
const bytes = readFileNoFollow(root, path50.join(root, ...step.rel.split("/")));
|
|
41630
42354
|
if (!bytes || computeHash(bytes) !== step.local.content_sha256) {
|
|
41631
|
-
throw expected(`${
|
|
42355
|
+
throw expected(`${safe5(step.rel)} changed while the push ran. Nothing was pushed; push again.`);
|
|
41632
42356
|
}
|
|
41633
42357
|
parts.set(step.local.content_sha256, bytes);
|
|
41634
42358
|
entries.push({ path: step.rel, type: "file", expect_sha: step.op === "update" ? step.ifMatch : null, sha: step.local.content_sha256 });
|
|
@@ -41648,7 +42372,7 @@ ${CONFIDENTIAL_NOTICE}`);
|
|
|
41648
42372
|
}
|
|
41649
42373
|
writeCloneRecord(root, next);
|
|
41650
42374
|
console.log(`
|
|
41651
|
-
Pushed revision ${saved.revision_id}: ${entries.length} change${entries.length === 1 ? "" : "s"} to case ${
|
|
42375
|
+
Pushed revision ${saved.revision_id}: ${entries.length} change${entries.length === 1 ? "" : "s"} to case ${safe5(record.code)}.`);
|
|
41652
42376
|
}
|
|
41653
42377
|
async function caseLog(selector, opts) {
|
|
41654
42378
|
const limit = opts.limit ?? LOG_DEFAULT;
|
|
@@ -41679,21 +42403,21 @@ async function caseLog(selector, opts) {
|
|
|
41679
42403
|
console.log(JSON.stringify({ revisions: shown3, more }, null, 2));
|
|
41680
42404
|
return;
|
|
41681
42405
|
}
|
|
41682
|
-
if (shown3.length === 0) console.log(`Case ${
|
|
42406
|
+
if (shown3.length === 0) console.log(`Case ${safe5(detail.code)} has no revision you read here.`);
|
|
41683
42407
|
for (const r of shown3) {
|
|
41684
42408
|
const author = r.author?.display_name ? one3(r.author.display_name) : "a person no longer named";
|
|
41685
42409
|
console.log(`revision ${r.revision_id} ${r.created_at} ${author} (${r.channel})`);
|
|
41686
42410
|
if (r.message !== null) console.log(` ${one3(r.message)}`);
|
|
41687
42411
|
else console.log(hideMessages ? " (message not shown without --confidential)" : " (message hidden)");
|
|
41688
42412
|
if (r.session) console.log(` session: ${one3(r.session)}`);
|
|
41689
|
-
for (const e of r.entries) console.log(` ${
|
|
42413
|
+
for (const e of r.entries) console.log(` ${safe5(e.path)}${e.sha === null ? " (removed)" : ""}`);
|
|
41690
42414
|
}
|
|
41691
42415
|
if (more && shown3.length > 0) console.log(`
|
|
41692
42416
|
Older revisions follow: --limit ${Math.min(LOG_MAX, limit * 2)} shows more.`);
|
|
41693
42417
|
if (!opts.confidential) console.log(`
|
|
41694
42418
|
${CONFIDENTIAL_NOTICE}`);
|
|
41695
42419
|
}
|
|
41696
|
-
var THEIRS_SUFFIX, MAX_LIST_PAGES2, LOG_DEFAULT, LOG_MAX, MAX_LOG_PAGES, PART_OVERHEAD_BYTES, CONFIDENTIAL_NOTICE,
|
|
42420
|
+
var THEIRS_SUFFIX, MAX_LIST_PAGES2, LOG_DEFAULT, LOG_MAX, MAX_LOG_PAGES, PART_OVERHEAD_BYTES, CONFIDENTIAL_NOTICE, safe5, one3, CaseCalls, phaseFoldersOf, isTheirs, recordedFile, PULL_CONFLICT2, inRunOf, PUSH_CONFLICT2;
|
|
41697
42421
|
var init_case_files2 = __esm({
|
|
41698
42422
|
"src/cases/case-files.ts"() {
|
|
41699
42423
|
"use strict";
|
|
@@ -41722,7 +42446,7 @@ var init_case_files2 = __esm({
|
|
|
41722
42446
|
MAX_LOG_PAGES = 40;
|
|
41723
42447
|
PART_OVERHEAD_BYTES = 512;
|
|
41724
42448
|
CONFIDENTIAL_NOTICE = "Confidential files are left out unless you pass --confidential.";
|
|
41725
|
-
|
|
42449
|
+
safe5 = (text5) => sanitizeTerminalText(text5);
|
|
41726
42450
|
one3 = (text5) => sanitizeTerminalText(text5).replace(/\s*\n\s*/g, " ");
|
|
41727
42451
|
CaseCalls = class {
|
|
41728
42452
|
constructor(session) {
|
|
@@ -41994,469 +42718,13 @@ var init_case_review2 = __esm({
|
|
|
41994
42718
|
}
|
|
41995
42719
|
});
|
|
41996
42720
|
|
|
41997
|
-
// ../../packages/core/dist/contracts/case-type-packages.js
|
|
41998
|
-
function headerSum(header) {
|
|
41999
|
-
let sum = 0;
|
|
42000
|
-
for (let i = 0; i < BLOCK; i++) sum += i >= 148 && i < 156 ? 32 : header[i];
|
|
42001
|
-
return sum;
|
|
42002
|
-
}
|
|
42003
|
-
function splitPath(path53) {
|
|
42004
|
-
if (ascii().encode(path53).length !== path53.length) return null;
|
|
42005
|
-
if (path53.length <= 100) return { name: path53, prefix: "" };
|
|
42006
|
-
for (let i = path53.indexOf("/"); i >= 0; i = path53.indexOf("/", i + 1)) {
|
|
42007
|
-
if (i <= 155 && path53.length - i - 1 <= 100) return { name: path53.slice(i + 1), prefix: path53.slice(0, i) };
|
|
42008
|
-
}
|
|
42009
|
-
return null;
|
|
42010
|
-
}
|
|
42011
|
-
function writeCasePackage(files) {
|
|
42012
|
-
const blocks = [];
|
|
42013
|
-
for (const { path: path53, bytes } of byPath(files)) {
|
|
42014
|
-
const header = new Uint8Array(BLOCK);
|
|
42015
|
-
const encoder = ascii();
|
|
42016
|
-
const put = (text5, at2) => header.set(encoder.encode(text5), at2);
|
|
42017
|
-
const split = splitPath(path53);
|
|
42018
|
-
if (!split) throw new Error(`A package path its archive can't hold: ${path53}`);
|
|
42019
|
-
const { name, prefix } = split;
|
|
42020
|
-
put(name, 0);
|
|
42021
|
-
put("0000644\0", 100);
|
|
42022
|
-
put("0000000\0", 108);
|
|
42023
|
-
put("0000000\0", 116);
|
|
42024
|
-
put(`${bytes.length.toString(8).padStart(11, "0")}\0`, 124);
|
|
42025
|
-
put("00000000000\0", 136);
|
|
42026
|
-
put("0", 156);
|
|
42027
|
-
put("ustar\x0000", 257);
|
|
42028
|
-
put(prefix, 345);
|
|
42029
|
-
put(`${headerSum(header).toString(8).padStart(6, "0")}\0 `, 148);
|
|
42030
|
-
blocks.push(header, bytes);
|
|
42031
|
-
if (bytes.length % BLOCK) blocks.push(new Uint8Array(BLOCK - bytes.length % BLOCK));
|
|
42032
|
-
}
|
|
42033
|
-
blocks.push(new Uint8Array(BLOCK * 2));
|
|
42034
|
-
const out = new Uint8Array(blocks.reduce((n, block2) => n + block2.length, 0));
|
|
42035
|
-
let at = 0;
|
|
42036
|
-
for (const block2 of blocks) {
|
|
42037
|
-
out.set(block2, at);
|
|
42038
|
-
at += block2.length;
|
|
42039
|
-
}
|
|
42040
|
-
return out;
|
|
42041
|
-
}
|
|
42042
|
-
function textField(block2, start, length) {
|
|
42043
|
-
const end = block2.subarray(start, start + length).indexOf(0);
|
|
42044
|
-
return new TextDecoder().decode(block2.subarray(start, end < 0 ? start + length : start + end));
|
|
42045
|
-
}
|
|
42046
|
-
function octalField(block2, start, length) {
|
|
42047
|
-
const text5 = textField(block2, start, length).trim();
|
|
42048
|
-
return /^[0-7]+$/.test(text5) ? parseInt(text5, 8) : NaN;
|
|
42049
|
-
}
|
|
42050
|
-
function readCasePackage(data) {
|
|
42051
|
-
const entries = [];
|
|
42052
|
-
const others = [];
|
|
42053
|
-
const notTar = { problems: [{ path: null, reason: "package_not_tar" }] };
|
|
42054
|
-
let at = 0;
|
|
42055
|
-
for (; ; ) {
|
|
42056
|
-
if (at + BLOCK > data.length) return notTar;
|
|
42057
|
-
const block2 = data.subarray(at, at + BLOCK);
|
|
42058
|
-
if (block2.every((byte) => byte === 0)) {
|
|
42059
|
-
if (!data.subarray(at).every((byte) => byte === 0)) return notTar;
|
|
42060
|
-
break;
|
|
42061
|
-
}
|
|
42062
|
-
if (octalField(block2, 148, 8) !== headerSum(block2) || textField(block2, 257, 6) !== "ustar") return notTar;
|
|
42063
|
-
const prefix = textField(block2, 345, 155);
|
|
42064
|
-
const name = textField(block2, 0, 100);
|
|
42065
|
-
const path53 = prefix ? `${prefix}/${name}` : name;
|
|
42066
|
-
const size = octalField(block2, 124, 12);
|
|
42067
|
-
if (Number.isNaN(size) || at + BLOCK + size > data.length) return notTar;
|
|
42068
|
-
at += BLOCK;
|
|
42069
|
-
const type = String.fromCharCode(block2[156]);
|
|
42070
|
-
if (type === "0" || type === "\0") entries.push({ path: path53, bytes: data.subarray(at, at + size), offset: at });
|
|
42071
|
-
else others.push(path53);
|
|
42072
|
-
at += size + (BLOCK - size % BLOCK) % BLOCK;
|
|
42073
|
-
}
|
|
42074
|
-
return { entries, others };
|
|
42075
|
-
}
|
|
42076
|
-
function pathProblem(path53) {
|
|
42077
|
-
if (path53.length === 0 || path53.length > CASE_PACKAGE_LIMITS.path_chars) return "package_path_invalid";
|
|
42078
|
-
const segments = path53.split("/");
|
|
42079
|
-
if (segments.length > CASE_PACKAGE_LIMITS.depth || segments.some((segment2) => !SEGMENT.test(segment2)) || !splitPath(path53)) return "package_path_invalid";
|
|
42080
|
-
return CASE_PACKAGE_FOLDERS.includes(segments[0]) ? null : "package_path_unexpected";
|
|
42081
|
-
}
|
|
42082
|
-
function classify2(path53) {
|
|
42083
|
-
const p = path53.split("/");
|
|
42084
|
-
const markdown = path53.endsWith(".md");
|
|
42085
|
-
if (p[0] === "instructions" || p[0] === "templates") {
|
|
42086
|
-
if (p.length === 3 && p[1] === "figures") return isCasePackageImage(path53) ? { kind: "figure" } : null;
|
|
42087
|
-
if (p[0] === "templates") return p.length === 3 && PHASE_FOLDER.test(p[1]) && markdown ? { kind: "template", folder: p[1], code: p[2].slice(0, -3) } : null;
|
|
42088
|
-
if (p.length === 2 && p[1] === "case.md") return { kind: "case" };
|
|
42089
|
-
if (p.length === 3 && PHASE_FOLDER.test(p[1]) && p[2] === "phase.md") return { kind: "phase", folder: p[1] };
|
|
42090
|
-
const kind = INSTRUCTION_KINDS[p[2] ?? ""];
|
|
42091
|
-
if (p.length === 4 && PHASE_FOLDER.test(p[1]) && markdown && kind) return { kind, folder: p[1], code: p[3].slice(0, -3) };
|
|
42092
|
-
return null;
|
|
42093
|
-
}
|
|
42094
|
-
if (p.length < 2) return null;
|
|
42095
|
-
if (p[0] === "tools") return TOOL_EXTENSIONS.has(extensionOf(path53)) ? { kind: "tool" } : null;
|
|
42096
|
-
return SOURCE_EXTENSIONS.has(extensionOf(path53)) || isCasePackageImage(path53) ? { kind: "source" } : null;
|
|
42097
|
-
}
|
|
42098
|
-
function decodeText(bytes) {
|
|
42099
|
-
try {
|
|
42100
|
-
const text5 = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
42101
|
-
return text5.includes("\0") ? null : text5;
|
|
42102
|
-
} catch {
|
|
42103
|
-
return null;
|
|
42104
|
-
}
|
|
42105
|
-
}
|
|
42106
|
-
function headingOf(line) {
|
|
42107
|
-
let indent = 0;
|
|
42108
|
-
while (indent < 3 && line[indent] === " ") indent++;
|
|
42109
|
-
let level = 0;
|
|
42110
|
-
while (line[indent + level] === "#") level++;
|
|
42111
|
-
const after = line[indent + level];
|
|
42112
|
-
if (level < 1 || level > 6 || after !== void 0 && after.trim() !== "") return null;
|
|
42113
|
-
const body = line.slice(indent + level).trim();
|
|
42114
|
-
let end = body.length;
|
|
42115
|
-
while (end > 0 && body[end - 1] === "#") end--;
|
|
42116
|
-
return body.slice(0, end).trimEnd().toLowerCase() || null;
|
|
42117
|
-
}
|
|
42118
|
-
function headingsOf(text5) {
|
|
42119
|
-
const found = /* @__PURE__ */ new Set();
|
|
42120
|
-
let fenced = false;
|
|
42121
|
-
for (const line of text5.split(/\r?\n/)) {
|
|
42122
|
-
const trimmed = line.trimStart();
|
|
42123
|
-
if (trimmed.startsWith("```") || trimmed.startsWith("~~~")) {
|
|
42124
|
-
fenced = !fenced;
|
|
42125
|
-
continue;
|
|
42126
|
-
}
|
|
42127
|
-
const heading = fenced ? null : headingOf(line);
|
|
42128
|
-
if (heading) found.add(heading);
|
|
42129
|
-
}
|
|
42130
|
-
return found;
|
|
42131
|
-
}
|
|
42132
|
-
function frontMatterOf(text5) {
|
|
42133
|
-
const lines = text5.split(/\r?\n/);
|
|
42134
|
-
if (lines[0] !== "---") return {};
|
|
42135
|
-
const fields = {};
|
|
42136
|
-
for (const line of lines.slice(1)) {
|
|
42137
|
-
if (line === "---") return fields;
|
|
42138
|
-
const colon = line.indexOf(":");
|
|
42139
|
-
if (colon > 0) fields[line.slice(0, colon).trim()] = line.slice(colon + 1).trim();
|
|
42140
|
-
}
|
|
42141
|
-
return {};
|
|
42142
|
-
}
|
|
42143
|
-
function indexOf(definition) {
|
|
42144
|
-
return new Map(definition.type_phases.map((phase) => [phase.folder, {
|
|
42145
|
-
tasks: new Set(phase.type_tasks.map((task) => task.code)),
|
|
42146
|
-
items: new Map(phase.phase_outputs.flatMap((output) => output.output_items.map((item) => [item.code, item]))),
|
|
42147
|
-
outputs: new Set(phase.phase_outputs.map((output) => output.code)),
|
|
42148
|
-
inputs: new Set(phase.phase_inputs.map((input) => input.key)),
|
|
42149
|
-
agenda: new Set(phase.agenda_groups.map((group) => group.code))
|
|
42150
|
-
}]));
|
|
42151
|
-
}
|
|
42152
|
-
function casePackageProblems(read, archiveBytes, definition) {
|
|
42153
|
-
const { entries, others = [] } = read;
|
|
42154
|
-
const problems2 = [];
|
|
42155
|
-
if (archiveBytes > CASE_PACKAGE_LIMITS.bytes) problems2.push({ path: null, reason: "package_too_large" });
|
|
42156
|
-
if (entries.length + others.length > CASE_PACKAGE_LIMITS.files) return [{ path: null, reason: "package_too_many_files" }, ...problems2];
|
|
42157
|
-
problems2.push(...others.map((path53) => ({ path: path53, reason: "package_entry_not_file" })));
|
|
42158
|
-
const phases = indexOf(definition);
|
|
42159
|
-
const seen = /* @__PURE__ */ new Set();
|
|
42160
|
-
const itemInstructions = /* @__PURE__ */ new Set();
|
|
42161
|
-
let textBytes = 0;
|
|
42162
|
-
for (const { path: path53, bytes } of entries) {
|
|
42163
|
-
const bad = pathProblem(path53);
|
|
42164
|
-
if (bad) {
|
|
42165
|
-
problems2.push({ path: path53, reason: bad });
|
|
42166
|
-
continue;
|
|
42167
|
-
}
|
|
42168
|
-
const folded = path53.toLowerCase();
|
|
42169
|
-
if (seen.has(folded)) problems2.push({ path: path53, reason: "package_path_repeated" });
|
|
42170
|
-
seen.add(folded);
|
|
42171
|
-
const found = classify2(path53);
|
|
42172
|
-
if (!found) {
|
|
42173
|
-
problems2.push({ path: path53, reason: "package_path_unexpected" });
|
|
42174
|
-
continue;
|
|
42175
|
-
}
|
|
42176
|
-
if (isCasePackageImage(path53)) {
|
|
42177
|
-
if (bytes.length > CASE_PACKAGE_LIMITS.image_bytes) problems2.push({ path: path53, reason: "package_image_too_large" });
|
|
42178
|
-
if (!IMAGE_SIGNATURES[extensionOf(path53)].every((byte, i) => bytes[i] === byte)) problems2.push({ path: path53, reason: "package_image_invalid" });
|
|
42179
|
-
} else {
|
|
42180
|
-
textBytes += bytes.length;
|
|
42181
|
-
const text5 = decodeText(bytes);
|
|
42182
|
-
if (text5 === null) problems2.push({ path: path53, reason: "package_not_text" });
|
|
42183
|
-
else {
|
|
42184
|
-
if (path53.endsWith(".md") && text5.trim() === "") problems2.push({ path: path53, reason: "package_file_empty" });
|
|
42185
|
-
if (found.kind === "task" || found.kind === "item") {
|
|
42186
|
-
const held = headingsOf(text5);
|
|
42187
|
-
const missing = SECTIONS[found.kind].filter((section) => !held.has(section.toLowerCase()));
|
|
42188
|
-
if (missing.length) problems2.push({ path: path53, reason: "package_sections_missing", detail: missing.join(", ") });
|
|
42189
|
-
}
|
|
42190
|
-
if (found.kind === "task" && !EXECUTORS.includes(frontMatterOf(text5).executor ?? "")) problems2.push({ path: path53, reason: "package_executor_missing" });
|
|
42191
|
-
}
|
|
42192
|
-
}
|
|
42193
|
-
if (found.folder === void 0) continue;
|
|
42194
|
-
const phase = phases.get(found.folder);
|
|
42195
|
-
if (!phase) {
|
|
42196
|
-
problems2.push({ path: path53, reason: "package_phase_unknown" });
|
|
42197
|
-
continue;
|
|
42198
|
-
}
|
|
42199
|
-
if (found.kind === "template" || found.kind === "item") {
|
|
42200
|
-
const item = phase.items.get(found.code);
|
|
42201
|
-
if (!item) problems2.push({ path: path53, reason: "package_code_unknown" });
|
|
42202
|
-
else if (found.kind === "template" && item.template_mode === "fixed") problems2.push({ path: path53, reason: "package_template_fixed" });
|
|
42203
|
-
else if (found.kind === "item") itemInstructions.add(`${found.folder}/${found.code}`);
|
|
42204
|
-
continue;
|
|
42205
|
-
}
|
|
42206
|
-
const set = CODE_SETS[found.kind];
|
|
42207
|
-
if (set && !phase[set].has(found.code)) problems2.push({ path: path53, reason: "package_code_unknown" });
|
|
42208
|
-
}
|
|
42209
|
-
if (textBytes > CASE_PACKAGE_LIMITS.text_bytes) problems2.push({ path: null, reason: "package_text_too_large" });
|
|
42210
|
-
for (const [folder, phase] of phases) {
|
|
42211
|
-
for (const [code2, item] of phase.items) {
|
|
42212
|
-
if (item.required && !item.grouping && !itemInstructions.has(`${folder}/${code2}`)) {
|
|
42213
|
-
problems2.push({ path: `instructions/${folder}/items/${code2}.md`, reason: "package_item_instruction_missing" });
|
|
42214
|
-
}
|
|
42215
|
-
}
|
|
42216
|
-
}
|
|
42217
|
-
return problems2;
|
|
42218
|
-
}
|
|
42219
|
-
function casePackageConfidentialPaths(definition) {
|
|
42220
|
-
const paths = /* @__PURE__ */ new Set();
|
|
42221
|
-
for (const phase of definition.type_phases) {
|
|
42222
|
-
const groups = new Set(phase.agenda_groups.filter((group) => group.confidential).map((group) => group.code));
|
|
42223
|
-
const tasks = new Set(phase.type_tasks.filter((task) => task.agenda_group !== null && groups.has(task.agenda_group)).map((task) => task.code));
|
|
42224
|
-
for (const group of groups) paths.add(`instructions/${phase.folder}/agenda/${group}.md`);
|
|
42225
|
-
for (const task of tasks) paths.add(`instructions/${phase.folder}/tasks/${task}.md`);
|
|
42226
|
-
for (const item of phase.phase_outputs.flatMap((output) => output.output_items)) {
|
|
42227
|
-
if (item.task === null || !tasks.has(item.task)) continue;
|
|
42228
|
-
paths.add(`instructions/${phase.folder}/items/${item.code}.md`);
|
|
42229
|
-
paths.add(`templates/${phase.folder}/${item.code}.md`);
|
|
42230
|
-
}
|
|
42231
|
-
}
|
|
42232
|
-
return paths;
|
|
42233
|
-
}
|
|
42234
|
-
async function casePackageSha(bytes) {
|
|
42235
|
-
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
42236
|
-
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
42237
|
-
}
|
|
42238
|
-
function casePackageChanges(draft, base) {
|
|
42239
|
-
const before = new Map(base.map((file) => [file.path, file]));
|
|
42240
|
-
const after = new Map(draft.map((file) => [file.path, file]));
|
|
42241
|
-
return [.../* @__PURE__ */ new Set([...before.keys(), ...after.keys()])].sort().map((path53) => {
|
|
42242
|
-
const [was, now] = [before.get(path53), after.get(path53)];
|
|
42243
|
-
return {
|
|
42244
|
-
path: path53,
|
|
42245
|
-
status: !was ? "added" : !now ? "removed" : was.sha === now.sha ? "same" : "changed",
|
|
42246
|
-
size: now?.size ?? null,
|
|
42247
|
-
base_size: was?.size ?? null,
|
|
42248
|
-
image: isCasePackageImage(path53),
|
|
42249
|
-
confidential: Boolean(was?.confidential || now?.confidential)
|
|
42250
|
-
};
|
|
42251
|
-
});
|
|
42252
|
-
}
|
|
42253
|
-
var CASE_PACKAGE_LIMITS, CASE_PACKAGE_FOLDERS, BLOCK, SEGMENT, PHASE_FOLDER, TOOL_EXTENSIONS, SOURCE_EXTENSIONS, IMAGE_SIGNATURES, SECTIONS, EXECUTORS, extensionOf, isCasePackageImage, byPath, ascii, INSTRUCTION_KINDS, CODE_SETS;
|
|
42254
|
-
var init_case_type_packages = __esm({
|
|
42255
|
-
"../../packages/core/dist/contracts/case-type-packages.js"() {
|
|
42256
|
-
"use strict";
|
|
42257
|
-
CASE_PACKAGE_LIMITS = {
|
|
42258
|
-
/** The archive, headers and end included. */
|
|
42259
|
-
bytes: 20 * 1024 * 1024,
|
|
42260
|
-
/** Every text file together: what a person reviews line by line before publishing. */
|
|
42261
|
-
text_bytes: 4 * 1024 * 1024,
|
|
42262
|
-
image_bytes: 1024 * 1024,
|
|
42263
|
-
files: 500,
|
|
42264
|
-
path_chars: 200,
|
|
42265
|
-
depth: 8
|
|
42266
|
-
};
|
|
42267
|
-
CASE_PACKAGE_FOLDERS = ["instructions", "templates", "tools", "sources"];
|
|
42268
|
-
BLOCK = 512;
|
|
42269
|
-
SEGMENT = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
42270
|
-
PHASE_FOLDER = /^[0-9]{2}-[a-z0-9-]+$/;
|
|
42271
|
-
TOOL_EXTENSIONS = /* @__PURE__ */ new Set(["py", "r", "sql", "js", "mjs", "sh", "json", "yaml", "yml", "csv", "txt", "md"]);
|
|
42272
|
-
SOURCE_EXTENSIONS = /* @__PURE__ */ new Set(["md", "txt", "csv", "json", "yaml", "yml"]);
|
|
42273
|
-
IMAGE_SIGNATURES = { png: [137, 80, 78, 71, 13, 10, 26, 10], jpg: [255, 216, 255], jpeg: [255, 216, 255] };
|
|
42274
|
-
SECTIONS = { task: ["Objective", "Inputs", "Steps", "Output", "Acceptance"], item: ["Content", "Steps", "Acceptance"] };
|
|
42275
|
-
EXECUTORS = ["agent", "person"];
|
|
42276
|
-
extensionOf = (path53) => path53.slice(path53.lastIndexOf(".") + 1).toLowerCase();
|
|
42277
|
-
isCasePackageImage = (path53) => Object.hasOwn(IMAGE_SIGNATURES, extensionOf(path53));
|
|
42278
|
-
byPath = (files) => [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
42279
|
-
ascii = () => new TextEncoder();
|
|
42280
|
-
INSTRUCTION_KINDS = { tasks: "task", items: "item", outputs: "output", inputs: "input", agenda: "agenda" };
|
|
42281
|
-
CODE_SETS = { task: "tasks", output: "outputs", input: "inputs", agenda: "agenda" };
|
|
42282
|
-
}
|
|
42283
|
-
});
|
|
42284
|
-
|
|
42285
|
-
// src/cases/case-type-folder.ts
|
|
42286
|
-
import * as fs37 from "fs";
|
|
42287
|
-
import * as path49 from "path";
|
|
42288
|
-
function isTypeFolderPath(rel) {
|
|
42289
|
-
if (rel === TYPE_FILE) return true;
|
|
42290
|
-
if (caseLocalPathProblem(rel) !== null) return false;
|
|
42291
|
-
return !casePackageProblems({ entries: [{ path: rel, bytes: new Uint8Array(), offset: 0 }] }, 0, NO_PHASES).some((problem) => PACKAGE_PATH_REASONS.has(problem.reason));
|
|
42292
|
-
}
|
|
42293
|
-
function isRecord4(value) {
|
|
42294
|
-
if (typeof value !== "object" || value === null) return false;
|
|
42295
|
-
const v = value;
|
|
42296
|
-
if (!caseTypeParam.safeParse({ org_id: v.org_id, space_id: v.space_id, type_id: v.type_id }).success || typeof v.abbreviation !== "string") return false;
|
|
42297
|
-
if (typeof v.version !== "number" || !Number.isInteger(v.version) || v.version < 1) return false;
|
|
42298
|
-
if (typeof v.files !== "object" || v.files === null || Array.isArray(v.files)) return false;
|
|
42299
|
-
return Object.entries(v.files).every(([rel, sha]) => isTypeFolderPath(rel) && typeof sha === "string" && CASE_FILE_SHA_PATTERN.test(sha));
|
|
42300
|
-
}
|
|
42301
|
-
function readTypeFolderRecord(root) {
|
|
42302
|
-
const file = path49.join(root, TYPE_FOLDER_MARKER);
|
|
42303
|
-
let marker;
|
|
42304
|
-
try {
|
|
42305
|
-
marker = fs37.lstatSync(file);
|
|
42306
|
-
} catch {
|
|
42307
|
-
return null;
|
|
42308
|
-
}
|
|
42309
|
-
const problem = ownProblem(marker) ?? (() => {
|
|
42310
|
-
const folder = ownProblem(fs37.lstatSync(root));
|
|
42311
|
-
return folder ? `its folder: ${folder}` : null;
|
|
42312
|
-
})();
|
|
42313
|
-
if (problem) {
|
|
42314
|
-
throw expected(safe4(
|
|
42315
|
-
`Refused the case type marker ${file}: ${problem}. A type folder counts only in a folder you own that not every user can write to: remove it, or pull the type into a folder of your own.`
|
|
42316
|
-
));
|
|
42317
|
-
}
|
|
42318
|
-
const text5 = readRealFileOrThrow(root, file);
|
|
42319
|
-
if (text5 === null) return null;
|
|
42320
|
-
let parsed;
|
|
42321
|
-
try {
|
|
42322
|
-
parsed = JSON.parse(text5);
|
|
42323
|
-
} catch {
|
|
42324
|
-
parsed = void 0;
|
|
42325
|
-
}
|
|
42326
|
-
if (!isRecord4(parsed)) throw expected(`${safe4(file)} is not a marker \`wayai cases type pull\` wrote. Move it aside and pull the type again.`);
|
|
42327
|
-
return parsed;
|
|
42328
|
-
}
|
|
42329
|
-
function writeTypeFolderRecord(root, record) {
|
|
42330
|
-
const files = {};
|
|
42331
|
-
for (const rel of Object.keys(record.files).sort()) files[rel] = record.files[rel];
|
|
42332
|
-
const body = {
|
|
42333
|
-
org_id: record.org_id,
|
|
42334
|
-
space_id: record.space_id,
|
|
42335
|
-
type_id: record.type_id,
|
|
42336
|
-
abbreviation: record.abbreviation,
|
|
42337
|
-
version: record.version,
|
|
42338
|
-
files
|
|
42339
|
-
};
|
|
42340
|
-
const tmp = path49.join(root, `${TYPE_FOLDER_MARKER}.tmp`);
|
|
42341
|
-
if (!writeFileNoFollow(root, tmp, Buffer.from(`${JSON.stringify(body, null, 2)}
|
|
42342
|
-
`, "utf-8"))) throw symlinkRefusal(tmp, "file");
|
|
42343
|
-
fs37.chmodSync(tmp, 420);
|
|
42344
|
-
fs37.renameSync(tmp, path49.join(root, TYPE_FOLDER_MARKER));
|
|
42345
|
-
}
|
|
42346
|
-
function findTypeFolder(from) {
|
|
42347
|
-
let dir = path49.resolve(from);
|
|
42348
|
-
for (; ; ) {
|
|
42349
|
-
try {
|
|
42350
|
-
dir = fs37.realpathSync(dir);
|
|
42351
|
-
break;
|
|
42352
|
-
} catch {
|
|
42353
|
-
const parent = path49.dirname(dir);
|
|
42354
|
-
if (parent === dir) return null;
|
|
42355
|
-
dir = parent;
|
|
42356
|
-
}
|
|
42357
|
-
}
|
|
42358
|
-
for (; ; ) {
|
|
42359
|
-
const record = readTypeFolderRecord(dir);
|
|
42360
|
-
if (record) return { root: dir, record };
|
|
42361
|
-
const parent = path49.dirname(dir);
|
|
42362
|
-
if (parent === dir) return null;
|
|
42363
|
-
dir = parent;
|
|
42364
|
-
}
|
|
42365
|
-
}
|
|
42366
|
-
function linkRefusal2(rel) {
|
|
42367
|
-
return expected(
|
|
42368
|
-
`${safe4(rel)} is a symlink, or not a regular file or folder. The CLI never follows one in a type folder: replace it with the file or folder itself, or move it out of the folder.`
|
|
42369
|
-
);
|
|
42370
|
-
}
|
|
42371
|
-
function ownRefusal(rel, problem) {
|
|
42372
|
-
return expected(`Refused ${safe4(rel)}: ${problem}. A type folder is read and written only in folders and files you own, never in one every user can write to.`);
|
|
42373
|
-
}
|
|
42374
|
-
function scanTypeFolder(root) {
|
|
42375
|
-
requireOwn(root);
|
|
42376
|
-
const files = /* @__PURE__ */ new Map();
|
|
42377
|
-
const read = (abs, rel) => {
|
|
42378
|
-
const bytes = readFileNoFollow(root, abs);
|
|
42379
|
-
if (!bytes) throw linkRefusal2(rel);
|
|
42380
|
-
return bytes;
|
|
42381
|
-
};
|
|
42382
|
-
const walk = (abs, rel) => {
|
|
42383
|
-
for (const name of fs37.readdirSync(abs).sort()) {
|
|
42384
|
-
if (name.startsWith(".")) continue;
|
|
42385
|
-
const childAbs = path49.join(abs, name);
|
|
42386
|
-
const childRel = `${rel}/${name}`;
|
|
42387
|
-
const st = fs37.lstatSync(childAbs);
|
|
42388
|
-
if (!st.isDirectory() && !st.isFile()) throw linkRefusal2(childRel);
|
|
42389
|
-
const problem = ownProblem(st);
|
|
42390
|
-
if (problem) throw ownRefusal(childRel, problem);
|
|
42391
|
-
if (st.isDirectory()) walk(childAbs, childRel);
|
|
42392
|
-
else files.set(childRel, read(childAbs, childRel));
|
|
42393
|
-
}
|
|
42394
|
-
};
|
|
42395
|
-
const top = new Set(fs37.readdirSync(root));
|
|
42396
|
-
let typeFile = null;
|
|
42397
|
-
if (top.has(TYPE_FILE)) {
|
|
42398
|
-
const st = fs37.lstatSync(path49.join(root, TYPE_FILE));
|
|
42399
|
-
if (!st.isFile()) throw linkRefusal2(TYPE_FILE);
|
|
42400
|
-
const problem = ownProblem(st);
|
|
42401
|
-
if (problem) throw ownRefusal(TYPE_FILE, problem);
|
|
42402
|
-
typeFile = read(path49.join(root, TYPE_FILE), TYPE_FILE);
|
|
42403
|
-
}
|
|
42404
|
-
for (const folder of CASE_PACKAGE_FOLDERS) {
|
|
42405
|
-
if (!top.has(folder)) continue;
|
|
42406
|
-
const abs = path49.join(root, folder);
|
|
42407
|
-
const st = fs37.lstatSync(abs);
|
|
42408
|
-
if (!st.isDirectory()) throw linkRefusal2(folder);
|
|
42409
|
-
const problem = ownProblem(st);
|
|
42410
|
-
if (problem) throw ownRefusal(folder, problem);
|
|
42411
|
-
walk(abs, folder);
|
|
42412
|
-
}
|
|
42413
|
-
return { typeFile, files: new Map([...files].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) };
|
|
42414
|
-
}
|
|
42415
|
-
function scanShas(scan) {
|
|
42416
|
-
const out = /* @__PURE__ */ new Map();
|
|
42417
|
-
if (scan.typeFile) out.set(TYPE_FILE, computeHash(scan.typeFile));
|
|
42418
|
-
for (const [rel, bytes] of scan.files) out.set(rel, computeHash(bytes));
|
|
42419
|
-
return out;
|
|
42420
|
-
}
|
|
42421
|
-
function localChanges(record, scan) {
|
|
42422
|
-
const now = scanShas(scan);
|
|
42423
|
-
const paths = /* @__PURE__ */ new Set([...Object.keys(record.files), ...now.keys()]);
|
|
42424
|
-
return [...paths].filter((rel) => record.files[rel] !== now.get(rel)).sort();
|
|
42425
|
-
}
|
|
42426
|
-
var TYPE_FOLDER_MARKER, TYPE_FILE, safe4, PACKAGE_PATH_REASONS, NO_PHASES;
|
|
42427
|
-
var init_case_type_folder = __esm({
|
|
42428
|
-
"src/cases/case-type-folder.ts"() {
|
|
42429
|
-
"use strict";
|
|
42430
|
-
init_case_type_packages();
|
|
42431
|
-
init_case_files();
|
|
42432
|
-
init_case_types();
|
|
42433
|
-
init_expected();
|
|
42434
|
-
init_fs_safety();
|
|
42435
|
-
init_resource_files();
|
|
42436
|
-
init_terminal_output();
|
|
42437
|
-
init_case_local_files();
|
|
42438
|
-
TYPE_FOLDER_MARKER = ".wayai-case-type.json";
|
|
42439
|
-
TYPE_FILE = "type.json";
|
|
42440
|
-
safe4 = (text5) => sanitizeTerminalText(text5);
|
|
42441
|
-
PACKAGE_PATH_REASONS = /* @__PURE__ */ new Set([
|
|
42442
|
-
"package_not_tar",
|
|
42443
|
-
"package_entry_not_file",
|
|
42444
|
-
"package_too_many_files",
|
|
42445
|
-
"package_path_invalid",
|
|
42446
|
-
"package_path_repeated",
|
|
42447
|
-
"package_path_unexpected"
|
|
42448
|
-
]);
|
|
42449
|
-
NO_PHASES = { type_party_roles: [], type_outcomes: [], type_phases: [], attributes: { type: "object" } };
|
|
42450
|
-
}
|
|
42451
|
-
});
|
|
42452
|
-
|
|
42453
42721
|
// src/cases/case-types.ts
|
|
42454
|
-
import * as
|
|
42455
|
-
import * as
|
|
42722
|
+
import * as fs39 from "fs";
|
|
42723
|
+
import * as path51 from "path";
|
|
42456
42724
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
42457
42725
|
function problemLine(problem) {
|
|
42458
|
-
const where = problem.path === null ? "the package" : JSON.stringify(
|
|
42459
|
-
return `${where}: ${PROBLEM_TEXT[problem.reason] ?? problem.reason}${problem.detail ? ` (${
|
|
42726
|
+
const where = problem.path === null ? "the package" : JSON.stringify(safe6(problem.path));
|
|
42727
|
+
return `${where}: ${PROBLEM_TEXT[problem.reason] ?? problem.reason}${problem.detail ? ` (${safe6(problem.detail)})` : ""}`;
|
|
42460
42728
|
}
|
|
42461
42729
|
function caseTypeRef(orgId, spaceId, typeId) {
|
|
42462
42730
|
const parsed = caseTypeParam.safeParse({ org_id: orgId, space_id: spaceId, type_id: typeId });
|
|
@@ -42474,7 +42742,7 @@ async function personApi(space) {
|
|
|
42474
42742
|
const caseTokens = listCaseConnections().filter((c) => c.org_id === space.org_id && c.space_id === space.space_id);
|
|
42475
42743
|
if (caseTokens.length > 0) {
|
|
42476
42744
|
throw expected(
|
|
42477
|
-
`This machine holds only a case token for this space (case ${caseTokens.map((c) =>
|
|
42745
|
+
`This machine holds only a case token for this space (case ${caseTokens.map((c) => safe6(c.code)).join(", ")}), and a case token never reaches a case type: it reaches its one case. ${LOGIN_NEEDED}`
|
|
42478
42746
|
);
|
|
42479
42747
|
}
|
|
42480
42748
|
throw expected(`Not logged in. ${LOGIN_NEEDED}`);
|
|
@@ -42482,54 +42750,38 @@ async function personApi(space) {
|
|
|
42482
42750
|
const { config: signedIn, accessToken } = await requireAuth();
|
|
42483
42751
|
return new ApiClient({ apiUrl: signedIn.api_url, accessToken, onUnauthorized: () => getAccessToken(signedIn) });
|
|
42484
42752
|
}
|
|
42485
|
-
function typeCallFailure(err,
|
|
42753
|
+
function typeCallFailure(err, notFound2) {
|
|
42486
42754
|
if (!(err instanceof ApiError)) return err;
|
|
42487
42755
|
if (err.status === 401) return expected(`Your sign-in has expired. Run \`wayai login\`, then try again.`);
|
|
42488
42756
|
if (err.status === 403) {
|
|
42489
42757
|
const override2 = envTokenOverride() ? " WAYAI_TOKEN is set in this shell and is sent instead of your sign-in: unset it first." : "";
|
|
42490
42758
|
return expected(
|
|
42491
|
-
`${
|
|
42759
|
+
`${safe6(extractApiMessage(err)).replace(/\.$/, "")}. A case type takes a space administrator's own browser sign-in on this CLI (\`wayai login\`, without --token); a case token or an API token is refused.${override2}`
|
|
42492
42760
|
);
|
|
42493
42761
|
}
|
|
42494
|
-
if (err.status === 404) return expected(
|
|
42762
|
+
if (err.status === 404) return expected(notFound2);
|
|
42495
42763
|
if (err.status === 413) return expected("The push is larger than the server takes for a draft.");
|
|
42496
42764
|
if (err.status === 429) return expected(`Too many requests for now. Try again in ${retryAfterSeconds(err) ?? 60} s.`);
|
|
42497
42765
|
if (err.status >= 400 && err.status < 500) {
|
|
42498
42766
|
const reason3 = extractApiErrorReason(err);
|
|
42499
|
-
return expected(
|
|
42767
|
+
return expected(safe6(`${extractApiMessage(err)}${reason3 ? ` (${reason3})` : ""}`));
|
|
42500
42768
|
}
|
|
42501
42769
|
return err;
|
|
42502
42770
|
}
|
|
42503
|
-
async function call3(run,
|
|
42771
|
+
async function call3(run, notFound2, refuse2) {
|
|
42504
42772
|
try {
|
|
42505
42773
|
return await run();
|
|
42506
42774
|
} catch (err) {
|
|
42507
|
-
throw err instanceof ApiError && refuse2?.(err) || typeCallFailure(err,
|
|
42775
|
+
throw err instanceof ApiError && refuse2?.(err) || typeCallFailure(err, notFound2);
|
|
42508
42776
|
}
|
|
42509
42777
|
}
|
|
42510
42778
|
function assertWritablePackagePaths(read, size, definition) {
|
|
42511
42779
|
const problems2 = casePackageProblems(read, size, definition).filter((p) => PACKAGE_PATH_REASONS.has(p.reason)).map(problemLine);
|
|
42512
|
-
const files = new Set(read.entries.map((e) => e.path.toLowerCase()));
|
|
42513
|
-
const spelled = /* @__PURE__ */ new Map();
|
|
42514
42780
|
for (const { path: rel } of read.entries) {
|
|
42515
42781
|
const local = caseLocalPathProblem(rel);
|
|
42516
|
-
if (local) problems2.push(`${JSON.stringify(
|
|
42517
|
-
const segments = rel.split("/");
|
|
42518
|
-
for (let i = 1; i <= segments.length; i++) {
|
|
42519
|
-
const spelling = segments.slice(0, i).join("/");
|
|
42520
|
-
const key = spelling.toLowerCase();
|
|
42521
|
-
const known = spelled.get(key);
|
|
42522
|
-
if (known === void 0) spelled.set(key, spelling);
|
|
42523
|
-
else if (known !== spelling) {
|
|
42524
|
-
problems2.push(`${JSON.stringify(safe5(known))} and ${JSON.stringify(safe5(spelling))} differ only in case, so they would be one entry here`);
|
|
42525
|
-
break;
|
|
42526
|
-
}
|
|
42527
|
-
if (i < segments.length && files.has(key)) {
|
|
42528
|
-
problems2.push(`${JSON.stringify(safe5(rel))}: lies in a folder that is also a file`);
|
|
42529
|
-
break;
|
|
42530
|
-
}
|
|
42531
|
-
}
|
|
42782
|
+
if (local) problems2.push(`${JSON.stringify(safe6(rel))}: ${local}`);
|
|
42532
42783
|
}
|
|
42784
|
+
problems2.push(...packagePathCollisions(read.entries.map((e) => e.path)));
|
|
42533
42785
|
if (problems2.length > 0) throw expected(`The type's package holds paths this folder will not write, so nothing was written:
|
|
42534
42786
|
${[...new Set(problems2)].join("\n ")}`);
|
|
42535
42787
|
}
|
|
@@ -42557,30 +42809,30 @@ async function caseTypePull(ref, opts) {
|
|
|
42557
42809
|
const abbreviation = source.type.abbreviation;
|
|
42558
42810
|
if (caseTypeAbbreviationSchema.safeParse(abbreviation).data !== abbreviation) throw expected("The server answered a type abbreviation this CLI will not name a folder by: nothing was written.");
|
|
42559
42811
|
const entries = await pulledPackage(api, ref, source);
|
|
42560
|
-
const dir =
|
|
42812
|
+
const dir = path51.resolve(opts.dir ?? abbreviation);
|
|
42561
42813
|
let st;
|
|
42562
42814
|
try {
|
|
42563
|
-
st =
|
|
42815
|
+
st = fs39.lstatSync(dir);
|
|
42564
42816
|
} catch {
|
|
42565
42817
|
st = void 0;
|
|
42566
42818
|
}
|
|
42567
|
-
if (st && !st.isDirectory()) throw expected(`${
|
|
42819
|
+
if (st && !st.isDirectory()) throw expected(`${safe6(dir)} is a symlink or not a folder: pull into a folder of its own.`);
|
|
42568
42820
|
const existing = st ? findTypeFolder(dir) : null;
|
|
42569
42821
|
const here = existing && existing.root === caseLocalRoot(dir) ? existing : null;
|
|
42570
42822
|
if (here && (here.record.org_id !== ref.org_id || here.record.space_id !== ref.space_id || here.record.type_id !== ref.type_id)) {
|
|
42571
|
-
throw expected(`${
|
|
42823
|
+
throw expected(`${safe6(dir)} holds case type ${safe6(here.record.abbreviation)}: pull into another folder.`);
|
|
42572
42824
|
}
|
|
42573
42825
|
if (!here) {
|
|
42574
|
-
const outer = findTypeFolder(
|
|
42575
|
-
if (outer) throw expected(`${
|
|
42576
|
-
const clone = findCaseClone(
|
|
42577
|
-
if (clone) throw expected(`${
|
|
42826
|
+
const outer = findTypeFolder(path51.dirname(dir));
|
|
42827
|
+
if (outer) throw expected(`${safe6(dir)} lies inside the folder of case type ${safe6(outer.record.abbreviation)} at ${safe6(outer.root)}: pull outside it.`);
|
|
42828
|
+
const clone = findCaseClone(path51.dirname(dir));
|
|
42829
|
+
if (clone) throw expected(`${safe6(dir)} lies inside the clone of case ${safe6(clone.record.code)} at ${safe6(clone.root)}: pull the type outside it.`);
|
|
42578
42830
|
}
|
|
42579
|
-
if (!st)
|
|
42831
|
+
if (!st) fs39.mkdirSync(dir, { recursive: true, mode: CASE_FOLDER_MODE });
|
|
42580
42832
|
const root = caseLocalRoot(dir);
|
|
42581
42833
|
const scan = scanTypeFolder(root);
|
|
42582
42834
|
if (!here && (scan.typeFile || scan.files.size > 0)) {
|
|
42583
|
-
throw expected(`${
|
|
42835
|
+
throw expected(`${safe6(dir)} already holds ${TYPE_FILE} or a package folder, but no type pulled there: pull into a new or empty folder.`);
|
|
42584
42836
|
}
|
|
42585
42837
|
const next = /* @__PURE__ */ new Map([[TYPE_FILE, typeFileBytes(source.type.name, source.definition)]]);
|
|
42586
42838
|
for (const entry of entries) next.set(entry.path, Buffer.from(entry.bytes));
|
|
@@ -42591,11 +42843,11 @@ async function caseTypePull(ref, opts) {
|
|
|
42591
42843
|
if (!opts.overwrite) {
|
|
42592
42844
|
const advice = here.record.version === source.version ? "Push them as a draft first (`wayai cases type push`), or pass --overwrite to replace them with the published version." : `The type was published at version ${source.version} since this folder was pulled at version ${here.record.version}, so a push from it is refused: copy your changes aside and pass --overwrite, or pull into a new folder and carry them over.`;
|
|
42593
42845
|
throw expected(`These files changed here since the last pull, so nothing was written:
|
|
42594
|
-
${changed.map(
|
|
42846
|
+
${changed.map(safe6).join("\n ")}
|
|
42595
42847
|
${advice}`);
|
|
42596
42848
|
}
|
|
42597
42849
|
console.log("These local changes would be replaced with the published version, or removed:");
|
|
42598
|
-
for (const rel of changed) console.log(` ${
|
|
42850
|
+
for (const rel of changed) console.log(` ${safe6(rel)}`);
|
|
42599
42851
|
if (!await agree(`Replace or remove ${changed.length} local file(s)?`, opts.yes)) {
|
|
42600
42852
|
console.log("Cancelled.");
|
|
42601
42853
|
return;
|
|
@@ -42603,17 +42855,17 @@ ${advice}`);
|
|
|
42603
42855
|
}
|
|
42604
42856
|
const gone = new Set([...Object.keys(here?.record.files ?? {}), ...opts.overwrite ? now.keys() : []].filter((rel) => !next.has(rel)));
|
|
42605
42857
|
const vanishes = (rel) => {
|
|
42606
|
-
const abs =
|
|
42858
|
+
const abs = path51.join(root, ...rel.split("/"));
|
|
42607
42859
|
let st2;
|
|
42608
42860
|
try {
|
|
42609
|
-
st2 =
|
|
42861
|
+
st2 = fs39.lstatSync(abs);
|
|
42610
42862
|
} catch {
|
|
42611
42863
|
return false;
|
|
42612
42864
|
}
|
|
42613
42865
|
if (st2.isFile()) return gone.has(rel);
|
|
42614
42866
|
if (!st2.isDirectory()) return false;
|
|
42615
42867
|
let removed = false;
|
|
42616
|
-
for (const name of
|
|
42868
|
+
for (const name of fs39.readdirSync(abs)) {
|
|
42617
42869
|
if (name === ".DS_Store") continue;
|
|
42618
42870
|
if (!vanishes(`${rel}/${name}`)) return false;
|
|
42619
42871
|
removed = true;
|
|
@@ -42624,7 +42876,7 @@ ${advice}`);
|
|
|
42624
42876
|
if (clashes.length > 0) {
|
|
42625
42877
|
throw expected(
|
|
42626
42878
|
`These paths would land on a name this folder spells differently, or on a folder, so nothing was written:
|
|
42627
|
-
${clashes.map(({ rel, clash }) => `${
|
|
42879
|
+
${clashes.map(({ rel, clash }) => `${safe6(rel)} (here: ${safe6(clash.other)})`).join("\n ")}
|
|
42628
42880
|
Rename or move those first.`
|
|
42629
42881
|
);
|
|
42630
42882
|
}
|
|
@@ -42640,7 +42892,7 @@ Rename or move those first.`
|
|
|
42640
42892
|
writeTypeFolderRecord(root, record);
|
|
42641
42893
|
const confidential = casePackageConfidentialPaths(source.definition);
|
|
42642
42894
|
const marked = entries.filter((e) => confidential.has(e.path)).length;
|
|
42643
|
-
console.log(`Pulled case type ${
|
|
42895
|
+
console.log(`Pulled case type ${safe6(abbreviation)} (${safe6(source.type.name)}), version ${source.version}, into ${safe6(root)}:`);
|
|
42644
42896
|
console.log(` ${TYPE_FILE} and ${entries.length} package file(s); ${written} written, ${gone.size} removed.`);
|
|
42645
42897
|
if (!source.package) console.log(" This version has no package.");
|
|
42646
42898
|
if (marked > 0) console.log(` ${marked} of them are marked confidential by the definition: they reach a case only through its confidentiality filter.`);
|
|
@@ -42660,8 +42912,8 @@ function readLocalDraft(scan) {
|
|
|
42660
42912
|
const name = typeof body === "object" && body !== null ? body.name : void 0;
|
|
42661
42913
|
if (!fields.success) {
|
|
42662
42914
|
const issue = fields.error.issues[0];
|
|
42663
|
-
if (issue?.path[0] === "name") return refused(`${TYPE_FILE}: the name is refused (${
|
|
42664
|
-
return refused(`${TYPE_FILE} holds an object of "name" and "definition" alone (${
|
|
42915
|
+
if (issue?.path[0] === "name") return refused(`${TYPE_FILE}: the name is refused (${safe6(issue.message)}).`, name);
|
|
42916
|
+
return refused(`${TYPE_FILE} holds an object of "name" and "definition" alone (${safe6(`${issue?.message ?? "malformed"}${issue?.path.length ? ` at ${issue.path.join(".")}` : ""}`)}).`, name);
|
|
42665
42917
|
}
|
|
42666
42918
|
const { definition } = body;
|
|
42667
42919
|
const parsed = caseTypeDefinitionSchema.safeParse(definition);
|
|
@@ -42669,7 +42921,7 @@ function readLocalDraft(scan) {
|
|
|
42669
42921
|
const broken = caseTypeDefinitionReasonOf(parsed.error);
|
|
42670
42922
|
const issue = parsed.error.issues[0];
|
|
42671
42923
|
const why = broken ? `${broken.reason}${broken.at ? ` at ${broken.at}` : ""}` : `${issue?.message ?? "malformed"}${issue?.path.length ? ` at ${issue.path.join(".")}` : ""}`;
|
|
42672
|
-
return refused(`${TYPE_FILE}: the definition is refused (${
|
|
42924
|
+
return refused(`${TYPE_FILE}: the definition is refused (${safe6(why)}).`, name);
|
|
42673
42925
|
}
|
|
42674
42926
|
return { ok: true, name: body.name, definition, parsed: parsed.data, entries };
|
|
42675
42927
|
}
|
|
@@ -42684,7 +42936,7 @@ function draftProblems(draft) {
|
|
|
42684
42936
|
function openTypeFolder(dir) {
|
|
42685
42937
|
const from = dir === void 0 ? process.cwd() : caseLocalRoot(dir);
|
|
42686
42938
|
const folder = findTypeFolder(from);
|
|
42687
|
-
if (!folder) throw expected(`${
|
|
42939
|
+
if (!folder) throw expected(`${safe6(from)} is not in a case type folder: run \`wayai cases type pull <org_id> <space_id> <type_id>\` first.`);
|
|
42688
42940
|
return folder;
|
|
42689
42941
|
}
|
|
42690
42942
|
function definitionChanges(local, published) {
|
|
@@ -42696,9 +42948,9 @@ function definitionChanges(local, published) {
|
|
|
42696
42948
|
const after = new Map(local.type_phases.map((p) => [p.folder, p]));
|
|
42697
42949
|
for (const folder of [.../* @__PURE__ */ new Set([...before.keys(), ...after.keys()])].sort()) {
|
|
42698
42950
|
const [was, now] = [before.get(folder), after.get(folder)];
|
|
42699
|
-
if (!was) out.push(`phase ${
|
|
42700
|
-
else if (!now) out.push(`phase ${
|
|
42701
|
-
else if (!sameJson(was, now)) out.push(`phase ${
|
|
42951
|
+
if (!was) out.push(`phase ${safe6(folder)} added`);
|
|
42952
|
+
else if (!now) out.push(`phase ${safe6(folder)} removed`);
|
|
42953
|
+
else if (!sameJson(was, now)) out.push(`phase ${safe6(folder)} changed`);
|
|
42702
42954
|
}
|
|
42703
42955
|
if (out.length === 0 && !sameJson(local.type_phases.map((p) => p.folder), published.type_phases.map((p) => p.folder))) out.push("phases reordered");
|
|
42704
42956
|
return out;
|
|
@@ -42739,13 +42991,13 @@ async function caseTypeDiff(opts) {
|
|
|
42739
42991
|
if (diff.problems.length > 0) process.exitCode = 1;
|
|
42740
42992
|
}
|
|
42741
42993
|
function printDiff2(diff, root) {
|
|
42742
|
-
console.log(`Case type ${
|
|
42743
|
-
console.log(`Name: ${diff.name.changed ? `${JSON.stringify(
|
|
42994
|
+
console.log(`Case type ${safe6(diff.type.abbreviation)}: ${safe6(root)}, pulled at version ${diff.base_version}, against version ${diff.published_version}, published.`);
|
|
42995
|
+
console.log(`Name: ${diff.name.changed ? `${JSON.stringify(safe6(diff.name.published))} -> ${JSON.stringify(safe6(String(diff.name.local)))}` : "same"}`);
|
|
42744
42996
|
console.log(`Definition: ${diff.definition === null ? "refused (below)" : diff.definition.changed ? `changed: ${diff.definition.parts.join(", ")}` : "same"}`);
|
|
42745
42997
|
const moved = diff.files.filter((f) => f.status !== "same");
|
|
42746
42998
|
const count = (status) => diff.files.filter((f) => f.status === status).length;
|
|
42747
42999
|
console.log(`Package: ${count("added")} added, ${count("changed")} changed, ${count("removed")} removed, ${count("same")} the same.`);
|
|
42748
|
-
for (const f of moved) console.log(` ${STATUS_WORD[f.status]} ${
|
|
43000
|
+
for (const f of moved) console.log(` ${STATUS_WORD[f.status]} ${safe6(f.path)}${f.confidential ? " (confidential)" : ""}`);
|
|
42749
43001
|
if (diff.problems.length > 0) {
|
|
42750
43002
|
console.log(`A push would be refused here, for ${diff.problems.length} problem(s):`);
|
|
42751
43003
|
for (const line of diff.problems) console.log(` ${line}`);
|
|
@@ -42763,7 +43015,7 @@ function pushRefusal(err, record) {
|
|
|
42763
43015
|
if (err.status === 409 && reason3 === CASE_TYPE_VERSION_CONFLICT_REASON) {
|
|
42764
43016
|
const current = errorDetails(err)?.current_version;
|
|
42765
43017
|
return expected(
|
|
42766
|
-
`Case type ${
|
|
43018
|
+
`Case type ${safe6(record.abbreviation)} was published${typeof current === "number" ? ` at version ${current}` : ""} since this folder was pulled at version ${record.version}, so the draft was refused: it would undo that version. Pull the type into a new folder and carry your changes over, then push from there.`
|
|
42767
43019
|
);
|
|
42768
43020
|
}
|
|
42769
43021
|
if (err.status === 400 && reason3 === CASE_PACKAGE_INVALID_REASON) {
|
|
@@ -42791,18 +43043,18 @@ async function caseTypePush(opts) {
|
|
|
42791
43043
|
const basePackaged = Object.keys(record.files).some((rel) => rel !== TYPE_FILE);
|
|
42792
43044
|
const shown3 = archive ? `${draft.entries.length} package file(s), ${archive.byteLength} bytes (SHA-256 ${await casePackageSha(archive)})` : "no package";
|
|
42793
43045
|
if (opts.dryRun) {
|
|
42794
|
-
console.log(`Would push a draft of case type ${
|
|
43046
|
+
console.log(`Would push a draft of case type ${safe6(record.abbreviation)} from version ${record.version}: ${shown3}. Nothing was sent.`);
|
|
42795
43047
|
return;
|
|
42796
43048
|
}
|
|
42797
43049
|
const api = await personApi(record);
|
|
42798
43050
|
const pushed = (await call3(() => api.pushCaseTypeDraft(record, fields, archive), NOT_FOUND, (err) => pushRefusal(err, record))).data;
|
|
42799
|
-
console.log(`Pushed draft ${pushed.draft_id} of case type ${
|
|
43051
|
+
console.log(`Pushed draft ${pushed.draft_id} of case type ${safe6(record.abbreviation)}, from version ${pushed.base_version}: ${shown3}.`);
|
|
42800
43052
|
console.log(PUBLISH_NOTICE);
|
|
42801
43053
|
if (!archive && basePackaged) {
|
|
42802
43054
|
console.log("This draft carries no package, and the version it was made from has one: publishing it would be refused.");
|
|
42803
43055
|
}
|
|
42804
43056
|
}
|
|
42805
|
-
var PUBLISH_NOTICE,
|
|
43057
|
+
var PUBLISH_NOTICE, safe6, PROBLEM_TEXT, LOGIN_NEEDED, NOT_FOUND, typeFileFields, sameJson, STATUS_WORD;
|
|
42806
43058
|
var init_case_types2 = __esm({
|
|
42807
43059
|
"src/cases/case-types.ts"() {
|
|
42808
43060
|
"use strict";
|
|
@@ -42824,7 +43076,7 @@ var init_case_types2 = __esm({
|
|
|
42824
43076
|
init_case_tokens();
|
|
42825
43077
|
init_case_type_folder();
|
|
42826
43078
|
PUBLISH_NOTICE = "It changes nothing yet: a space administrator publishes it in the WayAI web app, as the type's next version, which new cases open on. A later push replaces it.";
|
|
42827
|
-
|
|
43079
|
+
safe6 = (text5) => sanitizeTerminalText(text5);
|
|
42828
43080
|
PROBLEM_TEXT = {
|
|
42829
43081
|
package_not_tar: "not an uncompressed ustar archive",
|
|
42830
43082
|
package_entry_not_file: "not a plain file (a link, a folder entry or a device)",
|
|
@@ -42928,7 +43180,7 @@ async function casesCommand(args2) {
|
|
|
42928
43180
|
return caseExplain(await openCaseSession(selector), { json: json2, phase: values.phase });
|
|
42929
43181
|
case "check":
|
|
42930
43182
|
takesNone();
|
|
42931
|
-
if (values.phase === void 0) throw usageError4("check takes --phase <folder
|
|
43183
|
+
if (values.output !== void 0 && values.phase === void 0) throw usageError4("check --output takes --phase <folder> too.");
|
|
42932
43184
|
return caseCheck(await openCaseSession(selector), { json: json2, phase: values.phase, output: values.output });
|
|
42933
43185
|
case "decisions": {
|
|
42934
43186
|
takesNone();
|
|
@@ -43034,9 +43286,9 @@ function webOrigin(apiUrl) {
|
|
|
43034
43286
|
else return null;
|
|
43035
43287
|
return `${url.protocol}//${host}${url.port ? `:${url.port}` : ""}`;
|
|
43036
43288
|
}
|
|
43037
|
-
function webLocation(apiUrl,
|
|
43289
|
+
function webLocation(apiUrl, path54) {
|
|
43038
43290
|
const origin = webOrigin(apiUrl);
|
|
43039
|
-
return origin ? `${origin}${
|
|
43291
|
+
return origin ? `${origin}${path54}` : `${path54} (in the WayAI web app)`;
|
|
43040
43292
|
}
|
|
43041
43293
|
function pickupSecret() {
|
|
43042
43294
|
const bytes = crypto5.randomBytes(32);
|
|
@@ -43238,7 +43490,7 @@ Usage:
|
|
|
43238
43490
|
wayai cases brief [--json]
|
|
43239
43491
|
wayai cases next [--json]
|
|
43240
43492
|
wayai cases explain [--phase <folder>] [--json]
|
|
43241
|
-
wayai cases check --phase <folder> [--output <code>] [--json]
|
|
43493
|
+
wayai cases check [--phase <folder> [--output <code>]] [--json]
|
|
43242
43494
|
wayai cases decisions [--dir <folder>] [--confidential]
|
|
43243
43495
|
wayai cases note "<text>" [--kind observation|next_step|pending|contribution]
|
|
43244
43496
|
[--phase <folder>] [--task <task_id>] [--origin <who sent it>]
|
|
@@ -43275,7 +43527,10 @@ pull Bring the clone up to date, keeping your local changes. A file
|
|
|
43275
43527
|
${CASE_MIRROR_DIR}/: the case, its status, evidence, agenda and
|
|
43276
43528
|
deliveries of the phases under way, their linked inputs'
|
|
43277
43529
|
registered texts (each checked against its registered hash),
|
|
43278
|
-
|
|
43530
|
+
what changed since the last pull, and the case's package
|
|
43531
|
+
(its instructions, templates, tools and sources, each checked
|
|
43532
|
+
against the published manifest, read-only; confidential
|
|
43533
|
+
instructions only with --confidential). Push never sends it; an
|
|
43279
43534
|
edit there is lost.
|
|
43280
43535
|
--mirror-only rewrites the mirror alone, leaving your files as
|
|
43281
43536
|
they are: the session-start hook runs it, never with
|
|
@@ -43309,8 +43564,12 @@ next What to do next on the phases under way, then what waits on
|
|
|
43309
43564
|
explain Why each phase and task is not done, and who can move it. --phase
|
|
43310
43565
|
names everything holding one phase.
|
|
43311
43566
|
check A delivery's checks over the case's files as WayAI holds them:
|
|
43312
|
-
a joint phase's, or one output's (--output).
|
|
43313
|
-
|
|
43567
|
+
a joint phase's, or one output's (--output). Inside a clone, it
|
|
43568
|
+
also compares the case's package in the mirror with the published
|
|
43569
|
+
manifest: a tool that differs must not be run, a text that differs
|
|
43570
|
+
not followed (confidential files aside); without --phase, it does
|
|
43571
|
+
that alone. Exits 1 when a submit now would be refused, or when a
|
|
43572
|
+
package file differs.
|
|
43314
43573
|
decisions Write the approved decisions to analysis/decisions.csv under --dir
|
|
43315
43574
|
(default: the clone's root inside a clone of the case, else this
|
|
43316
43575
|
folder). With --confidential, a confidential group's
|
|
@@ -43948,8 +44207,8 @@ refresh-preview: make the knowledge base's preview hold its production base's fi
|
|
|
43948
44207
|
});
|
|
43949
44208
|
|
|
43950
44209
|
// src/lib/file-map.ts
|
|
43951
|
-
import * as
|
|
43952
|
-
import * as
|
|
44210
|
+
import * as fs40 from "fs";
|
|
44211
|
+
import * as path52 from "path";
|
|
43953
44212
|
function isSafeRelPath(rel) {
|
|
43954
44213
|
if (rel.length === 0 || rel.length > 300) return false;
|
|
43955
44214
|
if (rel.startsWith("/") || rel.includes("\\")) return false;
|
|
@@ -43964,9 +44223,9 @@ function writeFileMap(targetDir, files) {
|
|
|
43964
44223
|
if (!isSafeRelPath(rel)) {
|
|
43965
44224
|
throw new Error(`Refusing to write unsafe path: ${rel}`);
|
|
43966
44225
|
}
|
|
43967
|
-
const abs =
|
|
43968
|
-
|
|
43969
|
-
|
|
44226
|
+
const abs = path52.join(targetDir, rel);
|
|
44227
|
+
fs40.mkdirSync(path52.dirname(abs), { recursive: true });
|
|
44228
|
+
fs40.writeFileSync(abs, body, "utf-8");
|
|
43970
44229
|
written.push(rel);
|
|
43971
44230
|
}
|
|
43972
44231
|
return written;
|
|
@@ -44073,8 +44332,8 @@ var admin_exports = {};
|
|
|
44073
44332
|
__export(admin_exports, {
|
|
44074
44333
|
adminCommand: () => adminCommand
|
|
44075
44334
|
});
|
|
44076
|
-
import * as
|
|
44077
|
-
import * as
|
|
44335
|
+
import * as fs41 from "fs";
|
|
44336
|
+
import * as path53 from "path";
|
|
44078
44337
|
async function adminCommand(args2) {
|
|
44079
44338
|
const [group, ...afterGroup] = args2;
|
|
44080
44339
|
if (!group) {
|
|
@@ -44715,13 +44974,13 @@ async function runSkillInstall(positional) {
|
|
|
44715
44974
|
throw err;
|
|
44716
44975
|
}
|
|
44717
44976
|
const root = findGitRoot() ?? process.cwd();
|
|
44718
|
-
const present = HARNESS_SKILL_DIRS.filter((dir) =>
|
|
44977
|
+
const present = HARNESS_SKILL_DIRS.filter((dir) => fs41.existsSync(path53.join(root, dir)));
|
|
44719
44978
|
const targets = present.length > 0 ? present : HARNESS_SKILL_DIRS;
|
|
44720
44979
|
const fileCount = Object.keys(res.files).length;
|
|
44721
44980
|
const relDirs = targets.map((harness) => {
|
|
44722
|
-
const targetDir =
|
|
44981
|
+
const targetDir = path53.join(root, harness, "skills", name);
|
|
44723
44982
|
writeFileMap(targetDir, res.files);
|
|
44724
|
-
return `${
|
|
44983
|
+
return `${path53.relative(root, targetDir)}/`;
|
|
44725
44984
|
});
|
|
44726
44985
|
console.log(`Installed skill "${name}" (${fileCount} file${fileCount === 1 ? "" : "s"}) \u2192 ${relDirs.join(", ")}`);
|
|
44727
44986
|
console.log("Reload your agent (e.g. restart Claude Code) to pick up the skill.");
|
|
@@ -47986,16 +48245,16 @@ MCP URL: ${toolsetMcpUrl(slug)}`);
|
|
|
47986
48245
|
).option("--force", "Revoke even if the token appears to be in live use").action(async function(tokenId, opts) {
|
|
47987
48246
|
const client = await createDataClient();
|
|
47988
48247
|
const id = pathSegment(tokenId, "token id");
|
|
47989
|
-
const
|
|
48248
|
+
const path54 = (force) => `/v1/tokens/${id}${force ? "?force=true" : ""}`;
|
|
47990
48249
|
const format = outputFormat(this);
|
|
47991
48250
|
const revoked = (forced) => printOutput({ token_id: tokenId, revoked: true, forced }, format);
|
|
47992
48251
|
if (opts.force) {
|
|
47993
|
-
await client.request("DELETE",
|
|
48252
|
+
await client.request("DELETE", path54(true));
|
|
47994
48253
|
revoked(true);
|
|
47995
48254
|
return;
|
|
47996
48255
|
}
|
|
47997
48256
|
try {
|
|
47998
|
-
await client.request("DELETE",
|
|
48257
|
+
await client.request("DELETE", path54(false));
|
|
47999
48258
|
revoked(false);
|
|
48000
48259
|
} catch (err) {
|
|
48001
48260
|
if (!(err instanceof ApiError) || err.status !== 409 || dataErrorDetails(err)?.requires_force !== true) {
|
|
@@ -48010,7 +48269,7 @@ MCP URL: ${toolsetMcpUrl(slug)}`);
|
|
|
48010
48269
|
console.error("Aborted.");
|
|
48011
48270
|
return process.exit(1);
|
|
48012
48271
|
}
|
|
48013
|
-
await client.request("DELETE",
|
|
48272
|
+
await client.request("DELETE", path54(true));
|
|
48014
48273
|
revoked(true);
|
|
48015
48274
|
}
|
|
48016
48275
|
});
|
|
@@ -48162,9 +48421,9 @@ var init_base_tags = __esm({
|
|
|
48162
48421
|
|
|
48163
48422
|
// src/data/commands/bases.ts
|
|
48164
48423
|
import { Command as Command10 } from "commander";
|
|
48165
|
-
function pageOf(
|
|
48166
|
-
if (!cursor) return
|
|
48167
|
-
return `${
|
|
48424
|
+
function pageOf(path54, cursor) {
|
|
48425
|
+
if (!cursor) return path54;
|
|
48426
|
+
return `${path54}${path54.includes("?") ? "&" : "?"}cursor=${encodeURIComponent(cursor)}`;
|
|
48168
48427
|
}
|
|
48169
48428
|
function parseEnum(flag, value, allowed) {
|
|
48170
48429
|
if (value === void 0) return void 0;
|
|
@@ -48321,9 +48580,9 @@ function buildBasesCommand() {
|
|
|
48321
48580
|
});
|
|
48322
48581
|
bases.command("list-previews <origin-id>").description("List preview bases cloned from a base (production or preview)").action(async function(originId) {
|
|
48323
48582
|
const client = await createDataClient();
|
|
48324
|
-
const
|
|
48583
|
+
const path54 = `/v1/${pathSegment(originId, "origin base id")}/previews`;
|
|
48325
48584
|
printOutput(
|
|
48326
|
-
await client.collectPages((cursor) => pageOf(
|
|
48585
|
+
await client.collectPages((cursor) => pageOf(path54, cursor)),
|
|
48327
48586
|
outputFormat(this)
|
|
48328
48587
|
);
|
|
48329
48588
|
});
|
|
@@ -48362,9 +48621,9 @@ function buildBasesCommand() {
|
|
|
48362
48621
|
});
|
|
48363
48622
|
bases.command("promotions <production-id>").description("List promotion history for a production base").action(async function(productionId) {
|
|
48364
48623
|
const client = await createDataClient();
|
|
48365
|
-
const
|
|
48624
|
+
const path54 = `/v1/${pathSegment(productionId, "production base id")}/promotions`;
|
|
48366
48625
|
printOutput(
|
|
48367
|
-
await client.collectPages((cursor) => pageOf(
|
|
48626
|
+
await client.collectPages((cursor) => pageOf(path54, cursor)),
|
|
48368
48627
|
outputFormat(this)
|
|
48369
48628
|
);
|
|
48370
48629
|
});
|
|
@@ -48934,8 +49193,8 @@ function buildRecordsCommand() {
|
|
|
48934
49193
|
const body = { data: parseData(opts.data) };
|
|
48935
49194
|
if (opts.externalId) body.external_id = opts.externalId;
|
|
48936
49195
|
if (opts.externalSource) body.external_source = opts.externalSource;
|
|
48937
|
-
const
|
|
48938
|
-
printOutput(await client.request("PUT",
|
|
49196
|
+
const path54 = opts.id ? `/v1/${base}/records/${pathSegment(recordType2, "record_type")}/${pathSegment(opts.id, "--id")}` : `/v1/${base}/records/${pathSegment(recordType2, "record_type")}`;
|
|
49197
|
+
printOutput(await client.request("PUT", path54, body), outputFormat(this));
|
|
48939
49198
|
});
|
|
48940
49199
|
records.command("query <record_type>").description("List/search records: exact filters + fuzzy `search`, sorting, pagination").option(
|
|
48941
49200
|
"--external-source <source>",
|
|
@@ -48970,9 +49229,9 @@ function buildRecordsCommand() {
|
|
|
48970
49229
|
).action(async function(recordType2, id, opts) {
|
|
48971
49230
|
const base = pathSegment(requireBase(this), "--base");
|
|
48972
49231
|
const client = await createDataClient();
|
|
48973
|
-
let
|
|
48974
|
-
if (opts.externalSource)
|
|
48975
|
-
printOutput(await client.request("GET",
|
|
49232
|
+
let path54 = `/v1/${base}/records/${pathSegment(recordType2, "record_type")}/${recordKey(id, opts.externalSource)}`;
|
|
49233
|
+
if (opts.externalSource) path54 += `?external_source=${encodeURIComponent(opts.externalSource)}`;
|
|
49234
|
+
printOutput(await client.request("GET", path54), outputFormat(this));
|
|
48976
49235
|
});
|
|
48977
49236
|
records.command("delete <record_type> <id>").description(
|
|
48978
49237
|
"Delete a record by internal ID, or by external_id (pass --external-source to scope it)"
|
|
@@ -48986,11 +49245,11 @@ function buildRecordsCommand() {
|
|
|
48986
49245
|
}
|
|
48987
49246
|
const base = pathSegment(requireBase(this), "--base");
|
|
48988
49247
|
const client = await createDataClient();
|
|
48989
|
-
let
|
|
49248
|
+
let path54 = `/v1/${base}/records/${pathSegment(recordType2, "record_type")}/${recordKey(id, opts.externalSource)}`;
|
|
48990
49249
|
if (opts.externalSource) {
|
|
48991
|
-
|
|
49250
|
+
path54 += `?external_source=${encodeURIComponent(opts.externalSource)}&external_id=${encodeURIComponent(id)}`;
|
|
48992
49251
|
}
|
|
48993
|
-
await client.request("DELETE",
|
|
49252
|
+
await client.request("DELETE", path54);
|
|
48994
49253
|
console.log("Deleted");
|
|
48995
49254
|
});
|
|
48996
49255
|
records.command("history <id>").description(
|
|
@@ -49155,8 +49414,8 @@ function buildRelationshipsCommand() {
|
|
|
49155
49414
|
if (opts.data) body.data = parseData(opts.data);
|
|
49156
49415
|
const base = pathSegment(requireBase(this), "--base");
|
|
49157
49416
|
const client = await createDataClient();
|
|
49158
|
-
const
|
|
49159
|
-
printOutput(await client.request("PUT",
|
|
49417
|
+
const path54 = opts.id ? `/v1/${base}/relationships/${pathSegment(opts.id, "--id")}` : `/v1/${base}/relationships`;
|
|
49418
|
+
printOutput(await client.request("PUT", path54, body), outputFormat(this));
|
|
49160
49419
|
});
|
|
49161
49420
|
relationships.command("get <id>").description(
|
|
49162
49421
|
"Get a relationship by ID (or by its external key: pass the external_id with --rel-type)"
|
|
@@ -49389,8 +49648,8 @@ function buildToolsetsCommand() {
|
|
|
49389
49648
|
toolsets.command("get <slug>").description("Get a toolset").option("--resolved", "Include resolved record_type schemas").action(async function(slug, opts) {
|
|
49390
49649
|
const base = pathSegment(requireBase(this), "--base");
|
|
49391
49650
|
const client = await createDataClient();
|
|
49392
|
-
const
|
|
49393
|
-
printOutput(await client.request("GET",
|
|
49651
|
+
const path54 = opts.resolved ? `/v1/${base}/toolsets/${pathSegment(slug, "toolset slug")}/resolved` : `/v1/${base}/toolsets/${pathSegment(slug, "toolset slug")}`;
|
|
49652
|
+
printOutput(await client.request("GET", path54), outputFormat(this));
|
|
49394
49653
|
});
|
|
49395
49654
|
toolsets.command("list").description("List all toolsets").action(async function() {
|
|
49396
49655
|
const base = pathSegment(requireBase(this), "--base");
|
|
@@ -49527,7 +49786,7 @@ init_utils();
|
|
|
49527
49786
|
init_registry();
|
|
49528
49787
|
import { readFileSync as readFileSync25 } from "fs";
|
|
49529
49788
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
49530
|
-
import { dirname as dirname22, join as
|
|
49789
|
+
import { dirname as dirname22, join as join48 } from "path";
|
|
49531
49790
|
|
|
49532
49791
|
// src/lib/version-refresh.ts
|
|
49533
49792
|
init_version_cache();
|
|
@@ -49683,7 +49942,7 @@ Run \`wayai admin skill install\` to update.`);
|
|
|
49683
49942
|
|
|
49684
49943
|
// src/index.ts
|
|
49685
49944
|
var __dirname = dirname22(fileURLToPath2(import.meta.url));
|
|
49686
|
-
var pkg = JSON.parse(readFileSync25(
|
|
49945
|
+
var pkg = JSON.parse(readFileSync25(join48(__dirname, "..", "package.json"), "utf-8"));
|
|
49687
49946
|
var [, , command, ...args] = process.argv;
|
|
49688
49947
|
var isBackgroundRefresh = command === REFRESH_COMMAND;
|
|
49689
49948
|
if (!isBackgroundRefresh) initSentry(command, pkg.version);
|