@agentproto/corpus 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -976,7 +976,9 @@ declare class DistillRunner {
976
976
  */
977
977
 
978
978
  /** Build the distillation prompt for one source, capped at `maxItems`. */
979
- declare function buildDistillPrompt(input: DistillInput, maxItems: number): string;
979
+ declare function buildDistillPrompt(input: DistillInput, maxItems: number, opts?: {
980
+ readonly lang?: string;
981
+ }): string;
980
982
  /** Tolerant parse: grab the first `[...]` block (allows ```json fences / prose). */
981
983
  declare function parseItems(text: string): DistilledItem[];
982
984
 
@@ -3020,6 +3022,130 @@ declare class PlaybookRegistry {
3020
3022
  listBy(query?: PlaybookQuery): readonly Playbook[];
3021
3023
  }
3022
3024
 
3025
+ /**
3026
+ * CorpusHost — the missing wiring between the corpus engine and a runtime agent.
3027
+ *
3028
+ * The corpus package has all the primitives (StackResolver, PlaybookRegistry,
3029
+ * OperatorOverlayResolver, resolveKnowledge). What it lacked was a host object
3030
+ * that owns a per-scope FsPort and exposes `getPlaybookRegistry` /
3031
+ * `resolveKnowledgeEntries` so a Mastra processor or tool can call them without
3032
+ * knowing about Guilde or any app-specific storage.
3033
+ *
3034
+ * `MemFsCorpusHost` — reference implementation backed by in-memory FsPorts:
3035
+ * - `mountPack(scopeId, files)` installs a flat file map as the scope's corpus.
3036
+ * - `registerLayerProvider(provider)` wires additional layer providers into
3037
+ * the shared StackResolver (e.g. role-based or compliance packs).
3038
+ * - `registerPackFs(packId, fs)` registers a named FsPort so layer providers
3039
+ * that emit pack refs can have those refs mounted.
3040
+ *
3041
+ * Standalone: no Guilde, no database, no HTTP. The test proof uses this directly.
3042
+ */
3043
+
3044
+ /** Public interface every CorpusHost implementation must satisfy. */
3045
+ interface CorpusHost {
3046
+ /**
3047
+ * Return the PlaybookRegistry for a scope (resolved against any
3048
+ * registered layer providers).
3049
+ */
3050
+ getPlaybookRegistry(scopeId: string): Promise<PlaybookRegistry>;
3051
+ /**
3052
+ * Resolve knowledge entries matching `query` for a scope.
3053
+ * Pass `dimensions` to drive any registered StackResolver providers
3054
+ * (e.g. select role-specific packs before querying).
3055
+ */
3056
+ resolveKnowledgeEntries(scopeId: string, query: CorpusEntryQuery, dimensions?: Dimensions): Promise<readonly ResolvedEntry[]>;
3057
+ }
3058
+ /**
3059
+ * MemFs-backed reference implementation.
3060
+ *
3061
+ * Suitable for standalone tests, REPL prototyping, and as the inner
3062
+ * store for a production host that prefills scopes from a database.
3063
+ */
3064
+ declare class MemFsCorpusHost implements CorpusHost {
3065
+ /** Per-scope flat file map (path → content, workspace-relative). */
3066
+ private readonly scopeFiles;
3067
+ /** Shared layer-provider registry — same providers fire for every scope. */
3068
+ private readonly providerRegistry;
3069
+ /** Resolver that consults the provider registry to build a band-ordered stack. */
3070
+ private readonly stackResolver;
3071
+ /** Named pack FsPorts for refs emitted by layer providers. */
3072
+ private readonly packFs;
3073
+ /**
3074
+ * Mount a flat `{ path: content }` map as (or into) a scope's corpus.
3075
+ * Later calls MERGE — subsequent keys overwrite earlier ones, so you
3076
+ * can call `mountPack` multiple times to build up a scope.
3077
+ */
3078
+ mountPack(scopeId: string, files: Record<string, string>): void;
3079
+ /**
3080
+ * Register a `LayerProvider` into the shared StackResolver.
3081
+ * Providers run for every scope during `resolveFs`; guard with
3082
+ * `ctx.subject` or `ctx.dimensions` if you need scope-specific logic.
3083
+ */
3084
+ registerLayerProvider(provider: LayerProvider): void;
3085
+ /**
3086
+ * Register a named `FsPort` so layer providers that emit `{ ref: packId }`
3087
+ * can have those refs mounted by `buildOverlayFromStack`.
3088
+ */
3089
+ registerPackFs(packId: string, fs: FsPort): void;
3090
+ private getScopeBaseFs;
3091
+ /**
3092
+ * Resolve the effective FsPort for a scope:
3093
+ * - Run the StackResolver to compute additional layers.
3094
+ * - If none contribute, return the base MemFs directly.
3095
+ * - Otherwise, build an OverlayFs (constraints above, lenses below).
3096
+ */
3097
+ private resolveFs;
3098
+ getPlaybookRegistry(scopeId: string): Promise<PlaybookRegistry>;
3099
+ resolveKnowledgeEntries(scopeId: string, query: CorpusEntryQuery, dimensions?: Dimensions): Promise<readonly ResolvedEntry[]>;
3100
+ }
3101
+
3102
+ /**
3103
+ * Dimension assembly — portable port of guilde's dimension-sources.ts.
3104
+ *
3105
+ * An ordered list of `DimensionProvider`s is consulted left-to-right;
3106
+ * the first provider to supply a non-empty value for a key wins (same
3107
+ * semantics as guilde's first-match-per-key merge). The resulting
3108
+ * `Dimensions` bag feeds both the StackResolver (pick which layers apply)
3109
+ * and the PlaybookRegistry/OperatorOverlayResolver (which playbooks bind).
3110
+ *
3111
+ * No guilde-specific imports — only `slugify` from this package.
3112
+ */
3113
+
3114
+ /** A single dimension value: a scalar or a multi-valued axis. */
3115
+ type DimensionValue = string | readonly string[];
3116
+ /**
3117
+ * A pluggable source of dimension values for a subject.
3118
+ * First-match-per-key wins; register higher-priority sources earlier.
3119
+ */
3120
+ interface DimensionProvider<TSubject = unknown> {
3121
+ readonly id: string;
3122
+ resolve(subject: TSubject): Readonly<Record<string, DimensionValue | undefined>>;
3123
+ }
3124
+ /**
3125
+ * Merge providers left-to-right, first-match-per-key. Returns only
3126
+ * the keys that have a non-empty resolved value.
3127
+ */
3128
+ declare function assembleDimensions<TSubject = unknown>(providers: readonly DimensionProvider<TSubject>[], subject: TSubject): Dimensions;
3129
+ /**
3130
+ * Minimal subject shape for the four well-known AIP-12 axes:
3131
+ * identity, role, position, capability.
3132
+ */
3133
+ interface StandardSubject {
3134
+ readonly slug?: string;
3135
+ readonly role?: string;
3136
+ readonly title?: string;
3137
+ readonly capabilities?: readonly string[];
3138
+ }
3139
+ /**
3140
+ * Base dimension provider — maps the four well-known AIP-12 axes from
3141
+ * a `StandardSubject`. Host apps can prepend higher-priority providers
3142
+ * for app-specific axes (org / region / compliance / tier).
3143
+ *
3144
+ * Mirrors `operatorDimensionSource` from guilde's dimension-sources.ts
3145
+ * without importing anything guilde-specific.
3146
+ */
3147
+ declare const standardDimensionProvider: DimensionProvider<StandardSubject>;
3148
+
3023
3149
  /**
3024
3150
  * OperatorOverlayResolver — given an operator + conversation context,
3025
3151
  * returns the playbook overlays to splice into the operator's prompt.
@@ -3275,4 +3401,4 @@ declare class PlaybookEvaluator {
3275
3401
  declare const SPEC_NAME: "agentcorpus/v1";
3276
3402
  declare const SPEC_VERSION: "0.1.0-alpha";
3277
3403
 
3278
- export { ANY_REF, type AccessCaller, type AccessClassification, type AccessContext, type AccessDecision, type AccessModesMap, type ActivateResult, type AggregateOptions, type AggregateResult, type AipSchemaBundle, type AipSchemaKey, type ArchiveResult, type AttachmentAsset, type AttachmentDeclaration, type Attestation, type AttestationKind, type AutoPromoteConfig, type AutoPromoteRequirements, type AxisDefinition, type AxisRegistry, type BatchReport, type BuildOverlayOptions, type CalibrationOptions, type CandidateForGate, type CandidateRow, type CandidateStatus, CandidatesSidecar, type CandidatesSidecarOptions, type Capability, type CapabilityCaller, type CapabilityDecision, type CapabilityRule, type ChunkerOptions, ClaudeDistiller, type ClaudeDistillerOptions, ClockPort, type ConversationDoc, ConversationImporter, type ConversationImporterOptions, type ConversationSourcePort, type ConversationThreadRef, type ConversationTurn, type ConversationWindowSource, type CorpusAccessSpec, type CorpusEntryQuery, type CorpusEvent, CorpusEventEmitter, type CorpusEventEmitterOptions, type CorpusEventKind, type CorpusImporter, CorpusIndexer, type CorpusIndexerOptions, CorpusLinter, type CorpusLinterOptions, type CorpusPreset, type CorpusPresetBootstrapContext, CorpusPromoter, CorpusValidator, type CorpusValidatorOptions, CorpusVersionConflictError, CorpusWorkspaceReader, type CorpusWorkspaceReaderOptions, type CorpusWorkspaceSnapshot, CorpusWorkspaceWriter, type CorpusWorkspaceWriterOptions, type CustomLintRunner, DEFAULT_TRANSITIONS, DISTILL_INDEX_PATH, type Dimensions, type DistillBinding, type DistillCoreReport, type DistillDescriptor, type DistillFromImporterOptions, DistillIndex, type DistillIndexOptions, type DistillIndexRecord, type DistillInput, type DistillPort, type DistillRegistry, type DistillReport, type DistillRunReport, DistillRunner, type DistillRunnerOptions, type DistillScope, type DistillSource, type DistillTarget, type DistilledItem, EMPTY_SELECTOR, type EntryLayout, type EvalCase, EvalContextPort, EvalRubricPort, EvaluatorPort, FetcherPort, type FileKind, FsLockHandle, FsPort, FsStat, type GateFailure, type GateResult, IdentityPort, IllegalPlaybookTransitionError, IllegalTransitionError, type ImportedSource, ImporterRunner, type ImporterRunnerOptions, type ImporterTarget, type IndexReport, type KbListLike, type KbMigrationConfig, KbMigrationImporter, type KbSourceLike, type LanguageFilter, type LayerMode, type LayerProvider, type LayerRef, type LayerShadow, type Lens, type LensMode, type LensStaleness, type LintIssue, type LintReport, LocalFilesImporter, type LocalFilesImporterOptions, type MarkdownDoc, type MatchAttachmentsOptions, type MatchOptions, MemFs, type ModelDistillerOptions, OperatorOverlayResolver, OverlayFs, type OverlayFsOptions, type ParsedFile, type Playbook, type PlaybookBatchOptions, type PlaybookBatchResult, type PlaybookCorpusMeta, PlaybookEvaluator, type PlaybookEvaluatorOptions, type PlaybookKind, PlaybookLifecycle, type PlaybookLifecycleOptions, PlaybookNotFoundError, type PlaybookQuery, PlaybookRegistry, type PlaybookRegistryOptions, type PlaybookStatus, type PlaybookTarget, type PlaybookTargetKind, type PromoteContext, type PromoteOptions, PromoteRejectedError, type PromoteResult, type PushChunksInput, type PushSourceInput, REFINED_KIND_SCHEMA, ReadOnlyFs, type RefinedKind, type RenderedOverlays, type ResolutionContext, type ResolveContext, type ResolveKnowledgeOptions, type ResolveLanguageFilterInput, type ResolveResult, type ResolvedEntry, type ResolvedOverlay, type ReviewerCalibration, type ReviewerScore, ReviewerTrackRecord, type ReviewerTrackRecordOptions, type RunDistillOptions, SPEC_NAME, SPEC_VERSION, SYNTHESIS_ROLE_TAG, type Selector, type SelectorTerm, SidecarDuplicateError, SidecarNotFoundError, type SinkItem, type SinkPort, type SinkPushResult, type SlugifyOptions, type SourceRef, type SourceSelector, type StackEntry, type StackRefPartition, type StackResolution, StackResolver, type StackSkip, type SyncReport, SyncRunner, type SyncRunnerOptions, type SynthesisAtom, type SynthesisInput, type SynthesisPort, type SynthesizeLensOptions, type SynthesizeLensReport, type TrackRecordEntry, type TransitionCheck, type ValidationIssue, type ValidationResult, WELL_KNOWN_AXES, WHITEOUT_SUFFIX, WebImporter, type WebImporterOptions, type WriterChunk, type WriterPort, aggregateReviewerScores, appendAttestation, assertTransition, buildDistillPrompt, buildOverlayFromStack, buildSynthesisPrompt, canTransition, capabilityAxis, chunkText, compileLegacyPlaybookBinding, computeReviewerCalibration, createAxisRegistry, createDistillRegistry, currentLensAtoms, defaultSynthesisPath, distillFromImporter, enumerateWindowRefs, evaluateAccess, evaluateCapability, evaluateGate, extractAutoPromoteConfig, flattenPackRefs, identityAxis, isEmptySelector, isEntrySlug, isRefinedKind, isSourceSlug, lensAspect, lensAspectTag, lensSynthesisStale, makeAttestation, matchAttachmentRefs, matchAttachments, matchesLanguageFilter, matchesSelector, modelDistiller, normalizeLanguageTag, parseItems, parseSelectorFrontmatter, parseWindowRef, partitionStackRefs, pearsonCorrelation, positionAxis, prefixedRefNormalizer, readAccessModes, readAccessSpec, readAttestations, readEntryLanguage, readOperatorLocale, readWorkspaceDefaultLanguage, renderOverlays, resolveKnowledge, resolveLanguageFilter, roleAxis, runDistill, scanDistilledSourceIds, slugify, synthesizeLens, transitionGraphFromCollection, uniqueSlug, windowRef, windowSlug };
3404
+ export { ANY_REF, type AccessCaller, type AccessClassification, type AccessContext, type AccessDecision, type AccessModesMap, type ActivateResult, type AggregateOptions, type AggregateResult, type AipSchemaBundle, type AipSchemaKey, type ArchiveResult, type AttachmentAsset, type AttachmentDeclaration, type Attestation, type AttestationKind, type AutoPromoteConfig, type AutoPromoteRequirements, type AxisDefinition, type AxisRegistry, type BatchReport, type BuildOverlayOptions, type CalibrationOptions, type CandidateForGate, type CandidateRow, type CandidateStatus, CandidatesSidecar, type CandidatesSidecarOptions, type Capability, type CapabilityCaller, type CapabilityDecision, type CapabilityRule, type ChunkerOptions, ClaudeDistiller, type ClaudeDistillerOptions, ClockPort, type ConversationDoc, ConversationImporter, type ConversationImporterOptions, type ConversationSourcePort, type ConversationThreadRef, type ConversationTurn, type ConversationWindowSource, type CorpusAccessSpec, type CorpusEntryQuery, type CorpusEvent, CorpusEventEmitter, type CorpusEventEmitterOptions, type CorpusEventKind, type CorpusHost, type CorpusImporter, CorpusIndexer, type CorpusIndexerOptions, CorpusLinter, type CorpusLinterOptions, type CorpusPreset, type CorpusPresetBootstrapContext, CorpusPromoter, CorpusValidator, type CorpusValidatorOptions, CorpusVersionConflictError, CorpusWorkspaceReader, type CorpusWorkspaceReaderOptions, type CorpusWorkspaceSnapshot, CorpusWorkspaceWriter, type CorpusWorkspaceWriterOptions, type CustomLintRunner, DEFAULT_TRANSITIONS, DISTILL_INDEX_PATH, type DimensionProvider, type DimensionValue, type Dimensions, type DistillBinding, type DistillCoreReport, type DistillDescriptor, type DistillFromImporterOptions, DistillIndex, type DistillIndexOptions, type DistillIndexRecord, type DistillInput, type DistillPort, type DistillRegistry, type DistillReport, type DistillRunReport, DistillRunner, type DistillRunnerOptions, type DistillScope, type DistillSource, type DistillTarget, type DistilledItem, EMPTY_SELECTOR, type EntryLayout, type EvalCase, EvalContextPort, EvalRubricPort, EvaluatorPort, FetcherPort, type FileKind, FsLockHandle, FsPort, FsStat, type GateFailure, type GateResult, IdentityPort, IllegalPlaybookTransitionError, IllegalTransitionError, type ImportedSource, ImporterRunner, type ImporterRunnerOptions, type ImporterTarget, type IndexReport, type KbListLike, type KbMigrationConfig, KbMigrationImporter, type KbSourceLike, type LanguageFilter, type LayerMode, type LayerProvider, type LayerRef, type LayerShadow, type Lens, type LensMode, type LensStaleness, type LintIssue, type LintReport, LocalFilesImporter, type LocalFilesImporterOptions, type MarkdownDoc, type MatchAttachmentsOptions, type MatchOptions, MemFs, MemFsCorpusHost, type ModelDistillerOptions, OperatorOverlayResolver, OverlayFs, type OverlayFsOptions, type ParsedFile, type Playbook, type PlaybookBatchOptions, type PlaybookBatchResult, type PlaybookCorpusMeta, PlaybookEvaluator, type PlaybookEvaluatorOptions, type PlaybookKind, PlaybookLifecycle, type PlaybookLifecycleOptions, PlaybookNotFoundError, type PlaybookQuery, PlaybookRegistry, type PlaybookRegistryOptions, type PlaybookStatus, type PlaybookTarget, type PlaybookTargetKind, type PromoteContext, type PromoteOptions, PromoteRejectedError, type PromoteResult, type PushChunksInput, type PushSourceInput, REFINED_KIND_SCHEMA, ReadOnlyFs, type RefinedKind, type RenderedOverlays, type ResolutionContext, type ResolveContext, type ResolveKnowledgeOptions, type ResolveLanguageFilterInput, type ResolveResult, type ResolvedEntry, type ResolvedOverlay, type ReviewerCalibration, type ReviewerScore, ReviewerTrackRecord, type ReviewerTrackRecordOptions, type RunDistillOptions, SPEC_NAME, SPEC_VERSION, SYNTHESIS_ROLE_TAG, type Selector, type SelectorTerm, SidecarDuplicateError, SidecarNotFoundError, type SinkItem, type SinkPort, type SinkPushResult, type SlugifyOptions, type SourceRef, type SourceSelector, type StackEntry, type StackRefPartition, type StackResolution, StackResolver, type StackSkip, type StandardSubject, type SyncReport, SyncRunner, type SyncRunnerOptions, type SynthesisAtom, type SynthesisInput, type SynthesisPort, type SynthesizeLensOptions, type SynthesizeLensReport, type TrackRecordEntry, type TransitionCheck, type ValidationIssue, type ValidationResult, WELL_KNOWN_AXES, WHITEOUT_SUFFIX, WebImporter, type WebImporterOptions, type WriterChunk, type WriterPort, aggregateReviewerScores, appendAttestation, assembleDimensions, assertTransition, buildDistillPrompt, buildOverlayFromStack, buildSynthesisPrompt, canTransition, capabilityAxis, chunkText, compileLegacyPlaybookBinding, computeReviewerCalibration, createAxisRegistry, createDistillRegistry, currentLensAtoms, defaultSynthesisPath, distillFromImporter, enumerateWindowRefs, evaluateAccess, evaluateCapability, evaluateGate, extractAutoPromoteConfig, flattenPackRefs, identityAxis, isEmptySelector, isEntrySlug, isRefinedKind, isSourceSlug, lensAspect, lensAspectTag, lensSynthesisStale, makeAttestation, matchAttachmentRefs, matchAttachments, matchesLanguageFilter, matchesSelector, modelDistiller, normalizeLanguageTag, parseItems, parseSelectorFrontmatter, parseWindowRef, partitionStackRefs, pearsonCorrelation, positionAxis, prefixedRefNormalizer, readAccessModes, readAccessSpec, readAttestations, readEntryLanguage, readOperatorLocale, readWorkspaceDefaultLanguage, renderOverlays, resolveKnowledge, resolveLanguageFilter, roleAxis, runDistill, scanDistilledSourceIds, slugify, standardDimensionProvider, synthesizeLens, transitionGraphFromCollection, uniqueSlug, windowRef, windowSlug };
package/dist/index.mjs CHANGED
@@ -1083,7 +1083,28 @@ var DISTILLED_ITEM = z.object({
1083
1083
  confidence: z.number().optional(),
1084
1084
  tags: z.array(z.string()).optional()
1085
1085
  }).loose();
1086
- function buildDistillPrompt(input, maxItems) {
1086
+ var LANG_NAMES = {
1087
+ en: "ENGLISH",
1088
+ fr: "FRENCH",
1089
+ de: "GERMAN",
1090
+ es: "SPANISH",
1091
+ pt: "PORTUGUESE",
1092
+ it: "ITALIAN",
1093
+ nl: "DUTCH",
1094
+ ja: "JAPANESE",
1095
+ zh: "CHINESE",
1096
+ ko: "KOREAN",
1097
+ ru: "RUSSIAN",
1098
+ ar: "ARABIC",
1099
+ pl: "POLISH",
1100
+ sv: "SWEDISH",
1101
+ tr: "TURKISH"
1102
+ };
1103
+ function langName(code) {
1104
+ if (!code) return "ENGLISH";
1105
+ return LANG_NAMES[code.toLowerCase()] ?? code.toUpperCase();
1106
+ }
1107
+ function buildDistillPrompt(input, maxItems, opts) {
1087
1108
  const lensBlock = input.instruction?.trim() ? `LENS \u2014 read the source THROUGH this aspect, extract ONLY what serves it:
1088
1109
  ${input.instruction.trim()}
1089
1110
 
@@ -1103,7 +1124,7 @@ Guidance:
1103
1124
  "critique": a common mistake / anti-pattern. "summary": a compact overview.
1104
1125
  "example": a concrete worked instance worth remembering.
1105
1126
  - Drop filler, calls-to-action, tangents. Keep only what an operator could ACT on later.
1106
- - Write every title and body in ENGLISH, even when the source is in another language. Translate the insight; do not copy the source language.
1127
+ - Write every title and body in ${langName(opts?.lang)}, even when the source is in another language. Translate the insight; do not copy the source language.
1107
1128
 
1108
1129
  SOURCE TITLE: ${input.title}
1109
1130
  ${input.tags?.length ? `TAGS: ${input.tags.join(", ")}
@@ -3234,6 +3255,140 @@ function matches(p, q) {
3234
3255
  return true;
3235
3256
  }
3236
3257
 
3258
+ // src/host/host.ts
3259
+ var MemFsCorpusHost = class {
3260
+ /** Per-scope flat file map (path → content, workspace-relative). */
3261
+ scopeFiles = /* @__PURE__ */ new Map();
3262
+ /** Shared layer-provider registry — same providers fire for every scope. */
3263
+ providerRegistry = createRegistry({
3264
+ family: "corpus-layer-providers",
3265
+ keyBy: (p) => p.id
3266
+ });
3267
+ /** Resolver that consults the provider registry to build a band-ordered stack. */
3268
+ stackResolver = new StackResolver(this.providerRegistry);
3269
+ /** Named pack FsPorts for refs emitted by layer providers. */
3270
+ packFs = /* @__PURE__ */ new Map();
3271
+ /**
3272
+ * Mount a flat `{ path: content }` map as (or into) a scope's corpus.
3273
+ * Later calls MERGE — subsequent keys overwrite earlier ones, so you
3274
+ * can call `mountPack` multiple times to build up a scope.
3275
+ */
3276
+ mountPack(scopeId, files) {
3277
+ const existing = this.scopeFiles.get(scopeId) ?? {};
3278
+ this.scopeFiles.set(scopeId, { ...existing, ...files });
3279
+ }
3280
+ /**
3281
+ * Register a `LayerProvider` into the shared StackResolver.
3282
+ * Providers run for every scope during `resolveFs`; guard with
3283
+ * `ctx.subject` or `ctx.dimensions` if you need scope-specific logic.
3284
+ */
3285
+ registerLayerProvider(provider) {
3286
+ this.providerRegistry.register(provider);
3287
+ }
3288
+ /**
3289
+ * Register a named `FsPort` so layer providers that emit `{ ref: packId }`
3290
+ * can have those refs mounted by `buildOverlayFromStack`.
3291
+ */
3292
+ registerPackFs(packId, fs) {
3293
+ this.packFs.set(packId, fs);
3294
+ }
3295
+ getScopeBaseFs(scopeId) {
3296
+ return new MemFs(this.scopeFiles.get(scopeId) ?? {});
3297
+ }
3298
+ /**
3299
+ * Resolve the effective FsPort for a scope:
3300
+ * - Run the StackResolver to compute additional layers.
3301
+ * - If none contribute, return the base MemFs directly.
3302
+ * - Otherwise, build an OverlayFs (constraints above, lenses below).
3303
+ */
3304
+ async resolveFs(scopeId, dimensions) {
3305
+ const baseFs = this.getScopeBaseFs(scopeId);
3306
+ const stack = await this.stackResolver.resolve({ dimensions });
3307
+ if (stack.entries.length === 0) return baseFs;
3308
+ return buildOverlayFromStack({
3309
+ guildFs: baseFs,
3310
+ stack,
3311
+ loadFs: (ref) => {
3312
+ const fs = this.packFs.get(ref.ref);
3313
+ return fs ? new ReadOnlyFs(fs) : null;
3314
+ }
3315
+ });
3316
+ }
3317
+ async getPlaybookRegistry(scopeId) {
3318
+ const fs = await this.resolveFs(scopeId);
3319
+ let rels;
3320
+ try {
3321
+ rels = await fs.walk("playbooks");
3322
+ } catch {
3323
+ rels = [];
3324
+ }
3325
+ const playbooks = [];
3326
+ for (const rel of rels) {
3327
+ if (!rel.endsWith("PLAYBOOK.md")) continue;
3328
+ const path = `playbooks/${rel}`;
3329
+ let content;
3330
+ try {
3331
+ content = await fs.readFile(path);
3332
+ } catch {
3333
+ continue;
3334
+ }
3335
+ const parsed = matter6(content);
3336
+ playbooks.push({
3337
+ path,
3338
+ kind: "playbook",
3339
+ frontmatter: parsed.data,
3340
+ body: parsed.content,
3341
+ versionToken: ""
3342
+ });
3343
+ }
3344
+ return new PlaybookRegistry({
3345
+ snapshot: {
3346
+ root: "",
3347
+ workspace: null,
3348
+ sources: [],
3349
+ entries: [],
3350
+ collections: [],
3351
+ collectionItems: [],
3352
+ playbooks: Object.freeze(playbooks),
3353
+ operators: [],
3354
+ workflows: [],
3355
+ routines: [],
3356
+ unknown: []
3357
+ }
3358
+ });
3359
+ }
3360
+ async resolveKnowledgeEntries(scopeId, query, dimensions) {
3361
+ const fs = await this.resolveFs(scopeId, dimensions);
3362
+ return resolveKnowledge({ fs, query });
3363
+ }
3364
+ };
3365
+
3366
+ // src/host/dimensions.ts
3367
+ function assembleDimensions(providers, subject) {
3368
+ const out = {};
3369
+ for (const provider of providers) {
3370
+ const partial = provider.resolve(subject);
3371
+ for (const [key, value] of Object.entries(partial)) {
3372
+ if (key in out) continue;
3373
+ if (value == null || value === "") continue;
3374
+ if (Array.isArray(value) && value.length === 0) continue;
3375
+ out[key] = value;
3376
+ }
3377
+ }
3378
+ return out;
3379
+ }
3380
+ var standardDimensionProvider = {
3381
+ id: "standard",
3382
+ resolve: (subject) => {
3383
+ if (!subject) return {};
3384
+ const identity = subject.slug ?? subject.role ?? void 0;
3385
+ const role = subject.role ?? void 0;
3386
+ const position = subject.title ? slugify(subject.title) : void 0;
3387
+ const capability = subject.capabilities && subject.capabilities.length > 0 ? subject.capabilities : void 0;
3388
+ return { identity, role, position, capability };
3389
+ }
3390
+ };
3391
+
3237
3392
  // src/playbooks/resolver.ts
