refactor(session): route construction through Session.create

This commit is contained in:
imccyu
2026-08-04 18:41:07 +08:00
parent c7f693aa40
commit 8cbdd5b9d0
61 changed files with 305 additions and 292 deletions

View File

@@ -38,7 +38,7 @@ async function setup(home: string, config: toolSkill.Config = {}): Promise<Conte
function agentForCwd(cwd: string): Agent {
const id = SessionId(`tool-skill-${cwd}`)
const session = new Session(id, [], { version: 0, id, createdAt: 0, cwd })
const session = Session.create(id, [], { version: 0, id, createdAt: 0, cwd })
return {
ctx: new Context(),
id,
@@ -284,7 +284,7 @@ describe('dsh-tool-skill', () => {
invalidate = control.invalidate
return provider
})
const session = new Session(SessionId('incomplete-prefix'))
const session = Session.create(SessionId('incomplete-prefix'))
const agent = sessionAgent(session)
openMessageTurn(session)
@@ -300,7 +300,7 @@ describe('dsh-tool-skill', () => {
it('records an empty baseline across repeated step observations', async () => {
const home = await tempDir('tool-empty-step')
const ctx = await setup(home)
const session = new Session(SessionId('empty-step'))
const session = Session.create(SessionId('empty-step'))
const agent = sessionAgent(session)
openMessageTurn(session)
@@ -319,7 +319,7 @@ describe('dsh-tool-skill', () => {
source: 'runtime',
content: 'First body.',
})
const session = new Session(SessionId('dynamic-catalog'))
const session = Session.create(SessionId('dynamic-catalog'))
const agent = sessionAgent(session)
openMessageTurn(session)
@@ -363,7 +363,7 @@ describe('dsh-tool-skill', () => {
source: 'runtime',
content: 'Resumed body.',
})
const session = new Session(SessionId('catalog-resume'))
const session = Session.create(SessionId('catalog-resume'))
const agent = sessionAgent(session)
openMessageTurn(session)
session.append('user/message', createUserMessage({
@@ -402,7 +402,7 @@ describe('dsh-tool-skill', () => {
source: 'runtime',
content: 'First body.',
})
const session = new Session(SessionId('catalog-compaction'))
const session = Session.create(SessionId('catalog-compaction'))
const agent = sessionAgent(session)
openMessageTurn(session)
expect(JSON.stringify(await composePrefixForAgent(ctx, agent))).toContain('first-skill')
@@ -427,7 +427,7 @@ describe('dsh-tool-skill', () => {
const root = join(home, '.dsh/skills')
await writeSkill(root, 'body-skill', 'Stable description', 'First body.')
const ctx = await setup(home)
const session = new Session(SessionId('body-refresh'))
const session = Session.create(SessionId('body-refresh'))
const agent = sessionAgent(session)
openMessageTurn(session)
@@ -457,7 +457,7 @@ describe('dsh-tool-skill', () => {
source: 'runtime',
content: 'Stable body.',
})
const session = new Session(SessionId('incomplete-catalog'))
const session = Session.create(SessionId('incomplete-catalog'))
const agent = sessionAgent(session)
openMessageTurn(session)
expect(JSON.stringify(await composePrefixForAgent(ctx, agent))).toContain('stable-skill')
@@ -481,7 +481,7 @@ describe('dsh-tool-skill', () => {
const home = await tempDir('tool-restricted-catalog')
const ctx = await setup(home)
ctx.skills.register({ name: 'listed-skill', description: 'Listed', source: 'runtime', content: 'body' })
const session = new Session(SessionId('restricted-catalog'))
const session = Session.create(SessionId('restricted-catalog'))
const agent = sessionAgent(session)
openMessageTurn(session)
const { scope } = await mintAgentScope(ctx, agent)