@hasna/todos 0.15.20 → 0.15.24
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/ai-tools.d.ts +80 -0
- package/dist/ai-tools.d.ts.map +1 -0
- package/dist/ai.d.ts +313 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/cli/cloud-router.d.ts +10 -1
- package/dist/cli/cloud-router.d.ts.map +1 -1
- package/dist/cli/commands/ai-commands.d.ts +3 -0
- package/dist/cli/commands/ai-commands.d.ts.map +1 -0
- package/dist/cli/commands/help-commands.d.ts +2 -1
- package/dist/cli/commands/help-commands.d.ts.map +1 -1
- package/dist/cli/commands/task-commands.d.ts.map +1 -1
- package/dist/cli/index.js +2856 -547
- package/dist/cli/stage-a.d.ts +27 -16
- package/dist/cli/stage-a.d.ts.map +1 -1
- package/dist/contracts.d.ts +1 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +638 -18
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3142 -1089
- package/dist/lib/cli-help.d.ts +2 -2
- package/dist/lib/config.d.ts +4 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/saved-search-views.d.ts.map +1 -1
- package/dist/lib/stale-lock-handoff.d.ts.map +1 -1
- package/dist/mcp/index.js +127 -72
- package/dist/mcp.js +1 -1
- package/dist/project-registration.js +67 -29
- package/dist/registry.js +603 -18
- package/dist/release-provenance.json +5 -5
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/v1.generated.d.ts +2 -0
- package/dist/sdk/v1.generated.d.ts.map +1 -1
- package/dist/server/index.js +133 -78
- package/dist/server/openapi.d.ts +7 -0
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/storage/postgres-adapter.d.ts.map +1 -1
- package/dist/storage.js +60 -20
- package/dist/task-manifest.js +19 -3
- package/package.json +1 -1
package/dist/registry.js
CHANGED
|
@@ -4731,7 +4731,7 @@ var init_database = __esm(() => {
|
|
|
4731
4731
|
});
|
|
4732
4732
|
|
|
4733
4733
|
// src/lib/config.ts
|
|
4734
|
-
import { existsSync as existsSync4 } from "fs";
|
|
4734
|
+
import { existsSync as existsSync4, readFileSync as readFileSync2 } from "fs";
|
|
4735
4735
|
import { dirname as dirname2, join as join3 } from "path";
|
|
4736
4736
|
function getConfigPath() {
|
|
4737
4737
|
return join3(getTodosGlobalDir(), "config.json");
|
|
@@ -4763,6 +4763,22 @@ function saveConfig(config) {
|
|
|
4763
4763
|
function updateConfig(patch) {
|
|
4764
4764
|
return saveConfig({ ...loadConfig(), ...patch });
|
|
4765
4765
|
}
|
|
4766
|
+
function getTodosAiConfig() {
|
|
4767
|
+
const configPath = getConfigPath();
|
|
4768
|
+
if (!existsSync4(configPath))
|
|
4769
|
+
return {};
|
|
4770
|
+
const parsed = JSON.parse(readFileSync2(configPath, "utf8"));
|
|
4771
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
4772
|
+
throw new Error("Todos config must be a JSON object");
|
|
4773
|
+
}
|
|
4774
|
+
const ai = parsed["ai"];
|
|
4775
|
+
if (ai === undefined)
|
|
4776
|
+
return {};
|
|
4777
|
+
if (ai === null || typeof ai !== "object" || Array.isArray(ai)) {
|
|
4778
|
+
throw new Error("Todos AI configuration must be an object");
|
|
4779
|
+
}
|
|
4780
|
+
return { ...ai };
|
|
4781
|
+
}
|
|
4766
4782
|
function normalizeApiUrl(value) {
|
|
4767
4783
|
const trimmed = value?.trim();
|
|
4768
4784
|
if (!trimmed)
|
|
@@ -7093,7 +7109,7 @@ var init_shared_events = __esm(() => {
|
|
|
7093
7109
|
});
|
|
7094
7110
|
|
|
7095
7111
|
// src/lib/secret-redaction.ts
|
|
7096
|
-
import { readFileSync as
|
|
7112
|
+
import { readFileSync as readFileSync3, existsSync as existsSync6 } from "fs";
|
|
7097
7113
|
function registerCustomRedactor(fn) {
|
|
7098
7114
|
customRedactors.push(fn);
|
|
7099
7115
|
}
|
|
@@ -7160,7 +7176,7 @@ function scanAndRedactText(text, options = {}) {
|
|
|
7160
7176
|
function scanFileForSecrets(path, options = {}) {
|
|
7161
7177
|
if (!existsSync6(path))
|
|
7162
7178
|
throw new Error(`File not found: ${path}`);
|
|
7163
|
-
const content =
|
|
7179
|
+
const content = readFileSync3(path, "utf8");
|
|
7164
7180
|
return scanAndRedactText(content, options);
|
|
7165
7181
|
}
|
|
7166
7182
|
function safeStringify(value, space) {
|
|
@@ -8606,7 +8622,7 @@ function requireCanonicalLockVersion(value) {
|
|
|
8606
8622
|
throw new StaleLockHandoffError("STALE_LOCK_HANDOFF_INVALID_INPUT", "expected_lock_version must be the exact canonical locked_at timestamp (YYYY-MM-DDTHH:mm:ss.sssZ)", { field: "expected_lock_version" });
|
|
8607
8623
|
}
|
|
8608
8624
|
const parsed = Date.parse(value);
|
|
8609
|
-
if (Number.isNaN(parsed) || new Date(parsed).toISOString() !== value) {
|
|
8625
|
+
if (value.startsWith("0000-") || Number.isNaN(parsed) || new Date(parsed).toISOString() !== value) {
|
|
8610
8626
|
throw new StaleLockHandoffError("STALE_LOCK_HANDOFF_INVALID_INPUT", "expected_lock_version must name a real canonical UTC instant", { field: "expected_lock_version" });
|
|
8611
8627
|
}
|
|
8612
8628
|
return value;
|
|
@@ -8631,9 +8647,6 @@ function prepareStaleLockHandoff(input, options = {}) {
|
|
|
8631
8647
|
if (canonicalAgentRef(actor) !== canonicalAgentRef(newHolder)) {
|
|
8632
8648
|
throw new StaleLockHandoffError("STALE_LOCK_HANDOFF_ACTOR_MISMATCH", "new_holder must match the authenticated actor", { actor, new_holder: newHolder });
|
|
8633
8649
|
}
|
|
8634
|
-
if (canonicalAgentRef(expectedHolder) === canonicalAgentRef(newHolder)) {
|
|
8635
|
-
throw new StaleLockHandoffError("STALE_LOCK_HANDOFF_INVALID_INPUT", "new_holder must differ from expected_holder", { field: "new_holder" });
|
|
8636
|
-
}
|
|
8637
8650
|
const operationTimestamp = options.now ?? new Date().toISOString();
|
|
8638
8651
|
if (!CANONICAL_LOCK_VERSION_RE.test(operationTimestamp) || new Date(Date.parse(operationTimestamp)).toISOString() !== operationTimestamp) {
|
|
8639
8652
|
throw new StaleLockHandoffError("STALE_LOCK_HANDOFF_INVALID_INPUT", "operation timestamp must be a canonical UTC instant");
|
|
@@ -11211,7 +11224,7 @@ var init_boards = __esm(() => {
|
|
|
11211
11224
|
|
|
11212
11225
|
// src/lib/artifact-store.ts
|
|
11213
11226
|
import { createHash as createHash3 } from "crypto";
|
|
11214
|
-
import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as
|
|
11227
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync4, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
11215
11228
|
import { basename, dirname as dirname4, join as join5, resolve as resolve7 } from "path";
|
|
11216
11229
|
import { tmpdir as tmpdir2 } from "os";
|
|
11217
11230
|
function isInMemoryDb2(path) {
|
|
@@ -11278,7 +11291,7 @@ function storeArtifactContent(input) {
|
|
|
11278
11291
|
const sourceStat = statSync2(sourcePath);
|
|
11279
11292
|
if (!sourceStat.isFile())
|
|
11280
11293
|
throw new Error(`Artifact path is not a file: ${sanitizePreWriteText(input.path, "artifact.path")}`);
|
|
11281
|
-
const sourceBuffer =
|
|
11294
|
+
const sourceBuffer = readFileSync4(sourcePath);
|
|
11282
11295
|
const sourceSha = sha256(sourceBuffer);
|
|
11283
11296
|
const textLike = isTextLike(sourceBuffer, input.path);
|
|
11284
11297
|
let storedBuffer = sourceBuffer;
|
|
@@ -11365,7 +11378,7 @@ function verifyStoredArtifact(input) {
|
|
|
11365
11378
|
message: "stored artifact content is missing"
|
|
11366
11379
|
};
|
|
11367
11380
|
}
|
|
11368
|
-
const buffer =
|
|
11381
|
+
const buffer = readFileSync4(storedPath);
|
|
11369
11382
|
const actualSha = sha256(buffer);
|
|
11370
11383
|
const actualSize = buffer.length;
|
|
11371
11384
|
const ok = actualSha === store.sha256 && actualSize === store.size_bytes;
|
|
@@ -11385,7 +11398,7 @@ function exportStoredArtifactContent(input) {
|
|
|
11385
11398
|
const report = verifyStoredArtifact(input);
|
|
11386
11399
|
if (report.status !== "ok" || !report.relative_path || !report.actual_sha256 || report.actual_size_bytes === null)
|
|
11387
11400
|
return null;
|
|
11388
|
-
const content =
|
|
11401
|
+
const content = readFileSync4(artifactStorePath(report.relative_path));
|
|
11389
11402
|
return {
|
|
11390
11403
|
artifact_id: input.id,
|
|
11391
11404
|
sha256: report.actual_sha256,
|
|
@@ -11436,7 +11449,7 @@ function getArtifactStoreRoot(dbPath) {
|
|
|
11436
11449
|
return join5(dirname4(resolve7(path)), "artifacts");
|
|
11437
11450
|
}
|
|
11438
11451
|
function computeContentHash(path) {
|
|
11439
|
-
return sha256(
|
|
11452
|
+
return sha256(readFileSync4(resolve7(path)));
|
|
11440
11453
|
}
|
|
11441
11454
|
function storeArtifactFile(input) {
|
|
11442
11455
|
const sourcePath = resolve7(input.sourcePath);
|
|
@@ -11446,7 +11459,7 @@ function storeArtifactFile(input) {
|
|
|
11446
11459
|
if (!statSync2(sourcePath).isFile()) {
|
|
11447
11460
|
throw new Error(`Source path is not a file: ${input.sourcePath}`);
|
|
11448
11461
|
}
|
|
11449
|
-
const buffer =
|
|
11462
|
+
const buffer = readFileSync4(sourcePath);
|
|
11450
11463
|
const contentHash = sha256(buffer);
|
|
11451
11464
|
const mimeType = mediaTypeFor(sourcePath, isTextLike(buffer, sourcePath));
|
|
11452
11465
|
const storageMode = input.storageMode ?? "copy";
|
|
@@ -12645,7 +12658,7 @@ var init_tasks = __esm(() => {
|
|
|
12645
12658
|
// package.json
|
|
12646
12659
|
var package_default = {
|
|
12647
12660
|
name: "@hasna/todos",
|
|
12648
|
-
version: "0.15.
|
|
12661
|
+
version: "0.15.24",
|
|
12649
12662
|
description: "Universal task management for AI coding agents - CLI + MCP server + interactive TUI",
|
|
12650
12663
|
type: "module",
|
|
12651
12664
|
main: "dist/index.js",
|
|
@@ -15416,6 +15429,578 @@ function createJsonContractsManifest(options = {}) {
|
|
|
15416
15429
|
var TODOS_JSON_CONTRACTS_MANIFEST = createJsonContractsManifest({
|
|
15417
15430
|
generatedAt: "1970-01-01T00:00:00.000Z"
|
|
15418
15431
|
});
|
|
15432
|
+
|
|
15433
|
+
// src/ai.ts
|
|
15434
|
+
var TODOS_AI_SCHEMA_VERSION = 1;
|
|
15435
|
+
var TODOS_AI_RUNTIME_PROTOCOL_VERSION = 1;
|
|
15436
|
+
var TODOS_AI_RUNTIME_SPECIFIER = "@hasna/todos-ai/runtime";
|
|
15437
|
+
var TODOS_AI_UPDATE_TASK_RESULT_SCHEMA = "todos.ai.update_task.v1";
|
|
15438
|
+
var TODOS_AI_FORMATS = ["text", "json", "stream-json"];
|
|
15439
|
+
var TODOS_AI_WRITE_MODES = ["read-only", "plan", "execute"];
|
|
15440
|
+
var TODOS_AI_APPROVAL_MODES = ["deny", "required", "prompt", "existing"];
|
|
15441
|
+
var TODOS_AI_RUN_STATUSES = [
|
|
15442
|
+
"answered",
|
|
15443
|
+
"needs_input",
|
|
15444
|
+
"needs_approval",
|
|
15445
|
+
"completed",
|
|
15446
|
+
"failed"
|
|
15447
|
+
];
|
|
15448
|
+
var TODOS_AI_RUNTIME_EVENT_TYPES = [
|
|
15449
|
+
"run.started",
|
|
15450
|
+
"run.progress",
|
|
15451
|
+
"text.delta",
|
|
15452
|
+
"tool.started",
|
|
15453
|
+
"tool.completed",
|
|
15454
|
+
"input.required",
|
|
15455
|
+
"approval.required"
|
|
15456
|
+
];
|
|
15457
|
+
var TODOS_AI_TOOL_EFFECTS = ["read", "control", "write"];
|
|
15458
|
+
var TODOS_AI_UPDATE_TASK_FIELDS = [
|
|
15459
|
+
"title",
|
|
15460
|
+
"description",
|
|
15461
|
+
"status",
|
|
15462
|
+
"priority",
|
|
15463
|
+
"assigned_to",
|
|
15464
|
+
"tags",
|
|
15465
|
+
"due_at"
|
|
15466
|
+
];
|
|
15467
|
+
var TODOS_AI_UPDATE_TASK_LIMITS = {
|
|
15468
|
+
max_title_bytes: 1024,
|
|
15469
|
+
max_description_bytes: 8192,
|
|
15470
|
+
max_assignee_bytes: 256,
|
|
15471
|
+
max_tags: 16,
|
|
15472
|
+
max_tag_bytes: 128,
|
|
15473
|
+
max_due_at_bytes: 128,
|
|
15474
|
+
min_idempotency_key_bytes: 8,
|
|
15475
|
+
max_idempotency_key_bytes: 128,
|
|
15476
|
+
max_result_bytes: 65536
|
|
15477
|
+
};
|
|
15478
|
+
var TODOS_AI_DEFAULTS = {
|
|
15479
|
+
format: "text",
|
|
15480
|
+
max_steps: 8,
|
|
15481
|
+
timeout_ms: 60000,
|
|
15482
|
+
write_mode: "read-only"
|
|
15483
|
+
};
|
|
15484
|
+
var TODOS_AI_LIMITS = {
|
|
15485
|
+
max_prompt_bytes: 1048576,
|
|
15486
|
+
max_json_bytes: 1048576,
|
|
15487
|
+
max_result_bytes: 4194304,
|
|
15488
|
+
max_variable_count: 100,
|
|
15489
|
+
max_variable_value_bytes: 65536,
|
|
15490
|
+
max_approval_refs: 32,
|
|
15491
|
+
max_approval_ref_bytes: 1024,
|
|
15492
|
+
max_resume_run_id_bytes: 1024,
|
|
15493
|
+
max_pending_input_prompt_bytes: 1024,
|
|
15494
|
+
max_pending_input_fields: 16,
|
|
15495
|
+
max_pending_input_field_bytes: 128,
|
|
15496
|
+
max_pending_approval_id_bytes: 256,
|
|
15497
|
+
max_pending_approval_summary_bytes: 1024,
|
|
15498
|
+
max_pending_approval_operations: 4,
|
|
15499
|
+
max_pending_approval_bytes: 8192,
|
|
15500
|
+
max_stream_events: 1000,
|
|
15501
|
+
max_stream_record_bytes: 262144,
|
|
15502
|
+
max_stream_bytes: 8388608,
|
|
15503
|
+
min_steps: 1,
|
|
15504
|
+
max_steps: 20,
|
|
15505
|
+
min_timeout_ms: 1000,
|
|
15506
|
+
max_timeout_ms: 600000
|
|
15507
|
+
};
|
|
15508
|
+
var TODOS_AI_EXIT_CODES = {
|
|
15509
|
+
success: 0,
|
|
15510
|
+
usage: 2,
|
|
15511
|
+
needs_input: 3,
|
|
15512
|
+
needs_approval: 4,
|
|
15513
|
+
runtime_unavailable: 5,
|
|
15514
|
+
failed: 6,
|
|
15515
|
+
timeout: 124,
|
|
15516
|
+
interrupted: 130
|
|
15517
|
+
};
|
|
15518
|
+
var TODOS_AI_PROTOCOL = {
|
|
15519
|
+
schema_version: TODOS_AI_SCHEMA_VERSION,
|
|
15520
|
+
runtime_protocol_version: TODOS_AI_RUNTIME_PROTOCOL_VERSION,
|
|
15521
|
+
runtime_specifier: TODOS_AI_RUNTIME_SPECIFIER,
|
|
15522
|
+
formats: TODOS_AI_FORMATS,
|
|
15523
|
+
write_modes: TODOS_AI_WRITE_MODES,
|
|
15524
|
+
approval_modes: TODOS_AI_APPROVAL_MODES,
|
|
15525
|
+
statuses: TODOS_AI_RUN_STATUSES,
|
|
15526
|
+
event_types: TODOS_AI_RUNTIME_EVENT_TYPES,
|
|
15527
|
+
tool_effects: TODOS_AI_TOOL_EFFECTS,
|
|
15528
|
+
defaults: TODOS_AI_DEFAULTS,
|
|
15529
|
+
limits: TODOS_AI_LIMITS,
|
|
15530
|
+
exit_codes: TODOS_AI_EXIT_CODES
|
|
15531
|
+
};
|
|
15532
|
+
|
|
15533
|
+
class TodosAiContractError extends Error {
|
|
15534
|
+
code;
|
|
15535
|
+
exitCode;
|
|
15536
|
+
constructor(code, message, exitCode = TODOS_AI_EXIT_CODES.usage, options) {
|
|
15537
|
+
super(message, options);
|
|
15538
|
+
this.code = code;
|
|
15539
|
+
this.exitCode = exitCode;
|
|
15540
|
+
this.name = "TodosAiContractError";
|
|
15541
|
+
}
|
|
15542
|
+
}
|
|
15543
|
+
|
|
15544
|
+
class TodosAiNeedsInputSignal extends Error {
|
|
15545
|
+
pending_input;
|
|
15546
|
+
constructor(pendingInput) {
|
|
15547
|
+
if (!isTodosAiJsonValue(pendingInput) || !isPendingInput(pendingInput)) {
|
|
15548
|
+
throw new TodosAiContractError("invalid_input", "Todos AI pending input must be bounded stable control data");
|
|
15549
|
+
}
|
|
15550
|
+
super("Todos AI input required");
|
|
15551
|
+
this.name = "TodosAiNeedsInputSignal";
|
|
15552
|
+
this.pending_input = {
|
|
15553
|
+
prompt: pendingInput.prompt,
|
|
15554
|
+
fields: [...pendingInput.fields]
|
|
15555
|
+
};
|
|
15556
|
+
}
|
|
15557
|
+
}
|
|
15558
|
+
|
|
15559
|
+
class TodosAiNeedsApprovalSignal extends Error {
|
|
15560
|
+
pending_approval;
|
|
15561
|
+
constructor(pendingApproval) {
|
|
15562
|
+
if (!isTodosAiJsonValue(pendingApproval) || !isPendingApproval(pendingApproval)) {
|
|
15563
|
+
throw new TodosAiContractError("invalid_input", "Todos AI pending approval must be bounded stable control data");
|
|
15564
|
+
}
|
|
15565
|
+
super("Todos AI approval required");
|
|
15566
|
+
this.name = "TodosAiNeedsApprovalSignal";
|
|
15567
|
+
this.pending_approval = {
|
|
15568
|
+
id: pendingApproval.id,
|
|
15569
|
+
summary: pendingApproval.summary,
|
|
15570
|
+
operations: pendingApproval.operations.map((operation) => JSON.parse(JSON.stringify(operation)))
|
|
15571
|
+
};
|
|
15572
|
+
}
|
|
15573
|
+
}
|
|
15574
|
+
function isRecord(value) {
|
|
15575
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
15576
|
+
}
|
|
15577
|
+
function isJsonObject(value) {
|
|
15578
|
+
if (!isRecord(value))
|
|
15579
|
+
return false;
|
|
15580
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15581
|
+
return prototype === Object.prototype || prototype === null;
|
|
15582
|
+
}
|
|
15583
|
+
function prototypeDefinesToJson(value) {
|
|
15584
|
+
let prototype = Object.getPrototypeOf(value);
|
|
15585
|
+
while (prototype !== null) {
|
|
15586
|
+
if (Object.getOwnPropertyDescriptor(prototype, "toJSON") !== undefined)
|
|
15587
|
+
return true;
|
|
15588
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
15589
|
+
}
|
|
15590
|
+
return false;
|
|
15591
|
+
}
|
|
15592
|
+
function isStableJsonArray(value, ancestors, depth) {
|
|
15593
|
+
if (Object.getPrototypeOf(value) !== Array.prototype || prototypeDefinesToJson(value)) {
|
|
15594
|
+
return false;
|
|
15595
|
+
}
|
|
15596
|
+
const keys = Reflect.ownKeys(value);
|
|
15597
|
+
if (keys.length !== value.length + 1)
|
|
15598
|
+
return false;
|
|
15599
|
+
for (const key of keys) {
|
|
15600
|
+
if (key === "length")
|
|
15601
|
+
continue;
|
|
15602
|
+
if (typeof key !== "string" || !/^(0|[1-9]\d*)$/.test(key))
|
|
15603
|
+
return false;
|
|
15604
|
+
const index = Number(key);
|
|
15605
|
+
if (!Number.isSafeInteger(index) || index < 0 || index >= value.length)
|
|
15606
|
+
return false;
|
|
15607
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
15608
|
+
if (!descriptor || !descriptor.enumerable || !("value" in descriptor))
|
|
15609
|
+
return false;
|
|
15610
|
+
if (!isTodosAiJsonValueInternal(descriptor.value, ancestors, depth + 1))
|
|
15611
|
+
return false;
|
|
15612
|
+
}
|
|
15613
|
+
return true;
|
|
15614
|
+
}
|
|
15615
|
+
function isStableJsonObject(value, ancestors, depth) {
|
|
15616
|
+
if (!isJsonObject(value) || prototypeDefinesToJson(value))
|
|
15617
|
+
return false;
|
|
15618
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
15619
|
+
if (typeof key !== "string")
|
|
15620
|
+
return false;
|
|
15621
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
15622
|
+
if (!descriptor || !descriptor.enumerable || !("value" in descriptor))
|
|
15623
|
+
return false;
|
|
15624
|
+
if (!isTodosAiJsonValueInternal(descriptor.value, ancestors, depth + 1))
|
|
15625
|
+
return false;
|
|
15626
|
+
}
|
|
15627
|
+
return true;
|
|
15628
|
+
}
|
|
15629
|
+
function isOneOf(value, values) {
|
|
15630
|
+
return typeof value === "string" && values.includes(value);
|
|
15631
|
+
}
|
|
15632
|
+
function selectedString(...values) {
|
|
15633
|
+
for (const value of values) {
|
|
15634
|
+
if (value === undefined || value === null)
|
|
15635
|
+
continue;
|
|
15636
|
+
const trimmed = value.trim();
|
|
15637
|
+
if (trimmed)
|
|
15638
|
+
return trimmed;
|
|
15639
|
+
}
|
|
15640
|
+
return null;
|
|
15641
|
+
}
|
|
15642
|
+
function parseEnum(value, values, field2, fallback) {
|
|
15643
|
+
if (value === null)
|
|
15644
|
+
return fallback;
|
|
15645
|
+
if (isOneOf(value, values))
|
|
15646
|
+
return value;
|
|
15647
|
+
throw new TodosAiContractError("invalid_configuration", `${field2} must be one of: ${values.join(", ")}`);
|
|
15648
|
+
}
|
|
15649
|
+
function parseBoundedInteger(value, field2, fallback, min, max) {
|
|
15650
|
+
if (value === undefined || value === null || value === "")
|
|
15651
|
+
return fallback;
|
|
15652
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
15653
|
+
if (!Number.isSafeInteger(parsed) || parsed < min || parsed > max) {
|
|
15654
|
+
throw new TodosAiContractError("invalid_configuration", `${field2} must be an integer between ${min} and ${max}`);
|
|
15655
|
+
}
|
|
15656
|
+
return parsed;
|
|
15657
|
+
}
|
|
15658
|
+
function normalizeApprovalRefs(values) {
|
|
15659
|
+
const refs = [...new Set((values ?? []).map((value) => value.trim()).filter(Boolean))];
|
|
15660
|
+
if (refs.length > TODOS_AI_LIMITS.max_approval_refs) {
|
|
15661
|
+
throw new TodosAiContractError("invalid_configuration", `--approval may be repeated at most ${TODOS_AI_LIMITS.max_approval_refs} times`);
|
|
15662
|
+
}
|
|
15663
|
+
for (const ref of refs) {
|
|
15664
|
+
if (new TextEncoder().encode(ref).byteLength > TODOS_AI_LIMITS.max_approval_ref_bytes) {
|
|
15665
|
+
throw new TodosAiContractError("invalid_configuration", `--approval references may not exceed ${TODOS_AI_LIMITS.max_approval_ref_bytes} bytes`);
|
|
15666
|
+
}
|
|
15667
|
+
}
|
|
15668
|
+
return refs;
|
|
15669
|
+
}
|
|
15670
|
+
function resolveTodosAiCommandOptions(input) {
|
|
15671
|
+
const cli = input.cli ?? {};
|
|
15672
|
+
const config = input.config ?? {};
|
|
15673
|
+
const env = input.env ?? {};
|
|
15674
|
+
const format = parseEnum(selectedString(cli.format, env["TODOS_AI_FORMAT"], config.format), TODOS_AI_FORMATS, "format", TODOS_AI_DEFAULTS.format);
|
|
15675
|
+
const configuredWriteMode = parseEnum(selectedString(cli.writeMode, env["TODOS_AI_WRITE_MODE"], config.write_mode), TODOS_AI_WRITE_MODES, "write mode", TODOS_AI_DEFAULTS.write_mode);
|
|
15676
|
+
if (cli.dryRun && cli.writeMode === "execute") {
|
|
15677
|
+
throw new TodosAiContractError("invalid_configuration", "--dry-run cannot be combined with --write-mode execute");
|
|
15678
|
+
}
|
|
15679
|
+
const writeMode = cli.dryRun ? "plan" : configuredWriteMode;
|
|
15680
|
+
const explicitApproval = cli.dryRun ? selectedString(cli.approvalMode) : selectedString(cli.approvalMode, env["TODOS_AI_APPROVAL_MODE"], config.approval_mode);
|
|
15681
|
+
const defaultApproval = writeMode === "execute" ? input.interactive ? "prompt" : "required" : "deny";
|
|
15682
|
+
const approvalMode = cli.dryRun ? parseEnum(explicitApproval, TODOS_AI_APPROVAL_MODES, "approval mode", "deny") : parseEnum(explicitApproval, TODOS_AI_APPROVAL_MODES, "approval mode", defaultApproval);
|
|
15683
|
+
const approvalRefs = normalizeApprovalRefs(cli.approvalRefs);
|
|
15684
|
+
if (cli.dryRun && approvalMode !== "deny") {
|
|
15685
|
+
throw new TodosAiContractError("invalid_configuration", "--dry-run requires approval mode deny");
|
|
15686
|
+
}
|
|
15687
|
+
if (writeMode !== "execute" && approvalMode !== "deny") {
|
|
15688
|
+
throw new TodosAiContractError("invalid_configuration", "approval modes other than deny require --write-mode execute");
|
|
15689
|
+
}
|
|
15690
|
+
if (writeMode === "execute" && approvalMode === "deny") {
|
|
15691
|
+
throw new TodosAiContractError("invalid_configuration", "--write-mode execute requires approval mode required, prompt, or existing");
|
|
15692
|
+
}
|
|
15693
|
+
if (!input.interactive && approvalMode === "prompt") {
|
|
15694
|
+
throw new TodosAiContractError("invalid_configuration", "approval mode prompt is unavailable in non-interactive mode");
|
|
15695
|
+
}
|
|
15696
|
+
if (approvalMode === "existing" && approvalRefs.length === 0) {
|
|
15697
|
+
throw new TodosAiContractError("invalid_configuration", "approval mode existing requires at least one --approval reference");
|
|
15698
|
+
}
|
|
15699
|
+
if (approvalMode !== "existing" && approvalRefs.length > 0) {
|
|
15700
|
+
throw new TodosAiContractError("invalid_configuration", "--approval references require --approval-mode existing");
|
|
15701
|
+
}
|
|
15702
|
+
return {
|
|
15703
|
+
provider: selectedString(cli.provider, env["TODOS_AI_PROVIDER"], config.provider),
|
|
15704
|
+
model: selectedString(cli.model, env["TODOS_AI_MODEL"], config.model),
|
|
15705
|
+
profile: selectedString(cli.profile, env["TODOS_AI_PROFILE"], config.profile),
|
|
15706
|
+
format,
|
|
15707
|
+
max_steps: parseBoundedInteger(cli.maxSteps ?? env["TODOS_AI_MAX_STEPS"] ?? config.max_steps, "max steps", TODOS_AI_DEFAULTS.max_steps, TODOS_AI_LIMITS.min_steps, TODOS_AI_LIMITS.max_steps),
|
|
15708
|
+
timeout_ms: parseBoundedInteger(cli.timeoutMs ?? env["TODOS_AI_TIMEOUT_MS"] ?? config.timeout_ms, "timeout", TODOS_AI_DEFAULTS.timeout_ms, TODOS_AI_LIMITS.min_timeout_ms, TODOS_AI_LIMITS.max_timeout_ms),
|
|
15709
|
+
write_mode: writeMode,
|
|
15710
|
+
approval_mode: approvalMode,
|
|
15711
|
+
approval_refs: approvalRefs,
|
|
15712
|
+
dry_run: cli.dryRun === true,
|
|
15713
|
+
interactive: input.interactive
|
|
15714
|
+
};
|
|
15715
|
+
}
|
|
15716
|
+
function normalizeTodosAiPrompt(value) {
|
|
15717
|
+
const prompt = value.trim();
|
|
15718
|
+
if (new TextEncoder().encode(prompt).byteLength > TODOS_AI_LIMITS.max_prompt_bytes) {
|
|
15719
|
+
throw new TodosAiContractError("invalid_input", `prompt exceeds ${TODOS_AI_LIMITS.max_prompt_bytes} bytes`);
|
|
15720
|
+
}
|
|
15721
|
+
return prompt;
|
|
15722
|
+
}
|
|
15723
|
+
function parseTodosAiJson(value, field2) {
|
|
15724
|
+
if (new TextEncoder().encode(value).byteLength > TODOS_AI_LIMITS.max_json_bytes) {
|
|
15725
|
+
throw new TodosAiContractError("invalid_input", `${field2} exceeds ${TODOS_AI_LIMITS.max_json_bytes} bytes`);
|
|
15726
|
+
}
|
|
15727
|
+
let parsed;
|
|
15728
|
+
try {
|
|
15729
|
+
parsed = JSON.parse(value);
|
|
15730
|
+
} catch (error) {
|
|
15731
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
15732
|
+
throw new TodosAiContractError("invalid_input", `${field2} must be valid JSON: ${detail}`);
|
|
15733
|
+
}
|
|
15734
|
+
if (!isTodosAiJsonValue(parsed)) {
|
|
15735
|
+
throw new TodosAiContractError("invalid_input", `${field2} must contain only stable JSON values`);
|
|
15736
|
+
}
|
|
15737
|
+
return parsed;
|
|
15738
|
+
}
|
|
15739
|
+
function parseTodosAiOutputSchema(value) {
|
|
15740
|
+
const parsed = parseTodosAiJson(value, "output schema");
|
|
15741
|
+
if (!isRecord(parsed)) {
|
|
15742
|
+
throw new TodosAiContractError("invalid_input", "output schema must be a JSON object");
|
|
15743
|
+
}
|
|
15744
|
+
return parsed;
|
|
15745
|
+
}
|
|
15746
|
+
var SENSITIVE_VARIABLE_KEY = /(?:^|[_.-])(api[_-]?key|credential|password|secret|token)(?:$|[_.-])/i;
|
|
15747
|
+
function parseTodosAiVariables(values) {
|
|
15748
|
+
if (values.length > TODOS_AI_LIMITS.max_variable_count) {
|
|
15749
|
+
throw new TodosAiContractError("invalid_input", `--var may be repeated at most ${TODOS_AI_LIMITS.max_variable_count} times`);
|
|
15750
|
+
}
|
|
15751
|
+
const variables = Object.create(null);
|
|
15752
|
+
for (const entry of values) {
|
|
15753
|
+
const separator = entry.indexOf("=");
|
|
15754
|
+
const key = separator >= 0 ? entry.slice(0, separator).trim() : "";
|
|
15755
|
+
const value = separator >= 0 ? entry.slice(separator + 1) : "";
|
|
15756
|
+
if (!/^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/.test(key)) {
|
|
15757
|
+
throw new TodosAiContractError("invalid_input", `invalid --var entry ${JSON.stringify(entry)}; expected non-secret key=value`);
|
|
15758
|
+
}
|
|
15759
|
+
if (SENSITIVE_VARIABLE_KEY.test(key)) {
|
|
15760
|
+
throw new TodosAiContractError("invalid_input", `--var ${key} is credential-shaped; provide credentials through the runtime's secret configuration`);
|
|
15761
|
+
}
|
|
15762
|
+
if (Object.hasOwn(variables, key)) {
|
|
15763
|
+
throw new TodosAiContractError("invalid_input", `duplicate --var key: ${key}`);
|
|
15764
|
+
}
|
|
15765
|
+
if (new TextEncoder().encode(value).byteLength > TODOS_AI_LIMITS.max_variable_value_bytes) {
|
|
15766
|
+
throw new TodosAiContractError("invalid_input", `--var ${key} exceeds ${TODOS_AI_LIMITS.max_variable_value_bytes} bytes`);
|
|
15767
|
+
}
|
|
15768
|
+
variables[key] = value;
|
|
15769
|
+
}
|
|
15770
|
+
return variables;
|
|
15771
|
+
}
|
|
15772
|
+
function isTodosAiJsonValue(value) {
|
|
15773
|
+
return isTodosAiJsonValueInternal(value, new Set, 0);
|
|
15774
|
+
}
|
|
15775
|
+
function isTodosAiUpdateTaskResult(value) {
|
|
15776
|
+
if (!isTodosAiJsonValue(value) || !isRecord(value) || !hasOnlyKeys(value, [
|
|
15777
|
+
"schema",
|
|
15778
|
+
"operation",
|
|
15779
|
+
"mode",
|
|
15780
|
+
"applied",
|
|
15781
|
+
"readback_verified",
|
|
15782
|
+
"source",
|
|
15783
|
+
"target",
|
|
15784
|
+
"changed_fields",
|
|
15785
|
+
"approval_ref",
|
|
15786
|
+
"payload_digest",
|
|
15787
|
+
"idempotency"
|
|
15788
|
+
]) || value["schema"] !== TODOS_AI_UPDATE_TASK_RESULT_SCHEMA || value["operation"] !== "update_task" || value["mode"] !== "plan" && value["mode"] !== "execute" || value["source"] !== "sqlite" && value["source"] !== "http") {
|
|
15789
|
+
return false;
|
|
15790
|
+
}
|
|
15791
|
+
const changedFields = value["changed_fields"];
|
|
15792
|
+
const target = value["target"];
|
|
15793
|
+
const idempotency = value["idempotency"];
|
|
15794
|
+
const payloadDigest = value["payload_digest"];
|
|
15795
|
+
const approvalRef = value["approval_ref"];
|
|
15796
|
+
if (!Array.isArray(changedFields) || changedFields.length === 0 || changedFields.length > TODOS_AI_UPDATE_TASK_FIELDS.length || !changedFields.every((field2) => typeof field2 === "string" && TODOS_AI_UPDATE_TASK_FIELDS.includes(field2)) || new Set(changedFields).size !== changedFields.length || !TODOS_AI_UPDATE_TASK_FIELDS.filter((field2) => changedFields.includes(field2)).every((field2, index) => changedFields[index] === field2) || !isRecord(target) || !hasOnlyKeys(target, ["task_id", "expected_version", "result_version"]) || typeof target["task_id"] !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(target["task_id"]) || !Number.isSafeInteger(target["expected_version"]) || target["expected_version"] < 0 || typeof payloadDigest !== "string" || !/^[0-9a-f]{64}$/.test(payloadDigest) || approvalRef !== `todos-ai:update_task:${payloadDigest}` || !isRecord(idempotency) || !hasOnlyKeys(idempotency, ["key", "scope", "replay"]) || !boundedUtf8String(idempotency["key"], TODOS_AI_UPDATE_TASK_LIMITS.max_idempotency_key_bytes) || new TextEncoder().encode(idempotency["key"]).byteLength < TODOS_AI_UPDATE_TASK_LIMITS.min_idempotency_key_bytes || !/^[A-Za-z0-9._:-]+$/.test(idempotency["key"]) || idempotency["scope"] !== "run" || typeof idempotency["replay"] !== "boolean" || new TextEncoder().encode(JSON.stringify(value)).byteLength > TODOS_AI_UPDATE_TASK_LIMITS.max_result_bytes) {
|
|
15797
|
+
return false;
|
|
15798
|
+
}
|
|
15799
|
+
if (value["mode"] === "plan") {
|
|
15800
|
+
return value["applied"] === false && value["readback_verified"] === false && target["result_version"] === null;
|
|
15801
|
+
}
|
|
15802
|
+
return value["applied"] === true && value["readback_verified"] === true && Number.isSafeInteger(target["result_version"]) && target["result_version"] === target["expected_version"] + 1;
|
|
15803
|
+
}
|
|
15804
|
+
function isTodosAiJsonValueInternal(value, ancestors, depth) {
|
|
15805
|
+
if (depth > 64)
|
|
15806
|
+
return false;
|
|
15807
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
15808
|
+
return true;
|
|
15809
|
+
if (typeof value === "number")
|
|
15810
|
+
return Number.isFinite(value);
|
|
15811
|
+
if (typeof value !== "object")
|
|
15812
|
+
return false;
|
|
15813
|
+
if (ancestors.has(value))
|
|
15814
|
+
return false;
|
|
15815
|
+
ancestors.add(value);
|
|
15816
|
+
try {
|
|
15817
|
+
return Array.isArray(value) ? isStableJsonArray(value, ancestors, depth) : isStableJsonObject(value, ancestors, depth);
|
|
15818
|
+
} catch {
|
|
15819
|
+
return false;
|
|
15820
|
+
} finally {
|
|
15821
|
+
ancestors.delete(value);
|
|
15822
|
+
}
|
|
15823
|
+
}
|
|
15824
|
+
function isUsage(value) {
|
|
15825
|
+
if (!isRecord(value))
|
|
15826
|
+
return false;
|
|
15827
|
+
return ["input_tokens", "output_tokens", "total_tokens"].every((key) => Number.isSafeInteger(value[key]) && value[key] >= 0);
|
|
15828
|
+
}
|
|
15829
|
+
function hasOnlyKeys(value, keys) {
|
|
15830
|
+
const allowed = new Set(keys);
|
|
15831
|
+
return Reflect.ownKeys(value).every((key) => typeof key === "string" && allowed.has(key));
|
|
15832
|
+
}
|
|
15833
|
+
function boundedUtf8String(value, maximum, allowEmpty = false) {
|
|
15834
|
+
return typeof value === "string" && (allowEmpty || value.length > 0) && new TextEncoder().encode(value).byteLength <= maximum;
|
|
15835
|
+
}
|
|
15836
|
+
function isPendingInput(value) {
|
|
15837
|
+
if (!isRecord(value) || !hasOnlyKeys(value, ["prompt", "fields"]))
|
|
15838
|
+
return false;
|
|
15839
|
+
if (!boundedUtf8String(value["prompt"], TODOS_AI_LIMITS.max_pending_input_prompt_bytes)) {
|
|
15840
|
+
return false;
|
|
15841
|
+
}
|
|
15842
|
+
if (!Array.isArray(value["fields"]) || value["fields"].length === 0 || value["fields"].length > TODOS_AI_LIMITS.max_pending_input_fields) {
|
|
15843
|
+
return false;
|
|
15844
|
+
}
|
|
15845
|
+
const fields = value["fields"];
|
|
15846
|
+
const unique = new Set;
|
|
15847
|
+
for (const field2 of fields) {
|
|
15848
|
+
if (!boundedUtf8String(field2, TODOS_AI_LIMITS.max_pending_input_field_bytes) || !/^[A-Za-z_][A-Za-z0-9_.-]{0,127}$/.test(field2) || unique.has(field2)) {
|
|
15849
|
+
return false;
|
|
15850
|
+
}
|
|
15851
|
+
unique.add(field2);
|
|
15852
|
+
}
|
|
15853
|
+
return true;
|
|
15854
|
+
}
|
|
15855
|
+
function isPendingApproval(value) {
|
|
15856
|
+
if (!isRecord(value) || !hasOnlyKeys(value, ["id", "summary", "operations"])) {
|
|
15857
|
+
return false;
|
|
15858
|
+
}
|
|
15859
|
+
if (!boundedUtf8String(value["id"], TODOS_AI_LIMITS.max_pending_approval_id_bytes) || !boundedUtf8String(value["summary"], TODOS_AI_LIMITS.max_pending_approval_summary_bytes) || !Array.isArray(value["operations"]) || value["operations"].length === 0 || value["operations"].length > TODOS_AI_LIMITS.max_pending_approval_operations || !value["operations"].every(isRecord) || !value["operations"].every(isTodosAiJsonValue)) {
|
|
15860
|
+
return false;
|
|
15861
|
+
}
|
|
15862
|
+
return new TextEncoder().encode(JSON.stringify(value)).byteLength <= TODOS_AI_LIMITS.max_pending_approval_bytes;
|
|
15863
|
+
}
|
|
15864
|
+
function isAiError(value) {
|
|
15865
|
+
if (!isRecord(value))
|
|
15866
|
+
return false;
|
|
15867
|
+
const code = value["code"];
|
|
15868
|
+
const validCode = [
|
|
15869
|
+
"invalid_input",
|
|
15870
|
+
"invalid_configuration",
|
|
15871
|
+
"runtime_unavailable",
|
|
15872
|
+
"runtime_incompatible",
|
|
15873
|
+
"runtime_invalid_result",
|
|
15874
|
+
"needs_input",
|
|
15875
|
+
"needs_approval",
|
|
15876
|
+
"timeout",
|
|
15877
|
+
"interrupted",
|
|
15878
|
+
"provider_error",
|
|
15879
|
+
"tool_error",
|
|
15880
|
+
"schema_error",
|
|
15881
|
+
"internal_error"
|
|
15882
|
+
];
|
|
15883
|
+
return typeof code === "string" && validCode.includes(code) && typeof value["message"] === "string" && typeof value["retryable"] === "boolean" && (value["details"] === null || isRecord(value["details"]) && isTodosAiJsonValue(value["details"]));
|
|
15884
|
+
}
|
|
15885
|
+
function isTodosAiRunResult(value) {
|
|
15886
|
+
if (!isRecord(value) || !isTodosAiJsonValue(value))
|
|
15887
|
+
return false;
|
|
15888
|
+
const structurallyValid = value["schema_version"] === TODOS_AI_SCHEMA_VERSION && typeof value["run_id"] === "string" && Boolean(value["run_id"]) && isOneOf(value["status"], TODOS_AI_RUN_STATUSES) && (value["answer"] === null || typeof value["answer"] === "string") && isTodosAiJsonValue(value["data"]) && Number.isSafeInteger(value["steps"]) && value["steps"] >= 0 && (value["usage"] === null || isUsage(value["usage"])) && (value["pending_input"] === null || isPendingInput(value["pending_input"])) && (value["pending_approval"] === null || isPendingApproval(value["pending_approval"])) && (value["error"] === null || isAiError(value["error"]));
|
|
15889
|
+
if (!structurallyValid)
|
|
15890
|
+
return false;
|
|
15891
|
+
switch (value["status"]) {
|
|
15892
|
+
case "answered":
|
|
15893
|
+
return typeof value["answer"] === "string" && value["pending_input"] === null && value["pending_approval"] === null && value["error"] === null;
|
|
15894
|
+
case "completed":
|
|
15895
|
+
return isTodosAiUpdateTaskResult(value["data"]) && value["data"]["mode"] === "execute" && value["data"]["applied"] === true && value["data"]["readback_verified"] === true && value["pending_input"] === null && value["pending_approval"] === null && value["error"] === null;
|
|
15896
|
+
case "needs_input":
|
|
15897
|
+
return value["pending_input"] !== null && value["pending_approval"] === null && value["error"] === null;
|
|
15898
|
+
case "needs_approval":
|
|
15899
|
+
return value["pending_input"] === null && value["pending_approval"] !== null && value["error"] === null;
|
|
15900
|
+
case "failed":
|
|
15901
|
+
return value["pending_input"] === null && value["pending_approval"] === null && value["error"] !== null;
|
|
15902
|
+
}
|
|
15903
|
+
return false;
|
|
15904
|
+
}
|
|
15905
|
+
function assertTodosAiRunResult(value) {
|
|
15906
|
+
if (!isTodosAiRunResult(value)) {
|
|
15907
|
+
throw new TodosAiContractError("runtime_invalid_result", "optional AI runtime returned a result that does not satisfy the Todos AI protocol", TODOS_AI_EXIT_CODES.failed);
|
|
15908
|
+
}
|
|
15909
|
+
return value;
|
|
15910
|
+
}
|
|
15911
|
+
function isTodosAiRuntimeEvent(value) {
|
|
15912
|
+
if (!isRecord(value) || !isTodosAiJsonValue(value))
|
|
15913
|
+
return false;
|
|
15914
|
+
return value["schema_version"] === TODOS_AI_SCHEMA_VERSION && typeof value["run_id"] === "string" && Boolean(value["run_id"]) && Number.isSafeInteger(value["sequence"]) && value["sequence"] >= 0 && isOneOf(value["type"], TODOS_AI_RUNTIME_EVENT_TYPES) && typeof value["timestamp"] === "string" && isRecord(value["data"]) && isTodosAiJsonValue(value["data"]);
|
|
15915
|
+
}
|
|
15916
|
+
function assertTodosAiRuntimeModule(value) {
|
|
15917
|
+
if (!isRecord(value) || value["TODOS_AI_RUNTIME_PROTOCOL_VERSION"] !== TODOS_AI_RUNTIME_PROTOCOL_VERSION || typeof value["createTodosAiRuntime"] !== "function") {
|
|
15918
|
+
throw new TodosAiContractError("runtime_incompatible", `optional AI runtime must implement protocol ${TODOS_AI_RUNTIME_PROTOCOL_VERSION}`, TODOS_AI_EXIT_CODES.runtime_unavailable);
|
|
15919
|
+
}
|
|
15920
|
+
return value;
|
|
15921
|
+
}
|
|
15922
|
+
function assertTodosAiRuntime(value) {
|
|
15923
|
+
if (!isRecord(value) || typeof value["run"] !== "function") {
|
|
15924
|
+
throw new TodosAiContractError("runtime_incompatible", `optional AI runtime must implement protocol ${TODOS_AI_RUNTIME_PROTOCOL_VERSION}`, TODOS_AI_EXIT_CODES.runtime_unavailable);
|
|
15925
|
+
}
|
|
15926
|
+
return value;
|
|
15927
|
+
}
|
|
15928
|
+
var defaultTodosAiRuntimeImporter = async (specifier) => import(specifier);
|
|
15929
|
+
async function loadTodosAiRuntime(context, importer = defaultTodosAiRuntimeImporter) {
|
|
15930
|
+
let imported;
|
|
15931
|
+
try {
|
|
15932
|
+
imported = await importer(TODOS_AI_RUNTIME_SPECIFIER);
|
|
15933
|
+
} catch (cause) {
|
|
15934
|
+
throw new TodosAiContractError("runtime_unavailable", `optional AI runtime is unavailable; install a compatible ${TODOS_AI_RUNTIME_SPECIFIER}`, TODOS_AI_EXIT_CODES.runtime_unavailable, { cause });
|
|
15935
|
+
}
|
|
15936
|
+
const runtimeModule = assertTodosAiRuntimeModule(imported);
|
|
15937
|
+
return assertTodosAiRuntime(await runtimeModule.createTodosAiRuntime(context));
|
|
15938
|
+
}
|
|
15939
|
+
function createTodosAiFailureResult(runId, code, message, retryable = false, details = null) {
|
|
15940
|
+
return {
|
|
15941
|
+
schema_version: TODOS_AI_SCHEMA_VERSION,
|
|
15942
|
+
run_id: runId,
|
|
15943
|
+
status: "failed",
|
|
15944
|
+
answer: null,
|
|
15945
|
+
data: null,
|
|
15946
|
+
steps: 0,
|
|
15947
|
+
usage: null,
|
|
15948
|
+
pending_input: null,
|
|
15949
|
+
pending_approval: null,
|
|
15950
|
+
error: { code, message, retryable, details }
|
|
15951
|
+
};
|
|
15952
|
+
}
|
|
15953
|
+
function createTodosAiNeedsInputResult(runId, message) {
|
|
15954
|
+
return {
|
|
15955
|
+
schema_version: TODOS_AI_SCHEMA_VERSION,
|
|
15956
|
+
run_id: runId,
|
|
15957
|
+
status: "needs_input",
|
|
15958
|
+
answer: null,
|
|
15959
|
+
data: null,
|
|
15960
|
+
steps: 0,
|
|
15961
|
+
usage: null,
|
|
15962
|
+
pending_input: { prompt: message, fields: ["prompt"] },
|
|
15963
|
+
pending_approval: null,
|
|
15964
|
+
error: null
|
|
15965
|
+
};
|
|
15966
|
+
}
|
|
15967
|
+
function createTodosAiNeedsApprovalResult(runId, pendingApproval) {
|
|
15968
|
+
const signal = new TodosAiNeedsApprovalSignal(pendingApproval);
|
|
15969
|
+
return {
|
|
15970
|
+
schema_version: TODOS_AI_SCHEMA_VERSION,
|
|
15971
|
+
run_id: runId,
|
|
15972
|
+
status: "needs_approval",
|
|
15973
|
+
answer: null,
|
|
15974
|
+
data: null,
|
|
15975
|
+
steps: 0,
|
|
15976
|
+
usage: null,
|
|
15977
|
+
pending_input: null,
|
|
15978
|
+
pending_approval: signal.pending_approval,
|
|
15979
|
+
error: null
|
|
15980
|
+
};
|
|
15981
|
+
}
|
|
15982
|
+
function todosAiExitCodeForResult(result) {
|
|
15983
|
+
if (result.status === "answered" || result.status === "completed")
|
|
15984
|
+
return TODOS_AI_EXIT_CODES.success;
|
|
15985
|
+
if (result.status === "needs_input")
|
|
15986
|
+
return TODOS_AI_EXIT_CODES.needs_input;
|
|
15987
|
+
if (result.status === "needs_approval")
|
|
15988
|
+
return TODOS_AI_EXIT_CODES.needs_approval;
|
|
15989
|
+
switch (result.error?.code) {
|
|
15990
|
+
case "invalid_input":
|
|
15991
|
+
case "invalid_configuration":
|
|
15992
|
+
return TODOS_AI_EXIT_CODES.usage;
|
|
15993
|
+
case "runtime_unavailable":
|
|
15994
|
+
case "runtime_incompatible":
|
|
15995
|
+
return TODOS_AI_EXIT_CODES.runtime_unavailable;
|
|
15996
|
+
case "timeout":
|
|
15997
|
+
return TODOS_AI_EXIT_CODES.timeout;
|
|
15998
|
+
case "interrupted":
|
|
15999
|
+
return TODOS_AI_EXIT_CODES.interrupted;
|
|
16000
|
+
default:
|
|
16001
|
+
return TODOS_AI_EXIT_CODES.failed;
|
|
16002
|
+
}
|
|
16003
|
+
}
|
|
15419
16004
|
// src/lib/onboarding-fixtures.ts
|
|
15420
16005
|
import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
15421
16006
|
import { join as join6 } from "path";
|
|
@@ -16371,7 +16956,7 @@ function importOnboardingFixture(options = {}) {
|
|
|
16371
16956
|
// src/lib/local-backups.ts
|
|
16372
16957
|
init_database();
|
|
16373
16958
|
import { createHash as createHash4 } from "crypto";
|
|
16374
|
-
import { readFileSync as
|
|
16959
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "fs";
|
|
16375
16960
|
import { dirname as dirname5, resolve as resolve8 } from "path";
|
|
16376
16961
|
import { mkdirSync as mkdirSync6 } from "fs";
|
|
16377
16962
|
var TODOS_LOCAL_BACKUP_KIND = "hasna.todos.local-backup";
|
|
@@ -16486,7 +17071,7 @@ function writeLocalBackupFile(backup, outputPath) {
|
|
|
16486
17071
|
return path;
|
|
16487
17072
|
}
|
|
16488
17073
|
function readLocalBackupFile(path) {
|
|
16489
|
-
return JSON.parse(
|
|
17074
|
+
return JSON.parse(readFileSync5(resolve8(path), "utf-8"));
|
|
16490
17075
|
}
|
|
16491
17076
|
function verifyLocalBackup(value, options = {}, db) {
|
|
16492
17077
|
const verifiedAt = options.verified_at ?? now();
|
|
@@ -20433,7 +21018,7 @@ function renderLocalAuditLedgerMarkdown(ledger) {
|
|
|
20433
21018
|
// src/lib/release-compatibility.ts
|
|
20434
21019
|
init_migrations();
|
|
20435
21020
|
init_schema();
|
|
20436
|
-
import { readFileSync as
|
|
21021
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
20437
21022
|
import { join as join8, resolve as resolve9 } from "path";
|
|
20438
21023
|
import { Database as Database2 } from "bun:sqlite";
|
|
20439
21024
|
var LOCAL_RELEASE_COMPATIBILITY_SCHEMA_VERSION = 1;
|
|
@@ -20480,7 +21065,7 @@ function warn(id, message, details) {
|
|
|
20480
21065
|
return { id, status: "warning", message, details };
|
|
20481
21066
|
}
|
|
20482
21067
|
function readPackageJson(root) {
|
|
20483
|
-
return JSON.parse(
|
|
21068
|
+
return JSON.parse(readFileSync6(join8(root, "package.json"), "utf8"));
|
|
20484
21069
|
}
|
|
20485
21070
|
function sortedKeys(value) {
|
|
20486
21071
|
return Object.keys(value ?? {}).sort((left, right) => left.localeCompare(right));
|