@sentropic/h2a-runtime 0.98.6 → 0.98.7-rc.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 (58) hide show
  1. package/dist/attach.d.ts +2 -0
  2. package/dist/attach.d.ts.map +1 -1
  3. package/dist/attach.js +73 -6
  4. package/dist/attach.js.map +1 -1
  5. package/dist/auth-login.d.ts +24 -1
  6. package/dist/auth-login.d.ts.map +1 -1
  7. package/dist/auth-login.js +132 -4
  8. package/dist/auth-login.js.map +1 -1
  9. package/dist/central-mcp.d.ts +2 -0
  10. package/dist/central-mcp.d.ts.map +1 -1
  11. package/dist/central-mcp.js +90 -3
  12. package/dist/central-mcp.js.map +1 -1
  13. package/dist/cli-help-groups.js +1 -1
  14. package/dist/cli-help-groups.js.map +1 -1
  15. package/dist/crash-log.d.ts +112 -0
  16. package/dist/crash-log.d.ts.map +1 -0
  17. package/dist/crash-log.js +560 -0
  18. package/dist/crash-log.js.map +1 -0
  19. package/dist/gateway-host/live-declarations.d.ts +58 -0
  20. package/dist/gateway-host/live-declarations.d.ts.map +1 -0
  21. package/dist/gateway-host/live-declarations.js +423 -0
  22. package/dist/gateway-host/live-declarations.js.map +1 -0
  23. package/dist/gateway-host/live-registration.d.ts +162 -0
  24. package/dist/gateway-host/live-registration.d.ts.map +1 -0
  25. package/dist/gateway-host/live-registration.js +455 -0
  26. package/dist/gateway-host/live-registration.js.map +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +79 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/native-host.d.ts.map +1 -1
  31. package/dist/native-host.js +27 -5
  32. package/dist/native-host.js.map +1 -1
  33. package/dist/native-terminal/journal.d.ts +5 -0
  34. package/dist/native-terminal/journal.d.ts.map +1 -1
  35. package/dist/native-terminal/journal.js +28 -16
  36. package/dist/native-terminal/journal.js.map +1 -1
  37. package/dist/native-terminal/op.d.ts +13 -0
  38. package/dist/native-terminal/op.d.ts.map +1 -1
  39. package/dist/native-terminal/op.js +64 -5
  40. package/dist/native-terminal/op.js.map +1 -1
  41. package/dist/run.d.ts.map +1 -1
  42. package/dist/run.js +79 -16
  43. package/dist/run.js.map +1 -1
  44. package/dist/terminal-reset.d.ts +104 -0
  45. package/dist/terminal-reset.d.ts.map +1 -0
  46. package/dist/terminal-reset.js +229 -0
  47. package/dist/terminal-reset.js.map +1 -0
  48. package/dist/tmux.d.ts +23 -3
  49. package/dist/tmux.d.ts.map +1 -1
  50. package/dist/tmux.js +47 -16
  51. package/dist/tmux.js.map +1 -1
  52. package/dist/vendor/engram-live/contracts.d.ts +208 -0
  53. package/dist/vendor/engram-live/contracts.js +558 -0
  54. package/dist/vendor/engram-live/integration.d.ts +73 -0
  55. package/dist/vendor/engram-live/integration.js +194 -0
  56. package/dist/vendor/engram-live/registration.d.ts +138 -0
  57. package/dist/vendor/engram-live/registration.js +360 -0
  58. package/package.json +2 -2
