@cotal-ai/workspace 0.90.0 → 0.91.0

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 (189) hide show
  1. package/build/Release/win32-arm64/build.json +1 -1
  2. package/build/Release/win32-x64/build.json +1 -1
  3. package/dist/agent-secrets.d.ts +2 -2
  4. package/dist/agent-secrets.d.ts.map +1 -1
  5. package/dist/agent-secrets.js +2 -2
  6. package/dist/agent-secrets.js.map +1 -1
  7. package/dist/auth-paths.d.ts +8 -2
  8. package/dist/auth-paths.d.ts.map +1 -1
  9. package/dist/auth-paths.js +12 -5
  10. package/dist/auth-paths.js.map +1 -1
  11. package/dist/broker-display.d.ts +4 -0
  12. package/dist/broker-display.d.ts.map +1 -0
  13. package/dist/broker-display.js +29 -0
  14. package/dist/broker-display.js.map +1 -0
  15. package/dist/colors.d.ts +11 -4
  16. package/dist/colors.d.ts.map +1 -1
  17. package/dist/colors.js +36 -9
  18. package/dist/colors.js.map +1 -1
  19. package/dist/connect.d.ts +64 -6
  20. package/dist/connect.d.ts.map +1 -1
  21. package/dist/connect.js +170 -74
  22. package/dist/connect.js.map +1 -1
  23. package/dist/control-target.d.ts +2 -2
  24. package/dist/control-target.js +2 -2
  25. package/dist/credential-actions.d.ts +91 -0
  26. package/dist/credential-actions.d.ts.map +1 -0
  27. package/dist/credential-actions.js +74 -0
  28. package/dist/credential-actions.js.map +1 -0
  29. package/dist/deprecated-daemon-entries.d.ts +30 -0
  30. package/dist/deprecated-daemon-entries.d.ts.map +1 -0
  31. package/dist/deprecated-daemon-entries.js +37 -0
  32. package/dist/deprecated-daemon-entries.js.map +1 -0
  33. package/dist/endpoint-actions.d.ts +31 -0
  34. package/dist/endpoint-actions.d.ts.map +1 -0
  35. package/dist/endpoint-actions.js +2 -0
  36. package/dist/endpoint-actions.js.map +1 -0
  37. package/dist/endpoint-caller.d.ts +74 -0
  38. package/dist/endpoint-caller.d.ts.map +1 -0
  39. package/dist/endpoint-caller.js +118 -0
  40. package/dist/endpoint-caller.js.map +1 -0
  41. package/dist/endpoint-contract.d.ts +32 -0
  42. package/dist/endpoint-contract.d.ts.map +1 -0
  43. package/dist/endpoint-contract.js +92 -0
  44. package/dist/endpoint-contract.js.map +1 -0
  45. package/dist/extension-mutation.d.ts.map +1 -1
  46. package/dist/extension-mutation.js +4 -1
  47. package/dist/extension-mutation.js.map +1 -1
  48. package/dist/extensions.d.ts +28 -8
  49. package/dist/extensions.d.ts.map +1 -1
  50. package/dist/extensions.js +20 -8
  51. package/dist/extensions.js.map +1 -1
  52. package/dist/flags.d.ts +8 -1
  53. package/dist/flags.d.ts.map +1 -1
  54. package/dist/flags.js +9 -7
  55. package/dist/flags.js.map +1 -1
  56. package/dist/index.d.ts +25 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +25 -0
  59. package/dist/index.js.map +1 -1
  60. package/dist/launch-persona.d.ts +10 -0
  61. package/dist/launch-persona.d.ts.map +1 -0
  62. package/dist/launch-persona.js +34 -0
  63. package/dist/launch-persona.js.map +1 -0
  64. package/dist/local-process.d.ts +16 -12
  65. package/dist/local-process.d.ts.map +1 -1
  66. package/dist/local-process.js +7 -2
  67. package/dist/local-process.js.map +1 -1
  68. package/dist/maintenance.d.ts +267 -4
  69. package/dist/maintenance.d.ts.map +1 -1
  70. package/dist/maintenance.js +666 -12
  71. package/dist/maintenance.js.map +1 -1
  72. package/dist/mesh-manifest-schema.d.ts +118 -0
  73. package/dist/mesh-manifest-schema.d.ts.map +1 -0
  74. package/dist/mesh-manifest-schema.js +96 -0
  75. package/dist/mesh-manifest-schema.js.map +1 -0
  76. package/dist/mesh-registry.d.ts +27 -0
  77. package/dist/mesh-registry.d.ts.map +1 -1
  78. package/dist/mesh-registry.js +69 -13
  79. package/dist/mesh-registry.js.map +1 -1
  80. package/dist/mesh-target.d.ts +15 -7
  81. package/dist/mesh-target.d.ts.map +1 -1
  82. package/dist/mesh-target.js +77 -26
  83. package/dist/mesh-target.js.map +1 -1
  84. package/dist/official-connectors.d.ts +13 -0
  85. package/dist/official-connectors.d.ts.map +1 -1
  86. package/dist/official-connectors.js +18 -2
  87. package/dist/official-connectors.js.map +1 -1
  88. package/dist/output.d.ts +147 -0
  89. package/dist/output.d.ts.map +1 -0
  90. package/dist/output.js +186 -0
  91. package/dist/output.js.map +1 -0
  92. package/dist/pid.d.ts +5 -3
  93. package/dist/pid.d.ts.map +1 -1
  94. package/dist/pid.js +25 -13
  95. package/dist/pid.js.map +1 -1
  96. package/dist/preferences.d.ts +93 -0
  97. package/dist/preferences.d.ts.map +1 -0
  98. package/dist/preferences.js +272 -0
  99. package/dist/preferences.js.map +1 -0
  100. package/dist/preflight.d.ts +3 -0
  101. package/dist/preflight.d.ts.map +1 -1
  102. package/dist/preflight.js +6 -3
  103. package/dist/preflight.js.map +1 -1
  104. package/dist/prepared-spaces.d.ts +27 -0
  105. package/dist/prepared-spaces.d.ts.map +1 -0
  106. package/dist/prepared-spaces.js +57 -0
  107. package/dist/prepared-spaces.js.map +1 -0
  108. package/dist/present.d.ts +108 -0
  109. package/dist/present.d.ts.map +1 -0
  110. package/dist/present.js +249 -0
  111. package/dist/present.js.map +1 -0
  112. package/dist/prompt-input.d.ts +12 -0
  113. package/dist/prompt-input.d.ts.map +1 -0
  114. package/dist/prompt-input.js +35 -0
  115. package/dist/prompt-input.js.map +1 -0
  116. package/dist/protected-records.d.ts +102 -0
  117. package/dist/protected-records.d.ts.map +1 -0
  118. package/dist/protected-records.js +465 -0
  119. package/dist/protected-records.js.map +1 -0
  120. package/dist/registration-policy.d.ts +4 -1
  121. package/dist/registration-policy.d.ts.map +1 -1
  122. package/dist/registration-policy.js +4 -3
  123. package/dist/registration-policy.js.map +1 -1
  124. package/dist/render.d.ts +8 -0
  125. package/dist/render.d.ts.map +1 -1
  126. package/dist/render.js +49 -32
  127. package/dist/render.js.map +1 -1
  128. package/dist/service-adapter.d.ts +198 -0
  129. package/dist/service-adapter.d.ts.map +1 -0
  130. package/dist/service-adapter.js +294 -0
  131. package/dist/service-adapter.js.map +1 -0
  132. package/dist/service-custody.d.ts +5 -0
  133. package/dist/service-custody.d.ts.map +1 -0
  134. package/dist/service-custody.js +41 -0
  135. package/dist/service-custody.js.map +1 -0
  136. package/dist/service-definition.d.ts +52 -0
  137. package/dist/service-definition.d.ts.map +1 -0
  138. package/dist/service-definition.js +85 -0
  139. package/dist/service-definition.js.map +1 -0
  140. package/dist/service-definition.schema.json +79 -0
  141. package/dist/service-extension-metadata.d.ts +11 -0
  142. package/dist/service-extension-metadata.d.ts.map +1 -0
  143. package/dist/service-extension-metadata.js +66 -0
  144. package/dist/service-extension-metadata.js.map +1 -0
  145. package/dist/service-identity.d.ts +51 -0
  146. package/dist/service-identity.d.ts.map +1 -0
  147. package/dist/service-identity.js +103 -0
  148. package/dist/service-identity.js.map +1 -0
  149. package/dist/service-observation.d.ts +32 -0
  150. package/dist/service-observation.d.ts.map +1 -0
  151. package/dist/service-observation.js +134 -0
  152. package/dist/service-observation.js.map +1 -0
  153. package/dist/service-preset.d.ts +12 -0
  154. package/dist/service-preset.d.ts.map +1 -0
  155. package/dist/service-preset.js +10 -0
  156. package/dist/service-preset.js.map +1 -0
  157. package/dist/service-startup.d.ts +23 -0
  158. package/dist/service-startup.d.ts.map +1 -0
  159. package/dist/service-startup.js +39 -0
  160. package/dist/service-startup.js.map +1 -0
  161. package/dist/service-stop.d.ts +47 -0
  162. package/dist/service-stop.d.ts.map +1 -0
  163. package/dist/service-stop.js +152 -0
  164. package/dist/service-stop.js.map +1 -0
  165. package/dist/service-target.d.ts +5 -0
  166. package/dist/service-target.d.ts.map +1 -0
  167. package/dist/service-target.js +19 -0
  168. package/dist/service-target.js.map +1 -0
  169. package/dist/signer-export.d.ts +31 -0
  170. package/dist/signer-export.d.ts.map +1 -0
  171. package/dist/signer-export.js +114 -0
  172. package/dist/signer-export.js.map +1 -0
  173. package/dist/space-segmentation.d.ts +13 -2
  174. package/dist/space-segmentation.d.ts.map +1 -1
  175. package/dist/space-segmentation.js +7 -3
  176. package/dist/space-segmentation.js.map +1 -1
  177. package/dist/space.d.ts +5 -5
  178. package/dist/space.d.ts.map +1 -1
  179. package/dist/space.js +8 -6
  180. package/dist/space.js.map +1 -1
  181. package/dist/system-rotation.d.ts +4 -3
  182. package/dist/system-rotation.d.ts.map +1 -1
  183. package/dist/system-rotation.js +16 -6
  184. package/dist/system-rotation.js.map +1 -1
  185. package/dist/web-session.d.ts +7 -0
  186. package/dist/web-session.d.ts.map +1 -1
  187. package/dist/web-session.js +9 -0
  188. package/dist/web-session.js.map +1 -1
  189. package/package.json +6 -2
