@aionis/manifest 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +178 -0
  3. package/README.md +170 -0
  4. package/dist/ast/types.d.ts +34 -0
  5. package/dist/ast/types.js +1 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +122 -0
  8. package/dist/compile.d.ts +14 -0
  9. package/dist/compile.js +219 -0
  10. package/dist/contracts.d.ts +12610 -0
  11. package/dist/contracts.js +401 -0
  12. package/dist/diagnostics/types.d.ts +17 -0
  13. package/dist/diagnostics/types.js +1 -0
  14. package/dist/execute/localRuntime.d.ts +5 -0
  15. package/dist/execute/localRuntime.js +165 -0
  16. package/dist/execute/moduleRuntime.d.ts +25 -0
  17. package/dist/execute/moduleRuntime.js +352 -0
  18. package/dist/execute/types.d.ts +113 -0
  19. package/dist/execute/types.js +1 -0
  20. package/dist/execute-cli.d.ts +2 -0
  21. package/dist/execute-cli.js +112 -0
  22. package/dist/execute.d.ts +6 -0
  23. package/dist/execute.js +46 -0
  24. package/dist/graph/buildExecutionGraph.d.ts +8 -0
  25. package/dist/graph/buildExecutionGraph.js +69 -0
  26. package/dist/graph/types.d.ts +24 -0
  27. package/dist/graph/types.js +1 -0
  28. package/dist/handoff-store-cli.d.ts +2 -0
  29. package/dist/handoff-store-cli.js +139 -0
  30. package/dist/handoff-store.d.ts +103 -0
  31. package/dist/handoff-store.js +78 -0
  32. package/dist/index.d.ts +22 -0
  33. package/dist/index.js +21 -0
  34. package/dist/ir/types.d.ts +92 -0
  35. package/dist/ir/types.js +1 -0
  36. package/dist/parser/parseAst.d.ts +3 -0
  37. package/dist/parser/parseAst.js +207 -0
  38. package/dist/parser/payload.d.ts +6 -0
  39. package/dist/parser/payload.js +211 -0
  40. package/dist/plan/buildExecutionPlan.d.ts +9 -0
  41. package/dist/plan/buildExecutionPlan.js +98 -0
  42. package/dist/plan/types.d.ts +44 -0
  43. package/dist/plan/types.js +1 -0
  44. package/dist/publish-cli.d.ts +2 -0
  45. package/dist/publish-cli.js +249 -0
  46. package/dist/publish.d.ts +148 -0
  47. package/dist/publish.js +190 -0
  48. package/dist/recover-cli.d.ts +2 -0
  49. package/dist/recover-cli.js +258 -0
  50. package/dist/recover.d.ts +489 -0
  51. package/dist/recover.js +290 -0
  52. package/dist/refs/resolveRefs.d.ts +13 -0
  53. package/dist/refs/resolveRefs.js +104 -0
  54. package/dist/registry/loadModuleRegistry.d.ts +28 -0
  55. package/dist/registry/loadModuleRegistry.js +97 -0
  56. package/dist/registry/types.d.ts +20 -0
  57. package/dist/registry/types.js +2 -0
  58. package/dist/resume-cli.d.ts +2 -0
  59. package/dist/resume-cli.js +379 -0
  60. package/dist/resume.d.ts +2076 -0
  61. package/dist/resume.js +452 -0
  62. package/dist/run-cli.d.ts +2 -0
  63. package/dist/run-cli.js +119 -0
  64. package/dist/run.d.ts +9 -0
  65. package/dist/run.js +43 -0
  66. package/dist/runtime-handoff-cli.d.ts +2 -0
  67. package/dist/runtime-handoff-cli.js +179 -0
  68. package/dist/runtime-handoff.d.ts +914 -0
  69. package/dist/runtime-handoff.js +383 -0
  70. package/dist/scanner/scanSource.d.ts +9 -0
  71. package/dist/scanner/scanSource.js +43 -0
  72. package/dist/schema/validateIrSchemas.d.ts +3 -0
  73. package/dist/schema/validateIrSchemas.js +64 -0
  74. package/dist/validate-module-cli.d.ts +2 -0
  75. package/dist/validate-module-cli.js +93 -0
  76. package/dist/validate-registry-cli.d.ts +2 -0
  77. package/dist/validate-registry-cli.js +82 -0
  78. package/dist/validate.d.ts +52 -0
  79. package/dist/validate.js +91 -0
  80. package/fixtures/duplicate-doc.aionis.md +19 -0
  81. package/fixtures/fenced-example.aionis.md +27 -0
  82. package/fixtures/malformed-payload.aionis.md +9 -0
  83. package/fixtures/npm-installed-module-registry.json +17 -0
  84. package/fixtures/standalone-module-registry.json +13 -0
  85. package/fixtures/standalone-runner-plan.json +51 -0
  86. package/fixtures/standalone-runner.aionis.md +29 -0
  87. package/fixtures/unresolved-ref.aionis.md +14 -0
  88. package/fixtures/valid-minimal.aionis.md +24 -0
  89. package/fixtures/valid-workflow.aionis.md +29 -0
  90. package/official-modules/copy-summary/CHANGELOG.md +6 -0
  91. package/official-modules/copy-summary/README.md +43 -0
  92. package/official-modules/copy-summary/index.mjs +41 -0
  93. package/official-modules/copy-summary/package.json +31 -0
  94. package/official-modules/json-transform/CHANGELOG.md +6 -0
  95. package/official-modules/json-transform/README.md +51 -0
  96. package/official-modules/json-transform/index.mjs +53 -0
  97. package/official-modules/json-transform/package.json +31 -0
  98. package/official-modules/research-claims/CHANGELOG.md +6 -0
  99. package/official-modules/research-claims/README.md +47 -0
  100. package/official-modules/research-claims/index.mjs +44 -0
  101. package/official-modules/research-claims/package.json +31 -0
  102. package/package.json +74 -0
