refactor(working-directory): keep within out of the plugin entry
The plugin-entry-exports gate on master allows a function plugin entry to export only what the Loader loads. within moves to an internal module the service and its tests import; the subagent manager and its test fixture keep a local lexical containment helper instead of a cross-package value import.
This commit is contained in:
1 parent
902c657a45
commit
7b3efee4c2
5 files changed
+36
-18
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* @module @deepseek-ai/dsh-working-directory
|
||||
*/
|
||||
|
||||
import { isAbsolute, relative, sep } from 'node:path'
|
||||
import { isAbsolute } from 'node:path'
|
||||
import { Context, Service } from '@deepseek-ai/cordis'
|
||||
import z from '@deepseek-ai/schemastery'
|
||||
import { z as zod } from 'zod'
|
||||
@@ -13,6 +13,7 @@ import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
||||
import type { Session } from '@deepseek-ai/dsh-session'
|
||||
import type { ProjectionHandle } from '@deepseek-ai/dsh-session-projection'
|
||||
import type {} from '@deepseek-ai/dsh-system-prompt'
|
||||
import { within } from './within.ts'
|
||||
|
||||
declare module '@deepseek-ai/cordis' {
|
||||
interface Events {
|
||||
@@ -104,18 +105,6 @@ interface WorkspaceRootState {
|
||||
anchors: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether `path` is `root` or lies below it. Both paths are canonical absolute
|
||||
* paths of one execution world; the test is lexical and never touches the filesystem.
|
||||
* @param root - canonical absolute directory.
|
||||
* @param path - canonical absolute path to test.
|
||||
* @returns true for `root` itself and every path below it.
|
||||
*/
|
||||
export function within(root: string, path: string): boolean {
|
||||
const rest = relative(root, path)
|
||||
return rest === '' || (rest !== '..' && !rest.startsWith(`..${sep}`) && !isAbsolute(rest))
|
||||
}
|
||||
|
||||
/** The longest anchor containing `path`, or undefined when none does. */
|
||||
function anchorContaining(anchors: readonly string[], path: string): string | undefined {
|
||||
let selected: string | undefined
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Lexical path containment shared by the working-directory service and its tests.
|
||||
* @module @deepseek-ai/dsh-working-directory/within
|
||||
*/
|
||||
import { isAbsolute, relative, sep } from 'node:path'
|
||||
|
||||
/**
|
||||
* Whether `path` is `root` or lies below it. Both paths are canonical absolute
|
||||
* paths of one execution world; the test is lexical and never touches the filesystem.
|
||||
* @param root - canonical absolute directory.
|
||||
* @param path - canonical absolute path to test.
|
||||
* @returns true for `root` itself and every path below it.
|
||||
*/
|
||||
export function within(root: string, path: string): boolean {
|
||||
const rest = relative(root, path)
|
||||
return rest === '' || (rest !== '..' && !rest.startsWith(`..${sep}`) && !isAbsolute(rest))
|
||||
}
|
||||
@@ -5,10 +5,11 @@ import { dirname, join } from 'node:path'
|
||||
import { Context } from '@deepseek-ai/cordis'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import LocalFileSystem from '@deepseek-ai/dsh-fs-local'
|
||||
import WorkingDirectory, { within } from '@deepseek-ai/dsh-working-directory'
|
||||
import WorkingDirectory from '@deepseek-ai/dsh-working-directory'
|
||||
import { mountAgentLoopTestDependencies, mountAgentLoopTestHarness } from '@deepseek-ai/dsh-agent-loop-testkit'
|
||||
import { SessionId } from '@deepseek-ai/dsh-session'
|
||||
import { renderContextSnapshot } from '@deepseek-ai/dsh-system-prompt'
|
||||
import { within } from '../src/within.ts'
|
||||
|
||||
async function fixture() {
|
||||
const scratch = await realpath(await mkdtemp(join(tmpdir(), 'dsh-workspace-root-')))
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
*/
|
||||
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { isAbsolute, resolve } from 'node:path'
|
||||
import { isAbsolute, relative, resolve, sep } from 'node:path'
|
||||
import type {} from '@deepseek-ai/dsh-fs'
|
||||
import { within } from '@deepseek-ai/dsh-working-directory'
|
||||
import type {} from '@deepseek-ai/dsh-working-directory'
|
||||
import type { Context } from '@deepseek-ai/cordis'
|
||||
import type { Agent, AgentOptions, CreateAgentOptions } from '@deepseek-ai/dsh-agent'
|
||||
import { brandString } from '@deepseek-ai/dsh-brand'
|
||||
@@ -49,6 +49,12 @@ import type { SubagentDelivery } from './control-types.ts'
|
||||
import { ActivationPool, ChildLock, activationAgent, captureLocalResult, observeLocalFailure, requireLocalActivation } from './activation.ts'
|
||||
import type { Activation, ActivationResource, LocalActivation } from './activation.ts'
|
||||
|
||||
/** Whether `path` is `root` or lies below it: a lexical test of two canonical absolute paths of one execution world. */
|
||||
function within(root: string, path: string): boolean {
|
||||
const rest = relative(root, path)
|
||||
return rest === '' || (rest !== '..' && !rest.startsWith(`..${sep}`) && !isAbsolute(rest))
|
||||
}
|
||||
|
||||
/** Inputs shared by model steering and human prompt delivery. */
|
||||
type ChildDeliveryOptions = {
|
||||
readonly delivery: SubagentDelivery
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { Context, Service } from '@deepseek-ai/cordis'
|
||||
import { resolve } from 'node:path'
|
||||
import { isAbsolute, relative, resolve, sep } from 'node:path'
|
||||
import type { Agent } from '@deepseek-ai/dsh-agent'
|
||||
import type { Session } from '@deepseek-ai/dsh-session'
|
||||
import { within } from '@deepseek-ai/dsh-working-directory'
|
||||
import type { RelocateOptions, RelocatedDirectories } from '@deepseek-ai/dsh-working-directory'
|
||||
|
||||
/** Whether `path` is `root` or lies below it, lexically. */
|
||||
function within(root: string, path: string): boolean {
|
||||
const rest = relative(root, path)
|
||||
return rest === '' || (rest !== '..' && !rest.startsWith(`..${sep}`) && !isAbsolute(rest))
|
||||
}
|
||||
|
||||
/** Directory selection for orchestration fixtures whose paths are symbolic and whose logs exclude context providers. */
|
||||
class FixtureWorkingDirectory extends Service {
|
||||
private readonly directories = new WeakMap<Session, string>()
|
||||
|
||||
Reference in new issue
Block a user