@amalgm/core 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/PURPOSE.md CHANGED
@@ -20,13 +20,14 @@ Core owns exactly four things:
20
20
  identity, auth-store contracts, and the branch-binding rule surfaces use
21
21
  to decide whether they may attach.
22
22
  2. **Transport** — the pipe. The local gateway's routing and admission
23
- rules, the tunnel connection contract, and the event rail. The pipe
24
- carries payloads it never interprets: sync semantics belong to
23
+ rules plus the tunnel connection contract. The pipe carries payloads it
24
+ never interprets: sync semantics belong to
25
25
  `@amalgm/live`, chat semantics to `@amalgm/chat`. (SIM card, not
26
26
  FaceTime.)
27
- 3. **Supervision** — the cascade that keeps everything running: launchd →
28
- CLI parent → runtime → app supervisor, health contracts, restart policy,
29
- and the updater.
27
+ 3. **Supervision** — the cascade that keeps the machine runtime and product
28
+ services running, plus portable health and restart decision contracts used
29
+ by Apps. The stateful Apps supervisor and individual app processes remain
30
+ owned by `@amalgm/apps`.
30
31
  4. **Host capabilities** — the narrow, named powers a host grants
31
32
  (spawn a service, write a plist, open a port), expressed as adapter
32
33
  ports, never reached for directly.
@@ -51,10 +52,11 @@ that composes an exact Core release with the other product releases.
51
52
  definition of prefixes, ports, and admission. The engine's three drifted
52
53
  copies are the wound this axiom closes.
53
54
  5. **Supervision flows one way.** launchd supervises the parent, the parent
54
- supervises the runtime, the runtime supervises apps. A child never
55
- restarts its parent, and each layer reports its children's health
56
- honestly — `degraded` and `unresponsive` are states, not failures to
57
- hide.
55
+ supervises the Shell runtime, and product supervisors own their children.
56
+ A child never restarts its parent, and each layer reports its children's
57
+ health honestly — `degraded` and `unresponsive` are states, not failures to
58
+ hide. Core defines portable decisions; it does not become a second Apps
59
+ supervisor.
58
60
  6. **A host supplies its own effects.** The SDK receives process,
59
61
  filesystem, clock, network, and crypto adapters. Nothing in `src/` may
60
62
  import `node:fs`, `node:net`, `node:child_process`, or read an
@@ -64,8 +66,9 @@ that composes an exact Core release with the other product releases.
64
66
  legacy behavior. A change that breaks a deployed peer is rejected in
65
67
  review.
66
68
  8. **Contracts are byte-exact.** Path formats, plist labels, health
67
- vocabularies, error strings, and version-compare rules are preserved
68
- verbatim from the shipped engine; parity tests pin them until cutover.
69
+ vocabularies, error strings, and version-compare rules are preserved from
70
+ historical Engine evidence where still ratified. Stable contract tests pin
71
+ them after cutover.
69
72
  9. **Shell is the single production composer.** Core defines host-independent
70
73
  contracts and decisions; `@amalgm/shell` binds them to machine effects and
71
74
  exact product releases. Engine is historical reference evidence only and
@@ -102,6 +105,9 @@ that composes an exact Core release with the other product releases.
102
105
  compatibility surfaces cannot masquerade as unfinished product work.
103
106
  The retired `/email` compatibility door is owned by neither Core nor
104
107
  Shell; current-user delivery belongs to the standalone Channels product.
108
+ The retired machine-local `/events` door is replaced by Automations'
109
+ hosted durable webhook admission; an external sender never depends on a
110
+ target machine being online.
105
111
  18. **Machine setup is one trust rail with two entrances.** Browser polling and
106
112
  an approved setup code converge before the same registration, credential
107
113
  split, installation, canonical-runtime, and readiness path;
package/README.md CHANGED
@@ -13,7 +13,7 @@ installation, and mandatory managed updates is
13
13
 