@@ -0,0 +1,249 @@
1
+ #!/usr/bin/env node
2
+ import { readFile } from "node:fs/promises";
3
+ import { resolve } from "node:path";
4
+ import process from "node:process";
5
+ import { publishAionisManifestSource, publishHandoffStoreRequest, publishRuntimeHandoff, } from "./publish.js";
6
+ class CliUsageError extends Error {
7
+ }
8
+ function printHelp() {
9
+ process.stdout.write([
10
+ "publish-aionis-manifest-handoff",
11
+ "",
12
+ "Usage:",
13
+ " publish-aionis-manifest-handoff <input-file> [--input-kind source|runtime-handoff|handoff-store-request]",
14
+ " [--base-url http://127.0.0.1:3001] [--scope <scope>] [--tenant-id <tenant>]",
15
+ " [--actor <actor>] [--memory-lane private|shared] [--title <title>] [--tag <tag>]",
16
+ " [--repo-root <path>] [--file-path <path>] [--symbol <name>]",
17
+ " [--current-stage triage|patch|review|resume] [--active-role orchestrator|triage|patch|review|resume]",
18
+ " [--allow-compile-errors] [--timeout-ms <ms>] [--api-key <key>] [--auth-bearer <token>]",
19
+ " [--admin-token <token>] [--request-id <id>] [--compact]",
20
+ "",
21
+ ].join("\n"));
22
+ }
23
+ function parseArgs(argv) {
24
+ let inputPath = null;
25
+ const flags = {
26
+ inputKind: "source",
27
+ baseUrl: process.env.AIONIS_BASE_URL?.trim() || "http://127.0.0.1:3001",
28
+ scope: process.env.AIONIS_SCOPE?.trim() || null,
29
+ tenantId: null,
30
+ actor: null,
31
+ memoryLane: null,
32
+ title: null,
33
+ tags: [],
34
+ repoRoot: null,
35
+ filePath: null,
36
+ symbol: null,
37
+ currentStage: null,
38
+ activeRole: null,
39
+ allowCompileErrors: false,
40
+ timeoutMs: Number(process.env.AIONIS_TIMEOUT_MS || 10_000),
41
+ apiKey: process.env.API_KEY?.trim() || process.env.PERF_API_KEY?.trim() || null,
42
+ authBearer: process.env.AUTH_BEARER?.trim() || process.env.PERF_AUTH_BEARER?.trim() || null,
43
+ adminToken: process.env.ADMIN_TOKEN?.trim() || null,
44
+ requestId: null,
45
+ compact: false,
46
+ help: false,
47
+ };
48
+ for (let i = 0; i < argv.length; i += 1) {
49
+ const token = argv[i];
50
+ if (token === "--help" || token === "-h") {
51
+ flags.help = true;
52
+ continue;
53
+ }
54
+ if (token === "--compact") {
55
+ flags.compact = true;
56
+ continue;
57
+ }
58
+ if (token === "--allow-compile-errors") {
59
+ flags.allowCompileErrors = true;
60
+ continue;
61
+ }
62
+ if (token === "--tag") {
63
+ const value = argv[i + 1];
64
+ if (!value)
65
+ throw new CliUsageError("Missing value for --tag.");
66
+ flags.tags.push(value);
67
+ i += 1;
68
+ continue;
69
+ }
70
+ if (token === "--input-kind" ||
71
+ token === "--base-url" ||
72
+ token === "--scope" ||
73
+ token === "--tenant-id" ||
74
+ token === "--actor" ||
75
+ token === "--memory-lane" ||
76
+ token === "--title" ||
77
+ token === "--repo-root" ||
78
+ token === "--file-path" ||
79
+ token === "--symbol" ||
80
+ token === "--current-stage" ||
81
+ token === "--active-role" ||
82
+ token === "--timeout-ms" ||
83
+ token === "--api-key" ||
84
+ token === "--auth-bearer" ||
85
+ token === "--admin-token" ||
86
+ token === "--request-id") {
87
+ const value = argv[i + 1];
88
+ if (!value)
89
+ throw new CliUsageError(`Missing value for ${token}.`);
90
+ switch (token) {
91
+ case "--input-kind":
92
+ if (value !== "source" && value !== "runtime-handoff" && value !== "handoff-store-request") {
93
+ throw new CliUsageError(`Unsupported input kind '${value}'.`);
94
+ }
95
+ flags.inputKind = value;
96
+ break;
97
+ case "--base-url":
98
+ flags.baseUrl = value;
99
+ break;
100
+ case "--scope":
101
+ flags.scope = value;
102
+ break;
103
+ case "--tenant-id":
104
+ flags.tenantId = value;
105
+ break;
106
+ case "--actor":
107
+ flags.actor = value;
108
+ break;
109
+ case "--memory-lane":
110
+ if (value !== "private" && value !== "shared") {
111
+ throw new CliUsageError(`Unsupported memory lane '${value}'.`);
112
+ }
113
+ flags.memoryLane = value;
114
+ break;
115
+ case "--title":
116
+ flags.title = value;
117
+ break;
118
+ case "--repo-root":
119
+ flags.repoRoot = value;
120
+ break;
121
+ case "--file-path":
122
+ flags.filePath = value;
123
+ break;
124
+ case "--symbol":
125
+ flags.symbol = value;
126
+ break;
127
+ case "--current-stage":
128
+ if (!["triage", "patch", "review", "resume"].includes(value)) {
129
+ throw new CliUsageError(`Unsupported current stage '${value}'.`);
130
+ }
131
+ flags.currentStage = value;
132
+ break;
133
+ case "--active-role":
134
+ if (!["orchestrator", "triage", "patch", "review", "resume"].includes(value)) {
135
+ throw new CliUsageError(`Unsupported active role '${value}'.`);
136
+ }
137
+ flags.activeRole = value;
138
+ break;
139
+ case "--timeout-ms":
140
+ flags.timeoutMs = Number(value);
141
+ break;
142
+ case "--api-key":
143
+ flags.apiKey = value;
144
+ break;
145
+ case "--auth-bearer":
146
+ flags.authBearer = value;
147
+ break;
148
+ case "--admin-token":
149
+ flags.adminToken = value;
150
+ break;
151
+ case "--request-id":
152
+ flags.requestId = value;
153
+ break;
154
+ default:
155
+ break;
156
+ }
157
+ i += 1;
158
+ continue;
159
+ }
160
+ if (token.startsWith("--")) {
161
+ throw new CliUsageError(`Unknown flag '${token}'.`);
162
+ }
163
+ if (inputPath) {
164
+ throw new CliUsageError("Only one input file may be provided.");
165
+ }
166
+ inputPath = token;
167
+ }
168
+ return { inputPath, flags };
169
+ }
170
+ async function main() {
171
+ const { inputPath, flags } = parseArgs(process.argv.slice(2));
172
+ if (flags.help) {
173
+ printHelp();
174
+ return;
175
+ }
176
+ if (!inputPath) {
177
+ throw new CliUsageError("An input file path is required.");
178
+ }
179
+ const resolvedInput = resolve(process.cwd(), inputPath);
180
+ const inputText = await readFile(resolvedInput, "utf8");
181
+ const result = flags.inputKind === "source"
182
+ ? await publishAionisManifestSource({
183
+ source: inputText,
184
+ inputPath: resolvedInput,
185
+ baseUrl: flags.baseUrl,
186
+ scope: flags.scope ?? undefined,
187
+ tenantId: flags.tenantId ?? undefined,
188
+ actor: flags.actor ?? undefined,
189
+ memoryLane: flags.memoryLane ?? undefined,
190
+ title: flags.title ?? undefined,
191
+ tags: flags.tags,
192
+ repoRoot: flags.repoRoot,
193
+ filePath: flags.filePath,
194
+ symbol: flags.symbol,
195
+ currentStage: flags.currentStage ?? undefined,
196
+ activeRole: flags.activeRole ?? undefined,
197
+ allowCompileErrors: flags.allowCompileErrors,
198
+ timeoutMs: flags.timeoutMs,
199
+ apiKey: flags.apiKey ?? undefined,
200
+ authBearer: flags.authBearer ?? undefined,
201
+ adminToken: flags.adminToken ?? undefined,
202
+ requestId: flags.requestId ?? undefined,
203
+ })
204
+ : flags.inputKind === "runtime-handoff"
205
+ ? await publishRuntimeHandoff({
206
+ runtimeHandoff: JSON.parse(inputText),
207
+ baseUrl: flags.baseUrl,
208
+ scope: flags.scope ?? undefined,
209
+ tenantId: flags.tenantId ?? undefined,
210
+ actor: flags.actor ?? undefined,
211
+ memoryLane: flags.memoryLane ?? undefined,
212
+ title: flags.title ?? undefined,
213
+ tags: flags.tags,
214
+ repoRoot: flags.repoRoot,
215
+ filePath: flags.filePath,
216
+ symbol: flags.symbol,
217
+ currentStage: flags.currentStage ?? undefined,
218
+ activeRole: flags.activeRole ?? undefined,
219
+ allowCompileErrors: flags.allowCompileErrors,
220
+ timeoutMs: flags.timeoutMs,
221
+ apiKey: flags.apiKey ?? undefined,
222
+ authBearer: flags.authBearer ?? undefined,
223
+ adminToken: flags.adminToken ?? undefined,
224
+ requestId: flags.requestId ?? undefined,
225
+ })
226
+ : await publishHandoffStoreRequest({
227
+ baseUrl: flags.baseUrl,
228
+ handoffStoreRequest: JSON.parse(inputText),
229
+ inputKind: "handoff-store-request",
230
+ timeoutMs: flags.timeoutMs,
231
+ apiKey: flags.apiKey ?? undefined,
232
+ authBearer: flags.authBearer ?? undefined,
233
+ adminToken: flags.adminToken ?? undefined,
234
+ requestId: flags.requestId ?? undefined,
235
+ });
236
+ const rendered = flags.compact ? JSON.stringify(result) : `${JSON.stringify(result, null, 2)}\n`;
237
+ process.stdout.write(rendered);
238
+ }
239
+ main().catch((error) => {
240
+ if (error instanceof CliUsageError) {
241
+ process.stderr.write(`${error.message}\n`);
242
+ printHelp();
243
+ process.exitCode = 2;
244
+ return;
245
+ }
246
+ const message = error instanceof Error ? error.message : String(error);
247
+ process.stderr.write(`${message}\n`);
248
+ process.exitCode = 1;
249
+ });
@@ -0,0 +1,148 @@
1
+ import { z } from "zod";
2
+ export declare const AIONIS_MANIFEST_PUBLISH_RESULT_VERSION: "aionis_manifest_publish_result_v1";
3
+ export declare const PublishInputKindSchema: z.ZodEnum<["source", "runtime-handoff", "handoff-store-request"]>;
4
+ export type PublishInputKind = z.infer<typeof PublishInputKindSchema>;
5
+ export declare const PublishResultSchema: z.ZodObject<{
6
+ publish_result_version: z.ZodLiteral<"aionis_manifest_publish_result_v1">;
7
+ published_at: z.ZodString;
8
+ base_url: z.ZodString;
9
+ input_kind: z.ZodEnum<["source", "runtime-handoff", "handoff-store-request"]>;
10
+ source_doc_id: z.ZodNullable<z.ZodString>;
11
+ source_doc_version: z.ZodNullable<z.ZodString>;
12
+ request: z.ZodObject<{
13
+ anchor: z.ZodString;
14
+ handoff_kind: z.ZodString;
15
+ scope: z.ZodOptional<z.ZodString>;
16
+ memory_lane: z.ZodOptional<z.ZodEnum<["private", "shared"]>>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ anchor: string;
19
+ handoff_kind: string;
20
+ scope?: string | undefined;
21
+ memory_lane?: "private" | "shared" | undefined;
22
+ }, {
23
+ anchor: string;
24
+ handoff_kind: string;
25
+ scope?: string | undefined;
26
+ memory_lane?: "private" | "shared" | undefined;
27
+ }>;
28
+ response: z.ZodObject<{
29
+ status: z.ZodNumber;
30
+ request_id: z.ZodNullable<z.ZodString>;
31
+ tenant_id: z.ZodOptional<z.ZodString>;
32
+ scope: z.ZodOptional<z.ZodString>;
33
+ commit_id: z.ZodString;
34
+ commit_uri: z.ZodOptional<z.ZodString>;
35
+ handoff_anchor: z.ZodNullable<z.ZodString>;
36
+ handoff_kind: z.ZodNullable<z.ZodString>;
37
+ }, "strip", z.ZodTypeAny, {
38
+ status: number;
39
+ handoff_kind: string | null;
40
+ request_id: string | null;
41
+ commit_id: string;
42
+ handoff_anchor: string | null;
43
+ scope?: string | undefined;
44
+ tenant_id?: string | undefined;
45
+ commit_uri?: string | undefined;
46
+ }, {
47
+ status: number;
48
+ handoff_kind: string | null;
49
+ request_id: string | null;
50
+ commit_id: string;
51
+ handoff_anchor: string | null;
52
+ scope?: string | undefined;
53
+ tenant_id?: string | undefined;
54
+ commit_uri?: string | undefined;
55
+ }>;
56
+ handoff_store_request: z.ZodRecord<z.ZodString, z.ZodUnknown>;
57
+ }, "strip", z.ZodTypeAny, {
58
+ source_doc_id: string | null;
59
+ source_doc_version: string | null;
60
+ publish_result_version: "aionis_manifest_publish_result_v1";
61
+ published_at: string;
62
+ base_url: string;
63
+ input_kind: "source" | "runtime-handoff" | "handoff-store-request";
64
+ request: {
65
+ anchor: string;
66
+ handoff_kind: string;
67
+ scope?: string | undefined;
68
+ memory_lane?: "private" | "shared" | undefined;
69
+ };
70
+ response: {
71
+ status: number;
72
+ handoff_kind: string | null;
73
+ request_id: string | null;
74
+ commit_id: string;
75
+ handoff_anchor: string | null;
76
+ scope?: string | undefined;
77
+ tenant_id?: string | undefined;
78
+ commit_uri?: string | undefined;
79
+ };
80
+ handoff_store_request: Record<string, unknown>;
81
+ }, {
82
+ source_doc_id: string | null;
83
+ source_doc_version: string | null;
84
+ publish_result_version: "aionis_manifest_publish_result_v1";
85
+ published_at: string;
86
+ base_url: string;
87
+ input_kind: "source" | "runtime-handoff" | "handoff-store-request";
88
+ request: {
89
+ anchor: string;
90
+ handoff_kind: string;
91
+ scope?: string | undefined;
92
+ memory_lane?: "private" | "shared" | undefined;
93
+ };
94
+ response: {
95
+ status: number;
96
+ handoff_kind: string | null;
97
+ request_id: string | null;
98
+ commit_id: string;
99
+ handoff_anchor: string | null;
100
+ scope?: string | undefined;
101
+ tenant_id?: string | undefined;
102
+ commit_uri?: string | undefined;
103
+ };
104
+ handoff_store_request: Record<string, unknown>;
105
+ }>;
106
+ export type AionisManifestPublishResult = z.infer<typeof PublishResultSchema>;
107
+ type PublishFromSourceOptions = {
108
+ source: string;
109
+ inputPath: string;
110
+ baseUrl: string;
111
+ scope?: string;
112
+ tenantId?: string;
113
+ actor?: string;
114
+ memoryLane?: "private" | "shared";
115
+ title?: string;
116
+ tags?: string[];
117
+ repoRoot?: string | null;
118
+ filePath?: string | null;
119
+ symbol?: string | null;
120
+ currentStage?: "triage" | "patch" | "review" | "resume";
121
+ activeRole?: "orchestrator" | "triage" | "patch" | "review" | "resume";
122
+ allowCompileErrors?: boolean;
123
+ timeoutMs?: number;
124
+ apiKey?: string;
125
+ authBearer?: string;
126
+ adminToken?: string;
127
+ requestId?: string;
128
+ publishedAt?: string;
129
+ };
130
+ type PublishRequestOptions = {
131
+ baseUrl: string;
132
+ handoffStoreRequest: unknown;
133
+ inputKind: PublishInputKind;
134
+ sourceDocId?: string | null;
135
+ sourceDocVersion?: string | null;
136
+ timeoutMs?: number;
137
+ apiKey?: string;
138
+ authBearer?: string;
139
+ adminToken?: string;
140
+ requestId?: string;
141
+ publishedAt?: string;
142
+ };
143
+ export declare function publishHandoffStoreRequest(args: PublishRequestOptions): Promise<AionisManifestPublishResult>;
144
+ export declare function publishAionisManifestSource(args: PublishFromSourceOptions): Promise<AionisManifestPublishResult>;
145
+ export declare function publishRuntimeHandoff(args: {
146
+ runtimeHandoff: unknown;
147
+ } & Omit<PublishFromSourceOptions, "source" | "inputPath">): Promise<AionisManifestPublishResult>;
148
+ export {};
@@ -0,0 +1,190 @@
1
+ import { z } from "zod";
2
+ import { compileAionisManifest } from "./compile.js";
3
+ import { buildHandoffStoreRequestFromRuntimeHandoff, AionisManifestHandoffStoreRequestSchema, } from "./handoff-store.js";
4
+ import { buildRuntimeHandoffV1, AionisManifestRuntimeHandoffSchema, } from "./runtime-handoff.js";
5
+ export const AIONIS_MANIFEST_PUBLISH_RESULT_VERSION = "aionis_manifest_publish_result_v1";
6
+ export const PublishInputKindSchema = z.enum(["source", "runtime-handoff", "handoff-store-request"]);
7
+ export const PublishResultSchema = z.object({
8
+ publish_result_version: z.literal(AIONIS_MANIFEST_PUBLISH_RESULT_VERSION),
9
+ published_at: z.string().min(1),
10
+ base_url: z.string().min(1),
11
+ input_kind: PublishInputKindSchema,
12
+ source_doc_id: z.string().min(1).nullable(),
13
+ source_doc_version: z.string().min(1).nullable(),
14
+ request: z.object({
15
+ anchor: z.string().min(1),
16
+ handoff_kind: z.string().min(1),
17
+ scope: z.string().min(1).optional(),
18
+ memory_lane: z.enum(["private", "shared"]).optional(),
19
+ }),
20
+ response: z.object({
21
+ status: z.number().int().nonnegative(),
22
+ request_id: z.string().nullable(),
23
+ tenant_id: z.string().optional(),
24
+ scope: z.string().optional(),
25
+ commit_id: z.string().min(1),
26
+ commit_uri: z.string().optional(),
27
+ handoff_anchor: z.string().nullable(),
28
+ handoff_kind: z.string().nullable(),
29
+ }),
30
+ handoff_store_request: z.record(z.unknown()),
31
+ });
32
+ function joinUrl(baseUrl, path) {
33
+ return `${baseUrl.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
34
+ }
35
+ function withTimeout(timeoutMs) {
36
+ const controller = new AbortController();
37
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
38
+ return {
39
+ signal: controller.signal,
40
+ cancel: () => clearTimeout(timer),
41
+ };
42
+ }
43
+ async function parseResponseBody(res) {
44
+ const contentType = (res.headers.get("content-type") ?? "").toLowerCase();
45
+ if (contentType.includes("application/json")) {
46
+ return res.json();
47
+ }
48
+ const text = await res.text();
49
+ return text.length > 0 ? text : null;
50
+ }
51
+ function buildHeaders(args) {
52
+ const headers = {
53
+ "content-type": "application/json",
54
+ };
55
+ if (args.apiKey)
56
+ headers["x-api-key"] = args.apiKey;
57
+ if (args.adminToken)
58
+ headers["x-admin-token"] = args.adminToken;
59
+ if (args.authBearer) {
60
+ headers.authorization = args.authBearer.toLowerCase().startsWith("bearer ")
61
+ ? args.authBearer
62
+ : `Bearer ${args.authBearer}`;
63
+ }
64
+ if (args.requestId)
65
+ headers["x-request-id"] = args.requestId;
66
+ return headers;
67
+ }
68
+ function extractRequestId(headers) {
69
+ return headers.get("x-request-id") ?? headers.get("request-id") ?? null;
70
+ }
71
+ export async function publishHandoffStoreRequest(args) {
72
+ const handoffStoreRequest = AionisManifestHandoffStoreRequestSchema.parse(args.handoffStoreRequest);
73
+ const timeoutMs = args.timeoutMs ?? 10_000;
74
+ const url = joinUrl(args.baseUrl, "/v1/handoff/store");
75
+ const timeout = withTimeout(timeoutMs);
76
+ try {
77
+ const res = await fetch(url, {
78
+ method: "POST",
79
+ headers: buildHeaders({
80
+ apiKey: args.apiKey,
81
+ authBearer: args.authBearer,
82
+ adminToken: args.adminToken,
83
+ requestId: args.requestId,
84
+ }),
85
+ body: JSON.stringify(handoffStoreRequest),
86
+ signal: timeout.signal,
87
+ });
88
+ const body = await parseResponseBody(res);
89
+ if (!res.ok) {
90
+ const message = body && typeof body === "object" && "message" in body && typeof body.message === "string"
91
+ ? String(body.message)
92
+ : `handoff publish failed with status ${res.status}`;
93
+ throw new Error(message);
94
+ }
95
+ const payload = body && typeof body === "object" ? body : {};
96
+ return PublishResultSchema.parse({
97
+ publish_result_version: AIONIS_MANIFEST_PUBLISH_RESULT_VERSION,
98
+ published_at: args.publishedAt ?? new Date().toISOString(),
99
+ base_url: args.baseUrl,
100
+ input_kind: args.inputKind,
101
+ source_doc_id: args.sourceDocId ?? null,
102
+ source_doc_version: args.sourceDocVersion ?? null,
103
+ request: {
104
+ anchor: handoffStoreRequest.anchor,
105
+ handoff_kind: handoffStoreRequest.handoff_kind,
106
+ scope: handoffStoreRequest.scope,
107
+ memory_lane: handoffStoreRequest.memory_lane,
108
+ },
109
+ response: {
110
+ status: res.status,
111
+ request_id: extractRequestId(res.headers),
112
+ tenant_id: typeof payload.tenant_id === "string" ? payload.tenant_id : undefined,
113
+ scope: typeof payload.scope === "string" ? payload.scope : undefined,
114
+ commit_id: String(payload.commit_id ?? ""),
115
+ commit_uri: typeof payload.commit_uri === "string" ? payload.commit_uri : undefined,
116
+ handoff_anchor: payload.handoff && typeof payload.handoff === "object" && typeof payload.handoff.anchor === "string"
117
+ ? String(payload.handoff.anchor)
118
+ : null,
119
+ handoff_kind: payload.handoff && typeof payload.handoff === "object" && typeof payload.handoff.handoff_kind === "string"
120
+ ? String(payload.handoff.handoff_kind)
121
+ : null,
122
+ },
123
+ handoff_store_request: handoffStoreRequest,
124
+ });
125
+ }
126
+ finally {
127
+ timeout.cancel();
128
+ }
129
+ }
130
+ export async function publishAionisManifestSource(args) {
131
+ const compile = compileAionisManifest(args.source);
132
+ const runtimeHandoff = buildRuntimeHandoffV1({
133
+ inputPath: args.inputPath,
134
+ result: compile,
135
+ scope: args.scope,
136
+ repoRoot: args.repoRoot,
137
+ filePath: args.filePath,
138
+ symbol: args.symbol,
139
+ currentStage: args.currentStage,
140
+ activeRole: args.activeRole,
141
+ requireErrorFree: !(args.allowCompileErrors ?? false),
142
+ });
143
+ const storeRequest = buildHandoffStoreRequestFromRuntimeHandoff({
144
+ handoff: runtimeHandoff,
145
+ tenantId: args.tenantId,
146
+ scope: args.scope,
147
+ actor: args.actor,
148
+ memoryLane: args.memoryLane,
149
+ title: args.title,
150
+ tags: args.tags,
151
+ });
152
+ return publishHandoffStoreRequest({
153
+ baseUrl: args.baseUrl,
154
+ handoffStoreRequest: storeRequest,
155
+ inputKind: "source",
156
+ sourceDocId: runtimeHandoff.source_doc_id,
157
+ sourceDocVersion: runtimeHandoff.source_doc_version,
158
+ timeoutMs: args.timeoutMs,
159
+ apiKey: args.apiKey,
160
+ authBearer: args.authBearer,
161
+ adminToken: args.adminToken,
162
+ requestId: args.requestId,
163
+ publishedAt: args.publishedAt,
164
+ });
165
+ }
166
+ export async function publishRuntimeHandoff(args) {
167
+ const runtimeHandoff = AionisManifestRuntimeHandoffSchema.parse(args.runtimeHandoff);
168
+ const storeRequest = buildHandoffStoreRequestFromRuntimeHandoff({
169
+ handoff: runtimeHandoff,
170
+ tenantId: args.tenantId,
171
+ scope: args.scope,
172
+ actor: args.actor,
173
+ memoryLane: args.memoryLane,
174
+ title: args.title,
175
+ tags: args.tags,
176
+ });
177
+ return publishHandoffStoreRequest({
178
+ baseUrl: args.baseUrl,
179
+ handoffStoreRequest: storeRequest,
180
+ inputKind: "runtime-handoff",
181
+ sourceDocId: runtimeHandoff.source_doc_id,
182
+ sourceDocVersion: runtimeHandoff.source_doc_version,
183
+ timeoutMs: args.timeoutMs,
184
+ apiKey: args.apiKey,
185
+ authBearer: args.authBearer,
186
+ adminToken: args.adminToken,
187
+ requestId: args.requestId,
188
+ publishedAt: args.publishedAt,
189
+ });
190
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};