@@ -0,0 +1,194 @@
1
+ // Vendored from @sentropic/engram-live 0.1.0 dist/integration.js — same
2
+ // provenance as the sibling contracts.js header (graphify@70ebdfee, pinned
3
+ // tarball sha512 in the GUARD test). Only the derive* re-exports are
4
+ // consumed by H; the factory reads grammars lazily through injected ports.
5
+ // Portable: node: builtins plus siblings only. Do not hand-edit.
6
+ // @sentropic/engram-live/integration — executable neutral factory
7
+ // (spec/SPEC_LIVE_GIT_INDEXING.md §2–3, §11; plan/09 L1b).
8
+ //
9
+ // The factory composes injected capabilities only: Git, filesystem, clock,
10
+ // content, fact-sink, cache and grammar ports. It never imports the
11
+ // monolithic root CLI, another @sentropic/* consumer package, the h2a host,
12
+ // a model module or a storage-driver handle — those stay outside the neutral
13
+ // closure by construction and by tests/live-neutrality.test.ts.
14
+ //
15
+ // L1b supplies the package/factory seams and grammar loading. Every other
16
+ // capability is explicitly unavailable until its lot lands; the factory
17
+ // never fabricates facts, writes through the fact sink or silently
18
+ // degrades an unavailable capability into an empty success.
19
+ import { createHash } from "node:crypto";
20
+ import { dirname, join } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+ import { ADVERTISED_LANGUAGES, CAPABILITY_IDS, CAPABILITY_PLANNED_LOTS, GRAMMAR_UNAVAILABLE_REASON, NOT_IMPLEMENTED_REASON, validateFactBatch, validateWorkspaceDeclaration, } from "./contracts.js";
23
+ function decodeJson(bytes) {
24
+ return JSON.parse(new TextDecoder().decode(bytes));
25
+ }
26
+ function sha256(bytes) {
27
+ return createHash("sha256").update(bytes).digest("hex");
28
+ }
29
+ function errorMessage(error) {
30
+ return error instanceof Error ? error.message : String(error);
31
+ }
32
+ // The pinned manifest is validated before any grammar is trusted: a
33
+ // manifestVersion number and a languages record whose entries pin a
34
+ // non-empty file and sha256 are required.
35
+ function isGrammarManifest(value) {
36
+ if (typeof value !== "object" || value === null)
37
+ return false;
38
+ const candidate = value;
39
+ if (typeof candidate.manifestVersion !== "number")
40
+ return false;
41
+ if (typeof candidate.languages !== "object" || candidate.languages === null || Array.isArray(candidate.languages)) {
42
+ return false;
43
+ }
44
+ return Object.values(candidate.languages).every((entry) => {
45
+ if (typeof entry !== "object" || entry === null)
46
+ return false;
47
+ const record = entry;
48
+ return typeof record.file === "string" && record.file.length > 0
49
+ && typeof record.sha256 === "string" && record.sha256.length > 0;
50
+ });
51
+ }
52
+ export function createLiveFactory(options) {
53
+ const declarationCheck = validateWorkspaceDeclaration(options.declaration);
54
+ if (!declarationCheck.ok) {
55
+ throw new Error(`invalid live workspace declaration: ${declarationCheck.errors.join("; ")}`);
56
+ }
57
+ const ports = options.ports;
58
+ const distDir = dirname(fileURLToPath(import.meta.url));
59
+ const manifestPath = join(distDir, "..", "grammar-manifest.json");
60
+ const grammarDir = join(distDir, "grammars");
61
+ let manifestCache;
62
+ const loadManifest = async () => {
63
+ if (manifestCache)
64
+ return { ok: true, manifest: manifestCache };
65
+ let decoded;
66
+ try {
67
+ decoded = decodeJson(await ports.filesystem.readFileBytes(manifestPath));
68
+ }
69
+ catch (error) {
70
+ return {
71
+ ok: false,
72
+ reason: `the pinned grammar manifest cannot be read through the filesystem port (${errorMessage(error)})`,
73
+ };
74
+ }
75
+ if (!isGrammarManifest(decoded)) {
76
+ return {
77
+ ok: false,
78
+ reason: "the pinned grammar manifest is invalid: a manifestVersion number and a languages record pinning file/sha256 entries are required",
79
+ };
80
+ }
81
+ manifestCache = decoded;
82
+ return { ok: true, manifest: decoded };
83
+ };
84
+ const grammarLoadCache = new Map();
85
+ return {
86
+ describeCapabilities() {
87
+ return CAPABILITY_IDS.map((capability) => ({
88
+ capability,
89
+ state: "unavailable",
90
+ reason: NOT_IMPLEMENTED_REASON,
91
+ plannedLot: CAPABILITY_PLANNED_LOTS[capability],
92
+ }));
93
+ },
94
+ async runCapability(capability) {
95
+ if (!CAPABILITY_IDS.includes(capability)) {
96
+ throw new Error(`unknown capability "${String(capability)}"; known capabilities: ${CAPABILITY_IDS.join(", ")}`);
97
+ }
98
+ // Explicit unavailability: no port call, no fabricated facts, no
99
+ // empty-success degradation.
100
+ return {
101
+ capability,
102
+ state: "unavailable",
103
+ reason: NOT_IMPLEMENTED_REASON,
104
+ plannedLot: CAPABILITY_PLANNED_LOTS[capability],
105
+ delivered: false,
106
+ };
107
+ },
108
+ grammarCoverage(language) {
109
+ // Synchronous coverage uses the pinned manifest; loadGrammar caches the
110
+ // executed result per language so coverage reflects verified assets.
111
+ const loaded = grammarLoadCache.get(language);
112
+ if (loaded?.state === "available") {
113
+ return { axis: "ast", language, state: "current", reason: `packaged grammar verified (sha256 ${loaded.bytesSha256})` };
114
+ }
115
+ return {
116
+ axis: "ast",
117
+ language,
118
+ state: "unavailable",
119
+ reason: `${GRAMMAR_UNAVAILABLE_REASON}: "${language}" has no verified packaged grammar in this session`,
120
+ };
121
+ },
122
+ grammarCoverageReport(language) {
123
+ const coverage = this.grammarCoverage(language);
124
+ return {
125
+ axis: coverage.axis,
126
+ language,
127
+ state: coverage.state,
128
+ reason: coverage.reason,
129
+ checkedAt: ports.clock.now(),
130
+ };
131
+ },
132
+ async loadGrammar(language) {
133
+ const cached = grammarLoadCache.get(language);
134
+ if (cached)
135
+ return cached;
136
+ const unavailable = (reason) => {
137
+ const result = { language, state: "unavailable", reason };
138
+ grammarLoadCache.set(language, result);
139
+ return result;
140
+ };
141
+ // Reading and validating the manifest is part of the load: an absent,
142
+ // unreadable or invalid manifest yields an explicit unavailable result,
143
+ // never a thrown error and never a silent empty success.
144
+ const manifestOutcome = await loadManifest();
145
+ if (!manifestOutcome.ok || manifestOutcome.manifest === undefined) {
146
+ return unavailable(`${GRAMMAR_UNAVAILABLE_REASON}: ${manifestOutcome.reason ?? "the pinned grammar manifest is unavailable"}`);
147
+ }
148
+ // Clean own-property lookup: inherited names such as "constructor" or
149
+ // "toString" never reach a manifest entry.
150
+ if (!Object.hasOwn(manifestOutcome.manifest.languages, language)) {
151
+ return unavailable(`${GRAMMAR_UNAVAILABLE_REASON}: "${language}" is absent from the pinned grammar manifest`);
152
+ }
153
+ const entry = manifestOutcome.manifest.languages[language];
154
+ let bytes;
155
+ try {
156
+ bytes = await ports.filesystem.readFileBytes(join(grammarDir, entry.file));
157
+ }
158
+ catch (error) {
159
+ return unavailable(`${GRAMMAR_UNAVAILABLE_REASON}: the packaged WASM for "${language}" cannot be read through the filesystem port (${errorMessage(error)})`);
160
+ }
161
+ const digest = sha256(bytes);
162
+ if (digest !== entry.sha256) {
163
+ return unavailable(`packaged grammar digest mismatch for "${language}": pinned ${entry.sha256}, read ${digest}`);
164
+ }
165
+ try {
166
+ const grammar = await ports.grammarRuntime.loadLanguage(bytes);
167
+ const result = {
168
+ language,
169
+ state: "available",
170
+ bytesSha256: digest,
171
+ grammar,
172
+ };
173
+ grammarLoadCache.set(language, result);
174
+ return result;
175
+ }
176
+ catch (error) {
177
+ return unavailable(`grammar runtime rejected the packaged WASM for "${language}": ${errorMessage(error)}`);
178
+ }
179
+ },
180
+ validateBatch(batch) {
181
+ return validateFactBatch(batch);
182
+ },
183
+ };
184
+ }
185
+ /** The advertised grammar matrix of this build, from the pinned manifest data. */
186
+ export const ADVERTISED_GRAMMAR_LANGUAGES = ADVERTISED_LANGUAGES;
187
+ // The canonical identity derivation (L6a, spec §3/§12) is part of the public
188
+ // integration surface: h2a and cluster-mesh mint cloneId/worktreeId/
189
+ // declarationId through exactly these functions, so every seat derives
190
+ // byte-identical opaque ids from identical components. The minting needs
191
+ // node:crypto (sha256), which keeps it out of the data-pure /contracts
192
+ // entry; the derivation itself stays pure and deterministic over its
193
+ // arguments (see ./registration.js).
194
+ export { deriveCloneIdentity, deriveWorktreeIdentity, deriveDeclarationIdentity, } from "./registration.js";
@@ -0,0 +1,138 @@
1
+ // Vendored types for the sibling .js — see its provenance header; do not hand-edit.
2
+ import { type CloneIdentityDto, type DeclarationRevocationDto, type IdentityUncertaintyState, type NonActivatingLifecycleKind, type OidAlgorithm, type RevocationReason, type WorkspaceDeclarationDto, type WorktreeIdentityDto } from "./contracts.js";
3
+ /** Input for an explicit live declaration (revision starts at INITIAL_DECLARATION_REVISION). */
4
+ export interface CreateLiveDeclarationInput {
5
+ readonly tenant: string;
6
+ readonly principal: string;
7
+ readonly hostFingerprint?: string;
8
+ readonly identityUncertainty: readonly IdentityUncertaintyState[];
9
+ readonly declarationId: string;
10
+ readonly cloneId: string;
11
+ readonly worktreeId: string;
12
+ readonly authorizedRoots: readonly string[];
13
+ readonly liveCapability: "live";
14
+ readonly policyVersion: string;
15
+ readonly serverWorkspaceId?: string;
16
+ readonly serverIssuer?: string;
17
+ readonly bindingRevision?: number;
18
+ }
19
+ /** Patchable declaration fields. Identity (tenant, principal,
20
+ * hostFingerprint, the declarationId/cloneId/worktreeId triangle,
21
+ * liveCapability, declarationRevision) is immutable across revisions. */
22
+ export interface LiveDeclarationPatch {
23
+ readonly authorizedRoots?: readonly string[];
24
+ readonly policyVersion?: string;
25
+ readonly serverWorkspaceId?: string;
26
+ readonly serverIssuer?: string;
27
+ readonly bindingRevision?: number;
28
+ }
29
+ /** Input for deriving a clone identity from host-resolved components. */
30
+ export interface DeriveCloneIdentityInput {
31
+ readonly hostScope: string;
32
+ readonly commonDirRealpath: string;
33
+ readonly commonDirProjectFingerprint?: string;
34
+ readonly identityUncertainty?: readonly IdentityUncertaintyState[];
35
+ readonly oidAlgorithm: OidAlgorithm;
36
+ }
37
+ /** Input for deriving a worktree identity under an already derived clone. */
38
+ export interface DeriveWorktreeIdentityInput {
39
+ readonly hostScope: string;
40
+ readonly clone: Pick<CloneIdentityDto, "cloneId">;
41
+ readonly worktreePath: string;
42
+ readonly gitDir: string;
43
+ readonly worktreeFingerprint?: string;
44
+ readonly identityUncertainty?: readonly IdentityUncertaintyState[];
45
+ }
46
+ /** Input for deriving the identity of one declaration under a clone/worktree. */
47
+ export interface DeriveDeclarationIdentityInput {
48
+ readonly hostScope: string;
49
+ readonly clone: Pick<CloneIdentityDto, "cloneId">;
50
+ readonly worktree: Pick<WorktreeIdentityDto, "worktreeId">;
51
+ }
52
+ /** Opaque declaration identity: the declaration and its clone/worktree attachment. */
53
+ export interface DeclarationIdentityDto {
54
+ readonly declarationId: string;
55
+ readonly cloneId: string;
56
+ readonly worktreeId: string;
57
+ }
58
+ /**
59
+ * Create the initial live declaration for one workspace. Requires the
60
+ * explicit "live" capability and the full identity triangle
61
+ * (declarationId/cloneId/worktreeId, minted by the canonical derivation
62
+ * below): any other opt-in value (bind, upload, session kinds) is refused,
63
+ * so no lifecycle event can implicitly activate live. The declaration
64
+ * revision starts at the frozen INITIAL_DECLARATION_REVISION.
65
+ */
66
+ export declare function createLiveDeclaration(input: CreateLiveDeclarationInput): WorkspaceDeclarationDto;
67
+ /**
68
+ * Revise a declaration as a pure revision increment. The revision grows by
69
+ * exactly one; tenant, principal, hostFingerprint, the identity triangle
70
+ * and the live capability are immutable. The product binding is the
71
+ * complete (serverWorkspaceId, serverIssuer, bindingRevision) triplet.
72
+ * A revision outside the binding (roots, policy version) PRESERVES the
73
+ * binding: no renewal is imposed. Only a change of serverWorkspaceId or
74
+ * serverIssuer, or an explicit bindingRevision revalidation, renews the
75
+ * binding — and then strictly increasingly: the first binding carries
76
+ * exactly INITIAL_BINDING_REVISION, and every rebind/revalidation carries
77
+ * a strictly greater bindingRevision; binding revisions never go
78
+ * backwards. The host must additionally refuse to redirect in-flight
79
+ * collection/publication when a rebind lands.
80
+ */
81
+ export declare function reviseLiveDeclaration(previous: WorkspaceDeclarationDto, patch: LiveDeclarationPatch): WorkspaceDeclarationDto;
82
+ /**
83
+ * Revoke exactly one declaration as a pure private-purge request. The
84
+ * returned DTO names the single target by its opaque declarationId and
85
+ * carries the declaration's cloneId/worktreeId attachment and revision, so
86
+ * the recipient can never confuse two declarations of one tenant that
87
+ * happen to share public fingerprints or revisions. The host stops work,
88
+ * rejects delayed jobs and purges private snapshots, derived indexes and
89
+ * decryptability, while preserving authorized committed history.
90
+ * Revocation deletes no committed facts.
91
+ */
92
+ export declare function revokeLiveDeclaration(declaration: WorkspaceDeclarationDto, reason: RevocationReason): DeclarationRevocationDto;
93
+ /**
94
+ * Derive the clone identity for one common-dir — the ONE canonical clone
95
+ * derivation. The key components (hostScope, normalized common-dir
96
+ * realpath, common-dir project fingerprint) serialize through
97
+ * canonicalIdKey (unambiguous, NUL-refusing) and hash to the opaque
98
+ * cloneId: equal fingerprints under different realpaths derive distinct
99
+ * clones, while linked worktrees sharing one common-dir derive the same
100
+ * clone. The fingerprint may be absent only under explicit
101
+ * "missing_history" uncertainty; the hostScope + realpath components keep
102
+ * clones distinct even then (LIVE §12). The realpath stays host-local;
103
+ * only cloneId is shared. Deterministic and free of I/O.
104
+ */
105
+ export declare function deriveCloneIdentity(input: DeriveCloneIdentityInput): CloneIdentityDto;
106
+ /**
107
+ * Derive the identity of one worktree under an already derived clone —
108
+ * the ONE canonical worktree derivation. Worktrees of one clone share
109
+ * cloneId and keep an isolated host-scoped worktreeId plus per-worktree
110
+ * git-dir, fingerprint and path. The worktree fingerprint may be absent
111
+ * only under explicit "missing_history" uncertainty (LIVE §12).
112
+ */
113
+ export declare function deriveWorktreeIdentity(input: DeriveWorktreeIdentityInput): WorktreeIdentityDto;
114
+ /**
115
+ * Derive the identity of one declaration — the ONE canonical declaration
116
+ * derivation. One declaration per activated worktree: the declarationId
117
+ * binds the host scope, the clone and the worktree, so two worktrees of
118
+ * one clone (and two clones of one project) derive distinct declarationIds
119
+ * even without fingerprints. Stable across every revision of the same
120
+ * declaration. Deterministic and free of I/O.
121
+ */
122
+ export declare function deriveDeclarationIdentity(input: DeriveDeclarationIdentityInput): DeclarationIdentityDto;
123
+ /**
124
+ * Decide whether two clone references denote the same clone, by canonical
125
+ * identifier only: the cloneId minted by the shared canonical derivation is
126
+ * the clone identity, so the comparison is an equivalence (transitive and
127
+ * consistent between full DTOs and opaque references). Throws when either
128
+ * reference lacks a cloneId — equality is never guessed from components.
129
+ */
130
+ export declare function isSameClone(a: Pick<CloneIdentityDto, "cloneId">, b: Pick<CloneIdentityDto, "cloneId">): boolean;
131
+ /**
132
+ * Classify a host lifecycle event against live declarations. Bind, upload,
133
+ * code-workspace creation and session open/end never activate or remove a
134
+ * declaration: the only outcome is "no-activation-change". Unknown kinds
135
+ * are refused.
136
+ */
137
+ export declare function classifyLifecycleEvent(kind: NonActivatingLifecycleKind): "no-activation-change";
138
+ //# sourceMappingURL=registration.d.ts.map