14
14
  ```
15
15
  src/identity/ labels, layout grammar, ids, auth records
16
- src/transport/ the auth boundary, ONE routing table, admission, ingress
16
+ src/transport/ the auth boundary, ONE routing table, and admission
17
17
  src/supervision/ health contracts, restart machines, updater laws,
18
18
  service registration
19
19
  src/adapters/ the ports a host injects (clock, hash, random, hmac…)
@@ -9,6 +9,5 @@
9
9
  */
10
10
  export type { ClockIsoPort, ClockMsPort, RandomHexPort, Sha256HexPort, ResolvePathPort, } from '../identity/ports.js';
11
11
  export type { TimingSafeEqualPort } from '../transport/auth.js';
12
- export type { HmacHexPort } from '../transport/ingress.js';
13
12
  export type { CredentialCipherPort, CredentialStorePort } from '../identity/credentials/index.js';
14
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,YAAY,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -12,7 +12,6 @@
12
12
  * - admission: who gets routed to at all — app refs, the serving
13
13
  * gate and the advertising breaker, preview-port admission, header
14
14
  * hygiene, log redaction.
15
- * - ingress: the event rail's receipt and signature laws.
16
15
  */
17
16
  export * from './auth.js';
18
17
  export * from './routing.js';
@@ -21,5 +20,4 @@ export * from './state/index.js';
21
20
  export * from './pty/index.js';
22
21
  export * from './diagnostics.js';
23
22
  export * from './admission.js';
24
- export * from './ingress.js';
25
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -12,7 +12,6 @@
12
12
  * - admission: who gets routed to at all — app refs, the serving
13
13
  * gate and the advertising breaker, preview-port admission, header
14
14
  * hygiene, log redaction.
15
- * - ingress: the event rail's receipt and signature laws.
16
15
  */
17
16
  export * from './auth.js';
18
17
  export * from './routing.js';
@@ -21,5 +20,4 @@ export * from './state/index.js';
21
20
  export * from './pty/index.js';
22
21
  export * from './diagnostics.js';
23
22
  export * from './admission.js';
24
- export * from './ingress.js';
25
23
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -9,7 +9,7 @@
9
9
  * under its own '/pty' handling).
10
10
  *
11
11
  * Counts, pinned by tests: 3 gateway prefixes, 5 gateway exact paths,
12
- * 3 port-monitor prefixes, 1 chat prefix, 21 active MCP prefixes.
12
+ * 3 port-monitor prefixes, 1 chat prefix, 20 active MCP prefixes.
13
13
  *
14
14
  * This is product configuration riding in the kernel repo for the
15
15
  * cutover: the table SHAPE is core's; these CONTENTS belong to the
@@ -25,8 +25,10 @@ import type { RouteTable } from './routing.js';
25
25
  * plus credential references resolved by Core's machine-local vault; `/github`
26
26
  * is superseded by the next cloud integration and credential collection model;
27
27
  * `/email` was the in-process Notifications compatibility door and is replaced
28
- * by the independently deployed Channels product.
28
+ * by the independently deployed Channels product; `/events` pushed directly
29
+ * to an online machine and is replaced by Automations' hosted durable
30
+ * `automations.amalgm.ai/e/*` admission rail.
29
31
  */
30
- export declare const retiredEngineRoutePrefixes: readonly ["/tasks", "/mcp-connections", "/github", "/email"];
32
+ export declare const retiredEngineRoutePrefixes: readonly ["/tasks", "/mcp-connections", "/github", "/email", "/events"];
31
33
  export declare const shippedRouteTable: RouteTable;
32
34
  //# sourceMappingURL=shipped-routes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shipped-routes.d.ts","sourceRoot":"","sources":["../../src/transport/shipped-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,8DAA+D,CAAC;AAEvG,eAAO,MAAM,iBAAiB,EAAE,UA4B/B,CAAC"}
1
+ {"version":3,"file":"shipped-routes.d.ts","sourceRoot":"","sources":["../../src/transport/shipped-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,yEAE7B,CAAC;AAEX,eAAO,MAAM,iBAAiB,EAAE,UA2B/B,CAAC"}
@@ -9,7 +9,7 @@
9
9
  * under its own '/pty' handling).
10
10
  *
11
11
  * Counts, pinned by tests: 3 gateway prefixes, 5 gateway exact paths,
