@jini-ai/daemon 0.5.0 → 0.5.2

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/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- ## Unreleased
1
+ ## 0.5.2 — 2026-10-06
2
+
3
+ - No slow-run notice while a delegated tool waits on a surface: the first `emitSurface` of a call suspends the notice and the call's end resumes it. Suspensions are counted, so with two calls in flight the first to finish does not re-arm the notice over the other's open form; `resume()` drops suspensions left by an ended run.
4
+
5
+ ## 0.5.1 — 2026-10-05
6
+
7
+ - The `@jini-ai/db` peer range is `^0.2.0 || ^0.3.0` (daemon uses only db's kernel and store entries, which 0.3.0 leaves unchanged), so a host on db 0.3.0 installs without a peer conflict.
8
+ - Internal `@jini-ai/*` runtime dependencies are caret ranges (`workspace:^`) instead of exact pins.
9
+
10
+ ## Unreleased (shipped in 0.5.0)
2
11
 
3
12
  ### Fixes
4
13
 
@@ -109,9 +109,19 @@ export function createDelegatedToolBridge(options) {
109
109
  * screen, with no call left to answer it.
110
110
  */
111
111
  let settled = false;
112
+ // A handler emits a surface mid-call because it is about to WAIT on the human (a form, a card).
113
+ // Nothing reaches the run's event stream while they answer, so the slow-run watchdog would read
114
+ // that silence as a stall and post "Still working…" over an open form — which then reappears
115
+ // once the form is answered. Suspended from the first surface until the call settles (the
116
+ // `finally` below); the watchdog re-arms then, so a genuine stall afterwards is still caught.
117
+ let slowRunSuspended = false;
112
118
  const emitSurface = async (emission) => {
113
119
  if (settled)
114
120
  throw new Error(`emitSurface: tool call ${toolUseId} has already completed`);
121
+ if (!slowRunSuspended) {
122
+ slowRunSuspended = true;
123
+ lifecycle.suspendSlowRunNotice({ runId: runId });
124
+ }
115
125
  // Cast because `RunAgentPayload` is a closed union and `channel` is deliberately an open
116
126
  // string — a seam that only accepts channels this file already knows about is not a
117
127
  // channel-neutral seam. This mirrors `@jini-ai/protocol`'s own posture of typing each
@@ -202,6 +212,8 @@ export function createDelegatedToolBridge(options) {
202
212
  finally {
203
213
  unsubscribeCancel();
204
214
  invocation.signal?.removeEventListener('abort', abortFromTransport);
215
+ if (slowRunSuspended)
216
+ lifecycle.resumeSlowRunNotice({ runId: runId });
205
217
  }
206
218
  }
207
219
  return { execute };
@@ -106,6 +106,7 @@ export interface RunLifecycle {
106
106
  * on a run that never actually stalled. A driver that knows exactly why a run is quiet must say so
107
107
  * rather than leaving the watchdog to guess from silence alone. No-op if `runId` is unknown,
108
108
  * already terminal, or the slow-run notice is disabled kernel-wide (`slowRunThresholdMs: null`).
109
+ * Pairs nest: the notice stays suspended until every open suspension has been resumed.
109
110
  */
110
111
  suspendSlowRunNotice(args: {
111
112
  readonly runId: string;
@@ -102,6 +102,7 @@ function rehydratedRunRecord(runId, entries) {
102
102
  terminalEndEntry: endEntry,
103
103
  watchdog: undefined,
104
104
  slowRunWatchdog: undefined,
105
+ slowRunSuspensions: 0,
105
106
  startPromise: undefined,
106
107
  finishPromise: undefined,
107
108
  retentionTimer: undefined,
@@ -290,6 +291,7 @@ function buildNewRunRecord(startInput, runId, now) {
290
291
  terminalEndEntry: undefined,
291
292
  watchdog: undefined,
292
293
  slowRunWatchdog: undefined,
294
+ slowRunSuspensions: 0,
293
295
  startPromise: undefined,
294
296
  finishPromise: undefined,
295
297
  retentionTimer: undefined,
@@ -748,7 +750,9 @@ export function createRunLifecycle(requiredArgs, optionalArgs = {}) {
748
750
  // freshly-started one does. Without this, `finish()`'s `record.slowRunWatchdog?.cancel()` (which
749
751
  // never fires again on its own — the underlying timer is one-shot) left the notice permanently
750
752
  // dark for the rest of a resumed run's life, silently disabling a feature the run is otherwise
751
- // still eligible for.
753
+ // still eligible for. Suspensions left open when the run ended can never be resumed (resume is a
754
+ // no-op on a terminal run), so they are dropped here or they would keep the notice dark forever.
755
+ record.slowRunSuspensions = 0;
752
756
  armSlowRunWatchdogIfConfigured({ record: record, timeoutMs: slowRunThresholdMs, onTimeout: () => {
753
757
  void handleSlowRunNotice(runId);
754
758
  } });
@@ -762,12 +766,18 @@ export function createRunLifecycle(requiredArgs, optionalArgs = {}) {
762
766
  const record = runs.get(runId);
763
767
  if (!record || isTerminalRunState({ state: record.status.state }))
764
768
  return;
769
+ record.slowRunSuspensions += 1;
765
770
  record.slowRunWatchdog?.cancel({});
766
771
  },
767
772
  resumeSlowRunNotice({ runId }) {
768
773
  const record = runs.get(runId);
769
774
  if (!record || isTerminalRunState({ state: record.status.state }))
770
775
  return;
776
+ // Re-arm only when the LAST open suspension closes (see `RunRecord.slowRunSuspensions`).
777
+ if (record.slowRunSuspensions > 0)
778
+ record.slowRunSuspensions -= 1;
779
+ if (record.slowRunSuspensions > 0)
780
+ return;
771
781
  // Suspension cancels permanently. Resuming must create a new window, never revive that handle.
772
782
  record.slowRunWatchdog?.cancel({});
773
783
  armSlowRunWatchdogIfConfigured({ record, timeoutMs: slowRunThresholdMs, onTimeout: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/daemon",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "The stateful agent daemon runtime: run lifecycle, durable event-log port, the tool-execution boundary, agent executor, terminal sessions, and routines.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -116,10 +116,10 @@
116
116
  "registry": "https://registry.npmjs.org"
117
117
  },
118
118
  "dependencies": {
119
- "@jini-ai/core": "0.4.0",
120
- "@jini-ai/agent-runtime": "0.4.0",
121
- "@jini-ai/protocol": "0.4.0",
122
- "@jini-ai/platform": "0.5.0"
119
+ "@jini-ai/agent-runtime": "^0.4.0",
120
+ "@jini-ai/core": "^0.4.1",
121
+ "@jini-ai/platform": "^0.5.1",
122
+ "@jini-ai/protocol": "^0.4.0"
123
123
  },
124
124
  "devDependencies": {
125
125
  "@vitest/coverage-v8": "^2.1.9",
@@ -132,13 +132,13 @@
132
132
  "@types/pg": "8.23.1",
133
133
  "express": "^4.21.0",
134
134
  "@types/express": "^4.17.21",
135
- "@jini-ai/db": "0.2.0",
135
+ "@jini-ai/db": "0.3.0",
136
136
  "@jini-ai/http-kit": "0.4.0",
137
- "@jini-ai/chat": "0.5.0"
137
+ "@jini-ai/chat": "0.5.3"
138
138
  },
139
139
  "peerDependencies": {
140
140
  "node-pty": "^1.1.0",
141
- "@jini-ai/db": "^0.2.0",
141
+ "@jini-ai/db": "^0.2.0 || ^0.3.0",
142
142
  "kysely": "^0.29.6",
143
143
  "better-sqlite3": "^13.0.0",
144
144
  "@electric-sql/pglite": "0.5.8",
@@ -1,14 +0,0 @@
1
- /**
2
- * @module artifacts
3
- *
4
- * The generic artifact-store kernel port, ported from OD's
5
- * `apps/daemon/src/artifacts/` (6 files). See `source-map.md` for full
6
- * per-file provenance and the design decisions behind each generalization.
7
- */
8
- export * from './manifest.js';
9
- export * from './store.js';
10
- export * from './publication-guard.js';
11
- export * from './runtime-compat.js';
12
- export * from './stub-guard.js';
13
- export * from './text-suppression.js';
14
- //# sourceMappingURL=index.d.ts.map
@@ -1,14 +0,0 @@
1
- /**
2
- * @module artifacts
3
- *
4
- * The generic artifact-store kernel port, ported from OD's
5
- * `apps/daemon/src/artifacts/` (6 files). See `source-map.md` for full
6
- * per-file provenance and the design decisions behind each generalization.
7
- */
8
- export * from './manifest.js';
9
- export * from './store.js';
10
- export * from './publication-guard.js';
11
- export * from './runtime-compat.js';
12
- export * from './stub-guard.js';
13
- export * from './text-suppression.js';
14
- //# sourceMappingURL=index.js.map
@@ -1,90 +0,0 @@
1
- /**
2
- * @module artifacts/manifest
3
- *
4
- * Generic artifact-manifest validation: bounded-length string checks, path-
5
- * traversal rejection on `entry`/`primary`/`supportingFiles`, a JSON-size
6
- * cap on `metadata`, and version/timestamp stamping. Ported from OD's
7
- * `apps/daemon/src/artifacts/manifest.ts`.
8
- *
9
- * De-branded: the origin's `kind`/`renderer` fields were validated against
10
- * hardcoded `ALLOWED_KINDS`/`ALLOWED_RENDERERS` sets that bake in OD's own
11
- * artifact taxonomy — including a literal `'design-system'` kind, OD's own
12
- * product concept, not a generic engine noun. Both sets are now a
13
- * caller-supplied {@link ArtifactManifestTaxonomy} instead of module
14
- * constants — a host (like an OD adapter) supplies its own kind/renderer/
15
- * export vocabulary; the validation *mechanism* (bounded strings, traversal
16
- * rejection, size caps, version stamping) is what this module owns. `status`
17
- * (`'streaming' | 'complete' | 'error'`) is kept as a fixed literal union —
18
- * that's a generic artifact-lifecycle concept, not a product taxonomy.
19
- */
20
- export type ArtifactStatus = 'streaming' | 'complete' | 'error';
21
- /**
22
- * A host's own artifact-kind/renderer/export vocabulary. The engine treats
23
- * every value as an opaque string it only bounds-checks and validates
24
- * membership against — it assigns no meaning to any particular kind name.
25
- */
26
- export interface ArtifactManifestTaxonomy {
27
- readonly allowedKinds: ReadonlySet<string>;
28
- readonly allowedRenderers: ReadonlySet<string>;
29
- readonly allowedExports: ReadonlySet<string>;
30
- }
31
- /** A taxonomy that accepts nothing — forces a host to supply its own before any manifest can validate. */
32
- export declare const emptyArtifactManifestTaxonomy: ArtifactManifestTaxonomy;
33
- export interface ArtifactManifest {
34
- readonly version: number;
35
- readonly kind: string;
36
- readonly title: string;
37
- readonly entry: string;
38
- readonly renderer: string;
39
- readonly status: ArtifactStatus;
40
- readonly exports: readonly string[];
41
- readonly primary?: string | true;
42
- readonly supportingFiles?: readonly string[];
43
- readonly createdAt: string;
44
- readonly updatedAt: string;
45
- /** Generic "what produced or relates to this artifact" reference (OD: a skill id). Opaque to the engine. */
46
- readonly sourceContextId?: string;
47
- readonly metadata?: Readonly<Record<string, unknown>>;
48
- }
49
- type JsonRecord = Record<string, unknown>;
50
- type ValidationResult = {
51
- ok: true;
52
- value: ArtifactManifest | null;
53
- } | {
54
- ok: false;
55
- error: string;
56
- };
57
- export interface ValidateManifestOptions {
58
- /** Keep an existing `updatedAt` instead of stamping the current time (used when re-parsing a persisted manifest). */
59
- preserveUpdatedAt?: boolean;
60
- }
61
- /**
62
- * Validates a freeform manifest payload against `taxonomy`, returning a
63
- * sanitized, stamped {@link ArtifactManifest} on success. `manifest == null`
64
- * is a valid "no manifest supplied" outcome (`{ ok: true, value: null }`) —
65
- * callers that require a manifest check for `value === null` themselves
66
- * (see `store.ts`'s `resolveArtifactManifest`).
67
- */
68
- export declare function validateArtifactManifestInput(manifest: unknown, entry: unknown, taxonomy: ArtifactManifestTaxonomy, options?: ValidateManifestOptions): ValidationResult;
69
- /** Normalizes a validated manifest payload into the stamped, canonical {@link ArtifactManifest} shape. */
70
- export declare function sanitizeManifest(manifest: JsonRecord, entry: string, options?: ValidateManifestOptions): ArtifactManifest;
71
- /**
72
- * Re-validates a manifest read back from persistence (e.g. a sidecar file),
73
- * preserving its original `updatedAt`. Returns `null` on any validation
74
- * failure or version mismatch/parse error rather than throwing — a corrupt
75
- * or stale sidecar should degrade to "no manifest", not crash the reader.
76
- */
77
- export declare function parsePersistedManifest(raw: string, fallbackEntry: string, taxonomy: ArtifactManifestTaxonomy): ArtifactManifest | null;
78
- /**
79
- * Injectable seam for a host's own "what kind of artifact is this path"
80
- * heuristic (OD: extension-based HTML/deck/markdown/svg inference). The
81
- * engine has no default beyond "infer nothing" — see
82
- * {@link noopManifestInferrer} — a host wires in its own file-kind
83
- * classification (per the task brief: "keep OD's file-kind classification
84
- * as adapter").
85
- */
86
- export type ManifestInferrer = (entry: string) => Partial<ArtifactManifest> | null;
87
- /** Infers nothing — every create call must supply an explicit manifest. */
88
- export declare const noopManifestInferrer: ManifestInferrer;
89
- export {};
90
- //# sourceMappingURL=manifest.d.ts.map
@@ -1,229 +0,0 @@
1
- /**
2
- * @module artifacts/manifest
3
- *
4
- * Generic artifact-manifest validation: bounded-length string checks, path-
5
- * traversal rejection on `entry`/`primary`/`supportingFiles`, a JSON-size
6
- * cap on `metadata`, and version/timestamp stamping. Ported from OD's
7
- * `apps/daemon/src/artifacts/manifest.ts`.
8
- *
9
- * De-branded: the origin's `kind`/`renderer` fields were validated against
10
- * hardcoded `ALLOWED_KINDS`/`ALLOWED_RENDERERS` sets that bake in OD's own
11
- * artifact taxonomy — including a literal `'design-system'` kind, OD's own
12
- * product concept, not a generic engine noun. Both sets are now a
13
- * caller-supplied {@link ArtifactManifestTaxonomy} instead of module
14
- * constants — a host (like an OD adapter) supplies its own kind/renderer/
15
- * export vocabulary; the validation *mechanism* (bounded strings, traversal
16
- * rejection, size caps, version stamping) is what this module owns. `status`
17
- * (`'streaming' | 'complete' | 'error'`) is kept as a fixed literal union —
18
- * that's a generic artifact-lifecycle concept, not a product taxonomy.
19
- */
20
- const MANIFEST_VERSION = 1;
21
- const MAX_TITLE_LENGTH = 200;
22
- const MAX_SOURCE_CONTEXT_ID_LENGTH = 128;
23
- const MAX_SUPPORTING_FILE_LENGTH = 260;
24
- const MAX_SUPPORTING_FILES = 128;
25
- const MAX_METADATA_BYTES = 16 * 1024;
26
- const ALLOWED_STATUS = new Set(['streaming', 'complete', 'error']);
27
- /** A taxonomy that accepts nothing — forces a host to supply its own before any manifest can validate. */
28
- export const emptyArtifactManifestTaxonomy = {
29
- allowedKinds: new Set(),
30
- allowedRenderers: new Set(),
31
- allowedExports: new Set(),
32
- };
33
- function isPlainObject(value) {
34
- if (!value || typeof value !== 'object' || Array.isArray(value))
35
- return false;
36
- const proto = Object.getPrototypeOf(value);
37
- return proto === Object.prototype || proto === null;
38
- }
39
- function validateBoundedString(value, field, maxLen, { allowEmpty = false } = {}) {
40
- if (typeof value !== 'string')
41
- return `${field} must be a string`;
42
- if (!allowEmpty && value.length === 0)
43
- return `${field} is required`;
44
- if (value.length > maxLen)
45
- return `${field} exceeds max length (${maxLen})`;
46
- return null;
47
- }
48
- function validateSupportingPath(value) {
49
- if (typeof value !== 'string')
50
- return 'supportingFiles entries must be strings';
51
- if (value.length === 0)
52
- return 'supportingFiles entries cannot be empty';
53
- if (value.length > MAX_SUPPORTING_FILE_LENGTH) {
54
- return `supportingFiles entries exceed max length (${MAX_SUPPORTING_FILE_LENGTH})`;
55
- }
56
- if (/^[A-Za-z]:/.test(value) || value.startsWith('/')) {
57
- return 'supportingFiles cannot contain absolute paths';
58
- }
59
- if (value.includes('\u0000'))
60
- return 'supportingFiles cannot contain null bytes';
61
- const normalized = value.replace(/\\/g, '/');
62
- if (normalized.includes('..'))
63
- return 'supportingFiles cannot contain traversal segments';
64
- const parts = normalized.split('/').filter(Boolean);
65
- if (parts.length === 0 || parts.some((p) => p === '.' || p === '..')) {
66
- return 'supportingFiles cannot contain traversal segments';
67
- }
68
- return null;
69
- }
70
- /**
71
- * Validates a freeform manifest payload against `taxonomy`, returning a
72
- * sanitized, stamped {@link ArtifactManifest} on success. `manifest == null`
73
- * is a valid "no manifest supplied" outcome (`{ ok: true, value: null }`) —
74
- * callers that require a manifest check for `value === null` themselves
75
- * (see `store.ts`'s `resolveArtifactManifest`).
76
- */
77
- export function validateArtifactManifestInput(manifest, entry, taxonomy, options = {}) {
78
- if (manifest == null)
79
- return { ok: true, value: null };
80
- if (!isPlainObject(manifest)) {
81
- return { ok: false, error: 'artifactManifest must be an object' };
82
- }
83
- const kindErr = validateBoundedString(manifest.kind, 'artifactManifest.kind', 64);
84
- if (kindErr)
85
- return { ok: false, error: kindErr };
86
- // Cast, not a runtime guard: validateBoundedString's first check is
87
- // `typeof value !== 'string'`, which already returned above for any
88
- // non-string `kind` — this only narrows the type for `taxonomy.allowedKinds.has`.
89
- if (!taxonomy.allowedKinds.has(manifest.kind)) {
90
- return { ok: false, error: 'artifactManifest.kind is not allowed' };
91
- }
92
- const rendererErr = validateBoundedString(manifest.renderer, 'artifactManifest.renderer', 64);
93
- if (rendererErr)
94
- return { ok: false, error: rendererErr };
95
- // Same reasoning as `kind` above.
96
- if (!taxonomy.allowedRenderers.has(manifest.renderer)) {
97
- return { ok: false, error: 'artifactManifest.renderer is not allowed' };
98
- }
99
- if (!Array.isArray(manifest.exports) || manifest.exports.length === 0) {
100
- return { ok: false, error: 'artifactManifest.exports must be a non-empty array' };
101
- }
102
- for (const exp of manifest.exports) {
103
- if (typeof exp !== 'string') {
104
- return { ok: false, error: 'artifactManifest.exports must contain strings' };
105
- }
106
- if (!taxonomy.allowedExports.has(exp)) {
107
- return { ok: false, error: `artifactManifest.exports contains unsupported value: ${exp}` };
108
- }
109
- }
110
- if (manifest.status !== undefined) {
111
- if (typeof manifest.status !== 'string') {
112
- return { ok: false, error: 'artifactManifest.status must be a string' };
113
- }
114
- if (!ALLOWED_STATUS.has(manifest.status)) {
115
- return { ok: false, error: 'artifactManifest.status is not allowed' };
116
- }
117
- }
118
- if (manifest.primary !== undefined) {
119
- if (manifest.primary !== true) {
120
- const primaryErr = validateSupportingPath(manifest.primary);
121
- if (primaryErr)
122
- return { ok: false, error: `artifactManifest.primary ${primaryErr}` };
123
- }
124
- }
125
- if (manifest.supportingFiles !== undefined) {
126
- if (!Array.isArray(manifest.supportingFiles)) {
127
- return { ok: false, error: 'artifactManifest.supportingFiles must be an array' };
128
- }
129
- if (manifest.supportingFiles.length > MAX_SUPPORTING_FILES) {
130
- return {
131
- ok: false,
132
- error: `artifactManifest.supportingFiles exceeds max items (${MAX_SUPPORTING_FILES})`,
133
- };
134
- }
135
- for (const rel of manifest.supportingFiles) {
136
- const relErr = validateSupportingPath(rel);
137
- if (relErr)
138
- return { ok: false, error: relErr };
139
- }
140
- }
141
- if (manifest.title !== undefined) {
142
- const titleErr = validateBoundedString(manifest.title, 'artifactManifest.title', MAX_TITLE_LENGTH, {
143
- allowEmpty: false,
144
- });
145
- if (titleErr)
146
- return { ok: false, error: titleErr };
147
- }
148
- if (manifest.sourceContextId !== undefined) {
149
- const sourceErr = validateBoundedString(manifest.sourceContextId, 'artifactManifest.sourceContextId', MAX_SOURCE_CONTEXT_ID_LENGTH, { allowEmpty: true });
150
- if (sourceErr)
151
- return { ok: false, error: sourceErr };
152
- }
153
- if (manifest.metadata !== undefined) {
154
- if (!isPlainObject(manifest.metadata)) {
155
- return { ok: false, error: 'artifactManifest.metadata must be a plain object' };
156
- }
157
- // JSON.stringify always returns a string (never undefined) when called
158
- // directly on a plain object — undefined-return only happens when the
159
- // top-level argument itself is a function/symbol/undefined, which
160
- // isPlainObject above already rejected.
161
- const serialized = JSON.stringify(manifest.metadata);
162
- if (Buffer.byteLength(serialized, 'utf8') > MAX_METADATA_BYTES) {
163
- return {
164
- ok: false,
165
- error: `artifactManifest.metadata exceeds max size (${MAX_METADATA_BYTES} bytes)`,
166
- };
167
- }
168
- }
169
- const manifestEntry = typeof manifest.entry === 'string' && manifest.entry.trim() ? manifest.entry.trim() : entry;
170
- const entryErr = validateSupportingPath(manifestEntry);
171
- if (entryErr) {
172
- return { ok: false, error: `artifactManifest.entry ${entryErr}` };
173
- }
174
- const safeEntry = manifestEntry.replace(/\\/g, '/');
175
- return { ok: true, value: sanitizeManifest(manifest, safeEntry, options) };
176
- }
177
- /** Normalizes a validated manifest payload into the stamped, canonical {@link ArtifactManifest} shape. */
178
- export function sanitizeManifest(manifest, entry, options = {}) {
179
- const now = new Date().toISOString();
180
- const supportingFiles = Array.isArray(manifest.supportingFiles)
181
- ? manifest.supportingFiles.map((x) => String(x).replace(/\\/g, '/'))
182
- : undefined;
183
- const primary = manifest.primary === true
184
- ? true
185
- : typeof manifest.primary === 'string'
186
- ? manifest.primary.replace(/\\/g, '/')
187
- : undefined;
188
- return {
189
- version: MANIFEST_VERSION,
190
- kind: manifest.kind,
191
- title: manifest.title || entry,
192
- entry,
193
- renderer: manifest.renderer,
194
- status: typeof manifest.status === 'string' && ALLOWED_STATUS.has(manifest.status)
195
- ? manifest.status
196
- : 'complete',
197
- exports: manifest.exports,
198
- ...(primary !== undefined ? { primary } : {}),
199
- ...(supportingFiles !== undefined ? { supportingFiles } : {}),
200
- createdAt: typeof manifest.createdAt === 'string' ? manifest.createdAt : now,
201
- updatedAt: options.preserveUpdatedAt && typeof manifest.updatedAt === 'string'
202
- ? manifest.updatedAt
203
- : now,
204
- ...(manifest.sourceContextId !== undefined ? { sourceContextId: manifest.sourceContextId } : {}),
205
- ...(manifest.metadata !== undefined ? { metadata: manifest.metadata } : {}),
206
- };
207
- }
208
- /**
209
- * Re-validates a manifest read back from persistence (e.g. a sidecar file),
210
- * preserving its original `updatedAt`. Returns `null` on any validation
211
- * failure or version mismatch/parse error rather than throwing — a corrupt
212
- * or stale sidecar should degrade to "no manifest", not crash the reader.
213
- */
214
- export function parsePersistedManifest(raw, fallbackEntry, taxonomy) {
215
- try {
216
- const parsed = JSON.parse(raw);
217
- if (!isPlainObject(parsed) || parsed.version !== MANIFEST_VERSION)
218
- return null;
219
- const entry = typeof parsed.entry === 'string' && parsed.entry ? parsed.entry : fallbackEntry;
220
- const result = validateArtifactManifestInput(parsed, entry, taxonomy, { preserveUpdatedAt: true });
221
- return result.ok ? result.value : null;
222
- }
223
- catch {
224
- return null;
225
- }
226
- }
227
- /** Infers nothing — every create call must supply an explicit manifest. */
228
- export const noopManifestInferrer = () => null;
229
- //# sourceMappingURL=manifest.js.map
@@ -1,28 +0,0 @@
1
- export declare const ARTIFACT_PUBLICATION_BLOCKED_CODE: "ARTIFACT_PUBLICATION_BLOCKED";
2
- export interface PublicationGuardConfig {
3
- /** Artifact kinds this guard scans. A kind not in this set is never blocked, whatever its content. */
4
- readonly guardedKinds: ReadonlySet<string>;
5
- /** Substrings that mark an artifact as containing an unresolved placeholder. Matching is case-sensitive. */
6
- readonly blockedPlaceholders: readonly string[];
7
- }
8
- /** A guard that blocks nothing — no guarded kinds, no placeholder markers configured. */
9
- export declare const emptyPublicationGuardConfig: PublicationGuardConfig;
10
- export declare class ArtifactPublicationBlockedError extends Error {
11
- readonly code: "ARTIFACT_PUBLICATION_BLOCKED";
12
- readonly placeholders: readonly string[];
13
- constructor(placeholders: readonly string[]);
14
- }
15
- export declare function isPublicationGuardedKind(kind: unknown, config: PublicationGuardConfig): boolean;
16
- /** Returns every configured placeholder marker found in `value`'s stringified content, in declaration order. */
17
- export declare function findBlockedPlaceholders(value: unknown, config: PublicationGuardConfig): string[];
18
- export declare function shouldBlockPublication(value: unknown, config: PublicationGuardConfig): boolean;
19
- export declare function buildArtifactPublicationBlockedMessage(placeholders: readonly string[]): string;
20
- /**
21
- * Throws {@link ArtifactPublicationBlockedError} when `value` (for a
22
- * `kind` in `config.guardedKinds`) contains any of `config.blockedPlaceholders`.
23
- * No-ops for a kind outside `config.guardedKinds` — a guard scoped to
24
- * user-facing rendered documents shouldn't reject content in other kinds
25
- * where the same substrings could be legitimate.
26
- */
27
- export declare function assertArtifactPublicationAllowed(kind: unknown, value: unknown, config: PublicationGuardConfig): void;
28
- //# sourceMappingURL=publication-guard.d.ts.map
@@ -1,77 +0,0 @@
1
- /**
2
- * @module artifacts/publication-guard
3
- *
4
- * A pre-publish content guard: blocks an artifact write when its body
5
- * contains a caller-declared "unresolved placeholder" marker, scoped to a
6
- * caller-declared set of guarded kinds. Ported from OD's
7
- * `apps/daemon/src/artifacts/publication-guard.ts`.
8
- *
9
- * De-branded: the origin hardcoded `UNRESOLVED_ARTIFACT_PLACEHOLDERS` — five
10
- * literal strings ("Name to confirm", "$X.XM", ...) lifted from one specific
11
- * bundled example template's pitch-deck fill-in-the-blank convention — and
12
- * `PUBLICATION_GUARDED_ARTIFACT_KINDS = {'html', 'deck'}`. Both are entirely
13
- * OD's own content, not a generic engine mechanism, so this module now takes
14
- * a caller-supplied {@link PublicationGuardConfig} (empty by default — a
15
- * guard that never blocks anything until a host configures it) instead of
16
- * baking in that one template's marker strings. The guard *mechanism*
17
- * (scan a guarded-kind body for any configured marker, throw before
18
- * publish) is what this module owns.
19
- */
20
- import { Buffer } from 'node:buffer';
21
- export const ARTIFACT_PUBLICATION_BLOCKED_CODE = 'ARTIFACT_PUBLICATION_BLOCKED';
22
- /** A guard that blocks nothing — no guarded kinds, no placeholder markers configured. */
23
- export const emptyPublicationGuardConfig = {
24
- guardedKinds: new Set(),
25
- blockedPlaceholders: [],
26
- };
27
- export class ArtifactPublicationBlockedError extends Error {
28
- code = ARTIFACT_PUBLICATION_BLOCKED_CODE;
29
- placeholders;
30
- constructor(placeholders) {
31
- super(buildArtifactPublicationBlockedMessage(placeholders));
32
- this.name = 'ArtifactPublicationBlockedError';
33
- this.placeholders = [...placeholders];
34
- }
35
- }
36
- export function isPublicationGuardedKind(kind, config) {
37
- return typeof kind === 'string' && config.guardedKinds.has(kind);
38
- }
39
- function stringifyArtifactContent(value) {
40
- if (typeof value === 'string')
41
- return value;
42
- if (Buffer.isBuffer(value))
43
- return value.toString('utf8');
44
- if (value instanceof Uint8Array)
45
- return Buffer.from(value).toString('utf8');
46
- return '';
47
- }
48
- /** Returns every configured placeholder marker found in `value`'s stringified content, in declaration order. */
49
- export function findBlockedPlaceholders(value, config) {
50
- const text = stringifyArtifactContent(value);
51
- if (!text)
52
- return [];
53
- return config.blockedPlaceholders.filter((placeholder) => text.includes(placeholder));
54
- }
55
- export function shouldBlockPublication(value, config) {
56
- return findBlockedPlaceholders(value, config).length > 0;
57
- }
58
- export function buildArtifactPublicationBlockedMessage(placeholders) {
59
- const list = placeholders.length > 0 ? placeholders.join(', ') : 'unknown placeholders';
60
- return `Artifact still contains unresolved placeholders: ${list}. Resolve them before publishing.`;
61
- }
62
- /**
63
- * Throws {@link ArtifactPublicationBlockedError} when `value` (for a
64
- * `kind` in `config.guardedKinds`) contains any of `config.blockedPlaceholders`.
65
- * No-ops for a kind outside `config.guardedKinds` — a guard scoped to
66
- * user-facing rendered documents shouldn't reject content in other kinds
67
- * where the same substrings could be legitimate.
68
- */
69
- export function assertArtifactPublicationAllowed(kind, value, config) {
70
- if (!isPublicationGuardedKind(kind, config))
71
- return;
72
- const placeholders = findBlockedPlaceholders(value, config);
73
- if (placeholders.length > 0) {
74
- throw new ArtifactPublicationBlockedError(placeholders);
75
- }
76
- }
77
- //# sourceMappingURL=publication-guard.js.map
@@ -1,37 +0,0 @@
1
- /**
2
- * @module artifacts/runtime-compat
3
- *
4
- * The runtime-compat injection seam: a hook that gets a chance to rewrite an
5
- * artifact's body before it's served, for CDN/library-loading quirks a host
6
- * knows about but the engine can't. Ported from OD's
7
- * `apps/daemon/src/artifacts/runtime-compat.ts`.
8
- *
9
- * De-branded: the origin, `normalizeArtifactRuntimeImports`, is entirely a
10
- * fix for one specific third-party CDN-bundle bug (the vanilla `dist/
11
- * motion.js` UMD script tag lacking React hooks, rewritten to `dist/
12
- * framer-motion.js`) that OD's own system prompt steers models toward
13
- * hitting. That rewrite rule is product/library-specific knowledge, not a
14
- * generic engine mechanism — per the task brief ("keep OD's specific logic
15
- * as adapter"), it is not ported. What *is* generic and kept is the
16
- * seam itself: a host may need to rewrite an artifact body for any number
17
- * of environment-specific reasons (a different CDN quirk, a different
18
- * runtime library entirely) before it reaches a renderer, so the engine
19
- * defines the hook type and a safe default (identity) rather than hardcode
20
- * any one library's fix.
21
- */
22
- /**
23
- * Rewrites an artifact body before it is served, keyed by the artifact's
24
- * file name (a host typically gates on file extension, as OD's origin did
25
- * with `.html`/`.htm`). Returns the body unchanged when no rewrite applies.
26
- */
27
- export type RuntimeCompatNormalizer = (name: string, body: unknown) => unknown;
28
- /** Applies no rewrite — returns `body` unchanged. Safe default until a host supplies its own normalizer(s). */
29
- export declare const noopRuntimeCompatNormalizer: RuntimeCompatNormalizer;
30
- /**
31
- * Composes several normalizers into one, applying each in order — the
32
- * output of one becomes the input to the next. Lets a host layer multiple
33
- * independent CDN/library fixes without each needing to know about the
34
- * others.
35
- */
36
- export declare function composeRuntimeCompatNormalizers(normalizers: readonly RuntimeCompatNormalizer[]): RuntimeCompatNormalizer;
37
- //# sourceMappingURL=runtime-compat.d.ts.map