@robota-sdk/agent-product 3.0.0-beta.100

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/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @robota-sdk/agent-product
2
+
3
+ The **product-assembly kernel** for the Robota SDK.
4
+
5
+ `assembleProduct(profile)` is a **pure, deterministic, IO-free fold** over an `IProductProfile` — the
6
+ composition mechanism a third party imports to build their OWN product on Robota's published runtime.
7
+ Product identity and its runtime settings are supplied by the host; an external repo can define its own profile.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @robota-sdk/agent-product
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { assembleProduct } from '@robota-sdk/agent-product';
19
+ import type { ICapabilityPack } from '@robota-sdk/agent-capability-pack';
20
+ import type { IProviderDefinition } from '@robota-sdk/agent-core';
21
+
22
+ declare const providerDefinitions: readonly IProviderDefinition[]; // e.g. agent-builtin-providers
23
+ declare const acmeJiraPack: ICapabilityPack;
24
+ declare const cwd: string;
25
+
26
+ const product = assembleProduct({
27
+ id: 'acme-assistant',
28
+ agentName: 'acme',
29
+ providerDefinitions,
30
+ // The SHELL resolves settings/env and passes the result in as data; the kernel constructs the
31
+ // provider from it. Omit `providerSettings` and pass a pre-built `provider` to override.
32
+ providerSettings: { name: 'anthropic', model: 'claude-sonnet-4-5', apiKey: 'sk-…' },
33
+ packs: [acmeJiraPack], // additive capability
34
+ defaultPresetId: 'careful-reviewer', // Robota's built-in preset, reused
35
+ });
36
+
37
+ // The external repo binds product.buildRuntime(...) to ITS OWN presentation/transport.
38
+ // A provider passed in the session options would take precedence over the constructed one.
39
+ if (product.provider === undefined) throw new Error('no provider configured');
40
+ const session = product.buildRuntime({ session: { cwd, provider: product.provider } });
41
+ void product.acceptedPacks;
42
+ void product.rejectedCapabilities;
43
+ void product.rejectedPacks;
44
+ void session;
45
+ ```
46
+
47
+ `assembleProduct` hard-codes no product's choices — everything product-specific arrives as `profile` data.
48
+ It resolves presets via a per-call instance-scoped registry (never mutating a global), merges additive
49
+ capability packs while preserving accepted metadata and both rejection channels, and **delegates runtime
50
+ construction** to `agent-framework`'s `buildRuntimeSession` seam
51
+ — it never re-implements runtime assembly, and never imports a concrete transport, the TUI, or the CLI
52
+ (those are injected via the profile).
53
+
54
+ ## Exports
55
+
56
+ - `assembleProduct(profile)` — the fold.
57
+ - `IProductProfile` — the product declaration: identity, provider surface, presets, capability packs, base
58
+ command modules, and injected plumbing.
59
+ - `IAssembledProduct` — the result: the constructed provider, the merged command modules, tools, and
60
+ subagents, accepted pack metadata and both rejection channels, the preset registry and resolved
61
+ default preset, `buildRuntimeOptions(input)` (the session options with the product's materials laid
62
+ on top, for inspection), and `buildRuntime(input)`.
63
+ - `IBuildRuntimeInput` — the session options the shell resolves and passes to `buildRuntime`.
64
+
65
+ Capability packs come from [`@robota-sdk/agent-capability-pack`](../agent-capability-pack/README.md);
66
+ [`@robota-sdk/pack-coding`](../pack-coding/README.md) is Robota's coding pack. See
67
+ [`docs/SPEC.md`](./docs/SPEC.md) for the full contract.
68
+
69
+ ## License
70
+
71
+ AGPL-3.0-only OR LicenseRef-Commercial
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@robota-sdk/agent-capability-pack"),t=require("@robota-sdk/agent-core"),n=require("@robota-sdk/agent-framework"),r=require("@robota-sdk/agent-preset");function i(e,t){let n=e.provider??t.provider,r=e.providerErrorGuidance??t.providerErrorGuidance,i=e.promptFileReferenceTag??t.promptFileReferenceTag,a=e.modelCommandToolPrefix??t.modelCommandToolPrefix,o=e.subagentHookEnvironmentNames??t.subagentHookEnvironmentNames,s=e.observerFailureWarningCode??t.observerFailureWarningCode,c=e.permissionMode===void 0&&t.defaultPermissionMode!==void 0?{permissionMode:t.defaultPermissionMode}:{},l=e.commandModules??t.commandModules,u={...e.commandHostAdapters,presetRegistry:t.presetRegistry};if(`session`in e)return{...e,provider:n,...r===void 0?{}:{providerErrorGuidance:r},...i===void 0?{}:{promptFileReferenceTag:i},...a===void 0?{}:{modelCommandToolPrefix:a},...o===void 0?{}:{subagentHookEnvironmentNames:o},...s===void 0?{}:{observerFailureWarningCode:s},commandModules:l,commandHostAdapters:u,...c};if(n===void 0)throw Error("assembleProduct: no provider available — the profile carried neither `providerSettings` nor an injected `provider`, and the session options supplied none.");return{...e,provider:n,...r===void 0?{}:{providerErrorGuidance:r},...i===void 0?{}:{promptFileReferenceTag:i},...a===void 0?{}:{modelCommandToolPrefix:a},...o===void 0?{}:{subagentHookEnvironmentNames:o},...s===void 0?{}:{observerFailureWarningCode:s},commandModules:l,commandHostAdapters:u,additionalTools:[...e.additionalTools??[],...t.tools],...t.subagents.length>0?{agentDefinitions:t.subagents}:{},...c}}function a(a){let o=a.presetRegistry??(0,r.createPresetRegistry)(a.presets??[]),s=a.defaultPresetId===void 0?void 0:o.resolvePreset(a.defaultPresetId,a.presetContext),{merged:c,acceptedPacks:l,rejected:u,rejectedPacks:d}=(0,e.mergeCapabilityPacks)(a.baseCommandModules??[],a.packs??[]),f=a.provider??(a.providerSettings===void 0?void 0:(0,t.createProviderFromConfig)(a.providerSettings,a.providerDefinitions)),p=e=>i(e.session,{provider:f,providerErrorGuidance:a.providerErrorGuidance,promptFileReferenceTag:a.promptFileReferenceTag,modelCommandToolPrefix:a.modelCommandToolPrefix,subagentHookEnvironmentNames:a.subagentHookEnvironmentNames,observerFailureWarningCode:a.observerFailureWarningCode,commandModules:c.commandModules,tools:c.tools,subagents:c.subagents,defaultPermissionMode:s?.permissionMode,presetRegistry:o});return{id:a.id,...a.agentName===void 0?{}:{agentName:a.agentName},...a.version===void 0?{}:{version:a.version},...f===void 0?{}:{provider:f},providerDefinitions:a.providerDefinitions,commandModules:c.commandModules,tools:c.tools,subagents:c.subagents,acceptedPacks:l,rejectedCapabilities:u,rejectedPacks:d,presets:o,resolvePreset:(e,t)=>o.resolvePreset(e,t),...a.defaultPresetId===void 0?{}:{defaultPresetId:a.defaultPresetId},...s===void 0?{}:{defaultPreset:s},backgroundTaskRunners:a.backgroundTaskRunners??[],...a.subagentRunnerFactory===void 0?{}:{subagentRunnerFactory:a.subagentRunnerFactory},...a.transports===void 0?{}:{transports:typeof a.transports==`function`?a.transports():a.transports},buildRuntimeOptions:p,buildRuntime:e=>(0,n.buildRuntimeSession)(p(e))}}exports.assembleProduct=a;
@@ -0,0 +1,202 @@
1
+ import { ICapabilityPack, ICapabilityPackMetadata, IRejectedCapability, IRejectedCapabilityPack } from "@robota-sdk/agent-capability-pack";
2
+ import { FunctionTool, IAIProvider, IProviderDefinition, IProviderDefinitionConfig } from "@robota-sdk/agent-core";
3
+ import { IAgentDefinition, IBackgroundTaskRunner, ICommandModule, ICreateSessionOptions, IProviderErrorGuidance, InteractiveSession, TInteractiveSessionOptions, TSubagentRunnerFactory } from "@robota-sdk/agent-framework";
4
+ import { ITransportRegistryView } from "@robota-sdk/agent-interface-transport";
5
+ import { IPreset, IPresetRegistry, IResolvePresetContext, IResolvedPresetOptions } from "@robota-sdk/agent-preset";
6
+ //#region src/product-profile.d.ts
7
+ /**
8
+ * A declarative "this is my product" object — the sole argument of {@link assembleProduct}. Everything
9
+ * product-specific lives here as DATA (identity, provider, presets, packs, injected plumbing); the
10
+ * assembler hard-codes no product's choices. the configured CLI is one profile among many; an external host brings
11
+ * its own.
12
+ *
13
+ * The responsibility split (ARCH-005): **preset = behavior/persona**, **pack = capability**, **profile =
14
+ * product assembly** — the profile carries neither behavior nor capability *definitions*, it only
15
+ * *references* them and supplies identity + injected adapters.
16
+ */
17
+ interface IProductProfile {
18
+ /** Product id (diagnostics + surfaced on the assembled product). NEVER branched on by the assembler. */
19
+ id: string;
20
+ /** Product agent display name. */
21
+ agentName?: string;
22
+ /** Product version string. */
23
+ version?: string;
24
+ /**
25
+ * The product's provider surface: the vendor definitions it offers. Required — a product declares which
26
+ * providers it can speak to, and the kernel constructs from this registry. Pass `[]` for a product that
27
+ * only ever runs on an injected {@link provider}.
28
+ */
29
+ providerDefinitions: readonly IProviderDefinition[];
30
+ /**
31
+ * The ALREADY-RESOLVED provider configuration (name/model/apiKey/baseURL/…). The SHELL performs the
32
+ * settings/env/file reads that produce this value and passes it IN as plain data; the kernel then
33
+ * constructs the provider from it via `createProviderFromConfig`. That keeps the fold pure and IO-free
34
+ * (guard b) while returning provider construction to the kernel, per the spec's In-kernel boundary
35
+ * ("Provider construction FROM `IProviderDefinition[]` + already-resolved settings → In-kernel").
36
+ *
37
+ * Absent ⇒ no provider is constructed; the consumer either injects {@link provider} or supplies one at
38
+ * `buildRuntime` time (the Mode A shape, which carries only `providerDefinitions`).
39
+ */
40
+ providerSettings?: IProviderDefinitionConfig;
41
+ /**
42
+ * OPTIONAL injected provider override for advanced/test consumers — a pre-built provider that takes
43
+ * precedence over {@link providerSettings}. the configured CLI uses it for `--session-log` replay, where the
44
+ * provider answers from a recorded log instead of a vendor definition.
45
+ */
46
+ provider?: IAIProvider;
47
+ /** Product-specific, plain-data remediation text for recognized provider errors. */
48
+ providerErrorGuidance?: IProviderErrorGuidance;
49
+ /** Model-visible enclosure for workspace file references; neutral when omitted. */
50
+ promptFileReferenceTag?: string;
51
+ /** Prefix for model command tool names; neutral when omitted. */
52
+ modelCommandToolPrefix?: string;
53
+ /** Optional product aliases for subagent hook environment variables. */
54
+ subagentHookEnvironmentNames?: ICreateSessionOptions['subagentHookEnvironmentNames'];
55
+ /** Host-owned identity for background observer process warnings. */
56
+ observerFailureWarningCode?: ICreateSessionOptions['observerFailureWarningCode'];
57
+ /**
58
+ * External presets to register into a PER-CALL instance-scoped registry (R8). Ignored when
59
+ * {@link presetRegistry} is supplied — that registry is then used as-is.
60
+ */
61
+ presets?: readonly IPreset[];
62
+ /**
63
+ * An ALREADY-BUILT instance-scoped registry (from `agent-preset`'s `createPresetRegistry`) to use
64
+ * instead of building one from {@link presets}. When supplied it WINS over `presets`.
65
+ *
66
+ * This is the seam for a shell that must resolve a preset BEFORE it can build the profile — a preset
67
+ * can carry the `model` and `agentName` the profile itself is constructed from, so "resolve, then
68
+ * assemble" is a real ordering constraint, not a product-specific quirk. Handing the registry in (rather than the
69
+ * presets) is what keeps that pre-assembly resolution and `assembleProduct`'s own resolution on ONE
70
+ * registry instead of two equivalent-but-separate ones (ARCH-008). R8 is unaffected: the registry is
71
+ * still instance-scoped and no module-level state is read or mutated.
72
+ */
73
+ presetRegistry?: IPresetRegistry;
74
+ /** The default preset id, resolved to seed the assembled product's default posture. */
75
+ defaultPresetId?: string;
76
+ /**
77
+ * The override layers applied when resolving {@link defaultPresetId} (`cliOverrides` / `explicit`).
78
+ * A shell that resolved the same id with overrides passes the SAME context here, so
79
+ * {@link IAssembledProduct.defaultPreset} is the shell's resolution, not a half-resolved variant of it.
80
+ */
81
+ presetContext?: IResolvePresetContext;
82
+ /** Additive capability packs (merged via `mergeCapabilityPacks`). */
83
+ packs?: readonly ICapabilityPack[];
84
+ /** The product's own base command modules (the packs merge on top of these). */
85
+ baseCommandModules?: readonly ICommandModule[];
86
+ /** Background task runners the shell injects (from agent-executor, via the shell's composition root). */
87
+ backgroundTaskRunners?: readonly IBackgroundTaskRunner[];
88
+ /** Subagent runner factory the shell injects (concrete child-process / in-process runner). */
89
+ subagentRunnerFactory?: TSubagentRunnerFactory;
90
+ /** Transport registry VIEW (or a factory for one) — the read-only interface, never the concrete class. */
91
+ transports?: ITransportRegistryView | (() => ITransportRegistryView);
92
+ }
93
+ /**
94
+ * The shell-supplied input to {@link IAssembledProduct.buildRuntime}. The shell owns the session options
95
+ * it resolves (cwd, provider, session store, memory, persona, permission mode, …); `assembleProduct`
96
+ * overlays the product-owned assembled materials (command modules + pack tools) on top.
97
+ */
98
+ interface IBuildRuntimeInput {
99
+ /**
100
+ * The shell-resolved session options. `assembleProduct` overlays the assembled `commandModules` and pack
101
+ * `additionalTools` and (when unset) the default preset's `permissionMode` before delegating to
102
+ * `buildRuntimeSession`.
103
+ */
104
+ session: TInteractiveSessionOptions;
105
+ }
106
+ /**
107
+ * The neutral runtime materials {@link assembleProduct} produces — everything the shell needs to bind its
108
+ * own transport/presentation. Concrete transports, the TUI, and mode dispatch stay in the shell.
109
+ */
110
+ interface IAssembledProduct {
111
+ /** Product identity (passthrough — surfaced for the shell, never branched on by the assembler). */
112
+ id: string;
113
+ agentName?: string;
114
+ version?: string;
115
+ /**
116
+ * The provider the kernel constructed from `providerDefinitions` + `providerSettings` — or the injected
117
+ * `profile.provider` when one was supplied (it wins). `undefined` when the profile carried neither
118
+ * (Mode A): the consumer then supplies a provider in the `buildRuntime` session options.
119
+ */
120
+ provider?: IAIProvider;
121
+ /** The product's provider surface (passthrough) — the definitions hot-swap and setup flows read. */
122
+ providerDefinitions: readonly IProviderDefinition[];
123
+ /** `baseCommandModules ⊕ merged pack modules` (see `mergeCapabilityPacks`). */
124
+ commandModules: readonly ICommandModule[];
125
+ /** Merged pack tools (additive). */
126
+ tools: readonly FunctionTool[];
127
+ /** Merged pack subagents (additive) — exposed as material; the shell wires the subagent-runner seam. */
128
+ subagents: readonly IAgentDefinition[];
129
+ /** Contributions the merge rejected for a colliding id (surfaced, never silently dropped). */
130
+ rejectedCapabilities: readonly IRejectedCapability[];
131
+ /** Discovery metadata for accepted packs, preserved in profile order. */
132
+ acceptedPacks: readonly ICapabilityPackMetadata[];
133
+ /** Later duplicate pack ids rejected atomically before capability folding. */
134
+ rejectedPacks: readonly IRejectedCapabilityPack[];
135
+ /**
136
+ * The per-call instance-scoped preset registry (R8 — no module-global mutation). This is the SAME
137
+ * object the profile supplied as `presetRegistry`, when it supplied one.
138
+ */
139
+ presets: IPresetRegistry;
140
+ /** Convenience resolver bound over `presets` (equivalent to `presets.resolvePreset`). */
141
+ resolvePreset: (id: string, context?: Parameters<IPresetRegistry['resolvePreset']>[1]) => IResolvedPresetOptions;
142
+ /**
143
+ * The default preset id (passthrough) and its resolved posture — resolved over {@link presets} with the
144
+ * profile's `presetContext`, so a shell that resolved the same id with the same overrides gets the same
145
+ * value here (ARCH-008), not a variant missing its override layers.
146
+ */
147
+ defaultPresetId?: string;
148
+ defaultPreset?: IResolvedPresetOptions;
149
+ /** Injected plumbing (passthrough) the shell consumes when wiring the runtime. */
150
+ backgroundTaskRunners: readonly IBackgroundTaskRunner[];
151
+ subagentRunnerFactory?: TSubagentRunnerFactory;
152
+ transports?: ITransportRegistryView;
153
+ /**
154
+ * The PURE overlay `buildRuntime` delegates through: the shell-supplied session options with the
155
+ * product-owned materials laid on top (assembled command modules, pack tools, pack subagents as
156
+ * `agentDefinitions`, the constructed provider, and the default preset's `permissionMode` when the shell
157
+ * left it unset). Exposed so a consumer can inspect or further extend the options before construction —
158
+ * and so the overlay contract is assertable without building a live session.
159
+ */
160
+ buildRuntimeOptions: (input: IBuildRuntimeInput) => TInteractiveSessionOptions;
161
+ /**
162
+ * Build the runtime session by DELEGATING to `agent-framework`'s `buildRuntimeSession` seam (R2) — never
163
+ * a re-implementation. Equivalent to `buildRuntimeSession(buildRuntimeOptions(input))`; returns the
164
+ * framework `InteractiveSession` the shell binds its presentation over.
165
+ */
166
+ buildRuntime: (input: IBuildRuntimeInput) => InteractiveSession;
167
+ }
168
+ //#endregion
169
+ //#region src/assemble-product.d.ts
170
+ /**
171
+ * The single product-composition function — a PURE, deterministic, IO-free fold over `IProductProfile`.
172
+ *
173
+ * `assembleProduct` is a **peer** of the repo's already-blessed pure folds (`resolvePreset`,
174
+ * `mergeSettings`, `mergeCapabilityPacks`): it reads only its argument, calls only pure sub-folds and the
175
+ * framework's runtime-construction seam, and hard-codes **no** product's choices — there is ZERO
176
+ * product-specific branching (no `if (profile.id === '…')` ever). Everything product-specific arrives as
177
+ * `profile` DATA. This property is what makes the `agent-product` carve-out safe under the amended
178
+ * project-structure L129 rule, and it is enforced by the three composition-neutrality guards
179
+ * (dependency-graph neutrality, purity/no-IO, no product-name conditionals).
180
+ *
181
+ * What it does:
182
+ * 1. Builds a PER-CALL instance-scoped preset registry over `profile.presets` (R8) — or adopts the
183
+ * instance the caller already built and handed in as `profile.presetRegistry` (ARCH-008). Either way it
184
+ * never mutates agent-preset's module-level `externalPresets` global, so two products in one process do
185
+ * not share one registry and repeat calls do not accumulate. `defaultPresetId` is resolved over that
186
+ * registry with `profile.presetContext`, so the product's `defaultPreset` is the caller's resolution.
187
+ * 2. Merges the additive capability packs onto `profile.baseCommandModules` via `mergeCapabilityPacks`
188
+ * (base ⊕ packs, with a rejection channel — never a silent override).
189
+ * 3. Constructs the provider from `profile.providerDefinitions` + the shell's already-resolved
190
+ * `profile.providerSettings` (owner Decision 1) via agent-core's pure `createProviderFromConfig`; an
191
+ * injected `profile.provider` overrides it.
192
+ * 4. Produces `buildRuntimeOptions`/`buildRuntime`, which DELEGATE runtime construction to
193
+ * `agent-framework`'s `buildRuntimeSession` seam (R2, RUNTIME-001 SSOT) — never re-implementing runtime
194
+ * assembly — overlaying the assembled modules, pack tools, and pack subagents (`agentDefinitions`).
195
+ *
196
+ * Settings/args/env resolution and concrete transports/presentation stay in the shell; `assembleProduct`
197
+ * receives already-resolved data and returns neutral materials the shell binds its own transport over.
198
+ */
199
+ declare function assembleProduct(profile: IProductProfile): IAssembledProduct;
200
+ //#endregion
201
+ export { type IAssembledProduct, type IBuildRuntimeInput, type IProductProfile, assembleProduct };
202
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/product-profile.ts","../../src/assemble-product.ts"],"mappings":";;;;;;;;;;;;;;;;UAwCiB;;EAGf;;EAEA;;EAEA;;;;;;EAQA,8BAA8B;;;;;;;;;;;EAW9B,mBAAmB;;;;;;EAMnB,WAAW;;EAEX,wBAAwB;;EAExB;;EAEA;;EAEA,+BAA+B;;EAE/B,6BAA6B;;;;;EAM7B,mBAAmB;;;;;;;;;;;;EAYnB,iBAAiB;;EAEjB;;;;;;EAMA,gBAAgB;;EAIhB,iBAAiB;;EAEjB,8BAA8B;;EAI9B,iCAAiC;;EAEjC,wBAAwB;;EAExB,aAAa,gCAAgC;;;;;;;UAQ9B;;;;;;EAMf,SAAS;;;;;;UAOM;;EAEf;EACA;EACA;;;;;;EAOA,WAAW;;EAEX,8BAA8B;;EAG9B,yBAAyB;;EAEzB,gBAAgB;;EAEhB,oBAAoB;;EAEpB,+BAA+B;;EAE/B,wBAAwB;;EAExB,wBAAwB;;;;;EAMxB,SAAS;;EAET,gBACE,YACA,UAAU,WAAW,yCAClB;;;;;;EAML;EACA,gBAAgB;;EAGhB,gCAAgC;EAChC,wBAAwB;EACxB,aAAa;;;;;;;;EASb,sBAAsB,OAAO,uBAAuB;;;;;;EAOpD,eAAe,OAAO,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCtC/B,gBAAgB,SAAS,kBAAkB"}
@@ -0,0 +1,202 @@
1
+ import { ICapabilityPack, ICapabilityPackMetadata, IRejectedCapability, IRejectedCapabilityPack } from "@robota-sdk/agent-capability-pack";
2
+ import { FunctionTool, IAIProvider, IProviderDefinition, IProviderDefinitionConfig } from "@robota-sdk/agent-core";
3
+ import { IAgentDefinition, IBackgroundTaskRunner, ICommandModule, ICreateSessionOptions, IProviderErrorGuidance, InteractiveSession, TInteractiveSessionOptions, TSubagentRunnerFactory } from "@robota-sdk/agent-framework";
4
+ import { IPreset, IPresetRegistry, IResolvePresetContext, IResolvedPresetOptions } from "@robota-sdk/agent-preset";
5
+ import { ITransportRegistryView } from "@robota-sdk/agent-interface-transport";
6
+ //#region src/product-profile.d.ts
7
+ /**
8
+ * A declarative "this is my product" object — the sole argument of {@link assembleProduct}. Everything
9
+ * product-specific lives here as DATA (identity, provider, presets, packs, injected plumbing); the
10
+ * assembler hard-codes no product's choices. the configured CLI is one profile among many; an external host brings
11
+ * its own.
12
+ *
13
+ * The responsibility split (ARCH-005): **preset = behavior/persona**, **pack = capability**, **profile =
14
+ * product assembly** — the profile carries neither behavior nor capability *definitions*, it only
15
+ * *references* them and supplies identity + injected adapters.
16
+ */
17
+ interface IProductProfile {
18
+ /** Product id (diagnostics + surfaced on the assembled product). NEVER branched on by the assembler. */
19
+ id: string;
20
+ /** Product agent display name. */
21
+ agentName?: string;
22
+ /** Product version string. */
23
+ version?: string;
24
+ /**
25
+ * The product's provider surface: the vendor definitions it offers. Required — a product declares which
26
+ * providers it can speak to, and the kernel constructs from this registry. Pass `[]` for a product that
27
+ * only ever runs on an injected {@link provider}.
28
+ */
29
+ providerDefinitions: readonly IProviderDefinition[];
30
+ /**
31
+ * The ALREADY-RESOLVED provider configuration (name/model/apiKey/baseURL/…). The SHELL performs the
32
+ * settings/env/file reads that produce this value and passes it IN as plain data; the kernel then
33
+ * constructs the provider from it via `createProviderFromConfig`. That keeps the fold pure and IO-free
34
+ * (guard b) while returning provider construction to the kernel, per the spec's In-kernel boundary
35
+ * ("Provider construction FROM `IProviderDefinition[]` + already-resolved settings → In-kernel").
36
+ *
37
+ * Absent ⇒ no provider is constructed; the consumer either injects {@link provider} or supplies one at
38
+ * `buildRuntime` time (the Mode A shape, which carries only `providerDefinitions`).
39
+ */
40
+ providerSettings?: IProviderDefinitionConfig;
41
+ /**
42
+ * OPTIONAL injected provider override for advanced/test consumers — a pre-built provider that takes
43
+ * precedence over {@link providerSettings}. the configured CLI uses it for `--session-log` replay, where the
44
+ * provider answers from a recorded log instead of a vendor definition.
45
+ */
46
+ provider?: IAIProvider;
47
+ /** Product-specific, plain-data remediation text for recognized provider errors. */
48
+ providerErrorGuidance?: IProviderErrorGuidance;
49
+ /** Model-visible enclosure for workspace file references; neutral when omitted. */
50
+ promptFileReferenceTag?: string;
51
+ /** Prefix for model command tool names; neutral when omitted. */
52
+ modelCommandToolPrefix?: string;
53
+ /** Optional product aliases for subagent hook environment variables. */
54
+ subagentHookEnvironmentNames?: ICreateSessionOptions['subagentHookEnvironmentNames'];
55
+ /** Host-owned identity for background observer process warnings. */
56
+ observerFailureWarningCode?: ICreateSessionOptions['observerFailureWarningCode'];
57
+ /**
58
+ * External presets to register into a PER-CALL instance-scoped registry (R8). Ignored when
59
+ * {@link presetRegistry} is supplied — that registry is then used as-is.
60
+ */
61
+ presets?: readonly IPreset[];
62
+ /**
63
+ * An ALREADY-BUILT instance-scoped registry (from `agent-preset`'s `createPresetRegistry`) to use
64
+ * instead of building one from {@link presets}. When supplied it WINS over `presets`.
65
+ *
66
+ * This is the seam for a shell that must resolve a preset BEFORE it can build the profile — a preset
67
+ * can carry the `model` and `agentName` the profile itself is constructed from, so "resolve, then
68
+ * assemble" is a real ordering constraint, not a product-specific quirk. Handing the registry in (rather than the
69
+ * presets) is what keeps that pre-assembly resolution and `assembleProduct`'s own resolution on ONE
70
+ * registry instead of two equivalent-but-separate ones (ARCH-008). R8 is unaffected: the registry is
71
+ * still instance-scoped and no module-level state is read or mutated.
72
+ */
73
+ presetRegistry?: IPresetRegistry;
74
+ /** The default preset id, resolved to seed the assembled product's default posture. */
75
+ defaultPresetId?: string;
76
+ /**
77
+ * The override layers applied when resolving {@link defaultPresetId} (`cliOverrides` / `explicit`).
78
+ * A shell that resolved the same id with overrides passes the SAME context here, so
79
+ * {@link IAssembledProduct.defaultPreset} is the shell's resolution, not a half-resolved variant of it.
80
+ */
81
+ presetContext?: IResolvePresetContext;
82
+ /** Additive capability packs (merged via `mergeCapabilityPacks`). */
83
+ packs?: readonly ICapabilityPack[];
84
+ /** The product's own base command modules (the packs merge on top of these). */
85
+ baseCommandModules?: readonly ICommandModule[];
86
+ /** Background task runners the shell injects (from agent-executor, via the shell's composition root). */
87
+ backgroundTaskRunners?: readonly IBackgroundTaskRunner[];
88
+ /** Subagent runner factory the shell injects (concrete child-process / in-process runner). */
89
+ subagentRunnerFactory?: TSubagentRunnerFactory;
90
+ /** Transport registry VIEW (or a factory for one) — the read-only interface, never the concrete class. */
91
+ transports?: ITransportRegistryView | (() => ITransportRegistryView);
92
+ }
93
+ /**
94
+ * The shell-supplied input to {@link IAssembledProduct.buildRuntime}. The shell owns the session options
95
+ * it resolves (cwd, provider, session store, memory, persona, permission mode, …); `assembleProduct`
96
+ * overlays the product-owned assembled materials (command modules + pack tools) on top.
97
+ */
98
+ interface IBuildRuntimeInput {
99
+ /**
100
+ * The shell-resolved session options. `assembleProduct` overlays the assembled `commandModules` and pack
101
+ * `additionalTools` and (when unset) the default preset's `permissionMode` before delegating to
102
+ * `buildRuntimeSession`.
103
+ */
104
+ session: TInteractiveSessionOptions;
105
+ }
106
+ /**
107
+ * The neutral runtime materials {@link assembleProduct} produces — everything the shell needs to bind its
108
+ * own transport/presentation. Concrete transports, the TUI, and mode dispatch stay in the shell.
109
+ */
110
+ interface IAssembledProduct {
111
+ /** Product identity (passthrough — surfaced for the shell, never branched on by the assembler). */
112
+ id: string;
113
+ agentName?: string;
114
+ version?: string;
115
+ /**
116
+ * The provider the kernel constructed from `providerDefinitions` + `providerSettings` — or the injected
117
+ * `profile.provider` when one was supplied (it wins). `undefined` when the profile carried neither
118
+ * (Mode A): the consumer then supplies a provider in the `buildRuntime` session options.
119
+ */
120
+ provider?: IAIProvider;
121
+ /** The product's provider surface (passthrough) — the definitions hot-swap and setup flows read. */
122
+ providerDefinitions: readonly IProviderDefinition[];
123
+ /** `baseCommandModules ⊕ merged pack modules` (see `mergeCapabilityPacks`). */
124
+ commandModules: readonly ICommandModule[];
125
+ /** Merged pack tools (additive). */
126
+ tools: readonly FunctionTool[];
127
+ /** Merged pack subagents (additive) — exposed as material; the shell wires the subagent-runner seam. */
128
+ subagents: readonly IAgentDefinition[];
129
+ /** Contributions the merge rejected for a colliding id (surfaced, never silently dropped). */
130
+ rejectedCapabilities: readonly IRejectedCapability[];
131
+ /** Discovery metadata for accepted packs, preserved in profile order. */
132
+ acceptedPacks: readonly ICapabilityPackMetadata[];
133
+ /** Later duplicate pack ids rejected atomically before capability folding. */
134
+ rejectedPacks: readonly IRejectedCapabilityPack[];
135
+ /**
136
+ * The per-call instance-scoped preset registry (R8 — no module-global mutation). This is the SAME
137
+ * object the profile supplied as `presetRegistry`, when it supplied one.
138
+ */
139
+ presets: IPresetRegistry;
140
+ /** Convenience resolver bound over `presets` (equivalent to `presets.resolvePreset`). */
141
+ resolvePreset: (id: string, context?: Parameters<IPresetRegistry['resolvePreset']>[1]) => IResolvedPresetOptions;
142
+ /**
143
+ * The default preset id (passthrough) and its resolved posture — resolved over {@link presets} with the
144
+ * profile's `presetContext`, so a shell that resolved the same id with the same overrides gets the same
145
+ * value here (ARCH-008), not a variant missing its override layers.
146
+ */
147
+ defaultPresetId?: string;
148
+ defaultPreset?: IResolvedPresetOptions;
149
+ /** Injected plumbing (passthrough) the shell consumes when wiring the runtime. */
150
+ backgroundTaskRunners: readonly IBackgroundTaskRunner[];
151
+ subagentRunnerFactory?: TSubagentRunnerFactory;
152
+ transports?: ITransportRegistryView;
153
+ /**
154
+ * The PURE overlay `buildRuntime` delegates through: the shell-supplied session options with the
155
+ * product-owned materials laid on top (assembled command modules, pack tools, pack subagents as
156
+ * `agentDefinitions`, the constructed provider, and the default preset's `permissionMode` when the shell
157
+ * left it unset). Exposed so a consumer can inspect or further extend the options before construction —
158
+ * and so the overlay contract is assertable without building a live session.
159
+ */
160
+ buildRuntimeOptions: (input: IBuildRuntimeInput) => TInteractiveSessionOptions;
161
+ /**
162
+ * Build the runtime session by DELEGATING to `agent-framework`'s `buildRuntimeSession` seam (R2) — never
163
+ * a re-implementation. Equivalent to `buildRuntimeSession(buildRuntimeOptions(input))`; returns the
164
+ * framework `InteractiveSession` the shell binds its presentation over.
165
+ */
166
+ buildRuntime: (input: IBuildRuntimeInput) => InteractiveSession;
167
+ }
168
+ //#endregion
169
+ //#region src/assemble-product.d.ts
170
+ /**
171
+ * The single product-composition function — a PURE, deterministic, IO-free fold over `IProductProfile`.
172
+ *
173
+ * `assembleProduct` is a **peer** of the repo's already-blessed pure folds (`resolvePreset`,
174
+ * `mergeSettings`, `mergeCapabilityPacks`): it reads only its argument, calls only pure sub-folds and the
175
+ * framework's runtime-construction seam, and hard-codes **no** product's choices — there is ZERO
176
+ * product-specific branching (no `if (profile.id === '…')` ever). Everything product-specific arrives as
177
+ * `profile` DATA. This property is what makes the `agent-product` carve-out safe under the amended
178
+ * project-structure L129 rule, and it is enforced by the three composition-neutrality guards
179
+ * (dependency-graph neutrality, purity/no-IO, no product-name conditionals).
180
+ *
181
+ * What it does:
182
+ * 1. Builds a PER-CALL instance-scoped preset registry over `profile.presets` (R8) — or adopts the
183
+ * instance the caller already built and handed in as `profile.presetRegistry` (ARCH-008). Either way it
184
+ * never mutates agent-preset's module-level `externalPresets` global, so two products in one process do
185
+ * not share one registry and repeat calls do not accumulate. `defaultPresetId` is resolved over that
186
+ * registry with `profile.presetContext`, so the product's `defaultPreset` is the caller's resolution.
187
+ * 2. Merges the additive capability packs onto `profile.baseCommandModules` via `mergeCapabilityPacks`
188
+ * (base ⊕ packs, with a rejection channel — never a silent override).
189
+ * 3. Constructs the provider from `profile.providerDefinitions` + the shell's already-resolved
190
+ * `profile.providerSettings` (owner Decision 1) via agent-core's pure `createProviderFromConfig`; an
191
+ * injected `profile.provider` overrides it.
192
+ * 4. Produces `buildRuntimeOptions`/`buildRuntime`, which DELEGATE runtime construction to
193
+ * `agent-framework`'s `buildRuntimeSession` seam (R2, RUNTIME-001 SSOT) — never re-implementing runtime
194
+ * assembly — overlaying the assembled modules, pack tools, and pack subagents (`agentDefinitions`).
195
+ *
196
+ * Settings/args/env resolution and concrete transports/presentation stay in the shell; `assembleProduct`
197
+ * receives already-resolved data and returns neutral materials the shell binds its own transport over.
198
+ */
199
+ declare function assembleProduct(profile: IProductProfile): IAssembledProduct;
200
+ //#endregion
201
+ export { type IAssembledProduct, type IBuildRuntimeInput, type IProductProfile, assembleProduct };
202
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/product-profile.ts","../../src/assemble-product.ts"],"mappings":";;;;;;;;;;;;;;;;UAwCiB;;EAGf;;EAEA;;EAEA;;;;;;EAQA,8BAA8B;;;;;;;;;;;EAW9B,mBAAmB;;;;;;EAMnB,WAAW;;EAEX,wBAAwB;;EAExB;;EAEA;;EAEA,+BAA+B;;EAE/B,6BAA6B;;;;;EAM7B,mBAAmB;;;;;;;;;;;;EAYnB,iBAAiB;;EAEjB;;;;;;EAMA,gBAAgB;;EAIhB,iBAAiB;;EAEjB,8BAA8B;;EAI9B,iCAAiC;;EAEjC,wBAAwB;;EAExB,aAAa,gCAAgC;;;;;;;UAQ9B;;;;;;EAMf,SAAS;;;;;;UAOM;;EAEf;EACA;EACA;;;;;;EAOA,WAAW;;EAEX,8BAA8B;;EAG9B,yBAAyB;;EAEzB,gBAAgB;;EAEhB,oBAAoB;;EAEpB,+BAA+B;;EAE/B,wBAAwB;;EAExB,wBAAwB;;;;;EAMxB,SAAS;;EAET,gBACE,YACA,UAAU,WAAW,yCAClB;;;;;;EAML;EACA,gBAAgB;;EAGhB,gCAAgC;EAChC,wBAAwB;EACxB,aAAa;;;;;;;;EASb,sBAAsB,OAAO,uBAAuB;;;;;;EAOpD,eAAe,OAAO,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCtC/B,gBAAgB,SAAS,kBAAkB"}
@@ -0,0 +1,2 @@
1
+ import{mergeCapabilityPacks as e}from"@robota-sdk/agent-capability-pack";import{createProviderFromConfig as t}from"@robota-sdk/agent-core";import{buildRuntimeSession as n}from"@robota-sdk/agent-framework";import{createPresetRegistry as r}from"@robota-sdk/agent-preset";function i(e,t){let n=e.provider??t.provider,r=e.providerErrorGuidance??t.providerErrorGuidance,i=e.promptFileReferenceTag??t.promptFileReferenceTag,a=e.modelCommandToolPrefix??t.modelCommandToolPrefix,o=e.subagentHookEnvironmentNames??t.subagentHookEnvironmentNames,s=e.observerFailureWarningCode??t.observerFailureWarningCode,c=e.permissionMode===void 0&&t.defaultPermissionMode!==void 0?{permissionMode:t.defaultPermissionMode}:{},l=e.commandModules??t.commandModules,u={...e.commandHostAdapters,presetRegistry:t.presetRegistry};if(`session`in e)return{...e,provider:n,...r===void 0?{}:{providerErrorGuidance:r},...i===void 0?{}:{promptFileReferenceTag:i},...a===void 0?{}:{modelCommandToolPrefix:a},...o===void 0?{}:{subagentHookEnvironmentNames:o},...s===void 0?{}:{observerFailureWarningCode:s},commandModules:l,commandHostAdapters:u,...c};if(n===void 0)throw Error("assembleProduct: no provider available — the profile carried neither `providerSettings` nor an injected `provider`, and the session options supplied none.");return{...e,provider:n,...r===void 0?{}:{providerErrorGuidance:r},...i===void 0?{}:{promptFileReferenceTag:i},...a===void 0?{}:{modelCommandToolPrefix:a},...o===void 0?{}:{subagentHookEnvironmentNames:o},...s===void 0?{}:{observerFailureWarningCode:s},commandModules:l,commandHostAdapters:u,additionalTools:[...e.additionalTools??[],...t.tools],...t.subagents.length>0?{agentDefinitions:t.subagents}:{},...c}}function a(a){let o=a.presetRegistry??r(a.presets??[]),s=a.defaultPresetId===void 0?void 0:o.resolvePreset(a.defaultPresetId,a.presetContext),{merged:c,acceptedPacks:l,rejected:u,rejectedPacks:d}=e(a.baseCommandModules??[],a.packs??[]),f=a.provider??(a.providerSettings===void 0?void 0:t(a.providerSettings,a.providerDefinitions)),p=e=>i(e.session,{provider:f,providerErrorGuidance:a.providerErrorGuidance,promptFileReferenceTag:a.promptFileReferenceTag,modelCommandToolPrefix:a.modelCommandToolPrefix,subagentHookEnvironmentNames:a.subagentHookEnvironmentNames,observerFailureWarningCode:a.observerFailureWarningCode,commandModules:c.commandModules,tools:c.tools,subagents:c.subagents,defaultPermissionMode:s?.permissionMode,presetRegistry:o});return{id:a.id,...a.agentName===void 0?{}:{agentName:a.agentName},...a.version===void 0?{}:{version:a.version},...f===void 0?{}:{provider:f},providerDefinitions:a.providerDefinitions,commandModules:c.commandModules,tools:c.tools,subagents:c.subagents,acceptedPacks:l,rejectedCapabilities:u,rejectedPacks:d,presets:o,resolvePreset:(e,t)=>o.resolvePreset(e,t),...a.defaultPresetId===void 0?{}:{defaultPresetId:a.defaultPresetId},...s===void 0?{}:{defaultPreset:s},backgroundTaskRunners:a.backgroundTaskRunners??[],...a.subagentRunnerFactory===void 0?{}:{subagentRunnerFactory:a.subagentRunnerFactory},...a.transports===void 0?{}:{transports:typeof a.transports==`function`?a.transports():a.transports},buildRuntimeOptions:p,buildRuntime:e=>n(p(e))}}export{a as assembleProduct};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/assemble-product.ts"],"sourcesContent":["import { mergeCapabilityPacks } from '@robota-sdk/agent-capability-pack';\nimport { createProviderFromConfig } from '@robota-sdk/agent-core';\nimport { buildRuntimeSession } from '@robota-sdk/agent-framework';\nimport { createPresetRegistry } from '@robota-sdk/agent-preset';\n\nimport type { IAssembledProduct, IBuildRuntimeInput, IProductProfile } from './product-profile.js';\nimport type { TCompositionFieldPolicy } from '@robota-sdk/agent-capability-pack';\nimport type {\n FunctionTool,\n IAIProvider,\n IToolWithEventService,\n TPermissionMode,\n} from '@robota-sdk/agent-core';\nimport type {\n IAgentDefinition,\n ICommandHostAdapters,\n ICommandModule,\n TInteractiveSessionOptions,\n} from '@robota-sdk/agent-framework';\nimport type { IPresetRegistry, IResolvedPresetOptions } from '@robota-sdk/agent-preset';\n\nexport const PRODUCT_PROFILE_FIELD_POLICIES = {\n id: 'surfaced',\n agentName: 'surfaced',\n version: 'surfaced',\n providerDefinitions: 'consumed-and-surfaced',\n providerSettings: 'consumed',\n provider: 'consumed-and-surfaced',\n providerErrorGuidance: 'consumed',\n promptFileReferenceTag: 'consumed',\n modelCommandToolPrefix: 'consumed',\n subagentHookEnvironmentNames: 'consumed',\n observerFailureWarningCode: 'consumed',\n presets: 'consumed',\n presetRegistry: 'consumed-and-surfaced',\n defaultPresetId: 'consumed-and-surfaced',\n presetContext: 'consumed',\n packs: 'consumed',\n baseCommandModules: 'consumed',\n backgroundTaskRunners: 'surfaced',\n subagentRunnerFactory: 'surfaced',\n transports: 'consumed-and-surfaced',\n} as const satisfies Record<keyof IProductProfile, TCompositionFieldPolicy>;\n\n/** The product-owned materials the assembler overlays onto the shell-supplied session options. */\ninterface IOverlayMaterials {\n provider: IAIProvider | undefined;\n providerErrorGuidance: IProductProfile['providerErrorGuidance'];\n promptFileReferenceTag: IProductProfile['promptFileReferenceTag'];\n modelCommandToolPrefix: IProductProfile['modelCommandToolPrefix'];\n subagentHookEnvironmentNames: IProductProfile['subagentHookEnvironmentNames'];\n observerFailureWarningCode: IProductProfile['observerFailureWarningCode'];\n commandModules: readonly ICommandModule[];\n tools: readonly FunctionTool[];\n subagents: readonly IAgentDefinition[];\n defaultPermissionMode: TPermissionMode | undefined;\n /** ARCH-009: the instance preset registry, so `/preset` discovers this product's presets. */\n presetRegistry: IPresetRegistry;\n}\n\n/**\n * Overlay the assembled command modules, pack tools, and pack subagents onto the shell's session options.\n * The injected pre-built-session path gets command modules only (its session already owns its tools); the\n * standard construction path also receives the additive pack tools and — via the framework's\n * `agentDefinitions` injection seam (ARCH-005 S2, owner Decision 2) — the merged pack subagents, so a\n * pack's subagents actually reach the runtime instead of being inert material. `agentDefinitions` is left\n * UNSET when no pack contributes one, so the framework's own built-ins + discovery are unchanged.\n *\n * The default preset's `permissionMode` is applied only when the shell left it unset.\n */\nfunction overlaySessionOptions(\n base: TInteractiveSessionOptions,\n materials: IOverlayMaterials,\n): TInteractiveSessionOptions {\n const provider = base.provider ?? materials.provider;\n const providerErrorGuidance = base.providerErrorGuidance ?? materials.providerErrorGuidance;\n const promptFileReferenceTag = base.promptFileReferenceTag ?? materials.promptFileReferenceTag;\n const modelCommandToolPrefix = base.modelCommandToolPrefix ?? materials.modelCommandToolPrefix;\n const subagentHookEnvironmentNames =\n base.subagentHookEnvironmentNames ?? materials.subagentHookEnvironmentNames;\n const observerFailureWarningCode =\n base.observerFailureWarningCode ?? materials.observerFailureWarningCode;\n const permissionModeOverlay =\n base.permissionMode === undefined && materials.defaultPermissionMode !== undefined\n ? { permissionMode: materials.defaultPermissionMode }\n : {};\n // ARCH-007: the shell may hand in a selection it has ALREADY narrowed — the configured shell applies its preset's\n // enabled/disabledCommandModules delta to the merged `base ⊕ packs` superset before calling the seam\n // (the spec's composition order: the merge widens, the preset delta narrows). Overwriting it here would\n // silently undo that narrowing, so the assembled set is overlaid only when the caller left it unset —\n // the same \"only when the shell left it unset\" rule `permissionMode` already follows.\n const commandModules = base.commandModules ?? materials.commandModules;\n // ARCH-009: MERGED into the shell's bag, never substituted for it. The shell wires its own adapters\n // there (remote control, process, settings) and the registry stands beside them; replacing the bag\n // would silently drop capabilities this assembler knows nothing about. Both arms get it — an\n // injected session is exactly the embedded-host case the item is about.\n const commandHostAdapters: ICommandHostAdapters = {\n ...base.commandHostAdapters,\n presetRegistry: materials.presetRegistry,\n };\n\n if ('session' in base) {\n return {\n ...base,\n provider,\n ...(providerErrorGuidance !== undefined ? { providerErrorGuidance } : {}),\n ...(promptFileReferenceTag !== undefined ? { promptFileReferenceTag } : {}),\n ...(modelCommandToolPrefix !== undefined ? { modelCommandToolPrefix } : {}),\n ...(subagentHookEnvironmentNames !== undefined ? { subagentHookEnvironmentNames } : {}),\n ...(observerFailureWarningCode !== undefined ? { observerFailureWarningCode } : {}),\n commandModules,\n commandHostAdapters,\n ...permissionModeOverlay,\n };\n }\n\n if (provider === undefined) {\n throw new Error(\n 'assembleProduct: no provider available — the profile carried neither `providerSettings` nor an injected `provider`, and the session options supplied none.',\n );\n }\n\n return {\n ...base,\n provider,\n ...(providerErrorGuidance !== undefined ? { providerErrorGuidance } : {}),\n ...(promptFileReferenceTag !== undefined ? { promptFileReferenceTag } : {}),\n ...(modelCommandToolPrefix !== undefined ? { modelCommandToolPrefix } : {}),\n ...(subagentHookEnvironmentNames !== undefined ? { subagentHookEnvironmentNames } : {}),\n ...(observerFailureWarningCode !== undefined ? { observerFailureWarningCode } : {}),\n commandModules,\n commandHostAdapters,\n additionalTools: [\n ...(base.additionalTools ?? []),\n ...(materials.tools as readonly IToolWithEventService[]),\n ],\n ...(materials.subagents.length > 0 ? { agentDefinitions: materials.subagents } : {}),\n ...permissionModeOverlay,\n };\n}\n\n/**\n * The single product-composition function — a PURE, deterministic, IO-free fold over `IProductProfile`.\n *\n * `assembleProduct` is a **peer** of the repo's already-blessed pure folds (`resolvePreset`,\n * `mergeSettings`, `mergeCapabilityPacks`): it reads only its argument, calls only pure sub-folds and the\n * framework's runtime-construction seam, and hard-codes **no** product's choices — there is ZERO\n * product-specific branching (no `if (profile.id === '…')` ever). Everything product-specific arrives as\n * `profile` DATA. This property is what makes the `agent-product` carve-out safe under the amended\n * project-structure L129 rule, and it is enforced by the three composition-neutrality guards\n * (dependency-graph neutrality, purity/no-IO, no product-name conditionals).\n *\n * What it does:\n * 1. Builds a PER-CALL instance-scoped preset registry over `profile.presets` (R8) — or adopts the\n * instance the caller already built and handed in as `profile.presetRegistry` (ARCH-008). Either way it\n * never mutates agent-preset's module-level `externalPresets` global, so two products in one process do\n * not share one registry and repeat calls do not accumulate. `defaultPresetId` is resolved over that\n * registry with `profile.presetContext`, so the product's `defaultPreset` is the caller's resolution.\n * 2. Merges the additive capability packs onto `profile.baseCommandModules` via `mergeCapabilityPacks`\n * (base ⊕ packs, with a rejection channel — never a silent override).\n * 3. Constructs the provider from `profile.providerDefinitions` + the shell's already-resolved\n * `profile.providerSettings` (owner Decision 1) via agent-core's pure `createProviderFromConfig`; an\n * injected `profile.provider` overrides it.\n * 4. Produces `buildRuntimeOptions`/`buildRuntime`, which DELEGATE runtime construction to\n * `agent-framework`'s `buildRuntimeSession` seam (R2, RUNTIME-001 SSOT) — never re-implementing runtime\n * assembly — overlaying the assembled modules, pack tools, and pack subagents (`agentDefinitions`).\n *\n * Settings/args/env resolution and concrete transports/presentation stay in the shell; `assembleProduct`\n * receives already-resolved data and returns neutral materials the shell binds its own transport over.\n */\nexport function assembleProduct(profile: IProductProfile): IAssembledProduct {\n // (1) Per-call instance-scoped preset registry — pure w.r.t. process state (R8). A caller that had to\n // resolve a preset BEFORE it could build this profile (a preset can carry the `model`/`agentName` the\n // profile is constructed from) hands its own instance in as `presetRegistry`; the assembler then uses\n // THAT one rather than building a second, equivalent registry, so there is exactly one resolution path\n // (ARCH-008). Either way the registry is instance-scoped — no module-level state is read or mutated.\n const presets = profile.presetRegistry ?? createPresetRegistry(profile.presets ?? []);\n const defaultPreset: IResolvedPresetOptions | undefined =\n profile.defaultPresetId !== undefined\n ? presets.resolvePreset(profile.defaultPresetId, profile.presetContext)\n : undefined;\n\n // (2) Additive capability merge — base ⊕ packs, deterministic, with a rejection channel.\n const { merged, acceptedPacks, rejected, rejectedPacks } = mergeCapabilityPacks(\n profile.baseCommandModules ?? [],\n profile.packs ?? [],\n );\n\n // (3) Provider construction — IN-KERNEL, from the profile's definitions + the shell's ALREADY-RESOLVED\n // settings (owner Decision 1). `createProviderFromConfig` is a pure `config → IAIProvider` factory that\n // lives in `@robota-sdk/agent-core` (relocated there by ARCH-PROVIDER-003), an ALLOWED dependency layer,\n // so this reads no fs/env and the fold stays pure. An injected `profile.provider` wins (advanced/test\n // override, e.g. `--session-log` replay); with neither, no provider is constructed and the consumer\n // supplies one in the `buildRuntime` session options (the Mode A shape).\n const provider =\n profile.provider ??\n (profile.providerSettings !== undefined\n ? createProviderFromConfig(profile.providerSettings, profile.providerDefinitions)\n : undefined);\n\n // (4) The runtime-construction delegate — DELEGATES to the framework seam, never re-implements.\n const buildRuntimeOptions = (input: IBuildRuntimeInput): TInteractiveSessionOptions =>\n overlaySessionOptions(input.session, {\n provider,\n providerErrorGuidance: profile.providerErrorGuidance,\n promptFileReferenceTag: profile.promptFileReferenceTag,\n modelCommandToolPrefix: profile.modelCommandToolPrefix,\n subagentHookEnvironmentNames: profile.subagentHookEnvironmentNames,\n observerFailureWarningCode: profile.observerFailureWarningCode,\n commandModules: merged.commandModules,\n tools: merged.tools,\n subagents: merged.subagents,\n defaultPermissionMode: defaultPreset?.permissionMode,\n // ARCH-009: the instance registry reaches the SESSION through the host-adapter bag, so\n // `/preset` discovers through the same presets this product resolved with. It was already\n // assembled here and surfaced on the product; what was missing was the last hop, which is why\n // `/preset` read a module global and why two products in one process shared one mutable list.\n presetRegistry: presets,\n });\n\n return {\n id: profile.id,\n ...(profile.agentName !== undefined ? { agentName: profile.agentName } : {}),\n ...(profile.version !== undefined ? { version: profile.version } : {}),\n ...(provider !== undefined ? { provider } : {}),\n providerDefinitions: profile.providerDefinitions,\n commandModules: merged.commandModules,\n tools: merged.tools,\n subagents: merged.subagents,\n acceptedPacks,\n rejectedCapabilities: rejected,\n rejectedPacks,\n presets,\n resolvePreset: (id, context) => presets.resolvePreset(id, context),\n ...(profile.defaultPresetId !== undefined ? { defaultPresetId: profile.defaultPresetId } : {}),\n ...(defaultPreset !== undefined ? { defaultPreset } : {}),\n backgroundTaskRunners: profile.backgroundTaskRunners ?? [],\n ...(profile.subagentRunnerFactory !== undefined\n ? { subagentRunnerFactory: profile.subagentRunnerFactory }\n : {}),\n ...(profile.transports !== undefined\n ? {\n transports:\n typeof profile.transports === 'function' ? profile.transports() : profile.transports,\n }\n : {}),\n buildRuntimeOptions,\n buildRuntime: (input) => buildRuntimeSession(buildRuntimeOptions(input)),\n };\n}\n"],"mappings":"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"}
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@robota-sdk/agent-product",
3
+ "version": "3.0.0-beta.100",
4
+ "description": "The product-assembly kernel for the Robota SDK: assembleProduct — a pure, IO-free fold over IProductProfile that delegates runtime construction to agent-framework",
5
+ "type": "module",
6
+ "main": "dist/node/index.js",
7
+ "types": "dist/node/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "node": {
12
+ "import": {
13
+ "types": "./dist/node/index.d.ts",
14
+ "default": "./dist/node/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/node/index.d.cts",
18
+ "default": "./dist/node/index.cjs"
19
+ }
20
+ },
21
+ "default": {
22
+ "import": {
23
+ "types": "./dist/node/index.d.ts",
24
+ "default": "./dist/node/index.js"
25
+ },
26
+ "require": {
27
+ "types": "./dist/node/index.d.cts",
28
+ "default": "./dist/node/index.cjs"
29
+ }
30
+ }
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "engines": {
35
+ "node": ">=22.12.0"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "CHANGELOG.md"
40
+ ],
41
+ "dependencies": {
42
+ "@robota-sdk/agent-capability-pack": "3.0.0-beta.100",
43
+ "@robota-sdk/agent-core": "3.0.0-beta.100",
44
+ "@robota-sdk/agent-interface-transport": "3.0.0-beta.100",
45
+ "@robota-sdk/agent-preset": "3.0.0-beta.100",
46
+ "@robota-sdk/agent-framework": "3.0.0-beta.100"
47
+ },
48
+ "devDependencies": {
49
+ "rimraf": "^5.0.10",
50
+ "tsdown": "^0.22.14",
51
+ "typescript": "^6.0.3",
52
+ "vitest": "^3.2.6"
53
+ },
54
+ "license": "AGPL-3.0-only OR LicenseRef-Commercial",
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "volta": {
59
+ "extends": "../../package.json"
60
+ },
61
+ "repository": {
62
+ "type": "git",
63
+ "url": "https://github.com/woojubb/robota"
64
+ },
65
+ "bugs": {
66
+ "url": "https://github.com/woojubb/robota/issues"
67
+ },
68
+ "homepage": "https://robota.io/",
69
+ "scripts": {
70
+ "build": "rimraf dist && tsdown",
71
+ "build:js": "pnpm run build",
72
+ "build:types": "pnpm run build",
73
+ "test": "vitest run --passWithNoTests",
74
+ "test:coverage": "vitest run --coverage --passWithNoTests",
75
+ "scenario:verify": "pnpm scenario:verify:composition-contract",
76
+ "scenario:verify:composition-contract": "pnpm exec tsx --conditions=source examples/verify-composition-contract.ts",
77
+ "typecheck": "tsgo --noEmit && tsgo -p tsconfig.examples.json --noEmit",
78
+ "lint": "eslint src/ --ext .ts",
79
+ "clean": "rimraf dist"
80
+ }
81
+ }