12
- * 3 port-monitor prefixes, 1 chat prefix, 21 active MCP prefixes.
12
+ * 3 port-monitor prefixes, 1 chat prefix, 20 active MCP prefixes.
13
13
  *
14
14
  * This is product configuration riding in the kernel repo for the
15
15
  * cutover: the table SHAPE is core's; these CONTENTS belong to the
@@ -24,9 +24,13 @@
24
24
  * plus credential references resolved by Core's machine-local vault; `/github`
25
25
  * is superseded by the next cloud integration and credential collection model;
26
26
  * `/email` was the in-process Notifications compatibility door and is replaced
27
- * by the independently deployed Channels product.
27
+ * by the independently deployed Channels product; `/events` pushed directly
28
+ * to an online machine and is replaced by Automations' hosted durable
29
+ * `automations.amalgm.ai/e/*` admission rail.
28
30
  */
29
- export const retiredEngineRoutePrefixes = ['/tasks', '/mcp-connections', '/github', '/email'];
31
+ export const retiredEngineRoutePrefixes = [
32
+ '/tasks', '/mcp-connections', '/github', '/email', '/events',
33
+ ];
30
34
  export const shippedRouteTable = {
31
35
  gatewayPrefixes: ['/__amalgm', '/diagnostics', '/pty'],
32
36
  gatewayExactPaths: ['/', '/healthz', '/runtime-state', '/pty/session', '/pty/resize'],
@@ -34,7 +38,6 @@ export const shippedRouteTable = {
34
38
  chatPrefixes: ['/chat'],
35
39
  mcpPrefixes: [
36
40
  '/mcp',
37
- '/events',
38
41
  '/automations',
39
42
  '/event-triggers',
40
43
  '/workspace',
@@ -1 +1 @@
1
- {"version":3,"file":"shipped-routes.js","sourceRoot":"","sources":["../../src/transport/shipped-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,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,UAAU;QACV,QAAQ;QACR,QAAQ;QACR,cAAc;QACd,QAAQ;QACR,gBAAgB;QAChB,OAAO;QACP,YAAY;QACZ,SAAS;QACT,eAAe;QACf,gBAAgB;QAChB,SAAS;QACT,mBAAmB;QACnB,UAAU;KACX;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amalgm/core",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
4
4
  "description": "The Amalgm kernel SDK — identity, transport, supervision, and host capability contracts behind host-injected adapters.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -1,94 +0,0 @@
1
- /**
2
- * Event-rail ingress — the pipe half of the webhook rail. Success at
3
- * this layer means exactly one thing: the immutable envelope (raw
4
- * body + allowlisted headers) is durably queued and acknowledged.
5
- * What a delivery TRIGGERS — the automation fan-out below
6
- * events/processor.js:119 — is product logic and deliberately not
7
- * here: the pipe stores and acknowledges the mail, it never reads it
8
- * (axiom 3). The signature laws live at this layer because verifying
9
- * WHO sent a payload is admission, not interpretation.
10
- *
11
- * Ported from amalgm-mcp/events/ingress.js (receipt contract) and
12
- * events/matcher.js (signature laws — already pure in the engine).
13
- */
14
- import type { HeadersLike } from './auth.js';
15
- /** ingress.js:12 — the body cap. Counted over raw bytes as they stream in, not after assembly. */
16
- export declare const MAX_EVENT_BODY_BYTES: number;
17
- /** The over-limit rejection — ingress.js:50-53 surfaced through the generic error path (:80): status + byte-exact message. */
18
- export declare const EVENT_BODY_LIMIT_EXCEEDED: {
19
- readonly status: 413;
20
- readonly message: "Event body exceeds 2097152 bytes";
21
- };
22
- /**
23
- * The 17-header storage allowlist — ingress.js:13-31. Everything else
24
- * is dropped BEFORE the envelope is persisted: the envelope is
25
- * immutable and replayed, so an unlisted header stored today is a
26
- * secret leaked forever. The list is exactly: routing identity
27
- * (x-amalgm-*), each supported sender's event/delivery markers, and
28
- * every signature/secret header the matcher may need to re-verify.
29
- */
30
- export declare const STORED_HEADERS: ReadonlySet<string>;
31
- /**
32
- * ingress.js:33-42 — filter to the allowlist, lowercase the names,
33
- * join repeated values with ', ', stringify the rest. The result is
34
- * the envelope's header record — and the flattened shape every
35
- * signature function below reads.
36
- */
37
- export declare function storedHeaders(headers: HeadersLike | null | undefined): Record<string, string>;
38
- /** The receipt acknowledgment — ingress.js:73-78: 202, because acceptance is durable-queued, not processed. */
39
- export declare const EVENT_ACCEPTED_STATUS = 202;
40
- export declare function eventAcceptedBody(deliveryId: string, status: string): {
41
- ok: true;
42
- accepted: true;
43
- deliveryId: string;
44
- status: string;
45
- };
46
- /** Envelope-shaped headers: already lowercased and flattened by storedHeaders. */
47
- export interface FlatHeaders {
48
- readonly [name: string]: string | undefined;
49
- }
50
- /** matcher.js:13-17 — HMAC proof headers, in precedence order (generic first, then GitHub's sha256, then legacy sha1). */
51
- export declare const HMAC_SIGNATURE_HEADERS: readonly ["x-webhook-signature", "x-hub-signature-256", "x-hub-signature"];
52
- /** matcher.js:19-23 — plain shared-secret headers, in precedence order (ours, generic, GitLab's). */
53
- export declare const TOKEN_HEADERS: readonly ["x-amalgm-webhook-secret", "x-webhook-secret", "x-gitlab-token"];
54
- export interface ExtractedSignature {
55
- readonly header: string;
56
- readonly value: string;
57
- }
58
- /**
59
- * The extraction order — matcher.js:28-43: every HMAC header first
60
- * (an HMAC proof is stronger than a bearer secret, so it must win
61
- * when a sender supplies both), then `Authorization: Bearer <secret>`
62
- * (reported under header 'authorization'), then the plain token
63
- * headers. First PRESENT header wins — an empty value reads as
64
- * absent. Null when nothing proves anything.
65
- */
66
- export declare function extractSignature(headers: FlatHeaders): ExtractedSignature | null;
67
- /** The HMAC effect: hex digest of rawBody keyed by secret. The host wraps node:crypto's createHmac. */
68
- export type HmacHexPort = (algorithm: string, secret: string, rawBody: string) => string;
69
- /**
70
- * matcher.js:48-50 — the expected proof is `<algorithm>=<hex>`,
71
- * sha256 unless the caller says otherwise (verification picks sha1
72
- * only when the presented value announces it — GitHub's legacy
73
- * x-hub-signature).
74
- */
75
- export declare function computeSignature(secret: string, rawBody: string, hmacHex: HmacHexPort, algorithm?: string): string;
76
- /**
77
- * matcher.js:122-128 — the human-readable source label, first
78
- * recognized marker wins in this order: github → stripe → linear →
79
- * gitlab → 'external'.
80
- */
81
- export declare function pickSourceLabel(headers: FlatHeaders): 'github' | 'stripe' | 'linear' | 'gitlab' | 'external';
82
- /**
83
- * The 11 headers worth handing to the agent run context —
84
- * matcher.js:133-145. Note the deliberate asymmetry with
85
- * STORED_HEADERS: secrets used only for admission (authorization,
86
- * x-amalgm-webhook-secret, x-webhook-secret) are stored for
87
- * re-verification but NOT passed through to agent context — except
88
- * x-gitlab-token, which GitLab overloads as both auth and event
89
- * metadata.
90
- */
91
- export declare const PASSTHROUGH_HEADERS: readonly ["x-github-event", "x-github-delivery", "x-hub-signature-256", "x-hub-signature", "stripe-signature", "x-webhook-signature", "content-type", "x-linear-event", "x-linear-signature", "x-gitlab-event", "x-gitlab-token"];
92
- /** matcher.js:147-151 — project the passthrough subset, preserving list order. */
93
- export declare function collectPassthroughHeaders(headers: FlatHeaders): Record<string, string>;
94
- //# sourceMappingURL=ingress.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ingress.d.ts","sourceRoot":"","sources":["../../src/transport/ingress.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAM7C,kGAAkG;AAClG,eAAO,MAAM,oBAAoB,QAAkB,CAAC;AAEpD,8HAA8H;AAC9H,eAAO,MAAM,yBAAyB;;;CAG5B,CAAC;AAEX;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,CAkBpC,CAAC;AAEZ;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAS7F;AAED,+GAA+G;AAC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AC,MAAM,EAAE,MAAM,CAAC,CAOtF"}
@@ -1,171 +0,0 @@
1
- /**
2
- * Event-rail ingress — the pipe half of the webhook rail. Success at
3
- * this layer means exactly one thing: the immutable envelope (raw
4
- * body + allowlisted headers) is durably queued and acknowledged.
5
- * What a delivery TRIGGERS — the automation fan-out below
6
- * events/processor.js:119 — is product logic and deliberately not
7
- * here: the pipe stores and acknowledges the mail, it never reads it
8
- * (axiom 3). The signature laws live at this layer because verifying
9
- * WHO sent a payload is admission, not interpretation.
10
- *
11
- * Ported from amalgm-mcp/events/ingress.js (receipt contract) and
12
- * events/matcher.js (signature laws — already pure in the engine).
13
- */
14
- // ---------------------------------------------------------------------------
15
- // Receipt contract — events/ingress.js
16
- // ---------------------------------------------------------------------------
17
- /** ingress.js:12 — the body cap. Counted over raw bytes as they stream in, not after assembly. */
18
- export const MAX_EVENT_BODY_BYTES = 2 * 1024 * 1024;
19
- /** The over-limit rejection — ingress.js:50-53 surfaced through the generic error path (:80): status + byte-exact message. */
20
- export const EVENT_BODY_LIMIT_EXCEEDED = {
21
- status: 413,
22
- message: `Event body exceeds ${MAX_EVENT_BODY_BYTES} bytes`,
23
- };
24
- /**
25
- * The 17-header storage allowlist — ingress.js:13-31. Everything else
26
- * is dropped BEFORE the envelope is persisted: the envelope is
27
- * immutable and replayed, so an unlisted header stored today is a
28
- * secret leaked forever. The list is exactly: routing identity
29
- * (x-amalgm-*), each supported sender's event/delivery markers, and
30
- * every signature/secret header the matcher may need to re-verify.
31
- */
32
- export const STORED_HEADERS = new Set([
33
- 'authorization',
34
- 'content-type',
35
- 'stripe-signature',
36
- 'x-amalgm-delivery-id',
37
- 'x-amalgm-event',
38
- 'x-amalgm-source',
39
- 'x-amalgm-webhook-secret',
40
- 'x-github-delivery',
41
- 'x-github-event',
42
- 'x-gitlab-event',
43
- 'x-gitlab-token',
44
- 'x-hub-signature',
45
- 'x-hub-signature-256',
46
- 'x-linear-event',
47
- 'x-linear-signature',
48
- 'x-webhook-secret',
49
- 'x-webhook-signature',
50
- ]);
51
- /**
52
- * ingress.js:33-42 — filter to the allowlist, lowercase the names,
53
- * join repeated values with ', ', stringify the rest. The result is
54
- * the envelope's header record — and the flattened shape every
55
- * signature function below reads.
56
- */
57
- export function storedHeaders(headers) {
58
- const result = {};
59
- for (const [key, value] of Object.entries(headers || {})) {
60
- const normalized = key.toLowerCase();
61
- if (!STORED_HEADERS.has(normalized))
62
- continue;
63
- if (Array.isArray(value))
64
- result[normalized] = value.join(', ');
65
- else if (value != null)
66
- result[normalized] = String(value);
67
- }
68
- return result;
69
- }
70
- /** The receipt acknowledgment — ingress.js:73-78: 202, because acceptance is durable-queued, not processed. */
71
- export const EVENT_ACCEPTED_STATUS = 202;
72
- export function eventAcceptedBody(deliveryId, status) {
73
- return { ok: true, accepted: true, deliveryId, status };
74
- }
75
- /** matcher.js:13-17 — HMAC proof headers, in precedence order (generic first, then GitHub's sha256, then legacy sha1). */
76
- export const HMAC_SIGNATURE_HEADERS = [
77
- 'x-webhook-signature',
78
- 'x-hub-signature-256',
79
- 'x-hub-signature',
80
- ];
81
- /** matcher.js:19-23 — plain shared-secret headers, in precedence order (ours, generic, GitLab's). */
82
- export const TOKEN_HEADERS = [
83
- 'x-amalgm-webhook-secret',
84
- 'x-webhook-secret',
85
- 'x-gitlab-token',
86
- ];
87
- /**
88
- * The extraction order — matcher.js:28-43: every HMAC header first
89
- * (an HMAC proof is stronger than a bearer secret, so it must win
90
- * when a sender supplies both), then `Authorization: Bearer <secret>`
91
- * (reported under header 'authorization'), then the plain token
92
- * headers. First PRESENT header wins — an empty value reads as
93
- * absent. Null when nothing proves anything.
94
- */
95
- export function extractSignature(headers) {
96
- for (const header of HMAC_SIGNATURE_HEADERS) {
97
- const value = headers[header];
98
- if (value)
99
- return { header, value };
100
- }
101
- const authorization = headers['authorization'];
102
- if (typeof authorization === 'string') {
103
- const match = authorization.match(/^Bearer\s+(.+)$/i);
104
- if (match)
105
- return { header: 'authorization', value: match[1] ?? '' };
106
- }
107
- for (const header of TOKEN_HEADERS) {
108
- const value = headers[header];
109
- if (value)
110
- return { header, value };
111
- }
112
- return null;
113
- }
114
- /**
115
- * matcher.js:48-50 — the expected proof is `<algorithm>=<hex>`,
116
- * sha256 unless the caller says otherwise (verification picks sha1
117
- * only when the presented value announces it — GitHub's legacy
118
- * x-hub-signature).
119
- */
120
- export function computeSignature(secret, rawBody, hmacHex, algorithm = 'sha256') {
121
- return `${algorithm}=` + hmacHex(algorithm, secret, rawBody);
122
- }
123
- /**
124
- * matcher.js:122-128 — the human-readable source label, first
125
- * recognized marker wins in this order: github → stripe → linear →
126
- * gitlab → 'external'.
127
- */
128
- export function pickSourceLabel(headers) {
129
- if (headers['x-github-event'])
130
- return 'github';
131
- if (headers['stripe-signature'])
132
- return 'stripe';
133
- if (headers['x-linear-event'])
134
- return 'linear';
135
- if (headers['x-gitlab-event'])
136
- return 'gitlab';
137
- return 'external';
138
- }
139
- /**
140
- * The 11 headers worth handing to the agent run context —
141
- * matcher.js:133-145. Note the deliberate asymmetry with
142
- * STORED_HEADERS: secrets used only for admission (authorization,
143
- * x-amalgm-webhook-secret, x-webhook-secret) are stored for
144
- * re-verification but NOT passed through to agent context — except
145
- * x-gitlab-token, which GitLab overloads as both auth and event
146
- * metadata.
147
- */
148
- export const PASSTHROUGH_HEADERS = [
149
- 'x-github-event',
150
- 'x-github-delivery',
151
- 'x-hub-signature-256',
152
- 'x-hub-signature',
153
- 'stripe-signature',
154
- 'x-webhook-signature',
155
- 'content-type',
156
- 'x-linear-event',
157
- 'x-linear-signature',
158
- 'x-gitlab-event',
159
- 'x-gitlab-token',
160
- ];
161
- /** matcher.js:147-151 — project the passthrough subset, preserving list order. */
162
- export function collectPassthroughHeaders(headers) {
163
- const out = {};
164
- for (const header of PASSTHROUGH_HEADERS) {
165
- const value = headers[header];
166
- if (value)
167
- out[header] = value;
168
- }
169
- return out;
170
- }
171
- //# sourceMappingURL=ingress.js.map
@@ -1 +0,0 @@
1
- {"version":3,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