3238
3393
  var OperatorOverlayResolver = class {
3239
3394
  constructor(registry) {
@@ -3633,6 +3788,6 @@ function joinPath5(a, b) {
3633
3788
  var SPEC_NAME = "agentcorpus/v1";
3634
3789
  var SPEC_VERSION = "0.1.0-alpha";
3635
3790
 
3636
- export { ANY_REF, ClaudeDistiller, ConversationImporter, CorpusEventEmitter, CorpusIndexer, CorpusLinter, CorpusPromoter, CorpusValidator, CorpusVersionConflictError, CorpusWorkspaceReader, CorpusWorkspaceWriter, DEFAULT_TRANSITIONS, DISTILL_INDEX_PATH, DistillIndex, DistillRunner, EMPTY_SELECTOR, IllegalPlaybookTransitionError, IllegalTransitionError, ImporterRunner, KbMigrationImporter, LocalFilesImporter, MemFs, OperatorOverlayResolver, OverlayFs, PlaybookEvaluator, PlaybookLifecycle, PlaybookNotFoundError, PlaybookRegistry, PromoteRejectedError, ReadOnlyFs, ReviewerTrackRecord, SPEC_NAME, SPEC_VERSION, SYNTHESIS_ROLE_TAG, StackResolver, SyncRunner, WELL_KNOWN_AXES, WHITEOUT_SUFFIX, WebImporter, aggregateReviewerScores, appendAttestation, assertTransition, buildDistillPrompt, buildOverlayFromStack, buildSynthesisPrompt, canTransition, capabilityAxis, chunkText, compileLegacyPlaybookBinding, computeReviewerCalibration, createAxisRegistry, createDistillRegistry, currentLensAtoms, defaultSynthesisPath, distillFromImporter, enumerateWindowRefs, evaluateAccess, evaluateCapability, evaluateGate, extractAutoPromoteConfig, flattenPackRefs, identityAxis, isEmptySelector, isEntrySlug, isSourceSlug, lensAspect, lensAspectTag, lensSynthesisStale, makeAttestation, matchAttachmentRefs, matchAttachments, matchesLanguageFilter, matchesSelector, modelDistiller, normalizeLanguageTag, parseItems, parseSelectorFrontmatter, parseWindowRef, partitionStackRefs, pearsonCorrelation, positionAxis, prefixedRefNormalizer, readAccessModes, readAccessSpec, readAttestations, readEntryLanguage, readOperatorLocale, readWorkspaceDefaultLanguage, renderOverlays, resolveLanguageFilter, roleAxis, runDistill, scanDistilledSourceIds, slugify, synthesizeLens, transitionGraphFromCollection, uniqueSlug, windowRef, windowSlug };
3791
+ export { ANY_REF, ClaudeDistiller, ConversationImporter, CorpusEventEmitter, CorpusIndexer, CorpusLinter, CorpusPromoter, CorpusValidator, CorpusVersionConflictError, CorpusWorkspaceReader, CorpusWorkspaceWriter, DEFAULT_TRANSITIONS, DISTILL_INDEX_PATH, DistillIndex, DistillRunner, EMPTY_SELECTOR, IllegalPlaybookTransitionError, IllegalTransitionError, ImporterRunner, KbMigrationImporter, LocalFilesImporter, MemFs, MemFsCorpusHost, OperatorOverlayResolver, OverlayFs, PlaybookEvaluator, PlaybookLifecycle, PlaybookNotFoundError, PlaybookRegistry, PromoteRejectedError, ReadOnlyFs, ReviewerTrackRecord, SPEC_NAME, SPEC_VERSION, SYNTHESIS_ROLE_TAG, StackResolver, SyncRunner, WELL_KNOWN_AXES, WHITEOUT_SUFFIX, WebImporter, aggregateReviewerScores, appendAttestation, assembleDimensions, assertTransition, buildDistillPrompt, buildOverlayFromStack, buildSynthesisPrompt, canTransition, capabilityAxis, chunkText, compileLegacyPlaybookBinding, computeReviewerCalibration, createAxisRegistry, createDistillRegistry, currentLensAtoms, defaultSynthesisPath, distillFromImporter, enumerateWindowRefs, evaluateAccess, evaluateCapability, evaluateGate, extractAutoPromoteConfig, flattenPackRefs, identityAxis, isEmptySelector, isEntrySlug, isSourceSlug, lensAspect, lensAspectTag, lensSynthesisStale, makeAttestation, matchAttachmentRefs, matchAttachments, matchesLanguageFilter, matchesSelector, modelDistiller, normalizeLanguageTag, parseItems, parseSelectorFrontmatter, parseWindowRef, partitionStackRefs, pearsonCorrelation, positionAxis, prefixedRefNormalizer, readAccessModes, readAccessSpec, readAttestations, readEntryLanguage, readOperatorLocale, readWorkspaceDefaultLanguage, renderOverlays, resolveLanguageFilter, roleAxis, runDistill, scanDistilledSourceIds, slugify, standardDimensionProvider, synthesizeLens, transitionGraphFromCollection, uniqueSlug, windowRef, windowSlug };
3637
3792
  //# sourceMappingURL=index.mjs.map
3638
3793
  //# sourceMappingURL=index.mjs.map