diff --git a/.changeset/narrow-public-api.md b/.changeset/narrow-public-api.md new file mode 100644 index 0000000..aca26b1 --- /dev/null +++ b/.changeset/narrow-public-api.md @@ -0,0 +1,8 @@ +--- +"@anarchitecture/summon": minor +"@anarchitecture/summon-server": minor +"@anarchitecture/summon-react": minor +--- + +Narrow public package exports to explicit adoption-path APIs and move copied +implementation output under `dist/_internal`. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b15b384..7d75c09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,23 @@ jobs: with: node-version: 22 cache: pnpm - - run: pnpm install --frozen-lockfile + - name: Show package manager config + run: | + pnpm --version + pnpm config get registry + - name: Install dependencies + run: | + set +e + pnpm install --frozen-lockfile --reporter append-only 2>&1 | tee pnpm-install.log + status=${PIPESTATUS[0]} + if [ "$status" -ne 0 ]; then + echo "::group::pnpm install failure tail" + tail -120 pnpm-install.log + echo "::endgroup::" + message=$(tail -40 pnpm-install.log | sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e ':a;N;$!ba;s/\n/%0A/g') + echo "::error title=pnpm install failed::$message" + exit "$status" + fi - run: pnpm typecheck - run: pnpm test - run: pnpm build @@ -40,6 +56,22 @@ jobs: with: node-version: 22 cache: pnpm - - run: pnpm install --frozen-lockfile + - name: Show package manager config + run: | + pnpm --version + pnpm config get registry + - name: Install dependencies + run: | + set +e + pnpm install --frozen-lockfile --reporter append-only 2>&1 | tee pnpm-install.log + status=${PIPESTATUS[0]} + if [ "$status" -ne 0 ]; then + echo "::group::pnpm install failure tail" + tail -120 pnpm-install.log + echo "::endgroup::" + message=$(tail -40 pnpm-install.log | sed -e 's/%/%25/g' -e 's/\r/%0D/g' -e ':a;N;$!ba;s/\n/%0A/g') + echo "::error title=pnpm install failed::$message" + exit "$status" + fi - run: pnpm exec playwright install --with-deps chromium webkit - run: pnpm test:safety diff --git a/README.md b/README.md index 3edd4d9..871fc9b 100644 --- a/README.md +++ b/README.md @@ -82,8 +82,9 @@ generation starts. The model sees that plan as a contract but cannot widen it. ## Public Packages -- `@anarchitecture/summon` - core protocol, validation, surface plans, policy, - browser sandbox host, runtime assets, envelopes, and Devtools events. +- `@anarchitecture/summon` - core protocol, surface plans, host contract + helpers, diagnostics primitives, and explicit browser/policy/envelope/assets/ + Devtools subpaths. - `@anarchitecture/summon-server` - provider-neutral generation lifecycle, repair, summaries, and model-provider interfaces. - `@anarchitecture/summon-react` - `SummonSurface` and React component island diff --git a/apps/demo/package.json b/apps/demo/package.json index 3ff5298..626e550 100644 --- a/apps/demo/package.json +++ b/apps/demo/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@anarchitecture/summon": "workspace:*", + "@summon-internal/engine": "workspace:*", "zod": "^3.23.0" }, "devDependencies": { diff --git a/apps/demo/src/batch-main.ts b/apps/demo/src/batch-main.ts index 5094e92..99060c7 100644 --- a/apps/demo/src/batch-main.ts +++ b/apps/demo/src/batch-main.ts @@ -1,4 +1,5 @@ -import { spawnSandbox, PolicyEngine, type SandboxHandle } from '@anarchitecture/summon'; +import { spawnSandbox, type SandboxHandle } from '@anarchitecture/summon/browser'; +import { PolicyEngine } from '@anarchitecture/summon/policy'; import { parseProtocolLine, SectionAccumulator, diff --git a/apps/demo/src/capabilities.ts b/apps/demo/src/capabilities.ts index 4d3af11..6d84565 100644 --- a/apps/demo/src/capabilities.ts +++ b/apps/demo/src/capabilities.ts @@ -13,8 +13,8 @@ import { defineWorkerResource, type CapabilityDefinition, type CapabilityRegistry, - type IntentHandler, } from '@anarchitecture/summon'; +import type { IntentHandler } from '@anarchitecture/summon/policy'; import { z } from 'zod'; const logArgsSchema = z.object({ payload: z.any().optional() }).passthrough(); diff --git a/apps/demo/src/generate-main.ts b/apps/demo/src/generate-main.ts index 0873d68..afe4f5c 100644 --- a/apps/demo/src/generate-main.ts +++ b/apps/demo/src/generate-main.ts @@ -1,20 +1,21 @@ import { + type ComponentIslandRegistry, + type SurfaceStreamContext, + type SurfaceStreamResult, consumeSurfaceStream, createComponentIslandRegistry, spawnSandbox, - PolicyEngine, + type SandboxHandle, +} from '@anarchitecture/summon/browser'; +import { createSurfaceEnvelope, parseSurfaceEnvelope, - type SandboxHandle, - type ComponentIslandRegistry, - type SurfaceStreamContext, - type SurfaceStreamResult, type SurfaceEnvelope, -} from '@anarchitecture/summon'; +} from '@anarchitecture/summon/envelope'; +import { PolicyEngine } from '@anarchitecture/summon/policy'; import { deriveSurfacePlanControls, normalizeSurfacePlan, - parseTokenValues, SectionAccumulator, SURFACE_AUTHORITY_VALUES, SURFACE_DATA_VALUES, @@ -31,6 +32,7 @@ import { type ValidationCapability, type ValidationComponent, } from '@anarchitecture/summon'; +import { parseTokenValues } from '@summon-internal/engine'; import { createEventStore, type DevtoolsEvent } from '@anarchitecture/summon/devtools'; import bootstrapSource from '@anarchitecture/summon/bootstrap.js?raw'; import defaultTokensSource from '@anarchitecture/summon/tokens.css?raw'; diff --git a/apps/demo/src/main.ts b/apps/demo/src/main.ts index d79d3ea..fd9ba0b 100644 --- a/apps/demo/src/main.ts +++ b/apps/demo/src/main.ts @@ -1,4 +1,4 @@ -import { spawnSandbox } from '@anarchitecture/summon'; +import { spawnSandbox } from '@anarchitecture/summon/browser'; import bootstrapSource from '@anarchitecture/summon/bootstrap.js?raw'; import tokensSource from '@anarchitecture/summon/tokens.css?raw'; import { ADVERSARIAL_BODY_HTML } from './adversarial-artifact.js'; diff --git a/apps/demo/src/strict-main.ts b/apps/demo/src/strict-main.ts index ffc342a..d23c0e3 100644 --- a/apps/demo/src/strict-main.ts +++ b/apps/demo/src/strict-main.ts @@ -10,11 +10,11 @@ */ import { spawnSandbox, - PolicyEngine, createStrictInputRegistry, type SandboxHandle, type StrictInputController, -} from '@anarchitecture/summon'; +} from '@anarchitecture/summon/browser'; +import { PolicyEngine } from '@anarchitecture/summon/policy'; import bootstrapSource from '@anarchitecture/summon/bootstrap.js?raw'; import tokensSource from '@anarchitecture/summon/tokens.css?raw'; import { STRICT_DEMO_BODY_HTML } from './strict-demo-artifact.js'; diff --git a/apps/server/package.json b/apps/server/package.json index 407984e..c598fb4 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -15,7 +15,8 @@ "cors": "^2.8.5", "express": "^4.21.2", "@anarchitecture/summon": "workspace:*", - "@anarchitecture/summon-server": "workspace:*" + "@anarchitecture/summon-server": "workspace:*", + "@summon-internal/engine": "workspace:*" }, "devDependencies": { "@types/cors": "^2.8.17", diff --git a/apps/server/src/directions-loader.ts b/apps/server/src/directions-loader.ts index cab2701..7541682 100644 --- a/apps/server/src/directions-loader.ts +++ b/apps/server/src/directions-loader.ts @@ -5,7 +5,7 @@ import { compileDirectionContract, coerceOpts, type DirectionOpts, -} from '@anarchitecture/summon'; +} from '@summon-internal/engine'; export const PREFERRED_DEFAULT_DIRECTION_ID = 'ghost'; diff --git a/apps/server/src/ghost-adapter.ts b/apps/server/src/ghost-adapter.ts index e5c159c..55cdc32 100644 --- a/apps/server/src/ghost-adapter.ts +++ b/apps/server/src/ghost-adapter.ts @@ -8,7 +8,8 @@ import { type GhostMemoryStackLayer, type PackageMemory, } from '@anarchitecture/ghost/scan'; -import { compileTokenContract, type ProtocolLine } from '@anarchitecture/summon'; +import type { ProtocolLine } from '@anarchitecture/summon'; +import { compileTokenContract } from '@summon-internal/engine'; import { existsSync, readFileSync, statSync } from 'node:fs'; import { mkdtemp, readFile, rm } from 'node:fs/promises'; import { tmpdir } from 'node:os'; diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts index 49f0663..fb96671 100644 --- a/apps/server/src/main.ts +++ b/apps/server/src/main.ts @@ -2,7 +2,6 @@ import express from 'express'; import cors from 'cors'; import Anthropic from '@anthropic-ai/sdk'; import { - parseTokenValues, type CapabilityPack, type ContractPromptBlock, type ProtocolLine, @@ -10,6 +9,7 @@ import { type SummonLayout, type TokenOverride, } from '@anarchitecture/summon'; +import { parseTokenValues } from '@summon-internal/engine'; import { resolveSurfaceGenerationPlan, runSurfaceGeneration, diff --git a/docs/adoption/integration.md b/docs/adoption/integration.md index 7044113..ec7db94 100644 --- a/docs/adoption/integration.md +++ b/docs/adoption/integration.md @@ -213,10 +213,10 @@ not from the artifact. ```ts import { createComponentIslandRegistry, - PolicyEngine, spawnSandbox, type SandboxHandle, -} from '@anarchitecture/summon'; +} from '@anarchitecture/summon/browser'; +import { PolicyEngine } from '@anarchitecture/summon/policy'; import { bootstrapSource, tokensSource, diff --git a/docs/adoption/public-packaging.md b/docs/adoption/public-packaging.md index 624abc9..06e1d85 100644 --- a/docs/adoption/public-packaging.md +++ b/docs/adoption/public-packaging.md @@ -14,11 +14,11 @@ Publish by install environment, not by internal implementation layer. @anarchitecture/summon-react ``` -`@anarchitecture/summon` is the frameworkless client/core package. It owns the -browser-facing runtime contract: protocol types and parsers, surface envelopes, -capability registry helpers, `PolicyEngine`, stream consumption, -`spawnSandbox`, runtime assets, validation helpers, and Devtools event store -exports. +`@anarchitecture/summon` is the shared host/contract package. Its root export is +kept narrow: protocol parsing, surface-plan helpers, host capability/component +contract helpers, and public diagnostics types. Browser runtime, policy, +envelope, assets, and Devtools APIs live on explicit subpaths such as +`@anarchitecture/summon/browser` and `@anarchitecture/summon/policy`. `@anarchitecture/summon-server` is the provider-neutral generation package. It owns `runSurfaceGeneration`, prompt/contract assembly, repair feedback, summary @@ -73,9 +73,11 @@ Keep the private implementation graph boring: - Keep docs/examples on public package names. - Publish only `@anarchitecture/summon`, `@anarchitecture/summon-server`, and `@anarchitecture/summon-react`. -- Build public packages by copying implementation `dist` output and rewriting - private imports to public or relative imports. -- Fail CI if public JS or `.d.ts` imports `@summon-internal/*`. +- Build public packages by copying implementation `dist` output under + `dist/_internal/*` and writing explicit public wrapper files. +- Fail CI if public JS or `.d.ts` imports `@summon-internal/*`, public wrappers + use `export *`, public-looking implementation dirs appear at `dist/*`, or + wrapper exports drift from `scripts/public-api-manifest.json`. - Do source-health work here when it is destination-agnostic: tests, security fixes, API cleanup, build reliability, and package metadata correctness. diff --git a/package.json b/package.json index 8961519..1b1aecb 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,12 @@ "dev": "pnpm --filter @summon-internal/demo dev", "dev:server": "pnpm --filter @summon-internal/demo-server dev", "dev:all": "pnpm -r --parallel --stream --filter @summon-internal/demo-server --filter @summon-internal/demo dev", - "build:impl": "pnpm -r --filter @summon-internal/devtools --filter @summon-internal/engine --filter @summon-internal/sandbox-runtime --filter @summon-internal/host --filter @summon-internal/server --filter @summon-internal/react build", + "build:impl": "pnpm -r --filter @summon-internal/devtools --filter @summon-internal/engine --filter @summon-internal/sandbox-runtime --filter @summon-internal/host --filter @summon-internal/server build", + "build:react-impl": "pnpm --filter @summon-internal/react build", + "build:public-core": "node scripts/build-public-packages.mjs summon summon-server", "build:public": "node scripts/build-public-packages.mjs", "build:apps": "pnpm --filter @summon-internal/demo build", - "build": "pnpm build:impl && pnpm build:public && pnpm build:apps", + "build": "pnpm build:impl && pnpm build:public-core && pnpm build:react-impl && pnpm build:public && pnpm build:apps", "check:public-packages": "node scripts/check-public-packages.mjs", "pack:dry-run": "pnpm -r --filter \"@anarchitecture/*\" exec npm --cache /tmp/summon-npm-cache pack --dry-run --json", "smoke:public-packages": "node scripts/smoke-public-packages.mjs", @@ -24,7 +26,7 @@ "port-direction": "tsx scripts/port-direction.ts", "eval-directions": "tsx scripts/eval-directions.ts" }, - "packageManager": "pnpm@10.0.0", + "packageManager": "pnpm@10.33.0", "engines": { "node": ">=18" }, diff --git a/packages/devtools/src/index.ts b/packages/devtools/src/index.ts index 2bd9e84..71fa378 100644 --- a/packages/devtools/src/index.ts +++ b/packages/devtools/src/index.ts @@ -17,5 +17,8 @@ export type { ProtocolParseErrorEvent, StreamLifecycleEvent, StreamGraphEvent, + SurfacePlanEvent, RenderEvent, + ComponentSyncEvent, + ComponentErrorEvent, } from './types.js'; diff --git a/packages/react/package.json b/packages/react/package.json index a2936bb..bc6681b 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -19,10 +19,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@summon-internal/devtools": "workspace:*", - "@summon-internal/engine": "workspace:*", - "@summon-internal/host": "workspace:*", - "@summon-internal/sandbox-runtime": "workspace:*" + "@anarchitecture/summon": "workspace:*" }, "peerDependencies": { "react": ">=18.3.0 || >=19.0.0", diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index 80dd49f..7da4f29 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -1,23 +1,25 @@ -import { createEventStore, type DevtoolsEvent, type EventStore } from '@summon-internal/devtools'; -import { SectionAccumulator, type ProtocolLine } from '@summon-internal/engine'; +import { + type CapabilityRegistry, + type ComponentDefinition, + type ComponentRegistry, + SectionAccumulator, + type ProtocolLine, +} from '@anarchitecture/summon'; import { createComponentIslandRegistry, - defineComponent as defineHostComponent, - PolicyEngine, spawnSandbox, type Artifact, - type CapabilityRegistry, - type ComponentDefinition, type ComponentIslandError, type ComponentIslandRegistry, - type ComponentRegistry, type SandboxHandle, -} from '@summon-internal/host'; -import type { SurfaceEnvelope } from '@summon-internal/host/envelope'; +} from '@anarchitecture/summon/browser'; +import { createEventStore, type DevtoolsEvent } from '@anarchitecture/summon/devtools'; +import type { SurfaceEnvelope } from '@anarchitecture/summon/envelope'; +import { PolicyEngine } from '@anarchitecture/summon/policy'; import { bootstrapSource as defaultBootstrapSource, tokensSource as defaultTokensSource, -} from '@summon-internal/sandbox-runtime/assets'; +} from '@anarchitecture/summon/assets'; import { createElement, useEffect, useMemo, useRef, type ComponentType, type CSSProperties } from 'react'; import { createRoot, type Root } from 'react-dom/client'; @@ -193,7 +195,7 @@ export function defineReactComponent( ): ComponentDefinition { const roots = new WeakMap(); const { component, mapProps, ...rest } = definition; - return defineHostComponent({ + return { ...rest, render: ({ container, props, componentId, sandboxId, emitIntent }) => { let root = roots.get(container); @@ -215,7 +217,7 @@ export function defineReactComponent( root?.unmount(); roots.delete(container); }, - }); + }; } function resolveHtml(props: SummonSurfaceProps): string { diff --git a/packages/react/tsconfig.build.json b/packages/react/tsconfig.build.json index 5833a00..f3d2382 100644 --- a/packages/react/tsconfig.build.json +++ b/packages/react/tsconfig.build.json @@ -6,10 +6,18 @@ "noEmit": false, "outDir": "./dist", "paths": { + "@anarchitecture/summon": ["packages/summon/dist/index.d.ts"], + "@anarchitecture/summon/assets": ["packages/summon/dist/assets.d.ts"], + "@anarchitecture/summon/browser": ["packages/summon/dist/browser.d.ts"], + "@anarchitecture/summon/devtools": ["packages/summon/dist/devtools.d.ts"], + "@anarchitecture/summon/envelope": ["packages/summon/dist/envelope.d.ts"], + "@anarchitecture/summon/policy": ["packages/summon/dist/policy.d.ts"], "@summon-internal/devtools": ["packages/devtools/dist/index.d.ts"], "@summon-internal/engine": ["packages/engine/dist/index.d.ts"], "@summon-internal/host": ["packages/host/dist/index.d.ts"], + "@summon-internal/host/browser": ["packages/host/dist/browser.d.ts"], "@summon-internal/host/envelope": ["packages/host/dist/envelope.d.ts"], + "@summon-internal/host/policy": ["packages/host/dist/policy.d.ts"], "@summon-internal/sandbox-runtime/assets": ["packages/sandbox-runtime/dist/assets.d.ts"] }, "rootDir": "./src", diff --git a/packages/summon-react/src/index.ts b/packages/summon-react/src/index.ts index 90f501f..318ce6c 100644 --- a/packages/summon-react/src/index.ts +++ b/packages/summon-react/src/index.ts @@ -1 +1,10 @@ -export * from '@summon-internal/react'; +export { + SummonSurface, + defineReactComponent, +} from '@summon-internal/react'; +export type { + ReactComponentRuntimeContext, + ReactComponentWithRuntimeDefinition, + SummonSurfaceChrome, + SummonSurfaceProps, +} from '@summon-internal/react'; diff --git a/packages/summon-server/src/index.ts b/packages/summon-server/src/index.ts index b4aee44..2eed851 100644 --- a/packages/summon-server/src/index.ts +++ b/packages/summon-server/src/index.ts @@ -1 +1,27 @@ -export * from '@summon-internal/server'; +export { + generateSurfaceStream, + resolveSurfaceGenerationPlan, + runSurfaceGeneration, + summarizeContractIssues, +} from '@summon-internal/server'; +export type { + ContractIssue, + ContractPromptBlock, + GenerateEditInput, + GenerateSurfaceInput, + GenerationSummary, + ProtocolLine, + ProtocolSkipMetaValue, + RepairFeedbackMetaValue, + RepairOptions, + RepairStats, + ResolvedSurfaceGenerationPlan, + ResolveSurfaceGenerationPlanInput, + SummonModelChunk, + SummonModelProvider, + SummonModelRequest, + SummonRepairProvider, + SummonRepairRequest, + SurfaceGenerationInput, + SurfaceGenerationSummary, +} from '@summon-internal/server'; diff --git a/packages/summon/package.json b/packages/summon/package.json index a31fd45..161c25b 100644 --- a/packages/summon/package.json +++ b/packages/summon/package.json @@ -47,8 +47,8 @@ "types": "./dist/devtools.d.ts", "import": "./dist/devtools.js" }, - "./bootstrap.js": "./dist/sandbox-runtime/bootstrap.js", - "./tokens.css": "./dist/sandbox-runtime/tokens.css", + "./bootstrap.js": "./dist/_internal/sandbox-runtime/bootstrap.js", + "./tokens.css": "./dist/_internal/sandbox-runtime/tokens.css", "./package.json": "./package.json" }, "files": [ diff --git a/packages/summon/src/assets.ts b/packages/summon/src/assets.ts index 5c7c51e..b489296 100644 --- a/packages/summon/src/assets.ts +++ b/packages/summon/src/assets.ts @@ -1 +1,4 @@ -export * from '@summon-internal/sandbox-runtime/assets'; +export { + bootstrapSource, + tokensSource, +} from '@summon-internal/sandbox-runtime/assets'; diff --git a/packages/summon/src/browser.ts b/packages/summon/src/browser.ts index 1220ad0..701616d 100644 --- a/packages/summon/src/browser.ts +++ b/packages/summon/src/browser.ts @@ -1 +1,37 @@ -export * from '@summon-internal/host/browser'; +export { + consumeSurfaceStream, + createComponentIslandRegistry, + createStrictInputRegistry, + spawnSandbox, +} from '@summon-internal/host/browser'; +export type { + Artifact, + ComponentIslandBounds, + ComponentIslandDescriptor, + ComponentIslandError, + ComponentIslandErrorCode, + ComponentIslandRegistry, + ComponentIslandRegistryOptions, + ComponentIslandSyncContext, + ComponentsMessage, + FatalMessage, + IntentMessage, + ReadyMessage, + SandboxHandle, + SandboxInboundMessage, + SpawnOptions, + StateMessage, + StrictInputBounds, + StrictInputController, + StrictInputFactory, + StrictInputFactoryArgs, + StrictInputRegistry, + StrictInputRegistryOptions, + SurfaceStreamContext, + SurfaceStreamLineDecision, + SurfaceStreamOptions, + SurfaceStreamParseError, + SurfaceStreamRenderMode, + SurfaceStreamResult, + SurfaceStreamSource, +} from '@summon-internal/host/browser'; diff --git a/packages/summon/src/devtools.ts b/packages/summon/src/devtools.ts index 92ed025..6b9deaf 100644 --- a/packages/summon/src/devtools.ts +++ b/packages/summon/src/devtools.ts @@ -1 +1,25 @@ -export * from '@summon-internal/devtools'; +export { createEventStore } from '@summon-internal/devtools'; +export type { + BaseEvent, + ComponentErrorEvent, + ComponentSyncEvent, + DevtoolsEvent, + DevtoolsEventKind, + EventStore, + EventStoreOptions, + IntentDispatchedEvent, + IntentEmittedEvent, + IntentRejectedEvent, + IntentSettledEvent, + ProtocolLineEvent, + ProtocolParseErrorEvent, + RenderEvent, + SandboxDisposedEvent, + SandboxFatalEvent, + SandboxReadyEvent, + SandboxSpawnedEvent, + StatePushedEvent, + StreamGraphEvent, + StreamLifecycleEvent, + SurfacePlanEvent, +} from '@summon-internal/devtools'; diff --git a/packages/summon/src/envelope.ts b/packages/summon/src/envelope.ts index 3a27aa2..79d6694 100644 --- a/packages/summon/src/envelope.ts +++ b/packages/summon/src/envelope.ts @@ -1 +1,10 @@ -export * from '@summon-internal/host/envelope'; +export { + SUMMON_SURFACE_ENVELOPE_VERSION, + createSurfaceEnvelope, + isSurfaceEnvelope, + parseSurfaceEnvelope, +} from '@summon-internal/host/envelope'; +export type { + CreateSurfaceEnvelopeInput, + SurfaceEnvelope, +} from '@summon-internal/host/envelope'; diff --git a/packages/summon/src/index.ts b/packages/summon/src/index.ts index b295b12..f66d458 100644 --- a/packages/summon/src/index.ts +++ b/packages/summon/src/index.ts @@ -1,4 +1,103 @@ -export * from '@summon-internal/engine'; -export * from '@summon-internal/host'; -export * from '@summon-internal/devtools'; -export { bootstrapSource, tokensSource } from '@summon-internal/sandbox-runtime/assets'; +export { + DEFAULT_SURFACE_CEILING, + DEFAULT_SURFACE_PLAN, + ProtocolParseError, + SectionAccumulator, + StreamGraph, + SURFACE_AUTHORITY_VALUES, + SURFACE_DATA_VALUES, + SURFACE_PERSISTENCE_VALUES, + SURFACE_PURPOSE_VALUES, + SURFACE_RUNTIME_VALUES, + constrainSurfacePlan, + deriveSurfacePlanControls, + hintsForContractIssue, + inferSurfacePlan, + isProtocolLine, + normalizeSurfaceCeiling, + normalizeSurfacePlan, + parseProtocolLine, + parseProtocolLineStrict, + surfacePlanWithinCeiling, +} from '@summon-internal/engine'; +export type { + AddLine, + CapabilityKind, + CapabilityPack, + CapabilityPattern, + CapabilityStateKeys, + CapabilitySurface, + CapabilityTrigger, + ComponentExample, + ComponentPack, + ComponentSizing, + ComponentSpec, + ComponentSurface, + ContractIssue, + ContractIssueSeverity, + ContractIssueSource, + ContractPromptBlock, + DataResourceSpec, + DirectionContractInput, + DirectionInput, + Exemplar, + IntentSpec, + MetaLine, + ProtocolLine, + ProtocolParseErrorCode, + ProtocolParseOptions, + ProtocolSkipMetaValue, + RepairFeedbackMetaValue, + ScreenSynthesizedMetaValue, + ScriptPolicy, + SectionAccumulatorSnapshot, + SectionApplyKind, + SectionApplyResult, + SectionSnapshotEntry, + SetLine, + StreamGraphEdge, + StreamGraphHealth, + StreamGraphSection, + StreamGraphSnapshot, + SummonLayout, + SummonLayoutSlot, + SurfaceAuthority, + SurfaceCeiling, + SurfaceData, + SurfacePersistence, + SurfacePlan, + SurfacePlanControls, + SurfacePlanInferenceInput, + SurfacePlanMode, + SurfacePurpose, + SurfaceRuntime, + TokenOverride, + ValidationCapability, + ValidationComponent, +} from '@summon-internal/engine'; +export { + createCapabilityRegistry, + createComponentRegistry, + defineAction, + defineApprovalAction, + defineComponent, + defineDataResource, + defineWorkerAction, + defineWorkerResource, +} from '@summon-internal/host'; +export type { + ActionDefinition, + ApprovalActionDefinition, + ApprovalDecision, + ApprovalStateKeys, + CapabilityDefinition, + CapabilityRegistry, + ComponentDefinition, + ComponentDestroyer, + ComponentPropsParseResult, + ComponentRegistry, + ComponentRenderContext, + ComponentRenderer, + DataResourceDefinition, + StateShapeDescriptor, +} from '@summon-internal/host'; diff --git a/packages/summon/src/policy.ts b/packages/summon/src/policy.ts index 1fa0876..e7365b7 100644 --- a/packages/summon/src/policy.ts +++ b/packages/summon/src/policy.ts @@ -1 +1,12 @@ -export * from '@summon-internal/host/policy'; +export { + IntentArgsError, + PolicyEngine, + defineIntent, +} from '@summon-internal/host/policy'; +export type { + IntentContext, + IntentEntry, + IntentHandler, + PolicyEngineOptions, + TypedIntentEntry, +} from '@summon-internal/host/policy'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 385af9b..0dc6d8c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: '@anarchitecture/summon': specifier: workspace:* version: link:../../packages/summon + '@summon-internal/engine': + specifier: workspace:* + version: link:../../packages/engine zod: specifier: ^3.23.0 version: 3.25.76 @@ -54,6 +57,9 @@ importers: '@anthropic-ai/sdk': specifier: ^0.88.0 version: 0.88.0(zod@4.4.3) + '@summon-internal/engine': + specifier: workspace:* + version: link:../../packages/engine cors: specifier: ^2.8.5 version: 2.8.6 @@ -116,18 +122,9 @@ importers: packages/react: dependencies: - '@summon-internal/devtools': - specifier: workspace:* - version: link:../devtools - '@summon-internal/engine': - specifier: workspace:* - version: link:../engine - '@summon-internal/host': - specifier: workspace:* - version: link:../host - '@summon-internal/sandbox-runtime': + '@anarchitecture/summon': specifier: workspace:* - version: link:../sandbox-runtime + version: link:../summon devDependencies: '@types/react': specifier: ^18.3.0 @@ -173,7 +170,7 @@ importers: packages/summon-react: dependencies: '@anarchitecture/summon': - specifier: ^0.1.0 + specifier: ^0.2.0 version: link:../summon devDependencies: '@types/react': @@ -195,7 +192,7 @@ importers: packages/summon-server: dependencies: '@anarchitecture/summon': - specifier: ^0.1.0 + specifier: ^0.2.0 version: link:../summon devDependencies: typescript: diff --git a/scripts/build-public-packages.mjs b/scripts/build-public-packages.mjs index e8a1ac0..c89db57 100644 --- a/scripts/build-public-packages.mjs +++ b/scripts/build-public-packages.mjs @@ -1,5 +1,5 @@ import { mkdir, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises'; -import { dirname, extname, join, relative } from 'node:path'; +import { dirname, extname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const rootDir = dirname(fileURLToPath(new URL('../package.json', import.meta.url))); @@ -19,6 +19,292 @@ const targets = requested.length > 0 ? requested : ['summon', 'summon-server', ' const textExtensions = new Set(['.js', '.d.ts']); const copiedExtensions = new Set(['.js', '.d.ts', '.css']); +const coreExports = { + '.': { + values: { + './_internal/engine/index.js': [ + 'DEFAULT_SURFACE_CEILING', + 'DEFAULT_SURFACE_PLAN', + 'ProtocolParseError', + 'SectionAccumulator', + 'StreamGraph', + 'SURFACE_AUTHORITY_VALUES', + 'SURFACE_DATA_VALUES', + 'SURFACE_PERSISTENCE_VALUES', + 'SURFACE_PURPOSE_VALUES', + 'SURFACE_RUNTIME_VALUES', + 'constrainSurfacePlan', + 'deriveSurfacePlanControls', + 'hintsForContractIssue', + 'inferSurfacePlan', + 'isProtocolLine', + 'normalizeSurfaceCeiling', + 'normalizeSurfacePlan', + 'parseProtocolLine', + 'parseProtocolLineStrict', + 'surfacePlanWithinCeiling', + ], + './_internal/host/index.js': [ + 'createCapabilityRegistry', + 'createComponentRegistry', + 'defineAction', + 'defineApprovalAction', + 'defineComponent', + 'defineDataResource', + 'defineWorkerAction', + 'defineWorkerResource', + ], + }, + types: { + './_internal/engine/index.js': [ + 'AddLine', + 'CapabilityKind', + 'CapabilityPack', + 'CapabilityPattern', + 'CapabilityStateKeys', + 'CapabilitySurface', + 'CapabilityTrigger', + 'ComponentExample', + 'ComponentPack', + 'ComponentSizing', + 'ComponentSpec', + 'ComponentSurface', + 'ContractIssue', + 'ContractIssueSeverity', + 'ContractIssueSource', + 'ContractPromptBlock', + 'DataResourceSpec', + 'DirectionContractInput', + 'DirectionInput', + 'Exemplar', + 'IntentSpec', + 'MetaLine', + 'ProtocolLine', + 'ProtocolParseErrorCode', + 'ProtocolParseOptions', + 'ProtocolSkipMetaValue', + 'RepairFeedbackMetaValue', + 'ScreenSynthesizedMetaValue', + 'ScriptPolicy', + 'SectionAccumulatorSnapshot', + 'SectionApplyKind', + 'SectionApplyResult', + 'SectionSnapshotEntry', + 'SetLine', + 'StreamGraphEdge', + 'StreamGraphHealth', + 'StreamGraphSection', + 'StreamGraphSnapshot', + 'SummonLayout', + 'SummonLayoutSlot', + 'SurfaceAuthority', + 'SurfaceCeiling', + 'SurfaceData', + 'SurfacePersistence', + 'SurfacePlan', + 'SurfacePlanControls', + 'SurfacePlanInferenceInput', + 'SurfacePlanMode', + 'SurfacePurpose', + 'SurfaceRuntime', + 'TokenOverride', + 'ValidationCapability', + 'ValidationComponent', + ], + './_internal/host/index.js': [ + 'ActionDefinition', + 'ApprovalActionDefinition', + 'ApprovalDecision', + 'ApprovalStateKeys', + 'CapabilityDefinition', + 'CapabilityRegistry', + 'ComponentDefinition', + 'ComponentDestroyer', + 'ComponentPropsParseResult', + 'ComponentRegistry', + 'ComponentRenderContext', + 'ComponentRenderer', + 'DataResourceDefinition', + 'StateShapeDescriptor', + ], + }, + }, + './browser': { + values: { + './_internal/host/browser.js': [ + 'consumeSurfaceStream', + 'createComponentIslandRegistry', + 'createStrictInputRegistry', + 'spawnSandbox', + ], + }, + types: { + './_internal/host/browser.js': [ + 'Artifact', + 'ComponentIslandBounds', + 'ComponentIslandDescriptor', + 'ComponentIslandError', + 'ComponentIslandErrorCode', + 'ComponentIslandRegistry', + 'ComponentIslandRegistryOptions', + 'ComponentIslandSyncContext', + 'ComponentsMessage', + 'FatalMessage', + 'IntentMessage', + 'ReadyMessage', + 'SandboxHandle', + 'SandboxInboundMessage', + 'SpawnOptions', + 'StateMessage', + 'StrictInputBounds', + 'StrictInputController', + 'StrictInputFactory', + 'StrictInputFactoryArgs', + 'StrictInputRegistry', + 'StrictInputRegistryOptions', + 'SurfaceStreamContext', + 'SurfaceStreamLineDecision', + 'SurfaceStreamOptions', + 'SurfaceStreamParseError', + 'SurfaceStreamRenderMode', + 'SurfaceStreamResult', + 'SurfaceStreamSource', + ], + }, + }, + './policy': { + values: { + './_internal/host/policy.js': [ + 'IntentArgsError', + 'PolicyEngine', + 'defineIntent', + ], + }, + types: { + './_internal/host/policy.js': [ + 'IntentContext', + 'IntentEntry', + 'IntentHandler', + 'PolicyEngineOptions', + 'TypedIntentEntry', + ], + }, + }, + './envelope': { + values: { + './_internal/host/envelope.js': [ + 'SUMMON_SURFACE_ENVELOPE_VERSION', + 'createSurfaceEnvelope', + 'isSurfaceEnvelope', + 'parseSurfaceEnvelope', + ], + }, + types: { + './_internal/host/envelope.js': [ + 'CreateSurfaceEnvelopeInput', + 'SurfaceEnvelope', + ], + }, + }, + './assets': { + values: { + './_internal/sandbox-runtime/assets.js': [ + 'bootstrapSource', + 'tokensSource', + ], + }, + types: {}, + }, + './devtools': { + values: { + './_internal/devtools/index.js': [ + 'createEventStore', + ], + }, + types: { + './_internal/devtools/index.js': [ + 'BaseEvent', + 'ComponentErrorEvent', + 'ComponentSyncEvent', + 'DevtoolsEvent', + 'DevtoolsEventKind', + 'EventStore', + 'EventStoreOptions', + 'IntentDispatchedEvent', + 'IntentEmittedEvent', + 'IntentRejectedEvent', + 'IntentSettledEvent', + 'ProtocolLineEvent', + 'ProtocolParseErrorEvent', + 'RenderEvent', + 'SandboxDisposedEvent', + 'SandboxFatalEvent', + 'SandboxReadyEvent', + 'SandboxSpawnedEvent', + 'StatePushedEvent', + 'StreamGraphEvent', + 'StreamLifecycleEvent', + 'SurfacePlanEvent', + ], + }, + }, +}; + +const serverExports = { + '.': { + values: { + './_internal/server/index.js': [ + 'generateSurfaceStream', + 'resolveSurfaceGenerationPlan', + 'runSurfaceGeneration', + 'summarizeContractIssues', + ], + }, + types: { + './_internal/server/index.js': [ + 'ContractIssue', + 'ContractPromptBlock', + 'GenerateEditInput', + 'GenerateSurfaceInput', + 'GenerationSummary', + 'ProtocolLine', + 'ProtocolSkipMetaValue', + 'RepairFeedbackMetaValue', + 'RepairOptions', + 'RepairStats', + 'ResolvedSurfaceGenerationPlan', + 'ResolveSurfaceGenerationPlanInput', + 'SummonModelChunk', + 'SummonModelProvider', + 'SummonModelRequest', + 'SummonRepairProvider', + 'SummonRepairRequest', + 'SurfaceGenerationInput', + 'SurfaceGenerationSummary', + ], + }, + }, +}; + +const reactExports = { + '.': { + values: { + './_internal/react/index.js': [ + 'SummonSurface', + 'defineReactComponent', + ], + }, + types: { + './_internal/react/index.js': [ + 'ReactComponentRuntimeContext', + 'ReactComponentWithRuntimeDefinition', + 'SummonSurfaceChrome', + 'SummonSurfaceProps', + ], + }, + }, +}; + function resolveRoot(...parts) { return join(rootDir, ...parts); } @@ -73,6 +359,42 @@ async function assertBuilt(packageDir) { throw new Error(`${packageDir} must be built before public packages are assembled`); } +function exportLines(map, kind = 'value') { + const lines = []; + for (const [source, names] of Object.entries(map)) { + if (names.length === 0) continue; + const keyword = kind === 'type' ? 'export type' : 'export'; + lines.push(`${keyword} {\n${names.map((name) => ` ${name},`).join('\n')}\n} from '${source}';`); + } + return lines; +} + +function wrapperModule({ values, types }, includeTypes) { + return [ + ...exportLines(values), + ...(includeTypes ? exportLines(types, 'type') : []), + '', + ].join('\n'); +} + +async function writeWrappers(distDir, definitions) { + const files = { + '.': 'index', + './browser': 'browser', + './policy': 'policy', + './envelope': 'envelope', + './assets': 'assets', + './devtools': 'devtools', + }; + + for (const [subpath, definition] of Object.entries(definitions)) { + const basename = files[subpath]; + if (!basename) throw new Error(`No wrapper file mapping for ${subpath}`); + await writeText(join(distDir, `${basename}.js`), wrapperModule(definition, false)); + await writeText(join(distDir, `${basename}.d.ts`), wrapperModule(definition, true)); + } +} + async function buildCore() { await Promise.all([ assertBuilt('packages/devtools'), @@ -84,67 +406,39 @@ async function buildCore() { const distDir = resolveRoot('packages/summon/dist'); await rm(distDir, { recursive: true, force: true }); - await copyDistTree(resolveRoot('packages/engine/dist'), join(distDir, 'engine')); - await copyDistTree(resolveRoot('packages/devtools/dist'), join(distDir, 'devtools')); - await copyDistTree(resolveRoot('packages/sandbox-runtime/dist'), join(distDir, 'sandbox-runtime')); - await copyDistTree(resolveRoot('packages/host/dist'), join(distDir, 'host'), [ + await copyDistTree(resolveRoot('packages/engine/dist'), join(distDir, '_internal', 'engine')); + await copyDistTree(resolveRoot('packages/devtools/dist'), join(distDir, '_internal', 'devtools')); + await copyDistTree(resolveRoot('packages/sandbox-runtime/dist'), join(distDir, '_internal', 'sandbox-runtime')); + await copyDistTree(resolveRoot('packages/host/dist'), join(distDir, '_internal', 'host'), [ ['@summon-internal/sandbox-runtime/assets', '../sandbox-runtime/assets.js'], ['@summon-internal/devtools', '../devtools/index.js'], ['@summon-internal/engine', '../engine/index.js'], ]); - const wrappers = { - 'index.js': [ - "export * from './engine/index.js';", - "export * from './host/index.js';", - "export * from './devtools/index.js';", - "export { bootstrapSource, tokensSource } from './sandbox-runtime/assets.js';", - '', - ].join('\n'), - 'index.d.ts': [ - "export * from './engine/index.js';", - "export * from './host/index.js';", - "export * from './devtools/index.js';", - "export { bootstrapSource, tokensSource } from './sandbox-runtime/assets.js';", - '', - ].join('\n'), - 'browser.js': "export * from './host/browser.js';\n", - 'browser.d.ts': "export * from './host/browser.js';\n", - 'policy.js': "export * from './host/policy.js';\n", - 'policy.d.ts': "export * from './host/policy.js';\n", - 'envelope.js': "export * from './host/envelope.js';\n", - 'envelope.d.ts': "export * from './host/envelope.js';\n", - 'assets.js': "export * from './sandbox-runtime/assets.js';\n", - 'assets.d.ts': "export * from './sandbox-runtime/assets.js';\n", - 'devtools.js': "export * from './devtools/index.js';\n", - 'devtools.d.ts': "export * from './devtools/index.js';\n", - }; - - for (const [file, content] of Object.entries(wrappers)) { - await writeText(join(distDir, file), content); - } + await writeWrappers(distDir, coreExports); } async function buildServer() { - await assertBuilt('packages/server'); + await Promise.all([ + assertBuilt('packages/engine'), + assertBuilt('packages/server'), + ]); + const distDir = resolveRoot('packages/summon-server/dist'); await rm(distDir, { recursive: true, force: true }); - await copyDistTree(resolveRoot('packages/server/dist'), distDir, [ - ['@summon-internal/engine', '@anarchitecture/summon'], + await copyDistTree(resolveRoot('packages/engine/dist'), join(distDir, '_internal', 'engine')); + await copyDistTree(resolveRoot('packages/server/dist'), join(distDir, '_internal', 'server'), [ + ['@summon-internal/engine', '../engine/index.js'], ]); + await writeWrappers(distDir, serverExports); } async function buildReact() { await assertBuilt('packages/react'); const distDir = resolveRoot('packages/summon-react/dist'); await rm(distDir, { recursive: true, force: true }); - await copyDistTree(resolveRoot('packages/react/dist'), distDir, [ - ['@summon-internal/sandbox-runtime/assets', '@anarchitecture/summon/assets'], - ['@summon-internal/host/envelope', '@anarchitecture/summon/envelope'], - ['@summon-internal/devtools', '@anarchitecture/summon/devtools'], - ['@summon-internal/engine', '@anarchitecture/summon'], - ['@summon-internal/host', '@anarchitecture/summon'], - ]); + await copyDistTree(resolveRoot('packages/react/dist'), join(distDir, '_internal', 'react')); + await writeWrappers(distDir, reactExports); } const builders = { diff --git a/scripts/check-public-packages.mjs b/scripts/check-public-packages.mjs index 0402c2b..9a203e9 100644 --- a/scripts/check-public-packages.mjs +++ b/scripts/check-public-packages.mjs @@ -3,11 +3,10 @@ import { dirname, extname, join, relative } from 'node:path'; import { fileURLToPath } from 'node:url'; const rootDir = dirname(fileURLToPath(new URL('../package.json', import.meta.url))); -const publicPackages = [ - 'packages/summon', - 'packages/summon-server', - 'packages/summon-react', -]; +const publicApiManifest = JSON.parse( + await readFile(join(rootDir, 'scripts/public-api-manifest.json'), 'utf8'), +); +const publicPackages = Object.keys(publicApiManifest); const inspectedExtensions = new Set(['.js', '.d.ts']); async function* walk(dir) { @@ -34,6 +33,94 @@ async function assertDist(packageDir) { return distDir; } +function sortedUnique(values) { + return Array.from(new Set(values)).sort(); +} + +function exportedNames(text, kind) { + const names = []; + const re = /export\s+(type\s+)?\{([\s\S]*?)\}\s+from\s+['"][^'"]+['"]/g; + let match; + while ((match = re.exec(text))) { + const isType = Boolean(match[1]); + if ((kind === 'type') !== isType) continue; + for (const raw of match[2].split(',')) { + const name = raw.trim(); + if (!name) continue; + names.push(name.split(/\s+as\s+/)[1]?.trim() ?? name); + } + } + return sortedUnique(names); +} + +function equalList(a, b) { + const left = sortedUnique(a); + const right = sortedUnique(b); + return left.length === right.length && left.every((value, index) => value === right[index]); +} + +function listDiff(actual, expected) { + const actualSet = new Set(actual); + const expectedSet = new Set(expected); + const extra = actual.filter((name) => !expectedSet.has(name)); + const missing = expected.filter((name) => !actualSet.has(name)); + return { extra, missing }; +} + +function assertExportList(failures, label, actual, expected) { + if (equalList(actual, expected)) return; + const { extra, missing } = listDiff(actual, expected); + failures.push( + `${label} does not match public API manifest` + + `${extra.length ? `; extra: ${extra.join(', ')}` : ''}` + + `${missing.length ? `; missing: ${missing.join(', ')}` : ''}`, + ); +} + +async function assertNoPublicRootDirs(packageDir, distDir, failures) { + for (const entry of await readdir(distDir, { withFileTypes: true })) { + if (!entry.isDirectory()) continue; + if (entry.name === '_internal') continue; + failures.push(`${packageDir}/dist/${entry.name} is a public-looking implementation directory`); + } +} + +async function assertPublicApi(packageDir, distDir, failures) { + const packageManifest = publicApiManifest[packageDir]; + for (const [subpath, expected] of Object.entries(packageManifest)) { + const jsPath = join(distDir, `${expected.file}.js`); + const dtsPath = join(distDir, `${expected.file}.d.ts`); + const jsText = await readFile(jsPath, 'utf8'); + const dtsText = await readFile(dtsPath, 'utf8'); + + if (/export\s+\*/.test(jsText)) { + failures.push(`${relative(rootDir, jsPath)} must not use export *`); + } + if (/export\s+\*/.test(dtsText)) { + failures.push(`${relative(rootDir, dtsPath)} must not use export *`); + } + + assertExportList( + failures, + `${packageDir} ${subpath} value exports`, + exportedNames(jsText, 'value'), + expected.values, + ); + assertExportList( + failures, + `${packageDir} ${subpath} declaration value exports`, + exportedNames(dtsText, 'value'), + expected.values, + ); + assertExportList( + failures, + `${packageDir} ${subpath} type exports`, + exportedNames(dtsText, 'type'), + expected.types, + ); + } +} + const failures = []; for (const packageDir of publicPackages) { @@ -51,6 +138,8 @@ for (const packageDir of publicPackages) { failures.push(`${packageDir}/package.json exposes @summon-internal dependencies`); } const distDir = await assertDist(packageDir); + await assertNoPublicRootDirs(packageDir, distDir, failures); + await assertPublicApi(packageDir, distDir, failures); for await (const file of walk(distDir)) { if (file.endsWith('.map')) { failures.push(`${relative(rootDir, file)} should not be published in public package dist`); @@ -72,4 +161,4 @@ if (failures.length > 0) { process.exit(1); } -console.log('public package dist is clean'); +console.log('public package API and dist are clean'); diff --git a/scripts/public-api-manifest.json b/scripts/public-api-manifest.json new file mode 100644 index 0000000..67e614b --- /dev/null +++ b/scripts/public-api-manifest.json @@ -0,0 +1,244 @@ +{ + "packages/summon": { + ".": { + "file": "index", + "values": [ + "DEFAULT_SURFACE_CEILING", + "DEFAULT_SURFACE_PLAN", + "ProtocolParseError", + "SectionAccumulator", + "StreamGraph", + "SURFACE_AUTHORITY_VALUES", + "SURFACE_DATA_VALUES", + "SURFACE_PERSISTENCE_VALUES", + "SURFACE_PURPOSE_VALUES", + "SURFACE_RUNTIME_VALUES", + "constrainSurfacePlan", + "createCapabilityRegistry", + "createComponentRegistry", + "defineAction", + "defineApprovalAction", + "defineComponent", + "defineDataResource", + "defineWorkerAction", + "defineWorkerResource", + "deriveSurfacePlanControls", + "hintsForContractIssue", + "inferSurfacePlan", + "isProtocolLine", + "normalizeSurfaceCeiling", + "normalizeSurfacePlan", + "parseProtocolLine", + "parseProtocolLineStrict", + "surfacePlanWithinCeiling" + ], + "types": [ + "ActionDefinition", + "AddLine", + "ApprovalActionDefinition", + "ApprovalDecision", + "ApprovalStateKeys", + "CapabilityDefinition", + "CapabilityKind", + "CapabilityPack", + "CapabilityPattern", + "CapabilityRegistry", + "CapabilityStateKeys", + "CapabilitySurface", + "CapabilityTrigger", + "ComponentDefinition", + "ComponentDestroyer", + "ComponentExample", + "ComponentPack", + "ComponentPropsParseResult", + "ComponentRegistry", + "ComponentRenderContext", + "ComponentRenderer", + "ComponentSizing", + "ComponentSpec", + "ComponentSurface", + "ContractIssue", + "ContractIssueSeverity", + "ContractIssueSource", + "ContractPromptBlock", + "DataResourceDefinition", + "DataResourceSpec", + "DirectionContractInput", + "DirectionInput", + "Exemplar", + "IntentSpec", + "MetaLine", + "ProtocolLine", + "ProtocolParseErrorCode", + "ProtocolParseOptions", + "ProtocolSkipMetaValue", + "RepairFeedbackMetaValue", + "ScreenSynthesizedMetaValue", + "ScriptPolicy", + "SectionAccumulatorSnapshot", + "SectionApplyKind", + "SectionApplyResult", + "SectionSnapshotEntry", + "SetLine", + "StateShapeDescriptor", + "StreamGraphEdge", + "StreamGraphHealth", + "StreamGraphSection", + "StreamGraphSnapshot", + "SummonLayout", + "SummonLayoutSlot", + "SurfaceAuthority", + "SurfaceCeiling", + "SurfaceData", + "SurfacePersistence", + "SurfacePlan", + "SurfacePlanControls", + "SurfacePlanInferenceInput", + "SurfacePlanMode", + "SurfacePurpose", + "SurfaceRuntime", + "TokenOverride", + "ValidationCapability", + "ValidationComponent" + ] + }, + "./assets": { + "file": "assets", + "values": ["bootstrapSource", "tokensSource"], + "types": [] + }, + "./browser": { + "file": "browser", + "values": [ + "consumeSurfaceStream", + "createComponentIslandRegistry", + "createStrictInputRegistry", + "spawnSandbox" + ], + "types": [ + "Artifact", + "ComponentIslandBounds", + "ComponentIslandDescriptor", + "ComponentIslandError", + "ComponentIslandErrorCode", + "ComponentIslandRegistry", + "ComponentIslandRegistryOptions", + "ComponentIslandSyncContext", + "ComponentsMessage", + "FatalMessage", + "IntentMessage", + "ReadyMessage", + "SandboxHandle", + "SandboxInboundMessage", + "SpawnOptions", + "StateMessage", + "StrictInputBounds", + "StrictInputController", + "StrictInputFactory", + "StrictInputFactoryArgs", + "StrictInputRegistry", + "StrictInputRegistryOptions", + "SurfaceStreamContext", + "SurfaceStreamLineDecision", + "SurfaceStreamOptions", + "SurfaceStreamParseError", + "SurfaceStreamRenderMode", + "SurfaceStreamResult", + "SurfaceStreamSource" + ] + }, + "./devtools": { + "file": "devtools", + "values": ["createEventStore"], + "types": [ + "BaseEvent", + "ComponentErrorEvent", + "ComponentSyncEvent", + "DevtoolsEvent", + "DevtoolsEventKind", + "EventStore", + "EventStoreOptions", + "IntentDispatchedEvent", + "IntentEmittedEvent", + "IntentRejectedEvent", + "IntentSettledEvent", + "ProtocolLineEvent", + "ProtocolParseErrorEvent", + "RenderEvent", + "SandboxDisposedEvent", + "SandboxFatalEvent", + "SandboxReadyEvent", + "SandboxSpawnedEvent", + "StatePushedEvent", + "StreamGraphEvent", + "StreamLifecycleEvent", + "SurfacePlanEvent" + ] + }, + "./envelope": { + "file": "envelope", + "values": [ + "SUMMON_SURFACE_ENVELOPE_VERSION", + "createSurfaceEnvelope", + "isSurfaceEnvelope", + "parseSurfaceEnvelope" + ], + "types": ["CreateSurfaceEnvelopeInput", "SurfaceEnvelope"] + }, + "./policy": { + "file": "policy", + "values": ["IntentArgsError", "PolicyEngine", "defineIntent"], + "types": [ + "IntentContext", + "IntentEntry", + "IntentHandler", + "PolicyEngineOptions", + "TypedIntentEntry" + ] + } + }, + "packages/summon-react": { + ".": { + "file": "index", + "values": ["SummonSurface", "defineReactComponent"], + "types": [ + "ReactComponentRuntimeContext", + "ReactComponentWithRuntimeDefinition", + "SummonSurfaceChrome", + "SummonSurfaceProps" + ] + } + }, + "packages/summon-server": { + ".": { + "file": "index", + "values": [ + "generateSurfaceStream", + "resolveSurfaceGenerationPlan", + "runSurfaceGeneration", + "summarizeContractIssues" + ], + "types": [ + "ContractIssue", + "ContractPromptBlock", + "GenerateEditInput", + "GenerateSurfaceInput", + "GenerationSummary", + "ProtocolLine", + "ProtocolSkipMetaValue", + "RepairFeedbackMetaValue", + "RepairOptions", + "RepairStats", + "ResolvedSurfaceGenerationPlan", + "ResolveSurfaceGenerationPlanInput", + "SummonModelChunk", + "SummonModelProvider", + "SummonModelRequest", + "SummonRepairProvider", + "SummonRepairRequest", + "SurfaceGenerationInput", + "SurfaceGenerationSummary" + ] + } + } +} diff --git a/scripts/smoke-public-packages.mjs b/scripts/smoke-public-packages.mjs index 3ff1e3a..45af7d0 100644 --- a/scripts/smoke-public-packages.mjs +++ b/scripts/smoke-public-packages.mjs @@ -8,6 +8,7 @@ const rootDir = dirname(fileURLToPath(new URL('../package.json', import.meta.url const workDir = await mkdtemp(join(tmpdir(), 'summon-public-smoke-')); const tarballDir = join(workDir, 'tarballs'); const projectDir = join(workDir, 'project'); +const npmCacheDir = join(workDir, 'npm-cache'); function run(command, args, cwd = rootDir) { execFileSync(command, args, { cwd, stdio: 'inherit' }); @@ -18,7 +19,7 @@ await writeFile(join(workDir, 'README'), 'Summon public package smoke test scrat await mkdir(tarballDir, { recursive: true }); await mkdir(projectDir, { recursive: true }); for (const packageDir of ['packages/summon', 'packages/summon-server', 'packages/summon-react']) { - run('npm', ['pack', '--pack-destination', tarballDir], join(rootDir, packageDir)); + run('npm', ['--cache', npmCacheDir, 'pack', '--pack-destination', tarballDir], join(rootDir, packageDir)); } await writeFile(join(projectDir, 'package.json'), JSON.stringify({ @@ -37,27 +38,65 @@ await writeFile(join(projectDir, 'package.json'), JSON.stringify({ }, }, }, null, 2) + '\n'); +await writeFile(join(projectDir, '.npmrc'), [ + 'registry=https://registry.npmjs.org/', + 'link-workspace-packages=false', + 'auto-install-peers=false', + '', +].join('\n')); run('pnpm', ['install', '--ignore-scripts'], projectDir); await writeFile(join(projectDir, 'smoke.mjs'), [ - "import { parseProtocolLine, createCapabilityRegistry } from '@anarchitecture/summon';", - "import { spawnSandbox } from '@anarchitecture/summon/browser';", - "import { PolicyEngine } from '@anarchitecture/summon/policy';", - "import { createSurfaceEnvelope } from '@anarchitecture/summon/envelope';", + "import {", + " parseProtocolLine,", + " createCapabilityRegistry,", + " createComponentRegistry,", + " deriveSurfacePlanControls,", + " SectionAccumulator,", + " StreamGraph,", + "} from '@anarchitecture/summon';", + "import { spawnSandbox, consumeSurfaceStream, createComponentIslandRegistry, createStrictInputRegistry } from '@anarchitecture/summon/browser';", + "import { PolicyEngine, defineIntent } from '@anarchitecture/summon/policy';", + "import { createSurfaceEnvelope, parseSurfaceEnvelope } from '@anarchitecture/summon/envelope';", "import { bootstrapSource, tokensSource } from '@anarchitecture/summon/assets';", "import { createEventStore } from '@anarchitecture/summon/devtools';", - "import { runSurfaceGeneration, generateSurfaceStream, resolveSurfaceGenerationPlan } from '@anarchitecture/summon-server';", + "import { runSurfaceGeneration, generateSurfaceStream, resolveSurfaceGenerationPlan, summarizeContractIssues } from '@anarchitecture/summon-server';", "import { SummonSurface, defineReactComponent } from '@anarchitecture/summon-react';", + "", + "const root = await import('@anarchitecture/summon');", + "const server = await import('@anarchitecture/summon-server');", "if (typeof parseProtocolLine !== 'function') throw new Error('core import failed');", "if (typeof createCapabilityRegistry !== 'function') throw new Error('capability import failed');", - "if (typeof spawnSandbox !== 'function') throw new Error('browser import failed');", - "if (typeof PolicyEngine !== 'function') throw new Error('policy import failed');", - "if (typeof createSurfaceEnvelope !== 'function') throw new Error('envelope import failed');", + "if (typeof createComponentRegistry !== 'function') throw new Error('component import failed');", + "if (typeof deriveSurfacePlanControls !== 'function') throw new Error('surface plan import failed');", + "if (typeof SectionAccumulator !== 'function' || typeof StreamGraph !== 'function') throw new Error('diagnostic primitive import failed');", + "if (typeof spawnSandbox !== 'function' || typeof consumeSurfaceStream !== 'function') throw new Error('browser import failed');", + "if (typeof createComponentIslandRegistry !== 'function' || typeof createStrictInputRegistry !== 'function') throw new Error('browser helper import failed');", + "if (typeof PolicyEngine !== 'function' || typeof defineIntent !== 'function') throw new Error('policy import failed');", + "if (typeof createSurfaceEnvelope !== 'function' || typeof parseSurfaceEnvelope !== 'function') throw new Error('envelope import failed');", "if (typeof bootstrapSource !== 'string' || typeof tokensSource !== 'string') throw new Error('assets import failed');", "if (typeof createEventStore !== 'function') throw new Error('devtools import failed');", - "if (typeof runSurfaceGeneration !== 'function' || typeof generateSurfaceStream !== 'function' || typeof resolveSurfaceGenerationPlan !== 'function') throw new Error('server import failed');", + "if (typeof runSurfaceGeneration !== 'function' || typeof generateSurfaceStream !== 'function' || typeof resolveSurfaceGenerationPlan !== 'function' || typeof summarizeContractIssues !== 'function') throw new Error('server import failed');", "if (typeof SummonSurface !== 'function' || typeof defineReactComponent !== 'function') throw new Error('react import failed');", + "if ('spawnSandbox' in root || 'PolicyEngine' in root || 'compileSystemContracts' in root || 'createProtocolHardener' in root || 'buildDirectionBlock' in root || 'compileTokenContract' in root) throw new Error('core exposes implementation/runtime internals');", + "if ('buildEditBlock' in server) throw new Error('server exposes buildEditBlock');", + "", + "async function expectRejected(specifier) {", + " try {", + " await import(specifier);", + " } catch {", + " return;", + " }", + " throw new Error(`${specifier} should not be importable`);", + "}", + "", + "await expectRejected('@anarchitecture/summon/engine');", + "await expectRejected('@anarchitecture/summon/host');", + "await expectRejected('@anarchitecture/summon/server');", + "await expectRejected('@anarchitecture/summon/_internal/engine/index.js');", + "await expectRejected('@anarchitecture/summon-server/_internal/server/index.js');", + "await expectRejected('@anarchitecture/summon-react/_internal/react/index.js');", "console.log('public package smoke imports passed');", '', ].join('\n'));