@@ -0,0 +1,79 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Proposed CLI service definition version 1",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": ["schemaVersion", "space", "launch", "readiness"],
7
+ "properties": {
8
+ "schemaVersion": { "const": 1 },
9
+ "space": { "type": "string", "minLength": 1, "maxLength": 200 },
10
+ "launch": {
11
+ "oneOf": [
12
+ {
13
+ "type": "object", "additionalProperties": false,
14
+ "required": ["type", "executable", "args", "cwd"],
15
+ "properties": {
16
+ "type": { "const": "process" },
17
+ "executable": { "type": "string", "minLength": 1, "maxLength": 4096 },
18
+ "args": { "type": "array", "maxItems": 256, "items": { "type": "string", "maxLength": 8192 } },
19
+ "cwd": { "type": "string", "minLength": 1, "maxLength": 4096 }
20
+ }
21
+ },
22
+ {
23
+ "type": "object", "additionalProperties": false,
24
+ "required": ["type", "adapter", "options"],
25
+ "properties": {
26
+ "type": { "const": "adapter" },
27
+ "adapter": { "type": "string", "minLength": 1, "maxLength": 200 },
28
+ "options": { "type": "object" }
29
+ }
30
+ }
31
+ ]
32
+ },
33
+ "readiness": {
34
+ "oneOf": [
35
+ {
36
+ "type": "object", "additionalProperties": false,
37
+ "required": ["type", "timeoutMs"],
38
+ "properties": { "type": { "const": "process" }, "timeoutMs": { "$ref": "#/$defs/timeout" } }
39
+ },
40
+ {
41
+ "type": "object", "additionalProperties": false,
42
+ "required": ["type", "url", "expectedStatus", "timeoutMs"],
43
+ "properties": {
44
+ "type": { "const": "http" },
45
+ "url": { "type": "string", "format": "uri", "pattern": "^http://(127\\.0\\.0\\.1|\\[::1\\])(:[0-9]{1,5})?/" },
46
+ "expectedStatus": { "type": "integer", "minimum": 100, "maximum": 599 },
47
+ "timeoutMs": { "$ref": "#/$defs/timeout" }
48
+ }
49
+ },
50
+ {
51
+ "type": "object", "additionalProperties": false,
52
+ "required": ["type", "timeoutMs"],
53
+ "properties": { "type": { "const": "adapter" }, "timeoutMs": { "$ref": "#/$defs/timeout" } }
54
+ }
55
+ ]
56
+ },
57
+ "envRefs": {
58
+ "type": "object", "maxProperties": 64,
59
+ "propertyNames": { "pattern": "^(?!COTAL_|CLAUDE_CODE_|CLAUDECODE$)[A-Za-z_][A-Za-z0-9_]*$" },
60
+ "additionalProperties": { "type": "string", "pattern": "^(?!COTAL_|CLAUDE_CODE_|CLAUDECODE$)[A-Za-z_][A-Za-z0-9_]*$" }
61
+ },
62
+ "credentialRef": { "$ref": "#/$defs/credential" }
63
+ },
64
+ "allOf": [
65
+ {
66
+ "if": { "properties": { "launch": { "properties": { "type": { "const": "process" } }, "required": ["type"] } } },
67
+ "then": { "properties": { "readiness": { "properties": { "type": { "enum": ["process", "http"] } } } } },
68
+ "else": { "properties": { "readiness": { "properties": { "type": { "const": "adapter" } } } } }
69
+ }
70
+ ],
71
+ "$defs": {
72
+ "timeout": { "type": "integer", "minimum": 1, "maximum": 120000 },
73
+ "credential": {
74
+ "type": "object", "additionalProperties": false, "required": ["kind", "path"],
75
+ "properties": { "kind": { "const": "file" }, "path": { "type": "string", "minLength": 1, "maxLength": 4096 } }
76
+ }
77
+ },
78
+ "$comment": "Proposed local-file schema, not a wire schema. Adapter options need their installed closed schema; absolute paths, file modes, references, native names, loopback/port parsing, identities and runtime support require semantic validation before effects. No protected file is opened by this JSON Schema."
79
+ }
@@ -0,0 +1,11 @@
1
+ import { type InstalledExtension } from "./extensions.js";
2
+ import type { LocalProcess } from "./local-process.js";
3
+ import { type ServicePreset } from "./service-preset.js";
4
+ /** Run by ext add after its ordinary transactional import. Hashes detect cached declaration or
5
+ * package-metadata changes; they are neither publisher signatures nor executable-code proofs. */
6
+ export declare function cacheExtensionServiceMetadata(pkg: string, version: string, processes: readonly LocalProcess[], presets?: readonly ServicePreset[]): InstalledExtension["serviceMetadata"];
7
+ /** Metadata-only validation. Never imports executable provider code or fetches a schema. */
8
+ export declare function verifiedExtensionServiceProcesses(extension: InstalledExtension): readonly LocalProcess[];
9
+ /** Declarative preset inventory with the same package/version/cache checks as its adapters. */
10
+ export declare function verifiedExtensionServicePresets(extension: InstalledExtension): readonly ServicePreset[];
11
+ //# sourceMappingURL=service-extension-metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-extension-metadata.d.ts","sourceRoot":"","sources":["../src/service-extension-metadata.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0C,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAsB7E;kGACkG;AAClG,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,YAAY,EAAE,EAAE,OAAO,GAAE,SAAS,aAAa,EAAO,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAQ7L;AAED,4FAA4F;AAC5F,wBAAgB,iCAAiC,CAAC,SAAS,EAAE,kBAAkB,GAAG,SAAS,YAAY,EAAE,CAQxG;AAED,+FAA+F;AAC/F,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,kBAAkB,GAAG,SAAS,aAAa,EAAE,CAGvG"}
@@ -0,0 +1,66 @@
1
+ import { createHash } from "node:crypto";
2
+ import { realpathSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { cacheLocalProcess, extensionPackageDir } from "./extensions.js";
5
+ import { CommandFailure } from "./output.js";
6
+ import { assertProtectedFileAccess, decodeLocalJson, protectedFileAccessAvailable, protectedLocalDirectory, readLocalRecordSource } from "./protected-records.js";
7
+ import { cacheServicePreset } from "./service-preset.js";
8
+ import { serviceAdapterDeclaration, serviceMetadataDigest } from "./service-adapter.js";
9
+ function packageMetadata(pkg, version) {
10
+ // Resolve the operator-installed package directory once. Check the physical ancestry and pin
11
+ // this bounded descriptor read; this is not an atomic fence against arbitrary same-UID edits.
12
+ let directory;
13
+ try {
14
+ directory = realpathSync(extensionPackageDir(pkg));
15
+ }
16
+ catch {
17
+ throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the service adapter package is missing; re-add its extension explicitly");
18
+ }
19
+ protectedLocalDirectory(directory);
20
+ const bytes = readLocalRecordSource(join(directory, "package.json"), 1024 * 1024);
21
+ if (!bytes)
22
+ throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", "the service adapter package metadata is missing; re-add its extension explicitly");
23
+ const meta = decodeLocalJson(bytes);
24
+ if (!meta || meta.name !== pkg || meta.version !== version)
25
+ throw new CommandFailure("refused", "CONFLICT", "the installed service adapter package does not match its cached name and version; update or re-add it before use");
26
+ return createHash("sha256").update(bytes).digest("hex");
27
+ }
28
+ function declarations(processes, presets) {
29
+ const order = (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
30
+ return { adapters: processes.filter((component) => component.service !== undefined).map((component) => ({ name: component.name, controllerOnly: component.controllerOnly === true, service: serviceAdapterDeclaration(component.service) })).sort(order), presets: presets.map(cacheServicePreset).sort(order) };
31
+ }
32
+ /** Run by ext add after its ordinary transactional import. Hashes detect cached declaration or
33
+ * package-metadata changes; they are neither publisher signatures nor executable-code proofs. */
34
+ export function cacheExtensionServiceMetadata(pkg, version, processes, presets = []) {
35
+ if (!processes.some((component) => component.service !== undefined) && !presets.length)
36
+ return undefined;
37
+ for (const component of processes)
38
+ if (component.service !== undefined && (typeof component.buildServiceLaunch !== "function" || typeof component.checkServiceReadiness !== "function"))
39
+ throw new CommandFailure("refused", "SCHEMA_INVALID", "a service adapter must provide both declared launch and readiness hooks");
40
+ for (const component of processes)
41
+ if (component.service?.stop === "native" && (typeof component.prepareServiceStop !== "function" || typeof component.stopService !== "function"))
42
+ throw new CommandFailure("refused", "SCHEMA_INVALID", "a native stop adapter must provide both impact and terminal hooks; no generic signal fallback was cached");
43
+ // Without protected file access no service adapter can be verified or run here, so the extension
44
+ // installs with no receipt and every service use refuses UNSUPPORTED before reading one.
45
+ if (!protectedFileAccessAvailable())
46
+ return undefined;
47
+ return { schemaVersion: 1, packageJsonSha256: packageMetadata(pkg, version), declarationsSha256: serviceMetadataDigest(declarations(processes.map(cacheLocalProcess), presets)) };
48
+ }
49
+ /** Metadata-only validation. Never imports executable provider code or fetches a schema. */
50
+ export function verifiedExtensionServiceProcesses(extension) {
51
+ assertProtectedFileAccess();
52
+ const receipt = extension.serviceMetadata;
53
+ if (!receipt || receipt.schemaVersion !== 1 || Object.keys(receipt).some((key) => !["schemaVersion", "packageJsonSha256", "declarationsSha256"].includes(key)) || !/^[0-9a-f]{64}$/.test(receipt.packageJsonSha256) || !/^[0-9a-f]{64}$/.test(receipt.declarationsSha256))
54
+ throw new CommandFailure("refused", "CONFLICT", "the installed service adapter has no supported declaration-integrity receipt; update or re-add the extension before saving a definition");
55
+ const processes = extension.localProcesses ?? [];
56
+ const presets = extension.servicePresets ?? [];
57
+ if (!Array.isArray(processes) || !Array.isArray(presets) || packageMetadata(extension.pkg, extension.version) !== receipt.packageJsonSha256 || serviceMetadataDigest(declarations(processes, presets)) !== receipt.declarationsSha256)
58
+ throw new CommandFailure("refused", "CONFLICT", "the cached service declaration or installed package metadata changed; no provider was imported and no service definition was saved");
59
+ return processes.filter((component) => component.service !== undefined);
60
+ }
61
+ /** Declarative preset inventory with the same package/version/cache checks as its adapters. */
62
+ export function verifiedExtensionServicePresets(extension) {
63
+ verifiedExtensionServiceProcesses(extension);
64
+ return (extension.servicePresets ?? []).map(cacheServicePreset);
65
+ }
66
+ //# sourceMappingURL=service-extension-metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-extension-metadata.js","sourceRoot":"","sources":["../src/service-extension-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAA2B,MAAM,iBAAiB,CAAC;AAElG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAClK,OAAO,EAAE,kBAAkB,EAAsB,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAExF,SAAS,eAAe,CAAC,GAAW,EAAE,OAAe;IACnD,6FAA6F;IAC7F,8FAA8F;IAC9F,IAAI,SAAiB,CAAC;IACtB,IAAI,CAAC;QAAC,SAAS,GAAG,YAAY,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IAAC,CAAC;IAC3D,MAAM,CAAC;QAAC,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,wBAAwB,EAAE,yEAAyE,CAAC,CAAC;IAAC,CAAC;IACnJ,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC;IAClF,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,cAAc,CAAC,SAAS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{ type ProcessIdentityRecord } from "./pid.js";
3
+ import { type ServiceAdapterContext } from "./service-adapter.js";
4
+ type IdentityContext = Pick<ServiceAdapterContext, "space" | "instanceId" | "launchRequestId" | "stateDirectory">;
5
+ export interface NativeServiceIdentity {
6
+ endpoint: string;
7
+ instanceId: string;
8
+ principal: EpCaller;
9
+ }
10
+ export interface ServiceIdentityBinding {
11
+ schemaVersion: 1;
12
+ space: string;
13
+ instanceId: string;
14
+ launchRequestId: string;
15
+ process: ProcessIdentityRecord;
16
+ native: NativeServiceIdentity;
17
+ observedAt: string;
18
+ }
19
+ export declare function serviceIdentityPath(context: IdentityContext): string;
20
+ /** Publish from the real native child before its endpoint is constructed. This is an immutable
21
+ * same-UID launch binding, not readiness, an authenticated response or an exported caller grant. */
22
+ export declare function publishServiceIdentity(context: IdentityContext, native: NativeServiceIdentity): void;
23
+ /** The adapter must still make an attributed current query and compare this native incarnation.
24
+ * Do not turn a selected identity, a file's existence or a recycled PID into serving evidence. */
25
+ export declare function readServiceIdentity(context: IdentityContext, expected: ProcessIdentityRecord): ServiceIdentityBinding | undefined;
26
+ /** The cluster document one native child registered, beside its launch identity. Same-UID launch
27
+ * evidence of what this incarnation serves; it is verified against the contract store before use. */
28
+ export interface ServedContract {
29
+ schemaVersion: 1;
30
+ space: string;
31
+ instanceId: string;
32
+ launchRequestId: string;
33
+ process: ProcessIdentityRecord;
34
+ endpoint: string;
35
+ clusterDigest: string;
36
+ document: unknown;
37
+ observedAt: string;
38
+ }
39
+ export declare function servedContractPath(context: IdentityContext): string;
40
+ /** Write once, from the same cluster artifacts the child published and registered, before its
41
+ * serving startup receipt. A serving revision-33 child therefore always has this file. */
42
+ export declare function publishServedContract(context: IdentityContext, value: {
43
+ endpoint: string;
44
+ clusterDigest: string;
45
+ document: unknown;
46
+ }): void;
47
+ /** Read only by the preserved-exit capability proof. Absent means the child predates the file.
48
+ * The document must hash to the closure the record names, so the file cannot carry another one. */
49
+ export declare function readServedContract(context: IdentityContext, expected: ProcessIdentityRecord): ServedContract | undefined;
50
+ export {};
51
+ //# sourceMappingURL=service-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-identity.d.ts","sourceRoot":"","sources":["../src/service-identity.ts"],"names":[],"mappings":"AACA,OAAO,EAAgH,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG7J,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEtE,OAAO,EAAsB,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,KAAK,eAAe,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,YAAY,GAAG,iBAAiB,GAAG,gBAAgB,CAAC,CAAC;AAClH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,QAAQ,CAAC;CACrB;AACD,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,CAAC,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,MAAM,EAAE,qBAAqB,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;CACpB;AAID,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAIpE;AAUD;qGACqG;AACrG,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAMpG;AAED;mGACmG;AACnG,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,qBAAqB,GAAG,sBAAsB,GAAG,SAAS,CAQjI;AAED;sGACsG;AACtG,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,CAAC,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,qBAAqB,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAEnE;AAED;2FAC2F;AAC3F,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAQ3I;AAED;oGACoG;AACpG,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,qBAAqB,GAAG,cAAc,GAAG,SAAS,CAYxH"}
@@ -0,0 +1,103 @@
1
+ import { isAbsolute, join } from "node:path";
2
+ import { assertLifecycleToken, contractDigest, endpointToken, singleDocumentClosure, token, writeSecretFileCreateOnly } from "@cotal-ai/core";
3
+ import { spaceKey } from "./auth-paths.js";
4
+ import { CommandFailure } from "./output.js";
5
+ import { identityRecord } from "./pid.js";
6
+ import { decodeLocalJson, protectedLocalDirectory, readLocalRecordSource } from "./protected-records.js";
7
+ import { serviceOperationId } from "./service-adapter.js";
8
+ const invalid = () => { throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the private native service identity does not belong to this full owned launch; no other instance or caller was inferred"); };
9
+ const object = (value) => Boolean(value && typeof value === "object" && !Array.isArray(value) && [Object.prototype, null].includes(Object.getPrototypeOf(value)));
10
+ export function serviceIdentityPath(context) {
11
+ if (!isAbsolute(context.stateDirectory) || context.stateDirectory.length > 4096 || /[\u0000-\u001f\u007f]/u.test(context.stateDirectory) || !context.space || context.space.length > 200 || token(context.space) !== context.space)
12
+ return invalid();
13
+ protectedLocalDirectory(context.stateDirectory);
14
+ return join(context.stateDirectory, `.${spaceKey(serviceOperationId(context.instanceId))}.${spaceKey(serviceOperationId(context.launchRequestId))}.identity.json`);
15
+ }
16
+ function nativeIdentity(input) {
17
+ if (!object(input) || Object.keys(input).length !== 3 || Object.keys(input).some((key) => !["endpoint", "instanceId", "principal"].includes(key)) || typeof input.endpoint !== "string" || input.endpoint.length > 200 || typeof input.instanceId !== "string")
18
+ return invalid();
19
+ const principal = input.principal;
20
+ if (!object(principal) || Object.keys(principal).length !== 3 || !["owner", "actor", "uid"].every((key) => typeof principal[key] === "string" && principal[key].length > 0 && principal[key].length <= 200 && token(principal[key]) === principal[key]))
21
+ return invalid();
22
+ try {
23
+ endpointToken(input.endpoint);
24
+ assertLifecycleToken(input.instanceId);
25
+ assertLifecycleToken(String(principal.uid));
26
+ }
27
+ catch {
28
+ return invalid();
29
+ }
30
+ return { endpoint: input.endpoint, instanceId: input.instanceId, principal: { owner: String(principal.owner), actor: String(principal.actor), uid: String(principal.uid) } };
31
+ }
32
+ /** Publish from the real native child before its endpoint is constructed. This is an immutable
33
+ * same-UID launch binding, not readiness, an authenticated response or an exported caller grant. */
34
+ export function publishServiceIdentity(context, native) {
35
+ if (process.platform !== "linux")
36
+ throw new CommandFailure("refused", "UNSUPPORTED", "the native process binding requires the supported Linux service driver; no PID-only identity was substituted");
37
+ const self = identityRecord(process.pid);
38
+ if (!("token" in self))
39
+ throw new CommandFailure("refused", "UNSUPPORTED", "the native service has no process creation identity for its launch binding");
40
+ const value = { schemaVersion: 1, space: context.space, instanceId: context.instanceId, launchRequestId: context.launchRequestId, process: self, native: nativeIdentity(native), observedAt: new Date().toISOString() };
41
+ writeSecretFileCreateOnly(serviceIdentityPath(context), JSON.stringify(value) + "\n");
42
+ }
43
+ /** The adapter must still make an attributed current query and compare this native incarnation.
44
+ * Do not turn a selected identity, a file's existence or a recycled PID into serving evidence. */
45
+ export function readServiceIdentity(context, expected) {
46
+ const bytes = readLocalRecordSource(serviceIdentityPath(context), 8192, true);
47
+ if (bytes === undefined)
48
+ return undefined;
49
+ const value = decodeLocalJson(bytes);
50
+ if (!object(value) || Object.keys(value).length !== 7 || Object.keys(value).some((key) => !["schemaVersion", "space", "instanceId", "launchRequestId", "process", "native", "observedAt"].includes(key)) || value.schemaVersion !== 1 || value.space !== context.space || value.instanceId !== context.instanceId || value.launchRequestId !== context.launchRequestId || typeof value.observedAt !== "string" || value.observedAt.length > 100 || !Number.isFinite(Date.parse(value.observedAt)) || Date.parse(value.observedAt) > Date.now() + 1000)
51
+ return invalid();
52
+ const process = value.process;
53
+ if (!Number.isSafeInteger(expected.pid) || expected.pid <= 0 || expected.pid > 2_147_483_647 || typeof expected.token !== "string" || expected.token.length > 128 || !/^[0-9]+$/.test(expected.token) || !object(process) || Object.keys(process).length !== 2 || process.pid !== expected.pid || process.token !== expected.token)
54
+ return invalid();
55
+ return { schemaVersion: 1, space: context.space, instanceId: context.instanceId, launchRequestId: context.launchRequestId, process: { pid: expected.pid, token: expected.token }, native: nativeIdentity(value.native), observedAt: value.observedAt };
56
+ }
57
+ export function servedContractPath(context) {
58
+ return serviceIdentityPath(context).replace(/\.identity\.json$/u, ".served-contract.json");
59
+ }
60
+ /** Write once, from the same cluster artifacts the child published and registered, before its
61
+ * serving startup receipt. A serving revision-33 child therefore always has this file. */
62
+ export function publishServedContract(context, value) {
63
+ if (process.platform !== "linux")
64
+ throw new CommandFailure("refused", "UNSUPPORTED", "the served-contract binding requires the supported Linux service driver");
65
+ const self = identityRecord(process.pid);
66
+ if (!("token" in self))
67
+ throw new CommandFailure("refused", "UNSUPPORTED", "the native service has no process creation identity for its served-contract binding");
68
+ try {
69
+ endpointToken(value.endpoint);
70
+ }
71
+ catch {
72
+ return invalid();
73
+ }
74
+ if (singleDocumentClosure(value.document).closureDigest !== value.clusterDigest)
75
+ return invalid();
76
+ const record = { schemaVersion: 1, space: context.space, instanceId: context.instanceId, launchRequestId: context.launchRequestId, process: self, endpoint: value.endpoint, clusterDigest: value.clusterDigest, document: value.document, observedAt: new Date().toISOString() };
77
+ writeSecretFileCreateOnly(servedContractPath(context), JSON.stringify(record) + "\n");
78
+ }
79
+ /** Read only by the preserved-exit capability proof. Absent means the child predates the file.
80
+ * The document must hash to the closure the record names, so the file cannot carry another one. */
81
+ export function readServedContract(context, expected) {
82
+ const bytes = readLocalRecordSource(servedContractPath(context), 256 * 1024, true);
83
+ if (bytes === undefined)
84
+ return undefined;
85
+ const value = decodeLocalJson(bytes);
86
+ const keys = ["schemaVersion", "space", "instanceId", "launchRequestId", "process", "endpoint", "clusterDigest", "document", "observedAt"];
87
+ if (!object(value) || Object.keys(value).length !== keys.length || Object.keys(value).some((key) => !keys.includes(key)) || value.schemaVersion !== 1 || value.space !== context.space || value.instanceId !== context.instanceId || value.launchRequestId !== context.launchRequestId || typeof value.endpoint !== "string" || typeof value.clusterDigest !== "string" || !/^sha256:[0-9a-f]{64}$/.test(value.clusterDigest) || typeof value.observedAt !== "string" || value.observedAt.length > 100 || !Number.isFinite(Date.parse(value.observedAt)) || Date.parse(value.observedAt) > Date.now() + 1000 || !object(value.document))
88
+ return invalid();
89
+ const pinned = value.process;
90
+ if (!object(pinned) || Object.keys(pinned).length !== 2 || pinned.pid !== expected.pid || pinned.token !== expected.token)
91
+ return invalid();
92
+ try {
93
+ endpointToken(value.endpoint);
94
+ }
95
+ catch {
96
+ return invalid();
97
+ }
98
+ const closure = singleDocumentClosure(value.document);
99
+ if (closure.manifest.root !== contractDigest(value.document) || closure.closureDigest !== value.clusterDigest)
100
+ return invalid();
101
+ return { schemaVersion: 1, space: context.space, instanceId: context.instanceId, launchRequestId: context.launchRequestId, process: { pid: expected.pid, token: expected.token }, endpoint: value.endpoint, clusterDigest: value.clusterDigest, document: value.document, observedAt: value.observedAt };
102
+ }
103
+ //# sourceMappingURL=service-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-identity.js","sourceRoot":"","sources":["../src/service-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA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,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG,IAAI,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK;QAAE,OAAO,OAAO,EAAE,CAAC;IAC5I,IAAI,CAAC;QAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,OAAO,EAAE,CAAC;IAAC,CAAC;IAClE,MAAM,OAAO,GAAG,qBAAqB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtD,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,aAAa,KAAK,KAAK,CAAC,aAAa;QAAE,OAAO,OAAO,EAAE,CAAC;IAChI,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,eAAe,EAAE,OAAO,CAAC,eAAe,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC;AAC3S,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type ProcessIdentityRecord } from "./pid.js";
2
+ import { type ServiceAdapterContext } from "./service-adapter.js";
3
+ type ObservationContext = Pick<ServiceAdapterContext, "space" | "instanceId" | "launchRequestId" | "stateDirectory">;
4
+ export interface ServiceObservationRequest {
5
+ schemaVersion: 1;
6
+ space: string;
7
+ instanceId: string;
8
+ launchRequestId: string;
9
+ requestId: string;
10
+ target: ProcessIdentityRecord;
11
+ requester: ProcessIdentityRecord;
12
+ requestedAt: string;
13
+ }
14
+ export interface ServiceObservationResponse extends ServiceObservationRequest {
15
+ process: ProcessIdentityRecord;
16
+ payload: unknown;
17
+ observedAt: string;
18
+ }
19
+ /** Controller side. Publish one request for the exact live target, wait for that target's own
20
+ * bound response, then remove this request and its response. A timeout yields no evidence. */
21
+ export declare function requestServiceObservation(context: ObservationContext, target: ProcessIdentityRecord, options: {
22
+ timeoutMs: number;
23
+ signal: AbortSignal;
24
+ }): Promise<{
25
+ payload: unknown;
26
+ observedAt: string;
27
+ } | undefined>;
28
+ /** Child side. Answer every pending request addressed to this exact process and launch. A request
29
+ * for another process, a malformed one or an already-answered one is left untouched. */
30
+ export declare function answerServiceObservations(context: ObservationContext, payload: () => unknown): void;
31
+ export {};
32
+ //# sourceMappingURL=service-observation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-observation.d.ts","sourceRoot":"","sources":["../src/service-observation.ts"],"names":[],"mappings":"AAWA,OAAO,EAAwC,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAE5F,OAAO,EAAsB,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEtF,KAAK,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,YAAY,GAAG,iBAAiB,GAAG,gBAAgB,CAAC,CAAC;AACrH,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,CAAC,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,qBAAqB,CAAC;IAC9B,SAAS,EAAE,qBAAqB,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,0BAA2B,SAAQ,yBAAyB;IAC3E,OAAO,EAAE,qBAAqB,CAAC;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAqCD;+FAC+F;AAC/F,wBAAsB,yBAAyB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,qBAAqB,EAAE,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CA2B9N;AAED;yFACyF;AACzF,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,OAAO,GAAG,IAAI,CAqBnG"}
@@ -0,0 +1,134 @@
1
+ /** A same-UID, request-bound local observation of a controller-owned native child. The controller
2
+ * writes one create-only request naming the exact pinned target; only that live process answers,
3
+ * with one create-only response bound to the same request, launch and its own creation identity.
4
+ * This is local custody evidence from the child itself. It is not an authenticated endpoint
5
+ * response, a wire grant or a signature, and it never replaces a broker-attributed read. */
6
+ import { randomUUID } from "node:crypto";
7
+ import { readdirSync, rmSync } from "node:fs";
8
+ import { isAbsolute, join } from "node:path";
9
+ import { token, writeSecretFileCreateOnly } from "@cotal-ai/core";
10
+ import { spaceKey } from "./auth-paths.js";
11
+ import { CommandFailure } from "./output.js";
12
+ import { assertRecordIdentity, identityRecord } from "./pid.js";
13
+ import { decodeLocalJson, protectedLocalDirectory, readLocalRecordSource } from "./protected-records.js";
14
+ import { serviceOperationId } from "./service-adapter.js";
15
+ const LIMIT = 64 * 1024;
16
+ const requestKeys = ["schemaVersion", "space", "instanceId", "launchRequestId", "requestId", "target", "requester", "requestedAt"];
17
+ const object = (value) => Boolean(value && typeof value === "object" && !Array.isArray(value) && [Object.prototype, null].includes(Object.getPrototypeOf(value)));
18
+ const invalid = () => { throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the private service observation does not match this full process/launch/request; no other observation was adopted"); };
19
+ const time = (value) => {
20
+ if (typeof value !== "string" || value.length > 100 || !Number.isFinite(Date.parse(value)) || Date.parse(value) > Date.now() + 1000)
21
+ return invalid();
22
+ return value;
23
+ };
24
+ function pinned(value) {
25
+ if (!object(value) || Object.keys(value).length !== 2 || !Number.isSafeInteger(value.pid) || Number(value.pid) <= 0 || Number(value.pid) > 2_147_483_647 || typeof value.token !== "string" || value.token.length > 128 || !/^[0-9]+$/.test(value.token))
26
+ return invalid();
27
+ return { pid: Number(value.pid), token: value.token };
28
+ }
29
+ function prefix(context) {
30
+ if (!isAbsolute(context.stateDirectory) || context.stateDirectory.length > 4096 || /[\u0000-\u001f\u007f]/u.test(context.stateDirectory) || !context.space || context.space.length > 200 || token(context.space) !== context.space)
31
+ return invalid();
32
+ protectedLocalDirectory(context.stateDirectory);
33
+ return `.${spaceKey(serviceOperationId(context.instanceId))}.${spaceKey(serviceOperationId(context.launchRequestId))}.`;
34
+ }
35
+ const requestPath = (context, requestId) => join(context.stateDirectory, `${prefix(context)}${spaceKey(serviceOperationId(requestId))}.observe.json`);
36
+ const responsePath = (context, requestId) => join(context.stateDirectory, `${prefix(context)}${spaceKey(serviceOperationId(requestId))}.observation.json`);
37
+ function parseRequest(input, context) {
38
+ if (!object(input) || Object.keys(input).length !== requestKeys.length || Object.keys(input).some((key) => !requestKeys.includes(key)) || input.schemaVersion !== 1 || input.space !== context.space || input.instanceId !== context.instanceId || input.launchRequestId !== context.launchRequestId || typeof input.requestId !== "string")
39
+ return invalid();
40
+ try {
41
+ serviceOperationId(input.requestId);
42
+ }
43
+ catch {
44
+ return invalid();
45
+ }
46
+ return { schemaVersion: 1, space: context.space, instanceId: context.instanceId, launchRequestId: context.launchRequestId, requestId: input.requestId, target: pinned(input.target), requester: pinned(input.requester), requestedAt: time(input.requestedAt) };
47
+ }
48
+ const sameRequest = (a, b) => a.requestId === b.requestId && a.space === b.space && a.instanceId === b.instanceId && a.launchRequestId === b.launchRequestId && a.target.pid === b.target.pid && a.target.token === b.target.token && a.requester.pid === b.requester.pid && a.requester.token === b.requester.token && a.requestedAt === b.requestedAt;
49
+ /** Remove one exact private file only while it still holds the bytes this caller read or wrote. */
50
+ function removeExact(path, expected) {
51
+ const current = readLocalRecordSource(path, LIMIT, true);
52
+ if (current === undefined)
53
+ return;
54
+ if (!current.equals(expected))
55
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "a private observation file changed before cleanup; it was not removed");
56
+ rmSync(path, { force: true });
57
+ }
58
+ /** Controller side. Publish one request for the exact live target, wait for that target's own
59
+ * bound response, then remove this request and its response. A timeout yields no evidence. */
60
+ export async function requestServiceObservation(context, target, options) {
61
+ const self = identityRecord(process.pid);
62
+ if (!("token" in self))
63
+ throw new CommandFailure("refused", "UNSUPPORTED", "the observing controller has no creation-pinned identity; no observation was requested");
64
+ const checkedTarget = pinned(target);
65
+ if (assertRecordIdentity(checkedTarget).kind !== "match")
66
+ return undefined;
67
+ const request = { schemaVersion: 1, space: context.space, instanceId: context.instanceId, launchRequestId: context.launchRequestId, requestId: randomUUID(), target: checkedTarget, requester: { pid: self.pid, token: self.token }, requestedAt: new Date().toISOString() };
68
+ const requestBytes = Buffer.from(JSON.stringify(request) + "\n");
69
+ const path = requestPath(context, request.requestId), answer = responsePath(context, request.requestId);
70
+ writeSecretFileCreateOnly(path, requestBytes);
71
+ try {
72
+ const deadline = Date.now() + Math.max(1, Math.min(10_000, options.timeoutMs));
73
+ while (Date.now() < deadline) {
74
+ options.signal.throwIfAborted();
75
+ const bytes = readLocalRecordSource(answer, LIMIT, true);
76
+ if (bytes !== undefined) {
77
+ const row = decodeLocalJson(bytes);
78
+ if (!object(row) || Object.keys(row).length !== requestKeys.length + 3 || Object.keys(row).some((key) => ![...requestKeys, "process", "payload", "observedAt"].includes(key)))
79
+ return invalid();
80
+ const answered = parseRequest(Object.fromEntries(requestKeys.map((key) => [key, row[key]])), context), process_ = pinned(row.process), observedAt = time(row.observedAt);
81
+ if (!sameRequest(answered, request) || process_.pid !== checkedTarget.pid || process_.token !== checkedTarget.token || Date.parse(observedAt) < Date.parse(request.requestedAt) || assertRecordIdentity(checkedTarget).kind !== "match")
82
+ return invalid();
83
+ removeExact(answer, bytes);
84
+ return { payload: row.payload, observedAt };
85
+ }
86
+ if (assertRecordIdentity(checkedTarget).kind !== "match")
87
+ return undefined;
88
+ await new Promise((resolve) => setTimeout(resolve, 50));
89
+ }
90
+ return undefined;
91
+ }
92
+ finally {
93
+ removeExact(path, requestBytes);
94
+ }
95
+ }
96
+ /** Child side. Answer every pending request addressed to this exact process and launch. A request
97
+ * for another process, a malformed one or an already-answered one is left untouched. */
98
+ export function answerServiceObservations(context, payload) {
99
+ const self = identityRecord(process.pid);
100
+ if (!("token" in self))
101
+ return;
102
+ const start = prefix(context);
103
+ for (const name of readdirSync(context.stateDirectory)) {
104
+ if (!name.startsWith(start) || !name.endsWith(".observe.json"))
105
+ continue;
106
+ let request;
107
+ try {
108
+ const bytes = readLocalRecordSource(join(context.stateDirectory, name), LIMIT, true);
109
+ if (!bytes)
110
+ continue;
111
+ request = parseRequest(decodeLocalJson(bytes), context);
112
+ }
113
+ catch {
114
+ continue;
115
+ }
116
+ if (request.target.pid !== self.pid || request.target.token !== self.token || join(context.stateDirectory, name) !== requestPath(context, request.requestId) || readLocalRecordSource(responsePath(context, request.requestId), LIMIT, true) !== undefined)
117
+ continue;
118
+ const body = payload();
119
+ if (body === undefined)
120
+ continue;
121
+ const response = { ...request, process: { pid: self.pid, token: self.token }, payload: body, observedAt: new Date().toISOString() };
122
+ const text = JSON.stringify(response) + "\n";
123
+ if (Buffer.byteLength(text) > LIMIT)
124
+ throw new CommandFailure("refused", "SCHEMA_INVALID", "the service observation exceeds its bounded size; no response was published");
125
+ try {
126
+ writeSecretFileCreateOnly(responsePath(context, request.requestId), text);
127
+ }
128
+ catch (error) {
129
+ if (error.code !== "EEXIST")
130
+ throw error;
131
+ }
132
+ }
133
+ }
134
+ //# sourceMappingURL=service-observation.js.map
@@ -0,0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AAC,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK;YAAE,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,gBAAgB,EAAE,6EAA6E,CAAC,CAAC;QAC1K,IAAI,CAAC;YAAC,yBAAyB,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC;QAAC,CAAC;QAClF,OAAO,KAAK,EAAE,CAAC;YAAC,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;gBAAE,MAAM,KAAK,CAAC;QAAC,CAAC;IACxF,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Extension } from "@cotal-ai/core";
2
+ /** A declarative factory for an adapter definition. It starts nothing and supplies no credentials.
3
+ * Options and their CLI flags derive from the adapter's one closed schema, not another copy. */
4
+ export interface ServicePreset extends Extension {
5
+ readonly kind: "service-preset";
6
+ readonly name: string;
7
+ readonly summary: string;
8
+ readonly adapter: string;
9
+ readonly timeoutMs: number;
10
+ }
11
+ export declare function cacheServicePreset(input: ServicePreset): ServicePreset;
12
+ //# sourceMappingURL=service-preset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-preset.d.ts","sourceRoot":"","sources":["../src/service-preset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD;iGACiG;AACjG,MAAM,WAAW,aAAc,SAAQ,SAAS;IAC9C,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAKtE"}
@@ -0,0 +1,10 @@
1
+ import { CommandFailure } from "./output.js";
2
+ import { serviceMetadataDigest } from "./service-adapter.js";
3
+ export function cacheServicePreset(input) {
4
+ if (!input || input.kind !== "service-preset" || !/^[a-z][a-z0-9-]{0,63}$/.test(input.name) || typeof input.summary !== "string" || !input.summary || input.summary.length > 300 || /[\u0000-\u001f\u007f]/u.test(input.summary) || typeof input.adapter !== "string" || !input.adapter || input.adapter.length > 200 || /[\u0000-\u001f\u007f]/u.test(input.adapter) || !Number.isSafeInteger(input.timeoutMs) || input.timeoutMs <= 0 || input.timeoutMs > 120000 || Object.keys(input).some((key) => !["kind", "name", "summary", "adapter", "timeoutMs"].includes(key)))
5
+ throw new CommandFailure("refused", "SCHEMA_INVALID", "a service preset has an unsupported closed declaration; no provider was loaded to repair it");
6
+ const value = { kind: "service-preset", name: input.name, summary: input.summary, adapter: input.adapter, timeoutMs: input.timeoutMs };
7
+ serviceMetadataDigest(value);
8
+ return value;
9
+ }
10
+ //# sourceMappingURL=service-preset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-preset.js","sourceRoot":"","sources":["../src/service-preset.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAY7D,MAAM,UAAU,kBAAkB,CAAC,KAAoB;IACrD,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,IAAI,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,IAAI,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,KAAK,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAAE,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,gBAAgB,EAAE,6FAA6F,CAAC,CAAC;IAClsB,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,gBAAyB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IAChJ,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type ServiceAdapterContext, type ServiceAdapterReadiness } from "./service-adapter.js";
2
+ type StartupContext = Pick<ServiceAdapterContext, "space" | "instanceId" | "launchRequestId" | "stateDirectory">;
3
+ export declare const serviceStartupPath: (context: StartupContext) => string;
4
+ export declare function validateServiceStartupPath(path: string, id: string, request: string): void;
5
+ /** Call from the native child only after its real initialization and signal handlers exist.
6
+ * This receipt grants no authority and carries no bootstrap URL, token or credential. */
7
+ export declare function publishServiceStartup(path: string, value: {
8
+ phase: string;
9
+ space: string;
10
+ instanceId: string;
11
+ launchRequestId: string;
12
+ }): void;
13
+ /** A native startup receipt plus the controller's current process proof. This is not an HTTP
14
+ * health query, a native endpoint response or proof of ongoing application availability. */
15
+ export declare function observeServiceStartup(context: ServiceAdapterContext & {
16
+ process: {
17
+ pid: number;
18
+ token: string;
19
+ };
20
+ signal: AbortSignal;
21
+ }, phase: string): ServiceAdapterReadiness;
22
+ export {};
23
+ //# sourceMappingURL=service-startup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service-startup.d.ts","sourceRoot":"","sources":["../src/service-startup.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,qBAAqB,EAAE,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpH,KAAK,cAAc,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,YAAY,GAAG,iBAAiB,GAAG,gBAAgB,CAAC,CAAC;AAGjH,eAAO,MAAM,kBAAkB,GAAI,SAAS,cAAc,KAAG,MAAyF,CAAC;AAEvJ,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAG1F;AAED;0FAC0F;AAC1F,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAM9I;AAED;6FAC6F;AAC7F,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,qBAAqB,GAAG;IAAE,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,EAAE,KAAK,EAAE,MAAM,GAAG,uBAAuB,CAQ/K"}