feat(invariants): implement package runtime checks
This commit is contained in:
@@ -16,7 +16,7 @@ These package-specific rules supplement the repo-wide [conventions](../AGENTS.md
|
||||
- **Publish state only at its commit point.** Emit each notification and update derived state only after the success boundary that makes it true; derive caches, prompts, UI echoes, replay, and query views from one authoritative source.
|
||||
- **Apply bounds to the complete result.** Enforce byte, token, item, and time limits where the complete emitted or retained value, including wrappers and metadata, is known; test tiny and exact limits, oversized single chunks, and multibyte byte limits.
|
||||
- **Registry contributions prove disposal.** Add the HMR-safety test required by the [testing policy](../docs/testing.md): dispose the contributing fiber and observe removal.
|
||||
- **Every package owns an invariant companion.** Publish `./invariant`, register the manifest's exact npm name, and keep the generated ownership baseline until relational checks exist. `verify-package-invariants` gates source and publication wiring ([rationale](../docs/rfc/implemented/architecture/2026-07-19-package-owned-invariant-service.md)).
|
||||
- **Every package owns executable invariants.** Publish `./invariant`, register its exact name, and enforce a package runtime contract with the bound reporter; generated, empty, and reporter-free installers fail `verify-package-invariants` ([rationale](../docs/rfc/implemented/architecture/2026-07-19-package-invariant-runtime-contracts.md)).
|
||||
|
||||
Naming notes:
|
||||
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-bash-local`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-bash-local/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-bash-local`. @module @deepseek-ai/dsh-bash-local/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-bash-local'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'bash-local-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'LocalBashExecutor',
|
||||
effects: [
|
||||
'ctx.provide("bash")',
|
||||
'local bash teardown',
|
||||
],
|
||||
services: [
|
||||
'bash',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-bash-sandbox`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-bash-sandbox/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-bash-sandbox`. @module @deepseek-ai/dsh-bash-sandbox/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-bash-sandbox'
|
||||
|
||||
@@ -17,8 +10,21 @@ export const name = 'bash-sandbox-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'SandboxBashExecutor',
|
||||
inject: [
|
||||
'sandbox',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("bash")',
|
||||
],
|
||||
services: [
|
||||
'bash',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +33,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-bash`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-bash/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-bash`. @module @deepseek-ai/dsh-bash/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observeServiceInvariant, serviceShapeViolation, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-bash'
|
||||
|
||||
@@ -17,8 +10,12 @@ export const name = 'bash-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Validate every implementation bound to this package's service seam. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observeServiceInvariant(ctx, fail, 'bash', value => serviceShapeViolation(value, {
|
||||
methods: ['resolve', 'run', 'start'],
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +24,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-bash`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-bash/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-bash`. @module @deepseek-ai/dsh-tool-bash/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-bash'
|
||||
|
||||
@@ -17,8 +10,25 @@ export const name = 'tool-bash-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-bash',
|
||||
inject: [
|
||||
'tools',
|
||||
'bash',
|
||||
'systemPrompt',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("bashEnv")',
|
||||
'bashEnv.register()',
|
||||
'tools.register()',
|
||||
],
|
||||
services: [
|
||||
'bashEnv',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +37,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-code-runtime-worker`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* Package-owned runtime contract checks for `@deepseek-ai/dsh-code-runtime-worker`.
|
||||
* @module @deepseek-ai/dsh-code-runtime-worker/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-code-runtime-worker'
|
||||
|
||||
@@ -17,8 +13,19 @@ export const name = 'code-runtime-worker-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'WorkerCodeRuntime',
|
||||
effects: [
|
||||
'ctx.provide("codeRuntime")',
|
||||
'worker code-runtime teardown',
|
||||
],
|
||||
services: [
|
||||
'codeRuntime',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +34,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-code-runtime`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-code-runtime/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-code-runtime`. @module @deepseek-ai/dsh-code-runtime/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observeServiceInvariant, serviceShapeViolation, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-code-runtime'
|
||||
|
||||
@@ -17,8 +10,20 @@ export const name = 'code-runtime-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Validate every implementation bound to this package's service seam. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observeServiceInvariant(ctx, fail, 'codeRuntime', (value) => {
|
||||
const violation = serviceShapeViolation(value, {
|
||||
methods: ['run'],
|
||||
stringProperties: ['language', 'isolation'],
|
||||
})
|
||||
if (violation !== undefined) return violation
|
||||
const service = value as { language: string; isolation: string }
|
||||
return /^[a-z][a-z0-9-]*$/.test(service.language) && /^[a-z][a-z0-9-]*$/.test(service.isolation)
|
||||
? undefined
|
||||
: 'code runtime language and isolation must be lowercase identifiers'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +32,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -84,4 +84,18 @@ describe('CodeRuntime service seam', () => {
|
||||
const { ctx } = await setup()
|
||||
await expect(ctx.plugin(StubRuntime)).rejects.toThrow(/registered/)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ language: 'typescript', isolation: 'worker' }, /must expose method "run"/],
|
||||
[{ language: 'TypeScript', isolation: 'worker', run() {} }, /must be lowercase identifiers/],
|
||||
])('rejects an invalid runtime implementation through the package invariant', async (value, message) => {
|
||||
const ctx = new Context()
|
||||
const invalidRuntime = {
|
||||
name: 'invalid-code-runtime',
|
||||
apply(child: Context) {
|
||||
child.provide('codeRuntime', value as unknown as CodeRuntime)
|
||||
},
|
||||
}
|
||||
await expect(ctx.plugin(invalidRuntime)).rejects.toThrow(message)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-compact-basic`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-compact-basic/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-compact-basic`. @module @deepseek-ai/dsh-compact-basic/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-compact-basic'
|
||||
|
||||
@@ -17,8 +10,37 @@ export const name = 'compact-basic-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'BasicCompactService',
|
||||
inject: [
|
||||
'llm',
|
||||
'tokenMeter',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("compact")',
|
||||
],
|
||||
services: [
|
||||
'compact',
|
||||
],
|
||||
validate: (fiber, effectLabels) => {
|
||||
const automaticEffects = [
|
||||
'ctx.on("agent/post-step")',
|
||||
'ctx.on("agent/request-error")',
|
||||
]
|
||||
const installed = automaticEffects.filter(label => effectLabels.has(label)).length
|
||||
const automatic = (fiber.config as { auto?: boolean }).auto !== false
|
||||
if (automatic && installed !== automaticEffects.length) {
|
||||
return 'automatic compaction must install both pressure and overflow listeners'
|
||||
}
|
||||
if (!automatic && installed !== 0) {
|
||||
return 'auto:false must install neither automatic compaction listener'
|
||||
}
|
||||
return undefined
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +49,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { BasicCompactConfig } from '@deepseek-ai/dsh-compact-basic'
|
||||
import { selectCompactableRange } from '@deepseek-ai/dsh-compact-basic/src/region.ts'
|
||||
import { toolPairingBalancedAfter, toolPairingBalancedBefore } from '@deepseek-ai/dsh-compact'
|
||||
import { resolveConfig } from '@deepseek-ai/dsh-compact-basic/src/config.ts'
|
||||
import type { CompactionResult } from '@deepseek-ai/dsh-compact'
|
||||
import type { CompactService, CompactionResult } from '@deepseek-ai/dsh-compact'
|
||||
import LlmService, { CallId, CONTEXT_WINDOW_EXCEEDED_CODE, LlmAdapter } from '@deepseek-ai/dsh-llm'
|
||||
import type { ContentBlock, GenerateOptions, StreamChunk } from '@deepseek-ai/dsh-llm'
|
||||
import { Session, SessionId } from '@deepseek-ai/dsh-session'
|
||||
@@ -198,6 +198,29 @@ describe('compact configuration and defaults', () => {
|
||||
expect(() => resolveConfig(config as BasicCompactConfig, ctx.tokenMeter)).toThrow(pattern)
|
||||
}
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ auto: true }, false, /must install both pressure and overflow listeners/],
|
||||
[{ auto: false }, true, /must install neither automatic compaction listener/],
|
||||
])('rejects an inconsistent automatic-listener topology through the package invariant', async (config, installListener, message) => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(LlmService)
|
||||
await ctx.plugin(TokenMeterService)
|
||||
const invalidCompact = {
|
||||
name: 'BasicCompactService',
|
||||
inject: ['llm', 'tokenMeter'],
|
||||
apply(child: Context, _config: { auto?: boolean }) {
|
||||
child.provide('compact', {
|
||||
compactIfNeeded() {},
|
||||
compactRegion() {},
|
||||
} as unknown as CompactService)
|
||||
if (installListener) {
|
||||
child.effect(() => () => {}, 'ctx.on("agent/post-step")')
|
||||
}
|
||||
},
|
||||
}
|
||||
await expect(ctx.plugin(invalidCompact, config)).rejects.toThrow(message)
|
||||
})
|
||||
})
|
||||
|
||||
describe('pressure measurement and retention', () => {
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-compact`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-compact/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-compact`. @module @deepseek-ai/dsh-compact/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observeServiceInvariant, serviceShapeViolation, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-compact'
|
||||
|
||||
@@ -17,8 +10,12 @@ export const name = 'compact-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Validate every implementation bound to this package's service seam. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observeServiceInvariant(ctx, fail, 'compact', value => serviceShapeViolation(value, {
|
||||
methods: ['compactIfNeeded', 'compactRegion'],
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +24,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-time-context`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-time-context/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-time-context`. @module @deepseek-ai/dsh-time-context/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-time-context'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'time-context-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'time-context',
|
||||
inject: [
|
||||
'agents',
|
||||
],
|
||||
effects: [
|
||||
'ctx.on("agent/pre-step")',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-workspace-context`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-workspace-context/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-workspace-context`. @module @deepseek-ai/dsh-workspace-context/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-workspace-context'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'workspace-context-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'workspace-context',
|
||||
effects: [
|
||||
'ctx.on("session/event")',
|
||||
'ctx.on("agent/session-prefix")',
|
||||
'ctx.on("tools/post-execute")',
|
||||
'ctx.on("tools/result")',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-cordis`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-cordis/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-cordis`. @module @deepseek-ai/dsh-tool-cordis/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-cordis'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'tool-cordis-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-cordis',
|
||||
inject: [
|
||||
'tools',
|
||||
],
|
||||
effects: [
|
||||
'ctx.plugin()',
|
||||
'tools.register()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-system-prompt`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-system-prompt/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-system-prompt`. @module @deepseek-ai/dsh-system-prompt/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-system-prompt'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'system-prompt-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'SystemPrompt',
|
||||
effects: [
|
||||
'ctx.provide("systemPrompt")',
|
||||
'systemPrompt.section()',
|
||||
],
|
||||
services: [
|
||||
'systemPrompt',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tools`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tools/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tools`. @module @deepseek-ai/dsh-tools/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tools'
|
||||
|
||||
@@ -17,8 +10,22 @@ export const name = 'tools-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'ToolRegistry',
|
||||
inject: [
|
||||
'systemPrompt',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("tools")',
|
||||
'systemPrompt.tools()',
|
||||
],
|
||||
services: [
|
||||
'tools',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +34,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-acp-demo`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-acp-demo/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-acp-demo`. @module @deepseek-ai/dsh-acp-demo/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-acp-demo'
|
||||
|
||||
@@ -17,8 +10,15 @@ export const name = 'acp-demo-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'acp-demo',
|
||||
effects: [
|
||||
'ctx.plugin()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +27,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -21,7 +21,14 @@ import * as acpAgent from '../src/index.ts'
|
||||
*/
|
||||
async function mount(config: acpAgent.Config, withBash = false): Promise<Context> {
|
||||
const ctx = new Context()
|
||||
if (withBash) ctx.provide('bash', { sandboxMode: undefined })
|
||||
if (withBash) {
|
||||
ctx.provide('bash', {
|
||||
sandboxMode: undefined,
|
||||
resolve() { throw new Error('composition test does not execute bash') },
|
||||
run() { throw new Error('composition test does not execute bash') },
|
||||
start() { throw new Error('composition test does not execute bash') },
|
||||
})
|
||||
}
|
||||
await ctx.plugin(acpAgent, config)
|
||||
// The bundle mounts its children inside apply() (not awaited there); let their
|
||||
// fibers settle so the spine services are ready.
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-agent-spine-demo`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-agent-spine-demo/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-agent-spine-demo`. @module @deepseek-ai/dsh-agent-spine-demo/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-agent-spine-demo'
|
||||
|
||||
@@ -17,8 +10,15 @@ export const name = 'agent-spine-demo-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'agent-spine-demo',
|
||||
effects: [
|
||||
'ctx.plugin()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +27,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -48,7 +48,14 @@ async function mount(config: agentCore.Config, withBash = false): Promise<Contex
|
||||
process.env.DSH_HOME = await mkdtemp(join(tmpdir(), 'dsh-agent-spine-demo-home-'))
|
||||
process.env.DSH_AGENTS_HOME = await mkdtemp(join(tmpdir(), 'dsh-agent-spine-demo-agents-'))
|
||||
const ctx = new Context()
|
||||
if (withBash) ctx.provide('bash', { sandboxMode: undefined })
|
||||
if (withBash) {
|
||||
ctx.provide('bash', {
|
||||
sandboxMode: undefined,
|
||||
resolve() { throw new Error('composition test does not execute bash') },
|
||||
run() { throw new Error('composition test does not execute bash') },
|
||||
start() { throw new Error('composition test does not execute bash') },
|
||||
})
|
||||
}
|
||||
try {
|
||||
await ctx.plugin(agentCore, config)
|
||||
// The bundle mounts its children inside apply() (not awaited there); let their
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-cli-demo`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-cli-demo/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-cli-demo`. @module @deepseek-ai/dsh-cli-demo/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-cli-demo'
|
||||
|
||||
@@ -17,8 +10,15 @@ export const name = 'cli-demo-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'cli-demo',
|
||||
effects: [
|
||||
'ctx.plugin()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +27,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -22,7 +22,14 @@ async function skillConfig(catalogDescriptionMaxLength?: number): Promise<NonNul
|
||||
|
||||
async function mount(config: cliDemo.Config, withBash = false): Promise<Context> {
|
||||
const ctx = new Context()
|
||||
if (withBash) ctx.provide('bash', { sandboxMode: undefined })
|
||||
if (withBash) {
|
||||
ctx.provide('bash', {
|
||||
sandboxMode: undefined,
|
||||
resolve() { throw new Error('composition test does not execute bash') },
|
||||
run() { throw new Error('composition test does not execute bash') },
|
||||
start() { throw new Error('composition test does not execute bash') },
|
||||
})
|
||||
}
|
||||
contexts.push(ctx)
|
||||
await ctx.plugin(cliDemo, config)
|
||||
await new Promise(resolve => setTimeout(resolve, 80))
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-jsonrpc-demo`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-jsonrpc-demo/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract for @deepseek-ai/dsh-jsonrpc-demo. @module @deepseek-ai/dsh-jsonrpc-demo/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-jsonrpc-demo'
|
||||
|
||||
@@ -17,8 +11,15 @@ export const name = 'jsonrpc-demo-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert that Loader configuration, rather than a hidden root plugin, owns composition. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const packageEntry = await import('./index.ts')
|
||||
assertInvariant(fail, Object.keys(packageEntry).length === 0,
|
||||
'the JSON-RPC demo library entrypoint must remain empty because cordis.yml owns composition')
|
||||
return () => {}
|
||||
}, 'jsonrpc-demo: validate bin-only entrypoint')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-stdio-demo`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-stdio-demo/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-stdio-demo`. @module @deepseek-ai/dsh-stdio-demo/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-stdio-demo'
|
||||
|
||||
@@ -17,8 +10,15 @@ export const name = 'stdio-demo-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'stdio-demo',
|
||||
effects: [
|
||||
'ctx.plugin()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +27,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -18,7 +18,14 @@ import * as stdioAgent from '../src/index.ts'
|
||||
*/
|
||||
async function mount(config: stdioAgent.Config, withBash = false): Promise<Context> {
|
||||
const ctx = new Context()
|
||||
if (withBash) ctx.provide('bash', { sandboxMode: undefined })
|
||||
if (withBash) {
|
||||
ctx.provide('bash', {
|
||||
sandboxMode: undefined,
|
||||
resolve() { throw new Error('composition test does not execute bash') },
|
||||
run() { throw new Error('composition test does not execute bash') },
|
||||
start() { throw new Error('composition test does not execute bash') },
|
||||
})
|
||||
}
|
||||
await ctx.plugin(stdioAgent, config)
|
||||
// The app mounts its children inside apply() (not awaited there); let their
|
||||
// fibers settle so the spine services + the pre-created agent are ready.
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-fs-local`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-fs-local/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-fs-local`. @module @deepseek-ai/dsh-fs-local/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-fs-local'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'fs-local-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'LocalFileSystem',
|
||||
effects: [
|
||||
'ctx.provide("fs")',
|
||||
],
|
||||
services: [
|
||||
'fs',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-fs-policy`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-fs-policy/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-fs-policy`. @module @deepseek-ai/dsh-fs-policy/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-fs-policy'
|
||||
|
||||
@@ -17,8 +10,17 @@ export const name = 'fs-policy-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'fs-policy',
|
||||
effects: [
|
||||
'ctx.on("fs/write-intent")',
|
||||
'ctx.on("fs/edit-intent")',
|
||||
'ctx.on("fs/observed")',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +29,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-fs`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-fs/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-fs`. @module @deepseek-ai/dsh-fs/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observeServiceInvariant, serviceShapeViolation, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-fs'
|
||||
|
||||
@@ -17,8 +10,12 @@ export const name = 'fs-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Validate every implementation bound to this package's service seam. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observeServiceInvariant(ctx, fail, 'fs', value => serviceShapeViolation(value, {
|
||||
methods: ['resolve', 'stat', 'lstat', 'readText', 'streamText', 'listDir', 'writeText', 'editText'],
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +24,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-fs-search`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-fs-search/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-fs-search`. @module @deepseek-ai/dsh-tool-fs-search/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-fs-search'
|
||||
|
||||
@@ -17,8 +10,20 @@ export const name = 'tool-fs-search-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-fs-search',
|
||||
inject: [
|
||||
'tools',
|
||||
'systemPrompt',
|
||||
'bash',
|
||||
],
|
||||
effects: [
|
||||
'tools.register()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +32,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-fs`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-fs/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-fs`. @module @deepseek-ai/dsh-tool-fs/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-fs'
|
||||
|
||||
@@ -17,8 +10,20 @@ export const name = 'tool-fs-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-fs',
|
||||
inject: [
|
||||
'tools',
|
||||
'fs',
|
||||
'systemPrompt',
|
||||
],
|
||||
effects: [
|
||||
'tools.register()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +32,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-repeat-tool-guard`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-repeat-tool-guard/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-repeat-tool-guard`. @module @deepseek-ai/dsh-repeat-tool-guard/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-repeat-tool-guard'
|
||||
|
||||
@@ -17,8 +10,16 @@ export const name = 'repeat-tool-guard-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'repeat-tool-guard',
|
||||
effects: [
|
||||
'ctx.on("tools/post-execute")',
|
||||
'ctx.on("agent/prompt-submit")',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +28,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-hook-protocol`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-hook-protocol/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-hook-protocol. @module @deepseek-ai/dsh-hook-protocol/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-hook-protocol'
|
||||
|
||||
@@ -17,8 +11,24 @@ export const name = 'hook-protocol-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert blocking-exit decoding and restrictive merge precedence. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { parseHookOutput } = await import('./codec.ts')
|
||||
const { mergeHookOutputs } = await import('./merge.ts')
|
||||
const blocked = parseHookOutput(2, '', ' denied ')
|
||||
assertInvariant(fail, blocked.decision === 'block' && blocked.reason === 'denied',
|
||||
'exit 2 must decode as a block whose reason is trimmed stderr')
|
||||
|
||||
const merged = mergeHookOutputs([
|
||||
{ exitCode: 0, stderr: '', stdout: '', decision: 'allow', reason: 'permitted' },
|
||||
{ exitCode: 0, stderr: '', stdout: '', decision: 'deny', reason: 'forbidden' },
|
||||
])
|
||||
assertInvariant(fail, merged.decision === 'deny' && merged.reason === 'forbidden',
|
||||
'deny must override allow and retain only the winning decision reason')
|
||||
return () => {}
|
||||
}, 'hook-protocol: validate decode and merge algebra')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-hooks-claude`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-hooks-claude/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-hooks-claude`. @module @deepseek-ai/dsh-hooks-claude/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-hooks-claude'
|
||||
|
||||
@@ -17,8 +10,31 @@ export const name = 'hooks-claude-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'hooks-claude',
|
||||
inject: [
|
||||
'bash',
|
||||
],
|
||||
validate: (_fiber, effectLabels) => {
|
||||
const hookEffects = [
|
||||
'hooks-claude: drain detached hook runs',
|
||||
'ctx.on("agent/session-start")',
|
||||
'ctx.on("agent/prompt-submit")',
|
||||
'ctx.on("tools/pre-execute")',
|
||||
'ctx.on("tools/post-execute")',
|
||||
'ctx.on("agent/turn-continuation")',
|
||||
'ctx.on("subagent/start")',
|
||||
'ctx.on("subagent/end")',
|
||||
]
|
||||
const installed = hookEffects.filter(label => effectLabels.has(label)).length
|
||||
return installed === 0 || installed === hookEffects.length
|
||||
? undefined
|
||||
: 'a readable Claude hook config must install its complete listener set atomically'
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +43,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
26
packages/hooks/hooks-claude/tests/invariant.spec.ts
Normal file
26
packages/hooks/hooks-claude/tests/invariant.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import type { BashExecutor } from '@deepseek-ai/dsh-bash'
|
||||
|
||||
describe('Claude hook package invariant', () => {
|
||||
it('rejects a partially installed hook listener set', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin({
|
||||
name: 'claude-invariant-bash',
|
||||
apply(child: Context) {
|
||||
child.provide('bash', {
|
||||
resolve() {},
|
||||
async run() {},
|
||||
start() {},
|
||||
} as unknown as BashExecutor)
|
||||
},
|
||||
})
|
||||
await expect(ctx.plugin({
|
||||
name: 'hooks-claude',
|
||||
inject: ['bash'],
|
||||
apply(child: Context) {
|
||||
child.effect(() => () => {}, 'ctx.on("agent/session-start")')
|
||||
},
|
||||
})).rejects.toThrow(/must install its complete listener set atomically/)
|
||||
})
|
||||
})
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-hooks-codex`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-hooks-codex/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-hooks-codex`. @module @deepseek-ai/dsh-hooks-codex/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-hooks-codex'
|
||||
|
||||
@@ -17,8 +10,29 @@ export const name = 'hooks-codex-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'hooks-codex',
|
||||
inject: [
|
||||
'bash',
|
||||
],
|
||||
validate: (_fiber, effectLabels) => {
|
||||
const hookEffects = [
|
||||
'hooks-codex: drain detached hook runs',
|
||||
'ctx.on("agent/session-start")',
|
||||
'ctx.on("agent/prompt-submit")',
|
||||
'ctx.on("tools/pre-execute")',
|
||||
'ctx.on("tools/post-execute")',
|
||||
'ctx.on("agent/turn-continuation")',
|
||||
]
|
||||
const installed = hookEffects.filter(label => effectLabels.has(label)).length
|
||||
return installed === 0 || installed === hookEffects.length
|
||||
? undefined
|
||||
: 'a readable Codex hook config must install its complete listener set atomically'
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +41,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
26
packages/hooks/hooks-codex/tests/invariant.spec.ts
Normal file
26
packages/hooks/hooks-codex/tests/invariant.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
import type { BashExecutor } from '@deepseek-ai/dsh-bash'
|
||||
|
||||
describe('Codex hook package invariant', () => {
|
||||
it('rejects a partially installed hook listener set', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin({
|
||||
name: 'codex-invariant-bash',
|
||||
apply(child: Context) {
|
||||
child.provide('bash', {
|
||||
resolve() {},
|
||||
async run() {},
|
||||
start() {},
|
||||
} as unknown as BashExecutor)
|
||||
},
|
||||
})
|
||||
await expect(ctx.plugin({
|
||||
name: 'hooks-codex',
|
||||
inject: ['bash'],
|
||||
apply(child: Context) {
|
||||
child.effect(() => () => {}, 'ctx.on("agent/session-start")')
|
||||
},
|
||||
})).rejects.toThrow(/must install its complete listener set atomically/)
|
||||
})
|
||||
})
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-llm-deepseek`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-llm-deepseek/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-llm-deepseek`. @module @deepseek-ai/dsh-llm-deepseek/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-llm-deepseek'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'llm-deepseek-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'llm-deepseek',
|
||||
inject: [
|
||||
'llm',
|
||||
],
|
||||
effects: [
|
||||
'llm.registerAdapter()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-llm-pi-ai`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-llm-pi-ai/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-llm-pi-ai`. @module @deepseek-ai/dsh-llm-pi-ai/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-llm-pi-ai'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'llm-pi-ai-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'llm-pi-ai',
|
||||
inject: [
|
||||
'llm',
|
||||
],
|
||||
effects: [
|
||||
'llm.registerAdapter()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-llm`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-llm/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-llm`. @module @deepseek-ai/dsh-llm/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-llm'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'llm-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'LlmService',
|
||||
effects: [
|
||||
'ctx.provide("llm")',
|
||||
],
|
||||
services: [
|
||||
'llm',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-token-meter`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-token-meter/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-token-meter`. @module @deepseek-ai/dsh-token-meter/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-token-meter'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'token-meter-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'TokenMeterService',
|
||||
effects: [
|
||||
'ctx.provide("tokenMeter")',
|
||||
'ctx.on("session/event")',
|
||||
],
|
||||
services: [
|
||||
'tokenMeter',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-mcp-client`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-mcp-client/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-mcp-client`. @module @deepseek-ai/dsh-mcp-client/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-mcp-client'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'mcp-client-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'mcp-client',
|
||||
inject: [
|
||||
'tools',
|
||||
],
|
||||
effects: [
|
||||
'mcp-client.serverName',
|
||||
'mcp-client.connection',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-sandbox-local`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-sandbox-local/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-sandbox-local`. @module @deepseek-ai/dsh-sandbox-local/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-sandbox-local'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'sandbox-local-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'LocalSandboxProvider',
|
||||
effects: [
|
||||
'ctx.provide("sandbox")',
|
||||
],
|
||||
services: [
|
||||
'sandbox',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-sandbox`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-sandbox/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-sandbox`. @module @deepseek-ai/dsh-sandbox/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observeServiceInvariant, serviceShapeViolation, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-sandbox'
|
||||
|
||||
@@ -17,8 +10,12 @@ export const name = 'sandbox-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Validate every implementation bound to this package's service seam. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observeServiceInvariant(ctx, fail, 'sandbox', value => serviceShapeViolation(value, {
|
||||
methods: ['confine'],
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +24,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/create-sdk`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/create-sdk/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/create-sdk. @module @deepseek-ai/create-sdk/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/create-sdk'
|
||||
|
||||
@@ -17,8 +11,26 @@ export const name = 'create-sdk-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert the bin-only entrypoint and its core argument mapping. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { parseCreateArgs } = await import('./args.ts')
|
||||
const packageEntry = await import('./index.ts')
|
||||
assertInvariant(fail, Object.keys(packageEntry).length === 0,
|
||||
'the create-sdk library entrypoint must remain empty because the package is bin-only')
|
||||
const parsed = parseCreateArgs([
|
||||
'workspace', '--provider=custom', '--base-url=https://example.test', '--interface=embed', '--no-install',
|
||||
])
|
||||
assertInvariant(fail,
|
||||
parsed.directory === 'workspace'
|
||||
&& parsed.provider === 'custom'
|
||||
&& parsed.baseURL === 'https://example.test'
|
||||
&& parsed.runInterface === 'embed'
|
||||
&& parsed.install === false,
|
||||
'create-sdk arguments must preserve directory, provider, base URL, interface, and negative install flags')
|
||||
return () => {}
|
||||
}, 'create-sdk: validate bin and argument contracts')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-helper`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-helper/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-helper. @module @deepseek-ai/dsh-helper/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-helper'
|
||||
|
||||
@@ -17,8 +11,22 @@ export const name = 'helper-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert FeatureId's zero-cost representation and boundary validation. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { featureId } = await import('./ids.ts')
|
||||
assertInvariant(fail, featureId('local-plugin') === 'local-plugin',
|
||||
'a valid feature id must preserve its runtime string value')
|
||||
let rejected = false
|
||||
try {
|
||||
featureId('Invalid Feature')
|
||||
} catch (error) {
|
||||
rejected = error instanceof Error
|
||||
}
|
||||
assertInvariant(fail, rejected, 'feature ids must reject values outside lowercase kebab-case')
|
||||
return () => {}
|
||||
}, 'dsh-helper: validate feature identities')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import { parseArgs as parseNodeArgs } from 'node:util'
|
||||
import { Command } from 'commander'
|
||||
import { splitForwardedArgs } from './forwarding.ts'
|
||||
|
||||
/** Commands implemented by the dsh-sdk launcher. */
|
||||
type DshSdkCommand = 'start' | 'dev' | 'build' | 'config'
|
||||
@@ -33,9 +34,7 @@ export function parseDshSdkArgs(argv: readonly string[]): DshSdkArgs {
|
||||
if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
|
||||
return { forwarded: [], help: true }
|
||||
}
|
||||
const separator = argv.indexOf('--')
|
||||
const launcherArgv = separator === -1 ? argv : argv.slice(0, separator)
|
||||
const passthrough = separator === -1 ? [] : argv.slice(separator + 1)
|
||||
const { launcher: launcherArgv, forwarded: passthrough } = splitForwardedArgs(argv)
|
||||
let parsed: DshSdkArgs | undefined
|
||||
const program = new Command()
|
||||
.name('dsh-sdk')
|
||||
|
||||
21
packages/sdk/scripts/src/forwarding.ts
Normal file
21
packages/sdk/scripts/src/forwarding.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/** Argument-delimiter handling shared by the SDK launcher and its invariant. */
|
||||
|
||||
/** Launcher-owned arguments and opaque arguments following `--`. */
|
||||
export interface ForwardedArgumentSplit {
|
||||
/** Arguments parsed by the SDK launcher. */
|
||||
readonly launcher: readonly string[]
|
||||
/** Arguments passed unchanged to the selected project command. */
|
||||
readonly forwarded: readonly string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the first `--` delimiter without interpreting either side.
|
||||
* @param argv - complete user argument vector.
|
||||
* @returns launcher arguments and post-delimiter arguments.
|
||||
*/
|
||||
export function splitForwardedArgs(argv: readonly string[]): ForwardedArgumentSplit {
|
||||
const separator = argv.indexOf('--')
|
||||
return separator === -1
|
||||
? { launcher: argv, forwarded: [] }
|
||||
: { launcher: argv.slice(0, separator), forwarded: argv.slice(separator + 1) }
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-scripts`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-scripts/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-scripts. @module @deepseek-ai/dsh-scripts/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-scripts'
|
||||
|
||||
@@ -17,8 +11,24 @@ export const name = 'scripts-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert the launcher's opaque post-separator forwarding boundary. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { splitForwardedArgs } = await import('./forwarding.ts')
|
||||
const plain = splitForwardedArgs(['dev', 'src/index.ts'])
|
||||
const separated = splitForwardedArgs(['dev', 'src/index.ts', '--', '--inspect', '9229'])
|
||||
assertInvariant(fail,
|
||||
plain.launcher.length === 2
|
||||
&& plain.forwarded.length === 0
|
||||
&& separated.launcher.length === 2
|
||||
&& separated.launcher[1] === 'src/index.ts'
|
||||
&& separated.forwarded.length === 2
|
||||
&& separated.forwarded[0] === '--inspect'
|
||||
&& separated.forwarded[1] === '9229',
|
||||
'dsh-sdk must split the first delimiter without interpreting forwarded runtime arguments')
|
||||
return () => {}
|
||||
}, 'dsh-sdk: validate command argument contracts')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -132,6 +132,7 @@ describe('Commander launcher arguments', () => {
|
||||
expect(parseDshSdkArgs(['start'])).toEqual({ command: 'start', forwarded: [], help: false })
|
||||
expect(parseDshSdkArgs(['dev', 'index.ts'])).toMatchObject({ command: 'dev', target: 'index.ts' })
|
||||
expect(parseDshSdkArgs(['-h'])).toMatchObject({ help: true })
|
||||
expect(parseDshSdkArgs(['--help'])).toMatchObject({ help: true })
|
||||
expect(() => parseDshSdkArgs(['unknown'])).toThrow()
|
||||
expect(() => parseDshSdkArgs(['config', 'extra'])).toThrow()
|
||||
expect(() => parseDshSdkArgs(['config', '--', 'extra'])).toThrow('does not accept forwarded')
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-session-persistence-jsonl`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* Package-owned runtime contract checks for `@deepseek-ai/dsh-session-persistence-jsonl`.
|
||||
* @module @deepseek-ai/dsh-session-persistence-jsonl/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-session-persistence-jsonl'
|
||||
|
||||
@@ -17,8 +13,21 @@ export const name = 'session-persistence-jsonl-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'SessionPersistenceJsonl',
|
||||
inject: [
|
||||
'sessions',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("sessionPersistence")',
|
||||
],
|
||||
services: [
|
||||
'sessionPersistence',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +36,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-session-persistence-sqlite`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* Package-owned runtime contract checks for `@deepseek-ai/dsh-session-persistence-sqlite`.
|
||||
* @module @deepseek-ai/dsh-session-persistence-sqlite/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-session-persistence-sqlite'
|
||||
|
||||
@@ -17,8 +13,21 @@ export const name = 'session-persistence-sqlite-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'SessionPersistenceSqlite',
|
||||
inject: [
|
||||
'sessions',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("sessionPersistence")',
|
||||
],
|
||||
services: [
|
||||
'sessionPersistence',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +36,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-session-persistence`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* Package-owned runtime contract checks for `@deepseek-ai/dsh-session-persistence`.
|
||||
* @module @deepseek-ai/dsh-session-persistence/invariant
|
||||
*/
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observeServiceInvariant, serviceShapeViolation, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-session-persistence'
|
||||
|
||||
@@ -17,8 +13,12 @@ export const name = 'session-persistence-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Validate every implementation bound to this package's service seam. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observeServiceInvariant(ctx, fail, 'sessionPersistence', value => serviceShapeViolation(value, {
|
||||
methods: ['locate', 'create', 'append', 'load', 'list'],
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +27,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-session-query`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-session-query/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-session-query`. @module @deepseek-ai/dsh-session-query/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-session-query'
|
||||
|
||||
@@ -17,8 +10,21 @@ export const name = 'session-query-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'SessionQueryService',
|
||||
inject: [
|
||||
'sessions',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("sessionQuery")',
|
||||
],
|
||||
services: [
|
||||
'sessionQuery',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +33,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-skill-local`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-skill-local/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-skill-local`. @module @deepseek-ai/dsh-skill-local/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-skill-local'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'skill-local-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'skill-local',
|
||||
inject: [
|
||||
'skills',
|
||||
],
|
||||
effects: [
|
||||
'skills.registerProvider()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-skill`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-skill/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-skill`. @module @deepseek-ai/dsh-skill/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-skill'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'skill-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'SkillService',
|
||||
effects: [
|
||||
'ctx.provide("skills")',
|
||||
],
|
||||
services: [
|
||||
'skills',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-skill`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-skill/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-skill`. @module @deepseek-ai/dsh-tool-skill/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-skill'
|
||||
|
||||
@@ -17,8 +10,20 @@ export const name = 'tool-skill-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-skill',
|
||||
inject: [
|
||||
'tools',
|
||||
'skills',
|
||||
],
|
||||
effects: [
|
||||
'tools.register()',
|
||||
'ctx.on("agent/session-prefix")',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +32,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-spill-local`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-spill-local/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-spill-local`. @module @deepseek-ai/dsh-spill-local/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-spill-local'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'spill-local-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'LocalSpillStore',
|
||||
effects: [
|
||||
'ctx.provide("spillStore")',
|
||||
],
|
||||
services: [
|
||||
'spillStore',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-spill-policy`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-spill-policy/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-spill-policy`. @module @deepseek-ai/dsh-spill-policy/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-spill-policy'
|
||||
|
||||
@@ -17,8 +10,22 @@ export const name = 'spill-policy-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'spill-policy',
|
||||
inject: [
|
||||
'tools',
|
||||
],
|
||||
validate: (fiber, effectLabels) => {
|
||||
const installed = effectLabels.has('ctx.on("tools/post-execute")')
|
||||
const enabled = (fiber.config as { maxInlineBytes?: number }).maxInlineBytes !== undefined
|
||||
return installed === enabled
|
||||
? undefined
|
||||
: 'the post-execute spill policy listener must exist exactly when maxInlineBytes is configured'
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +34,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -109,6 +109,17 @@ describe('config validation', () => {
|
||||
it('rejects a fractional maxInlineBytes at load', async () => {
|
||||
await expect(setup({ maxInlineBytes: 1.5 })).rejects.toThrow(/non-negative integer/)
|
||||
})
|
||||
|
||||
it('rejects a configured policy that omits its post-execute listener', async () => {
|
||||
const ctx = new Context()
|
||||
await ctx.plugin(SystemPrompt)
|
||||
await ctx.plugin(ToolRegistry)
|
||||
await expect(ctx.plugin({
|
||||
name: 'spill-policy',
|
||||
inject: ['tools'],
|
||||
apply(_child: Context, _config: { maxInlineBytes?: number }) {},
|
||||
}, { maxInlineBytes: 10 })).rejects.toThrow(/listener must exist exactly when maxInlineBytes is configured/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('oversized plain-text replacement', () => {
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-spill`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-spill/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-spill`. @module @deepseek-ai/dsh-spill/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observeServiceInvariant, serviceShapeViolation, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-spill'
|
||||
|
||||
@@ -17,8 +10,12 @@ export const name = 'spill-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Validate every implementation bound to this package's service seam. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observeServiceInvariant(ctx, fail, 'spillStore', value => serviceShapeViolation(value, {
|
||||
methods: ['saveText'],
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +24,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-subagent-acp`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-subagent-acp/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-subagent-acp`. @module @deepseek-ai/dsh-subagent-acp/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-subagent-acp'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'subagent-acp-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'subagent-acp',
|
||||
inject: [
|
||||
'subagents',
|
||||
],
|
||||
effects: [
|
||||
'subagents.registerProvider()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-subagent-fork`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-subagent-fork/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-subagent-fork`. @module @deepseek-ai/dsh-subagent-fork/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-subagent-fork'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'subagent-fork-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'subagent-fork',
|
||||
inject: [
|
||||
'subagents',
|
||||
],
|
||||
effects: [
|
||||
'subagents.registerProvider()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-subagent-inprocess`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-subagent-inprocess/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-subagent-inprocess. @module @deepseek-ai/dsh-subagent-inprocess/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-subagent-inprocess'
|
||||
|
||||
@@ -17,8 +11,17 @@ export const name = 'subagent-inprocess-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert that structured-output guidance names the tool it actually installs. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { STRUCTURED_OUTPUT_INSTRUCTION, STRUCTURED_OUTPUT_TOOL } = await import('./structured-protocol.ts')
|
||||
assertInvariant(fail, /^[a-z][a-z0-9_]*$/.test(STRUCTURED_OUTPUT_TOOL),
|
||||
'the structured-output tool must retain a stable lowercase protocol name')
|
||||
assertInvariant(fail, STRUCTURED_OUTPUT_INSTRUCTION.includes(STRUCTURED_OUTPUT_TOOL),
|
||||
'the structured-output instruction must name the exact installed tool')
|
||||
return () => {}
|
||||
}, 'subagent-inprocess: validate structured-output protocol')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/** Model-facing constants shared by structured child execution and its invariant. */
|
||||
|
||||
/** The model-facing tool name a structured child must call to finish. */
|
||||
export const STRUCTURED_OUTPUT_TOOL = 'structured_output'
|
||||
|
||||
/** The terminal structured-result instruction appended to a child request. */
|
||||
export const STRUCTURED_OUTPUT_INSTRUCTION
|
||||
= 'When you have your final answer, you MUST report it by calling the '
|
||||
+ `\`${STRUCTURED_OUTPUT_TOOL}\` tool with arguments matching its parameter schema exactly. `
|
||||
+ 'Do not finish with a plain text answer: only the tool call counts as your result.'
|
||||
@@ -15,19 +15,9 @@ import type { ContinuationStop } from '@deepseek-ai/dsh-agent'
|
||||
import type { ContentBlock, ToolSchema } from '@deepseek-ai/dsh-llm'
|
||||
import type { ToolExecution } from '@deepseek-ai/dsh-tools'
|
||||
import { ToolArgsError, validateStructuredValue, type StructuredOutputSchema } from '@deepseek-ai/dsh-tools'
|
||||
import { STRUCTURED_OUTPUT_INSTRUCTION, STRUCTURED_OUTPUT_TOOL } from './structured-protocol.ts'
|
||||
|
||||
/** The model-facing tool name a structured child must call to finish. */
|
||||
export const STRUCTURED_OUTPUT_TOOL = 'structured_output'
|
||||
|
||||
/**
|
||||
* The instruction registered as the child's trailing (order-190, the end of
|
||||
* the tool-guidance band) scoped prompt section: the demand travels with the
|
||||
* tool, as ordinary prompt state of exactly one agent.
|
||||
*/
|
||||
export const STRUCTURED_OUTPUT_INSTRUCTION
|
||||
= 'When you have your final answer, you MUST report it by calling the '
|
||||
+ `\`${STRUCTURED_OUTPUT_TOOL}\` tool with arguments matching its parameter schema exactly. `
|
||||
+ 'Do not finish with a plain text answer: only the tool call counts as your result.'
|
||||
export { STRUCTURED_OUTPUT_INSTRUCTION, STRUCTURED_OUTPUT_TOOL } from './structured-protocol.ts'
|
||||
|
||||
/** One structured run's live handle: read the captured value once the child settles. */
|
||||
export interface StructuredAttachment {
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-subagent-spawn`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-subagent-spawn/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-subagent-spawn`. @module @deepseek-ai/dsh-subagent-spawn/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-subagent-spawn'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'subagent-spawn-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'subagent-spawn',
|
||||
inject: [
|
||||
'subagents',
|
||||
],
|
||||
effects: [
|
||||
'subagents.registerProvider()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,24 +1,32 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-subagent-subprocess`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-subagent-subprocess/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-subagent-subprocess. @module @deepseek-ai/dsh-subagent-subprocess/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-subagent-subprocess'
|
||||
const SENSITIVE_ENV_PATTERN = /KEY|SECRET|TOKEN/i
|
||||
|
||||
/** Cordis companion plugin name. */
|
||||
export const name = 'subagent-subprocess-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert ambient credential scrubbing and explicit credential precedence. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { buildChildEnv } = await import('./index.ts')
|
||||
const scrubbed = buildChildEnv({})
|
||||
const ambientSensitiveNames = Object.keys(process.env).filter(key => SENSITIVE_ENV_PATTERN.test(key))
|
||||
assertInvariant(fail, ambientSensitiveNames.every(key => !Object.hasOwn(scrubbed, key)),
|
||||
'subprocess environments must omit every credential-shaped ambient variable')
|
||||
|
||||
const explicit = buildChildEnv({ DSH_INVARIANT_TOKEN: 'explicit-child-value' })
|
||||
assertInvariant(fail, explicit.DSH_INVARIANT_TOKEN === 'explicit-child-value',
|
||||
'explicit child credentials must be applied after ambient scrubbing')
|
||||
return () => {}
|
||||
}, 'subagent-subprocess: validate child environment isolation')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-subagent`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-subagent/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-subagent`. @module @deepseek-ai/dsh-subagent/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-subagent'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'subagent-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'SubagentService',
|
||||
effects: [
|
||||
'ctx.provide("subagents")',
|
||||
],
|
||||
services: [
|
||||
'subagents',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-subagent`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-subagent/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-subagent`. @module @deepseek-ai/dsh-tool-subagent/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-subagent'
|
||||
|
||||
@@ -17,8 +10,20 @@ export const name = 'tool-subagent-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-subagent',
|
||||
inject: [
|
||||
'tools',
|
||||
'subagents',
|
||||
],
|
||||
effects: [
|
||||
'ctx.on("subagent/provider-added")',
|
||||
'ctx.on("subagent/provider-removed")',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +32,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-acp-snapshot`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-acp-snapshot/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-acp-snapshot. @module @deepseek-ai/dsh-acp-snapshot/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-acp-snapshot'
|
||||
|
||||
@@ -17,8 +11,27 @@ export const name = 'acp-snapshot-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert stable JSON-RPC correlation and volatile-value tokenization. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { normalizeStdout } = await import('./normalize.ts')
|
||||
const sessionId = '12345678-1234-1234-1234-123456789abc'
|
||||
const volatile = { sessionIds: [sessionId], cwd: '/tmp/dsh-acp-invariant' }
|
||||
const raw = [
|
||||
JSON.stringify({ jsonrpc: '2.0', id: 'request-7', result: { cwd: volatile.cwd } }),
|
||||
JSON.stringify({ jsonrpc: '2.0', id: 'request-7', result: { sessionId } }),
|
||||
].join('\n')
|
||||
const normalized = normalizeStdout(raw, volatile)
|
||||
assertInvariant(fail,
|
||||
normalized.includes('"id":1')
|
||||
&& normalized.includes('"cwd":"{{cwd}}"')
|
||||
&& normalized.includes('"sessionId":"{{sessionId}}"'),
|
||||
'ACP normalization must preserve RPC correlation while tokenizing cwd and session ids')
|
||||
assertInvariant(fail, normalizeStdout(normalized, volatile) === normalized,
|
||||
'ACP stdout normalization must be idempotent')
|
||||
return () => {}
|
||||
}, 'acp-snapshot: validate stable transcript normalization')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -6,12 +6,7 @@
|
||||
*/
|
||||
|
||||
import type { Context } from 'cordis'
|
||||
import AgentRegistry from '@deepseek-ai/dsh-agent'
|
||||
import LlmService from '@deepseek-ai/dsh-llm'
|
||||
import SessionStore from '@deepseek-ai/dsh-session'
|
||||
import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
|
||||
import type { Config as SystemPromptConfig } from '@deepseek-ai/dsh-system-prompt'
|
||||
import ToolRegistry from '@deepseek-ai/dsh-tools'
|
||||
import type { Config as ToolRegistryConfig } from '@deepseek-ai/dsh-tools'
|
||||
|
||||
/** Configuration forwarded to the prerequisite service plugins. */
|
||||
@@ -38,6 +33,19 @@ export async function mountAgentLoopTestDependencies(
|
||||
ctx: Context,
|
||||
options: AgentLoopTestDependenciesOptions = {},
|
||||
): Promise<void> {
|
||||
const [
|
||||
{ default: LlmService },
|
||||
{ default: SessionStore },
|
||||
{ default: SystemPrompt },
|
||||
{ default: ToolRegistry },
|
||||
{ default: AgentRegistry },
|
||||
] = await Promise.all([
|
||||
import('@deepseek-ai/dsh-llm'),
|
||||
import('@deepseek-ai/dsh-session'),
|
||||
import('@deepseek-ai/dsh-system-prompt'),
|
||||
import('@deepseek-ai/dsh-tools'),
|
||||
import('@deepseek-ai/dsh-agent'),
|
||||
])
|
||||
await ctx.plugin(LlmService)
|
||||
await ctx.plugin(SessionStore)
|
||||
await ctx.plugin(SystemPrompt, options.systemPrompt ?? {})
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-agent-loop-testkit`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-agent-loop-testkit/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-agent-loop-testkit. @module @deepseek-ai/dsh-agent-loop-testkit/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-agent-loop-testkit'
|
||||
|
||||
@@ -17,8 +11,18 @@ export const name = 'agent-loop-testkit-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert the awaitable helper shape and optional-options call boundary. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { mountAgentLoopTestDependencies } = await import('./index.ts')
|
||||
assertInvariant(fail,
|
||||
mountAgentLoopTestDependencies.constructor.name === 'AsyncFunction',
|
||||
'the prerequisite mount helper must remain awaitable so tests cannot race service activation')
|
||||
assertInvariant(fail, mountAgentLoopTestDependencies.length === 1,
|
||||
'the prerequisite mount helper must keep its options argument optional')
|
||||
return () => {}
|
||||
}, 'agent-loop-testkit: validate prerequisite mount boundary')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -24,9 +24,17 @@ The service owns every registration fiber, while the returned disposer also belo
|
||||
|
||||
## Package companions
|
||||
|
||||
An ownership-only generated baseline installs no listeners but still reserves its package name through the real service boundary. A package replaces that marked file when it gains a relational check, retaining the same registration. `pnpm run verify-package-invariants` checks every package's source registration, export, published files, dependencies, TypeScript reference, and bundle entry.
|
||||
Every companion installs at least one executable, package-specific contract and reports failure through its bound reporter. There is no generated or ownership-only baseline. `pnpm run verify-package-invariants` rejects generated markers, empty installers, installers that ignore the reporter, duplicate name-based plugin observers, incorrect registration names, and incomplete export, publication, dependency, TypeScript-reference, or bundle wiring.
|
||||
|
||||
Four companions currently install stateful checks:
|
||||
Packages select the narrowest runtime form that protects their public contract:
|
||||
|
||||
| Package shape | Companion check |
|
||||
|---|---|
|
||||
| Cordis plugin | `observePluginInvariant` validates the plugin's own declared name, required injections, owned effect group, provided services, and optional package-specific relation for existing, late, and HMR-activated fibers. |
|
||||
| Cordis service seam | `observeServiceInvariant` plus `serviceShapeViolation` validates current and future structural implementations, including conforming third-party backends and test doubles. |
|
||||
| Pure library, bin, or support package | `assertInvariant` checks stable protocol algebra, parser mapping, path/timeout/retention rules, normalization, or entrypoint shape in a child effect. |
|
||||
|
||||
Four companions additionally install stateful event and request checks:
|
||||
|
||||
| Companion | Registration | Checks |
|
||||
|---|---|---|
|
||||
@@ -35,7 +43,7 @@ Four companions currently install stateful checks:
|
||||
| `@deepseek-ai/dsh-scope/invariant` | `@deepseek-ai/dsh-scope` | scoped-event carrier presence and subject consistency |
|
||||
| `@deepseek-ai/dsh-agent-loop/invariant` | `@deepseek-ai/dsh-agent-loop` | loop-built model-request reconstruction from the session log |
|
||||
|
||||
The root entrypoint of each owner remains independent of diagnostics. Loading the service alone installs no checks; loading a companion without the service remains pending on its declared `invariants` dependency.
|
||||
The root entrypoint of each owner remains independent of diagnostics. Loading the service alone installs no checks; loading a companion without the service remains pending on its declared `invariants` dependency. Name-based plugin observers match only a fiber's own declared runtime name, not anonymous child fibers that inherit a parent display name. They avoid importing the product entrypoint before it is loaded; pure-library checks likewise defer owner imports into the installer child so Vitest mocks and deployment loaders establish their module boundary first.
|
||||
|
||||
## Composition
|
||||
|
||||
@@ -54,7 +62,7 @@ ctx.plugin(InvariantService, {
|
||||
ctx.plugin(SessionInvariant)
|
||||
```
|
||||
|
||||
The standard agent spine mounts the service and the four stateful companions. Custom compositions choose the companions they want and may disable or filter them without changing package entrypoints. Vitest mounts every package companion against an explicitly enabled service for ordinary Cordis roots, so baseline ownership and stateful checks execute across unit, snapshot, and e2e suites; focused invariant-service tests construct their own topology to exercise filtering and lifecycle behavior.
|
||||
The standard agent spine mounts the service and the four stateful companions. Custom compositions explicitly add the companions for the packages whose contracts they want checked and may disable or filter them without changing package entrypoints. Vitest mounts every package companion against an explicitly enabled service for ordinary Cordis roots, so all package checks execute across unit, snapshot, and e2e suites; focused invariant-service tests construct their own topology to exercise filtering and lifecycle behavior.
|
||||
|
||||
## Model Experience
|
||||
|
||||
@@ -62,6 +70,7 @@ None, as the service and companions observe runtime events and requests but neve
|
||||
|
||||
## Known Limitations and Deferred Work
|
||||
|
||||
- Stateful checks cover only the four listed package contracts; other companions reserve ownership but add no listeners until their packages gain relational assertions.
|
||||
- A name-based plugin observer assumes Cordis plugin names are unique within one root; a package can provide the exact callback when importing it does not preload an unrelated runtime.
|
||||
- Pure-library contracts are sampled when their companion child activates rather than observed continuously; mutable package behavior belongs on an event, service, or plugin-fiber observer.
|
||||
- Request reconstruction covers frozen loop-built requests with a live session id; direct one-shot calls remain outside that companion's marker contract.
|
||||
- Regular-expression filters are fixed for the service lifetime; changing them requires ordinary Cordis plugin reload.
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
/**
|
||||
* Configurable registry for package-owned runtime invariant contributions.
|
||||
* Every workspace package registers its name from a `./invariant` companion;
|
||||
* ordinary package entrypoints stay independent of diagnostics, and packages
|
||||
* without relational checks use an ownership-only installer.
|
||||
* Every workspace package registers checks from a `./invariant` companion;
|
||||
* ordinary package entrypoints stay independent of diagnostics.
|
||||
*
|
||||
* @module @deepseek-ai/dsh-invariants
|
||||
*/
|
||||
|
||||
import { Context, Service } from 'cordis'
|
||||
import type { Inject } from 'cordis'
|
||||
import { Context, FiberState, Service } from 'cordis'
|
||||
import type { Fiber, Inject, Plugin } from 'cordis'
|
||||
import z from 'schemastery'
|
||||
import type Schema from 'schemastery'
|
||||
|
||||
@@ -42,6 +41,173 @@ export interface InvariantInstaller {
|
||||
readonly inject?: Inject
|
||||
}
|
||||
|
||||
/** Runtime facts one package expects from its Cordis plugin fiber. */
|
||||
export interface PluginInvariantContract {
|
||||
/** Exact plugin value when checking it does not preload an unrelated runtime; otherwise matching uses `name`. */
|
||||
readonly plugin?: Plugin
|
||||
/** Exact Cordis display name for the plugin fiber. */
|
||||
readonly name: string
|
||||
/** Required service injections that must be present when the fiber activates. */
|
||||
readonly inject?: readonly string[]
|
||||
/** Required owned effect labels; an inner array means at least one alternative must exist. */
|
||||
readonly effects?: readonly (string | readonly string[])[]
|
||||
/** Services the active fiber must provide. */
|
||||
readonly services?: readonly string[]
|
||||
/** Optional package-owned validation after the structural checks pass. */
|
||||
readonly validate?: (fiber: Fiber, effectLabels: ReadonlySet<string>) => string | undefined
|
||||
}
|
||||
|
||||
/** Collect all live effect labels below a plugin fiber. */
|
||||
function collectEffectLabels(fiber: Fiber): ReadonlySet<string> {
|
||||
const labels = new Set<string>()
|
||||
const visit = (effects: ReturnType<Fiber['getEffects']>): void => {
|
||||
for (const effect of effects) {
|
||||
labels.add(effect.label)
|
||||
visit(effect.children)
|
||||
}
|
||||
}
|
||||
visit(fiber.getEffects())
|
||||
return labels
|
||||
}
|
||||
|
||||
/**
|
||||
* Observe one package plugin and fail whenever an active fiber violates its
|
||||
* declared name, dependency, effect, service, or package-specific contract.
|
||||
* Existing fibers are checked immediately; later starts and HMR activations
|
||||
* are checked through Cordis lifecycle events.
|
||||
* @param ctx - invariant child context that owns the observers.
|
||||
* @param fail - reporter bound to the package that owns the plugin.
|
||||
* @param contract - expected runtime facts for the package plugin.
|
||||
* @returns nothing after lifecycle observers are installed.
|
||||
*/
|
||||
export function observePluginInvariant(
|
||||
ctx: Context,
|
||||
fail: InvariantFailure,
|
||||
contract: PluginInvariantContract,
|
||||
): void {
|
||||
const callback = contract.plugin === undefined ? undefined : ctx.registry.resolve(contract.plugin)
|
||||
if (contract.plugin !== undefined && callback === undefined) {
|
||||
fail('invariant contract does not identify a Cordis plugin')
|
||||
}
|
||||
|
||||
const inspect = (fiber: Fiber): void => {
|
||||
const matches = callback === undefined
|
||||
? fiber.runtime?.name === contract.name
|
||||
: fiber.runtime?.callback === callback
|
||||
if (!matches || fiber.state !== FiberState.ACTIVE) return
|
||||
if (callback !== undefined && fiber.name !== contract.name) {
|
||||
fail(`active plugin name must be ${JSON.stringify(contract.name)}, got ${JSON.stringify(fiber.name)}`)
|
||||
}
|
||||
const injections = new Set(Object.keys(fiber.inject))
|
||||
for (const service of contract.inject ?? []) {
|
||||
if (!injections.has(service)) fail(`active plugin must inject ${JSON.stringify(service)}`)
|
||||
}
|
||||
|
||||
const effectLabels = collectEffectLabels(fiber)
|
||||
for (const requirement of contract.effects ?? []) {
|
||||
const alternatives = typeof requirement === 'string' ? [requirement] : requirement
|
||||
if (!alternatives.some(label => effectLabels.has(label))) {
|
||||
fail(`active plugin must own effect ${alternatives.map(label => JSON.stringify(label)).join(' or ')}`)
|
||||
}
|
||||
}
|
||||
for (const service of contract.services ?? []) {
|
||||
const provided = Reflect.ownKeys(fiber.ctx.reflect.store).some((key) => {
|
||||
const implementation = fiber.ctx.reflect.store[key as symbol]
|
||||
return implementation?.fiber === fiber && implementation.name === service
|
||||
})
|
||||
if (!provided) fail(`active plugin must provide service ${JSON.stringify(service)}`)
|
||||
}
|
||||
const message = contract.validate?.(fiber, effectLabels)
|
||||
if (message !== undefined) fail(message)
|
||||
}
|
||||
|
||||
if (contract.plugin === undefined) {
|
||||
for (const runtime of ctx.registry.values()) {
|
||||
for (const fiber of runtime.fibers) inspect(fiber)
|
||||
}
|
||||
} else {
|
||||
for (const fiber of ctx.registry.get(contract.plugin)?.fibers ?? []) inspect(fiber)
|
||||
}
|
||||
ctx.on('internal/plugin', inspect, { global: true })
|
||||
ctx.on('internal/status', inspect, { global: true })
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate every current and future implementation bound to one Cordis service.
|
||||
* @param ctx - invariant child context that owns the service observer.
|
||||
* @param fail - reporter bound to the package that owns the service seam.
|
||||
* @param serviceName - Cordis service name to observe.
|
||||
* @param validate - returns the violated contract, or `undefined` for a valid implementation.
|
||||
* @returns nothing after the current binding is checked and the observer is installed.
|
||||
*/
|
||||
export function observeServiceInvariant(
|
||||
ctx: Context,
|
||||
fail: InvariantFailure,
|
||||
serviceName: string,
|
||||
validate: (value: unknown) => string | undefined,
|
||||
): void {
|
||||
const inspect = (value: unknown): void => {
|
||||
if (value === undefined) return
|
||||
const message = validate(value)
|
||||
if (message !== undefined) fail(message)
|
||||
}
|
||||
const current: unknown = ctx.get(serviceName)
|
||||
inspect(current)
|
||||
ctx.on('internal/service', (name, value: unknown) => {
|
||||
if (name === serviceName) inspect(value)
|
||||
}, { global: true })
|
||||
}
|
||||
|
||||
/** Structural runtime surface required from a Cordis service implementation. */
|
||||
export interface ServiceShapeInvariant {
|
||||
/** Members that must be callable. */
|
||||
readonly methods: readonly string[]
|
||||
/** Members that must be non-empty strings. */
|
||||
readonly stringProperties?: readonly string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe the first missing member in a structural service implementation.
|
||||
* This deliberately accepts test doubles and third-party implementations that
|
||||
* satisfy the seam without inheriting the first-party abstract service class.
|
||||
* @param value - candidate service implementation.
|
||||
* @param shape - callable and string members owned by the service package.
|
||||
* @returns the violated shape, or `undefined` when the candidate conforms.
|
||||
*/
|
||||
export function serviceShapeViolation(
|
||||
value: unknown,
|
||||
shape: ServiceShapeInvariant,
|
||||
): string | undefined {
|
||||
if ((typeof value !== 'object' && typeof value !== 'function') || value === null) {
|
||||
return 'service implementation must be an object'
|
||||
}
|
||||
const record = value as Record<string, unknown>
|
||||
for (const method of shape.methods) {
|
||||
if (typeof record[method] !== 'function') return `service implementation must expose method ${JSON.stringify(method)}`
|
||||
}
|
||||
for (const property of shape.stringProperties ?? []) {
|
||||
if (typeof record[property] !== 'string' || record[property].length === 0) {
|
||||
return `service implementation must expose non-empty string ${JSON.stringify(property)}`
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Report a failed package-owned synchronous invariant.
|
||||
* @param fail - reporter bound to the package that owns the assertion.
|
||||
* @param condition - condition that must hold.
|
||||
* @param message - violated contract when `condition` is false.
|
||||
* @returns nothing when the condition holds.
|
||||
*/
|
||||
export function assertInvariant(
|
||||
fail: InvariantFailure,
|
||||
condition: unknown,
|
||||
message: string,
|
||||
): void {
|
||||
if (!condition) fail(message)
|
||||
}
|
||||
|
||||
/** Internal effect shape used to join child startup before a companion loads. */
|
||||
interface PendingInvariantRegistration extends PromiseLike<() => void> {
|
||||
(): void | Promise<void>
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-invariants`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-invariants/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-invariants`. @module @deepseek-ai/dsh-invariants/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from './index.ts'
|
||||
import InvariantService, { observePluginInvariant, type InvariantInstaller } from './index.ts'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-invariants'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'invariants-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
plugin: InvariantService,
|
||||
name: 'InvariantService',
|
||||
effects: [
|
||||
'ctx.provide("invariants")',
|
||||
],
|
||||
services: [
|
||||
'invariants',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { Context, Service } from 'cordis'
|
||||
import InvariantService, { InvariantError, type Config } from '@deepseek-ai/dsh-invariants'
|
||||
import InvariantService, {
|
||||
InvariantError,
|
||||
assertInvariant,
|
||||
observePluginInvariant,
|
||||
observeServiceInvariant,
|
||||
serviceShapeViolation,
|
||||
type Config,
|
||||
type InvariantInstaller,
|
||||
type PluginInvariantContract,
|
||||
} from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
declare module 'cordis' {
|
||||
interface Context {
|
||||
invariantProbe: InvariantProbeService
|
||||
watchedInvariantProbe: WatchedInvariantProbeService
|
||||
}
|
||||
|
||||
interface Events {
|
||||
@@ -18,6 +28,12 @@ class InvariantProbeService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
class WatchedInvariantProbeService extends Service {
|
||||
constructor(ctx: Context) {
|
||||
super(ctx, 'watchedInvariantProbe')
|
||||
}
|
||||
}
|
||||
|
||||
interface RuntimeRegistration extends PromiseLike<() => void> {
|
||||
(): void | Promise<void>
|
||||
}
|
||||
@@ -264,3 +280,207 @@ describe('InvariantService lifecycle', () => {
|
||||
expect(() => service.register('@deepseek-ai/dsh-session', () => {})).toThrow(/inactive/i)
|
||||
})
|
||||
})
|
||||
|
||||
describe('package-owned invariant helpers', () => {
|
||||
async function registerInstaller(
|
||||
ctx: Context,
|
||||
packageName: string,
|
||||
installer: InvariantInstaller,
|
||||
): Promise<() => void> {
|
||||
const registration = runtimeRegistration(ctx.invariants.register(packageName, installer))
|
||||
const dispose = await Promise.resolve(registration)
|
||||
return dispose
|
||||
}
|
||||
|
||||
function effectPlugin(options: {
|
||||
name?: string
|
||||
inject?: string[]
|
||||
effect?: string
|
||||
service?: string
|
||||
} = {}) {
|
||||
return {
|
||||
name: options.name ?? 'effect-probe',
|
||||
inject: options.inject ?? [],
|
||||
apply(ctx: Context) {
|
||||
if (options.service !== undefined) ctx.provide(options.service, {})
|
||||
if (options.effect !== undefined) {
|
||||
ctx.effect(() => {
|
||||
ctx.effect(() => () => {}, `${options.effect}.child`)
|
||||
return () => {}
|
||||
}, options.effect)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async function expectPluginViolation(
|
||||
contract: PluginInvariantContract,
|
||||
plugin: ReturnType<typeof effectPlugin>,
|
||||
message: RegExp,
|
||||
): Promise<void> {
|
||||
const { ctx } = await setup()
|
||||
await registerInstaller(ctx, `@deepseek-ai/${contract.name}`, (child, fail) => {
|
||||
observePluginInvariant(child, fail, contract)
|
||||
})
|
||||
await expect(Promise.resolve(ctx.plugin(plugin))).rejects.toThrow(message)
|
||||
}
|
||||
|
||||
it('checks existing and later plugin fibers, including nested effects and alternatives', async () => {
|
||||
const { ctx } = await setup()
|
||||
await ctx.plugin(InvariantProbeService)
|
||||
const plugin = effectPlugin({
|
||||
inject: ['invariantProbe'],
|
||||
effect: 'probe.effect',
|
||||
service: 'pluginProbe',
|
||||
})
|
||||
await ctx.plugin(plugin)
|
||||
const validated = vi.fn(() => undefined)
|
||||
await registerInstaller(ctx, '@deepseek-ai/dsh-existing-probe', (child, fail) => {
|
||||
observePluginInvariant(child, fail, {
|
||||
plugin,
|
||||
name: 'effect-probe',
|
||||
inject: ['invariantProbe'],
|
||||
effects: [['missing.effect', 'probe.effect.child']],
|
||||
services: ['pluginProbe'],
|
||||
validate: validated,
|
||||
})
|
||||
})
|
||||
expect(validated).toHaveBeenCalledOnce()
|
||||
|
||||
const later = effectPlugin({ name: 'later-probe', effect: 'later.effect' })
|
||||
await registerInstaller(ctx, '@deepseek-ai/dsh-later-probe', (child, fail) => {
|
||||
observePluginInvariant(child, fail, {
|
||||
plugin: later,
|
||||
name: 'later-probe',
|
||||
effects: ['later.effect'],
|
||||
})
|
||||
})
|
||||
await ctx.plugin(later)
|
||||
})
|
||||
|
||||
it('matches package plugins by Cordis name without importing their callback', async () => {
|
||||
const { ctx } = await setup()
|
||||
const plugin = {
|
||||
name: 'name-only-probe',
|
||||
apply(pluginCtx: Context) {
|
||||
pluginCtx.effect(() => () => {}, 'name-only.effect')
|
||||
pluginCtx.inject([], () => {})
|
||||
},
|
||||
}
|
||||
await registerInstaller(ctx, '@deepseek-ai/dsh-name-only-probe', (child, fail) => {
|
||||
observePluginInvariant(child, fail, {
|
||||
name: 'name-only-probe',
|
||||
effects: ['name-only.effect'],
|
||||
})
|
||||
})
|
||||
await ctx.plugin(plugin)
|
||||
})
|
||||
|
||||
it('rejects a contract that does not identify a plugin', async () => {
|
||||
const { ctx } = await setup()
|
||||
const registration = runtimeRegistration(ctx.invariants.register('@deepseek-ai/dsh-invalid-plugin', (child, fail) => {
|
||||
observePluginInvariant(child, fail, {
|
||||
plugin: {} as never,
|
||||
name: 'invalid-plugin',
|
||||
})
|
||||
}))
|
||||
await expect(Promise.resolve(registration)).rejects.toThrow(/does not identify a Cordis plugin/)
|
||||
})
|
||||
|
||||
it('rejects wrong plugin names, missing injections, effects, services, and custom checks', async () => {
|
||||
const wrongName = effectPlugin({ name: 'actual-name', effect: 'probe.effect' })
|
||||
await expectPluginViolation({
|
||||
plugin: wrongName,
|
||||
name: 'expected-name',
|
||||
}, wrongName, /plugin name must be "expected-name"/)
|
||||
|
||||
const missingInjection = effectPlugin({ effect: 'probe.effect' })
|
||||
await expectPluginViolation({
|
||||
plugin: missingInjection,
|
||||
name: 'effect-probe',
|
||||
inject: ['missingService'],
|
||||
}, missingInjection, /must inject "missingService"/)
|
||||
|
||||
const missingEffect = effectPlugin()
|
||||
await expectPluginViolation({
|
||||
plugin: missingEffect,
|
||||
name: 'effect-probe',
|
||||
effects: [['first.effect', 'second.effect']],
|
||||
}, missingEffect, /must own effect "first.effect" or "second.effect"/)
|
||||
|
||||
const missingService = effectPlugin({ effect: 'probe.effect' })
|
||||
await expectPluginViolation({
|
||||
plugin: missingService,
|
||||
name: 'effect-probe',
|
||||
services: ['missingService'],
|
||||
}, missingService, /must provide service "missingService"/)
|
||||
|
||||
const invalidCustom = effectPlugin({ effect: 'probe.effect' })
|
||||
await expectPluginViolation({
|
||||
plugin: invalidCustom,
|
||||
name: 'effect-probe',
|
||||
validate: () => 'custom plugin contract failed',
|
||||
}, invalidCustom, /custom plugin contract failed/)
|
||||
})
|
||||
|
||||
it('checks existing and future service implementations while ignoring unrelated changes', async () => {
|
||||
const existing = await setup()
|
||||
await existing.ctx.plugin(WatchedInvariantProbeService)
|
||||
await registerInstaller(existing.ctx, '@deepseek-ai/dsh-existing-service', (child, fail) => {
|
||||
observeServiceInvariant(child, fail, 'watchedInvariantProbe', value => (
|
||||
value instanceof WatchedInvariantProbeService ? undefined : 'wrong watched service'
|
||||
))
|
||||
})
|
||||
|
||||
const future = await setup()
|
||||
await registerInstaller(future.ctx, '@deepseek-ai/dsh-future-service', (child, fail) => {
|
||||
observeServiceInvariant(child, fail, 'watchedInvariantProbe', value => (
|
||||
value instanceof WatchedInvariantProbeService ? undefined : 'wrong watched service'
|
||||
))
|
||||
})
|
||||
await future.ctx.plugin(InvariantProbeService)
|
||||
await future.ctx.plugin(WatchedInvariantProbeService)
|
||||
|
||||
const invalid = await setup()
|
||||
await registerInstaller(invalid.ctx, '@deepseek-ai/dsh-invalid-service', (child, fail) => {
|
||||
observeServiceInvariant(child, fail, 'watchedInvariantProbe', () => 'wrong watched service')
|
||||
})
|
||||
await expect(Promise.resolve(invalid.ctx.plugin(WatchedInvariantProbeService)))
|
||||
.rejects.toThrow(/wrong watched service/)
|
||||
})
|
||||
|
||||
it('reports synchronous package assertions through the bound failure reporter', async () => {
|
||||
const { ctx } = await setup()
|
||||
const valid = await registerInstaller(ctx, '@deepseek-ai/dsh-valid-assertion', (_child, fail) => {
|
||||
assertInvariant(fail, true, 'must stay true')
|
||||
})
|
||||
valid()
|
||||
|
||||
const invalid = runtimeRegistration(ctx.invariants.register('@deepseek-ai/dsh-invalid-assertion', (_child, fail) => {
|
||||
assertInvariant(fail, false, 'must stay true')
|
||||
}))
|
||||
await expect(Promise.resolve(invalid)).rejects.toThrow(/must stay true/)
|
||||
})
|
||||
|
||||
it('accepts structural service implementations and test doubles', () => {
|
||||
expect(serviceShapeViolation({ kind: 'probe', run() {} }, {
|
||||
methods: ['run'],
|
||||
stringProperties: ['kind'],
|
||||
})).toBeUndefined()
|
||||
expect(serviceShapeViolation(Object.assign(() => {}, { run() {} }), {
|
||||
methods: ['run'],
|
||||
})).toBeUndefined()
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ value: null, message: 'service implementation must be an object' },
|
||||
{ value: 42, message: 'service implementation must be an object' },
|
||||
{ value: {}, message: 'service implementation must expose method "run"' },
|
||||
{ value: { run() {}, kind: '' }, message: 'service implementation must expose non-empty string "kind"' },
|
||||
])('rejects invalid structural service implementations: $message', ({ value, message }) => {
|
||||
expect(serviceShapeViolation(value, {
|
||||
methods: ['run'],
|
||||
stringProperties: ['kind'],
|
||||
})).toBe(message)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-llm-replay`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-llm-replay/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-llm-replay`. @module @deepseek-ai/dsh-llm-replay/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-llm-replay'
|
||||
|
||||
@@ -17,8 +10,21 @@ export const name = 'llm-replay-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'llm-replay',
|
||||
inject: [
|
||||
'llm',
|
||||
],
|
||||
effects: [
|
||||
[
|
||||
'llm.registerAdapter()',
|
||||
'ctx.on("llm/stream")',
|
||||
],
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +33,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-loader-smoke`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-loader-smoke/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-loader-smoke. @module @deepseek-ai/dsh-loader-smoke/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-loader-smoke'
|
||||
|
||||
@@ -17,8 +11,25 @@ export const name = 'loader-smoke-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert default source mode and plain-Node built-artifact launch resolution. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { resolveExampleLaunch, resolveExampleMode } = await import('./index.ts')
|
||||
assertInvariant(fail, resolveExampleMode('') === 'src',
|
||||
'an empty example-mode selection must preserve source-mode development')
|
||||
const launch = resolveExampleLaunch({
|
||||
srcBin: '/workspace/probe/src/bin.ts',
|
||||
mode: 'lib',
|
||||
})
|
||||
assertInvariant(fail,
|
||||
launch.command === process.execPath
|
||||
&& launch.args.length === 1
|
||||
&& launch.args[0] === '/workspace/probe/lib/bin.js'
|
||||
&& launch.env.TSX_TSCONFIG_PATH === undefined,
|
||||
'built example launches must use plain Node, the derived lib entry, and no tsx paths map')
|
||||
return () => {}
|
||||
}, 'loader-smoke: validate source and built launch resolution')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tasks`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tasks/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tasks`. @module @deepseek-ai/dsh-tasks/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tasks'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'tasks-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'TaskService',
|
||||
effects: [
|
||||
'ctx.provide("tasks")',
|
||||
'tasks teardown',
|
||||
],
|
||||
services: [
|
||||
'tasks',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-tasks`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-tasks/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-tasks`. @module @deepseek-ai/dsh-tool-tasks/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-tasks'
|
||||
|
||||
@@ -17,8 +10,20 @@ export const name = 'tool-tasks-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-tasks',
|
||||
inject: [
|
||||
'tools',
|
||||
'tasks',
|
||||
'systemPrompt',
|
||||
],
|
||||
effects: [
|
||||
'tools.register()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +32,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-timeout-policy`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-timeout-policy/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-timeout-policy`. @module @deepseek-ai/dsh-timeout-policy/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-timeout-policy'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'timeout-policy-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'timeout-policy',
|
||||
inject: [
|
||||
'tools',
|
||||
],
|
||||
effects: [
|
||||
'ctx.on("tools/execute")',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-todo`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-todo/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-todo`. @module @deepseek-ai/dsh-tool-todo/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-todo'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'tool-todo-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-todo',
|
||||
inject: [
|
||||
'tools',
|
||||
],
|
||||
effects: [
|
||||
'tools.register()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-acp`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-acp/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-acp`. @module @deepseek-ai/dsh-acp/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-acp'
|
||||
|
||||
@@ -17,8 +10,25 @@ export const name = 'acp-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'acp',
|
||||
inject: [
|
||||
'agents',
|
||||
'sessionPersistence',
|
||||
'tools',
|
||||
'userInteraction',
|
||||
'llm',
|
||||
'systemPrompt',
|
||||
],
|
||||
effects: [
|
||||
'userInteraction.registerProvider()',
|
||||
'ctx.on("session/event")',
|
||||
'acp.connection',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +37,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
23
packages/ui/app-boot/src/config-path.ts
Normal file
23
packages/ui/app-boot/src/config-path.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/** Snapshot-aware application configuration path selection. @module @deepseek-ai/dsh-app-boot/config-path */
|
||||
|
||||
import { basename, dirname, resolve } from 'node:path'
|
||||
|
||||
/**
|
||||
* Resolve the config to boot. Replay swaps a `cordis.yml` basename for
|
||||
* `cordis.snapshot.yml` in the same directory; every other mode keeps the path.
|
||||
* @param configPath - requested config path, absolute or relative to `cwd`.
|
||||
* @param snapshotMode - bin `$DSH_SNAPSHOT`; only `replay` swaps the basename.
|
||||
* @param cwd - base for a relative `configPath`.
|
||||
* @returns the absolute path of the config to boot.
|
||||
*/
|
||||
export function resolveConfigPath(
|
||||
configPath: string,
|
||||
snapshotMode: string | undefined,
|
||||
cwd: string = process.cwd(),
|
||||
): string {
|
||||
const absolute = resolve(cwd, configPath)
|
||||
if (snapshotMode !== 'replay') return absolute
|
||||
const dir = dirname(absolute)
|
||||
const replayName = basename(absolute).replace(/cordis\.ya?ml$/, 'cordis.snapshot.yml')
|
||||
return resolve(dir, replayName)
|
||||
}
|
||||
@@ -6,29 +6,12 @@
|
||||
*/
|
||||
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { basename, dirname, resolve } from 'node:path'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { Context } from 'cordis'
|
||||
import Loader from '@cordisjs/plugin-loader'
|
||||
import Include from '@cordisjs/plugin-include'
|
||||
|
||||
/**
|
||||
* Resolve the config to boot. Replay swaps a `cordis.yml` basename for
|
||||
* `cordis.snapshot.yml` in the same directory; every other mode keeps the path.
|
||||
* @param configPath - the requested config path (absolute, or relative to `cwd`).
|
||||
* @param snapshotMode - the bin's `$DSH_SNAPSHOT` value; only `'replay'` swaps the
|
||||
* basename.
|
||||
* @param cwd - the base a relative `configPath` resolves against.
|
||||
* @returns the absolute path of the config to boot.
|
||||
*/
|
||||
export function resolveConfigPath(
|
||||
configPath: string, snapshotMode: string | undefined, cwd: string = process.cwd(),
|
||||
): string {
|
||||
const absolute = resolve(cwd, configPath)
|
||||
if (snapshotMode !== 'replay') return absolute
|
||||
const dir = dirname(absolute)
|
||||
const replayName = basename(absolute).replace(/cordis\.ya?ml$/, 'cordis.snapshot.yml')
|
||||
return resolve(dir, replayName)
|
||||
}
|
||||
export { resolveConfigPath } from './config-path.ts'
|
||||
|
||||
/**
|
||||
* Load the optional gitignored `.env` from `dir`. Missing files fall back to the
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-app-boot`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-app-boot/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-app-boot. @module @deepseek-ai/dsh-app-boot/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import { resolve } from 'node:path'
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-app-boot'
|
||||
|
||||
@@ -17,8 +12,20 @@ export const name = 'app-boot-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert ordinary and replay config-path selection. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { resolveConfigPath } = await import('./config-path.ts')
|
||||
const cwd = '/tmp/dsh-app-boot-invariant'
|
||||
const ordinary = resolveConfigPath('cordis.yml', undefined, cwd)
|
||||
const replay = resolveConfigPath('cordis.yml', 'replay', cwd)
|
||||
assertInvariant(fail, ordinary === resolve(cwd, 'cordis.yml'),
|
||||
'ordinary app boot must retain the requested config basename')
|
||||
assertInvariant(fail, replay === resolve(cwd, 'cordis.snapshot.yml'),
|
||||
'snapshot replay must select cordis.snapshot.yml in the requested config directory')
|
||||
return () => {}
|
||||
}, 'app-boot: validate ordinary and replay config selection')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-jsonrpc`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-jsonrpc/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-jsonrpc`. @module @deepseek-ai/dsh-jsonrpc/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-jsonrpc'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'jsonrpc-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'jsonrpc',
|
||||
inject: [
|
||||
'agents',
|
||||
],
|
||||
effects: [
|
||||
'jsonrpc.serve',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-permission`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-permission/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-permission`. @module @deepseek-ai/dsh-permission/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-permission'
|
||||
|
||||
@@ -17,8 +10,22 @@ export const name = 'permission-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'PermissionService',
|
||||
inject: [
|
||||
'bash',
|
||||
'approval',
|
||||
],
|
||||
effects: [
|
||||
'ctx.provide("permission")',
|
||||
],
|
||||
services: [
|
||||
'permission',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +34,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -12,7 +12,12 @@ async function mounted(options: {
|
||||
approvalDefault?: ApprovalPolicy | undefined
|
||||
} = {}): Promise<Context> {
|
||||
const ctx = new Context()
|
||||
ctx.provide('bash', { sandboxMode: 'bashDefault' in options ? options.bashDefault : 'workspace-write' })
|
||||
ctx.provide('bash', {
|
||||
sandboxMode: 'bashDefault' in options ? options.bashDefault : 'workspace-write',
|
||||
resolve() { throw new Error('permission tests do not execute bash') },
|
||||
run() { throw new Error('permission tests do not execute bash') },
|
||||
start() { throw new Error('permission tests do not execute bash') },
|
||||
})
|
||||
ctx.provide('approval', { config: { policy: 'approvalDefault' in options ? options.approvalDefault : 'ask' } })
|
||||
await ctx.plugin(PermissionService, options.config ?? {})
|
||||
return ctx
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-stdio`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-stdio/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-stdio`. @module @deepseek-ai/dsh-stdio/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-stdio'
|
||||
|
||||
@@ -17,8 +10,20 @@ export const name = 'stdio-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'ui-stdio',
|
||||
inject: [
|
||||
'agents',
|
||||
'userInteraction',
|
||||
],
|
||||
effects: [
|
||||
'ctx.on("session/event")',
|
||||
'userInteraction.registerProvider()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +32,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tool-ask-user`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tool-ask-user/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tool-ask-user`. @module @deepseek-ai/dsh-tool-ask-user/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tool-ask-user'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'tool-ask-user-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'tool-ask-user',
|
||||
inject: [
|
||||
'tools',
|
||||
'userInteraction',
|
||||
],
|
||||
effects: [
|
||||
'tools.register()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-tui`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-tui/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-tui`. @module @deepseek-ai/dsh-tui/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-tui'
|
||||
|
||||
@@ -17,8 +10,21 @@ export const name = 'tui-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'ui-tui',
|
||||
inject: [
|
||||
'agents',
|
||||
'userInteraction',
|
||||
'tools',
|
||||
],
|
||||
effects: [
|
||||
'ctx.on("session/event")',
|
||||
'userInteraction.registerProvider()',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +33,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -94,7 +94,7 @@ async function disposeSnapshot(harness: SnapshotHarness): Promise<void> {
|
||||
async function configureAdvancedTools(ctx: Context): Promise<void> {
|
||||
await ctx.plugin(SystemPrompt)
|
||||
await ctx.plugin(ToolRegistry, { mode: 'code' })
|
||||
ctx.provide('workflows', {} as never)
|
||||
ctx.provide('workflows', { start() {} } as never)
|
||||
await ctx.plugin(ToolWorkflow, { toolName: 'workflow', maxResultChars: 50_000 })
|
||||
await ctx.plugin(ToolCordis, { vmTimeoutMs: 5_000 })
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-user-approval`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-user-approval/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-user-approval`. @module @deepseek-ai/dsh-user-approval/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-user-approval'
|
||||
|
||||
@@ -17,8 +10,19 @@ export const name = 'user-approval-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'ApprovalService',
|
||||
effects: [
|
||||
'ctx.provide("approval")',
|
||||
'ctx.on("agent/pre-step")',
|
||||
],
|
||||
services: [
|
||||
'approval',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +31,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-user-interaction`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-user-interaction/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract checks for `@deepseek-ai/dsh-user-interaction`. @module @deepseek-ai/dsh-user-interaction/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { observePluginInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-user-interaction'
|
||||
|
||||
@@ -17,8 +10,18 @@ export const name = 'user-interaction-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Install checks for this package's active plugin fibers. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
observePluginInvariant(ctx, fail, {
|
||||
name: 'UserInteractionService',
|
||||
effects: [
|
||||
'ctx.provide("userInteraction")',
|
||||
],
|
||||
services: [
|
||||
'userInteraction',
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
@@ -27,4 +30,3 @@ const install: InvariantInstaller = () => {}
|
||||
*/
|
||||
export const apply = (ctx: Context): Promise<() => void> =>
|
||||
Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install))
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-brand`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-brand/invariant
|
||||
*/
|
||||
/** Package-owned runtime contract for @deepseek-ai/dsh-brand. @module @deepseek-ai/dsh-brand/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-brand'
|
||||
|
||||
@@ -17,8 +11,15 @@ export const name = 'brand-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert that the nominal-type primitive remains erased at runtime. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const brandRuntime = await import('./index.ts')
|
||||
assertInvariant(fail, Object.keys(brandRuntime).length === 0,
|
||||
'the branded-id primitive must remain type-only with no runtime exports')
|
||||
return () => {}
|
||||
}, 'brand: validate type-only runtime erasure')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-home`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-home/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-home. @module @deepseek-ai/dsh-home/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import { resolve } from 'node:path'
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-home'
|
||||
|
||||
@@ -17,8 +12,19 @@ export const name = 'home-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert the canonical environment key and configured-path precedence. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { DSH_HOME_ENV, resolveDshHome } = await import('./index.ts')
|
||||
const environmentKey: string = DSH_HOME_ENV
|
||||
assertInvariant(fail, environmentKey === ['DSH', 'HOME'].join('_'),
|
||||
'the canonical Harness home environment key must remain DSH_HOME')
|
||||
const configured = 'relative-invariant-home'
|
||||
assertInvariant(fail, resolveDshHome(configured) === resolve(configured),
|
||||
'an explicitly configured Harness home must normalize to an absolute path')
|
||||
return () => {}
|
||||
}, 'home: validate canonical DSH home resolution')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-paths`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-paths/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-paths. @module @deepseek-ai/dsh-paths/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import { homedir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-paths'
|
||||
|
||||
@@ -17,8 +13,19 @@ export const name = 'paths-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert tilde expansion and explicit-over-environment home precedence. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { DSH_HOME_ENV, expandHomePath, resolveDshHome } = await import('./index.ts')
|
||||
assertInvariant(fail, expandHomePath('~/invariant-probe') === join(homedir(), 'invariant-probe'),
|
||||
'supported tilde prefixes must expand against the operating-system home')
|
||||
const configured = 'relative-invariant-home'
|
||||
const resolved = resolveDshHome(configured, { [DSH_HOME_ENV]: '/ignored-environment-home' })
|
||||
assertInvariant(fail, resolved === resolve(configured),
|
||||
'an explicit DSH home must override the environment and normalize to an absolute path')
|
||||
return () => {}
|
||||
}, 'paths: validate DSH home resolution')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-retention`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-retention/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-retention. @module @deepseek-ai/dsh-retention/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-retention'
|
||||
|
||||
@@ -17,8 +11,26 @@ export const name = 'retention-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert exact head-retention accounting after the budget is exceeded. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { ItemRetainer } = await import('./index.ts')
|
||||
const retainer = new ItemRetainer<string>({ kind: 'head', maxItems: 2 })
|
||||
retainer.push('first')
|
||||
retainer.push('second')
|
||||
retainer.push('third')
|
||||
const result = retainer.finish()
|
||||
assertInvariant(fail,
|
||||
result.items.join(',') === 'first,second'
|
||||
&& result.seen === 3
|
||||
&& result.kept === 2
|
||||
&& result.truncated
|
||||
&& result.omitted.kind === 'exact'
|
||||
&& result.omitted.count === 1,
|
||||
'head retention must keep the prefix and report exact seen, kept, and omitted counts')
|
||||
return () => {}
|
||||
}, 'retention: validate exact head accounting')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
/**
|
||||
* Generated invariant ownership companion for `@deepseek-ai/dsh-timeout`.
|
||||
* Replace this file with package-owned checks while preserving its registration.
|
||||
*
|
||||
* @generated scripts/gen-package-invariants.ts
|
||||
* @module @deepseek-ai/dsh-timeout/invariant
|
||||
*/
|
||||
/** Package-owned runtime contracts for @deepseek-ai/dsh-timeout. @module @deepseek-ai/dsh-timeout/invariant */
|
||||
|
||||
/* jscpd:ignore-start */
|
||||
import type { Context } from 'cordis'
|
||||
import type { InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
import { assertInvariant, type InvariantInstaller } from '@deepseek-ai/dsh-invariants'
|
||||
|
||||
const PACKAGE_NAME = '@deepseek-ai/dsh-timeout'
|
||||
|
||||
@@ -17,8 +11,21 @@ export const name = 'timeout-invariant'
|
||||
/** Services required before the companion can register. */
|
||||
export const inject = ['invariants']
|
||||
|
||||
/** Reserve this package's invariant ownership until it adds relational checks. */
|
||||
const install: InvariantInstaller = () => {}
|
||||
/** Assert default-before-cap arithmetic and capability-code classification. */
|
||||
const install: InvariantInstaller = (ctx, fail) => {
|
||||
ctx.effect(async () => {
|
||||
const { clampTimeout, TimeoutReason, timeoutOf } = await import('./index.ts')
|
||||
assertInvariant(fail,
|
||||
clampTimeout(undefined, 50, 30) === 30 && clampTimeout(20, 50, 30) === 20,
|
||||
'timeout resolution must apply the default before capping and preserve smaller requests')
|
||||
const reason = new TimeoutReason('INVARIANT_TIMEOUT', 25)
|
||||
assertInvariant(fail, timeoutOf({ reason }, 'INVARIANT_TIMEOUT') === reason,
|
||||
'timeout classification must recover a matching capability-owned reason')
|
||||
assertInvariant(fail, timeoutOf({ reason }, 'FOREIGN_TIMEOUT') === undefined,
|
||||
'timeout classification must reject a reason owned by another capability')
|
||||
return () => {}
|
||||
}, 'timeout: validate resolution and reason classification')
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this package's invariant companion.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user