@fish-under-sea/dsh-agent-teams-fish 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +13 -7
- package/README.en.md +20 -12
- package/README.md +20 -12
- package/compatibility.json +82 -46
- package/icon.png +0 -0
- package/lib/artifacts.js +148 -25
- package/lib/client/ActivityPanel.js +26 -5
- package/lib/client/WorkspaceActivity.js +6 -4
- package/lib/client/activity-monitor.js +113 -41
- package/lib/client/locales.js +14 -0
- package/lib/client.js +433 -199
- package/lib/client.js.map +1 -1
- package/lib/command.js +7 -4
- package/lib/git-artifact-stamp.json +2 -2
- package/lib/harness-compat.js +120 -62
- package/lib/index.js +7 -10
- package/lib/mailbox.js +15 -5
- package/lib/members.js +221 -154
- package/lib/snapshot.js +15 -10
- package/lib/state.js +41 -8
- package/lib/tools.js +123 -64
- package/lib/types/artifacts.d.ts +6 -3
- package/lib/types/client/activity-monitor.d.ts +13 -4
- package/lib/types/client/locales.d.ts +14 -0
- package/lib/types/harness-compat.d.ts +63 -16
- package/lib/types/mailbox.d.ts +2 -0
- package/lib/types/members.d.ts +5 -17
- package/lib/types/snapshot.d.ts +12 -7
- package/lib/types/state.d.ts +10 -3
- package/lib/types/types.d.ts +5 -0
- package/lib/types/web-routes.d.ts +2 -0
- package/lib/types/workspace-audit-service.d.ts +35 -0
- package/lib/types/workspace-audit-worker.d.ts +1 -0
- package/lib/web-routes.js +31 -0
- package/lib/workspace-audit-service.js +165 -0
- package/lib/workspace-audit-worker.js +11 -0
- package/lib/workspace-audit.js +6 -5
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +69 -64
- package/pnpm-workspace.yaml +306 -273
- package/release-notes/v0.1.25.md +16 -0
- package/release-notes/v0.1.26.md +19 -0
- package/release-notes/v0.1.27.md +42 -0
- package/release-notes/v0.1.28.md +45 -0
- package/release-notes/v0.1.29.md +23 -0
- package/release-notes/v1.1.0.md +42 -0
- package/release-notes/v2.0.0.md +17 -0
- package/scripts/artwork-role-match.test.mjs +517 -0
- package/scripts/capabilities.test.mjs +301 -0
- package/scripts/check-install-channel.mjs +55 -0
- package/scripts/check-install-channel.test.mjs +39 -0
- package/scripts/clean-build.mjs +14 -0
- package/scripts/client-harness-migration.test.mjs +46 -0
- package/scripts/compatibility.mjs +20 -0
- package/scripts/compatibility.test.mjs +187 -0
- package/scripts/corrupt-teamjson.test.mjs +180 -0
- package/scripts/custom-artwork.test.mjs +273 -0
- package/scripts/fallback-tdd.mjs +61 -0
- package/scripts/fixtures/harness-benchmark-scope.mjs +16 -0
- package/scripts/fixtures/harness-benchmark-scope.test.mjs +18 -0
- package/scripts/fixtures/harness-complex-case.mjs +201 -0
- package/scripts/fixtures/harness-complex-case.test.mjs +21 -0
- package/scripts/fixtures/harness-complex-oracle.mjs +63 -0
- package/scripts/fixtures/harness-issue-case.mjs +51 -0
- package/scripts/fixtures/harness-issue159-case.mjs +28 -0
- package/scripts/fixtures/harness-model-case.mjs +127 -0
- package/scripts/fixtures/harness-model-case.test.mjs +37 -0
- package/scripts/fixtures/harness-model-driver.mjs +100 -0
- package/scripts/fixtures/harness-runtime-credentials.mjs +23 -0
- package/scripts/fixtures/harness-runtime-entry.mjs +171 -0
- package/scripts/fixtures/harness-runtime-idle.mjs +42 -0
- package/scripts/fixtures/harness-runtime-llm.mjs +193 -0
- package/scripts/fixtures/harness-runtime-protocol.mjs +187 -0
- package/scripts/fixtures/harness-runtime-resume.mjs +24 -0
- package/scripts/fixtures/harness-runtime-stability.mjs +282 -0
- package/scripts/fixtures/harness-runtime-tools.mjs +13 -0
- package/scripts/fixtures/harness-runtime-web-approval.mjs +341 -0
- package/scripts/fixtures/issue-336-audit-worker.mjs +18 -0
- package/scripts/git-artifacts.mjs +64 -0
- package/scripts/git-artifacts.test.mjs +32 -0
- package/scripts/harness-compat-tdd.mjs +492 -0
- package/scripts/harness-issue-verify.mjs +26 -0
- package/scripts/harness-model-benchmark.mjs +163 -0
- package/scripts/harness-runtime-platform.test.mjs +31 -0
- package/scripts/harness-runtime-scenarios.mjs +297 -0
- package/scripts/harness-runtime-verify.mjs +169 -0
- package/scripts/harness-source-verify.mjs +211 -0
- package/scripts/harness-source-verify.test.mjs +97 -0
- package/scripts/harness-validation.mjs +68 -0
- package/scripts/harness-validation.test.mjs +95 -0
- package/scripts/http-body.test.mjs +72 -0
- package/scripts/import-vendor-artwork.mjs +78 -0
- package/scripts/inline-plan-blank-optional-tdd.mjs +121 -0
- package/scripts/issue-159.test.mjs +78 -0
- package/scripts/issue-188.test.mjs +148 -0
- package/scripts/issue-189.test.mjs +100 -0
- package/scripts/issue-203-card.test.mjs +181 -0
- package/scripts/issue-205.test.mjs +163 -0
- package/scripts/issue-234.test.mjs +424 -0
- package/scripts/issue-236-stale-module.test.mjs +63 -0
- package/scripts/issue-236.test.mjs +59 -0
- package/scripts/issue-262.test.mjs +98 -0
- package/scripts/issue-336.test.mjs +404 -0
- package/scripts/legacy-session-source-repair.test.mjs +201 -0
- package/scripts/lifecycle-verify.mjs +1573 -0
- package/scripts/lineage-identity.test.mjs +77 -0
- package/scripts/member-failure-tdd.mjs +451 -0
- package/scripts/member-spawn-recovery.test.mjs +92 -0
- package/scripts/quality-gates-amend.test.mjs +161 -0
- package/scripts/quality-gates-content-bound.test.mjs +572 -0
- package/scripts/quality-gates-cross-binding.test.mjs +184 -0
- package/scripts/quality-gates-excluded-scope.test.mjs +163 -0
- package/scripts/quality-gates-repair-scope.test.mjs +143 -0
- package/scripts/quality-gates-repair-wiring.test.mjs +189 -0
- package/scripts/quality-gates-tdd.mjs +1238 -0
- package/scripts/quality-gates-work-order.test.mjs +494 -0
- package/scripts/readme-version.mjs +89 -0
- package/scripts/readme-version.test.mjs +77 -0
- package/scripts/release-metadata.mjs +45 -0
- package/scripts/release-metadata.test.mjs +66 -0
- package/scripts/scoped-release.test.mjs +52 -0
- package/scripts/stability-tdd.mjs +144 -0
- package/scripts/stress-verify.mjs +548 -0
- package/scripts/symlink-support.mjs +46 -0
- package/scripts/sync-skill.mjs +103 -0
- package/scripts/tool-policies.test.mjs +280 -0
- package/scripts/update-skills.mjs +105 -0
- package/scripts/update-skills.test.mjs +79 -0
- package/scripts/upgrade-status.mjs +66 -0
- package/scripts/upgrade-status.test.mjs +83 -0
- package/scripts/verify-package.mjs +73 -0
- package/scripts/verify.mjs +2199 -0
- package/scripts/web-routes-verify.mjs +142 -0
- package/scripts/workspace-activity.test.mjs +346 -0
- package/scripts/workspace-summary.test.mjs +49 -0
- package/src/artifacts.ts +487 -0
- package/src/artwork-source.ts +262 -0
- package/src/capabilities.ts +113 -0
- package/src/client/ActivityPanel.module.css +2390 -0
- package/src/client/ActivityPanel.tsx +1507 -0
- package/src/client/AgentTeamsCard.module.css +148 -0
- package/src/client/AgentTeamsCard.tsx +155 -0
- package/src/client/StagingPlanEditor.tsx +829 -0
- package/src/client/TeamChatEntry.tsx +27 -0
- package/src/client/WorkspaceActivity.module.css +41 -0
- package/src/client/WorkspaceActivity.tsx +137 -0
- package/src/client/activity-model.ts +372 -0
- package/src/client/activity-monitor.ts +440 -0
- package/src/client/agent-teams-card-definition.ts +250 -0
- package/src/client/artwork.ts +374 -0
- package/src/client/icons.tsx +17 -0
- package/src/client/index.tsx +140 -0
- package/src/client/locales.ts +481 -0
- package/src/client/panel-geometry.ts +194 -0
- package/src/client/session-navigation.ts +73 -0
- package/src/client/workspace-state.ts +52 -0
- package/src/command.ts +145 -0
- package/src/css-modules.d.ts +4 -0
- package/src/event-types.ts +177 -0
- package/src/events.ts +78 -0
- package/src/harness-compat.ts +570 -0
- package/src/index.ts +599 -0
- package/src/lineage.ts +248 -0
- package/src/mailbox.ts +185 -0
- package/src/members.ts +1230 -0
- package/src/profiles.ts +765 -0
- package/src/quality-gates.ts +2124 -0
- package/src/scheduler.ts +554 -0
- package/src/snapshot.ts +333 -0
- package/src/state.ts +1317 -0
- package/src/tool-names.ts +14 -0
- package/src/tool-policies.ts +219 -0
- package/src/tools.ts +2939 -0
- package/src/types.ts +414 -0
- package/src/web-routes.ts +128 -0
- package/src/workspace-audit-service.ts +182 -0
- package/src/workspace-audit-worker.ts +12 -0
- package/src/workspace-audit.ts +57 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { chmod, mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises'
|
|
4
|
+
import { dirname, join, resolve } from 'node:path'
|
|
5
|
+
|
|
6
|
+
const root = resolve(import.meta.dirname, '..')
|
|
7
|
+
const sourceRoot = resolve(root, 'skills')
|
|
8
|
+
const mirrorRoot = resolve(root, '.dsh/skills')
|
|
9
|
+
const args = process.argv.slice(2)
|
|
10
|
+
if (args.some(arg => arg !== '--check')) {
|
|
11
|
+
console.error('Usage: sync-skill.mjs [--check]')
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|
|
14
|
+
const checkOnly = args.includes('--check')
|
|
15
|
+
|
|
16
|
+
async function filesIn(directory, prefix = '') {
|
|
17
|
+
const files = []
|
|
18
|
+
let entries
|
|
19
|
+
try {
|
|
20
|
+
entries = await readdir(join(directory, prefix), { withFileTypes: true })
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error.code === 'ENOENT') return files
|
|
23
|
+
throw error
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
const relativePath = join(prefix, entry.name)
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
files.push(...await filesIn(directory, relativePath))
|
|
30
|
+
} else if (entry.isFile()) {
|
|
31
|
+
files.push(relativePath)
|
|
32
|
+
} else {
|
|
33
|
+
throw new Error(`Unsupported skill entry: ${join(directory, relativePath)}`)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return files.sort()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function main() {
|
|
40
|
+
const entries = await readdir(sourceRoot, { withFileTypes: true })
|
|
41
|
+
let skillCount = 0
|
|
42
|
+
let fileCount = 0
|
|
43
|
+
let mismatchCount = 0
|
|
44
|
+
const sourceSkills = new Set()
|
|
45
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
46
|
+
if (!entry.isDirectory()) continue
|
|
47
|
+
const sourceDirectory = join(sourceRoot, entry.name)
|
|
48
|
+
const sourceFiles = await filesIn(sourceDirectory)
|
|
49
|
+
if (!sourceFiles.includes('SKILL.md')) continue
|
|
50
|
+
skillCount++
|
|
51
|
+
sourceSkills.add(entry.name)
|
|
52
|
+
const mirrorDirectory = join(mirrorRoot, entry.name)
|
|
53
|
+
const mirrorFiles = new Set(await filesIn(mirrorDirectory))
|
|
54
|
+
for (const file of sourceFiles) {
|
|
55
|
+
const sourcePath = join(sourceDirectory, file)
|
|
56
|
+
const source = await readFile(sourcePath)
|
|
57
|
+
const sourceMode = (await stat(sourcePath)).mode & 0o777
|
|
58
|
+
const mirrorPath = join(mirrorDirectory, file)
|
|
59
|
+
if (checkOnly) {
|
|
60
|
+
if (!mirrorFiles.has(file) || !(await readFile(mirrorPath)).equals(source)) {
|
|
61
|
+
console.error(`Missing or out-of-date skill mirror: ${mirrorPath}`)
|
|
62
|
+
mismatchCount++
|
|
63
|
+
} else if (process.platform !== 'win32' && ((await stat(mirrorPath)).mode & 0o111) !== (sourceMode & 0o111)) {
|
|
64
|
+
console.error(`Skill mirror executable mode differs: ${mirrorPath}`)
|
|
65
|
+
mismatchCount++
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
await mkdir(dirname(mirrorPath), { recursive: true })
|
|
69
|
+
await writeFile(mirrorPath, source)
|
|
70
|
+
if (process.platform !== 'win32') await chmod(mirrorPath, sourceMode)
|
|
71
|
+
}
|
|
72
|
+
mirrorFiles.delete(file)
|
|
73
|
+
fileCount++
|
|
74
|
+
}
|
|
75
|
+
for (const file of mirrorFiles) {
|
|
76
|
+
console.error(`Extra skill mirror file (review before removing): ${join(mirrorDirectory, file)}`)
|
|
77
|
+
mismatchCount++
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let mirrorEntries = []
|
|
82
|
+
try {
|
|
83
|
+
mirrorEntries = await readdir(mirrorRoot, { withFileTypes: true })
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error.code !== 'ENOENT') throw error
|
|
86
|
+
}
|
|
87
|
+
for (const entry of mirrorEntries) {
|
|
88
|
+
if (!entry.isDirectory() || sourceSkills.has(entry.name)) continue
|
|
89
|
+
if (!(await readdir(join(mirrorRoot, entry.name))).includes('SKILL.md')) continue
|
|
90
|
+
console.error(`Extra skill mirror directory (review before removing): ${join(mirrorRoot, entry.name)}`)
|
|
91
|
+
mismatchCount++
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!skillCount) throw new Error(`No skills found in ${sourceRoot}`)
|
|
95
|
+
if (mismatchCount) {
|
|
96
|
+
console.error('Run pnpm sync:skill for missing or changed files; review extra files separately.')
|
|
97
|
+
process.exitCode = 1
|
|
98
|
+
} else {
|
|
99
|
+
console.log(`DSH skill mirrors ${checkOnly ? 'are up to date' : 'synced'}: ${skillCount} skills, ${fileCount} files.`)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
await main()
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { mkdtemp, rm } from 'node:fs/promises'
|
|
4
|
+
import { tmpdir } from 'node:os'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import {
|
|
7
|
+
BUILTIN_DENY_TOOLS,
|
|
8
|
+
dedupeToolNames,
|
|
9
|
+
memberSpawnRelaxableDeny,
|
|
10
|
+
normalizeToolPolicy,
|
|
11
|
+
optionalToolPolicy,
|
|
12
|
+
parseToolPolicies,
|
|
13
|
+
requireToolPolicy,
|
|
14
|
+
resolveMemberToolFilter,
|
|
15
|
+
} from '../lib/tool-policies.js'
|
|
16
|
+
import { memberToolFilter, startMemberWithLenientFilter } from '../lib/harness-compat.js'
|
|
17
|
+
import { CAPTAIN_TOOL_NAMES, MEMBER_TOOL_NAMES } from '../lib/tool-names.js'
|
|
18
|
+
import { createTeamDir, readTeam } from '../lib/state.js'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Issue #59: reusable per-member tool policies. These are the pure resolver /
|
|
22
|
+
* helper contracts; the real host path (child schema assembly, forced
|
|
23
|
+
* invocation rejection, cold resume) is covered by the acceptance case under
|
|
24
|
+
* `docs/issue-maintenance-2026-10-10/policies/REPORT.md`.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
test('policy resolution trims, de-duplicates, and keeps declaration order', () => {
|
|
28
|
+
const policy = normalizeToolPolicy('researcher', {
|
|
29
|
+
allow: [' read ', 'glob', 'read', '', 'grep'],
|
|
30
|
+
deny: ['web_search', ' web_search '],
|
|
31
|
+
})
|
|
32
|
+
assert.deepEqual(policy.allow, ['read', 'glob', 'grep'])
|
|
33
|
+
assert.deepEqual(policy.deny, ['web_search'])
|
|
34
|
+
assert.deepEqual(dedupeToolNames(['a', ' a ', 'b', '']), ['a', 'b'])
|
|
35
|
+
|
|
36
|
+
const filter = resolveMemberToolFilter(policy)
|
|
37
|
+
assert.deepEqual(filter.allow, [...policy.allow, ...MEMBER_TOOL_NAMES])
|
|
38
|
+
assert.ok(filter.deny.includes('web_search'))
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('an allow-list policy injects the four required coordination tools', () => {
|
|
42
|
+
const filter = resolveMemberToolFilter({ allow: ['read'] })
|
|
43
|
+
for (const name of MEMBER_TOOL_NAMES) {
|
|
44
|
+
assert.ok(filter.allow?.includes(name), `${name} stays available through an allow list`)
|
|
45
|
+
assert.ok(!filter.deny.includes(name), `${name} is never denied`)
|
|
46
|
+
}
|
|
47
|
+
assert.deepEqual(MEMBER_TOOL_NAMES, [
|
|
48
|
+
'agent_teams_claim_task',
|
|
49
|
+
'agent_teams_update_task',
|
|
50
|
+
'agent_teams_send_message',
|
|
51
|
+
'agent_teams_status',
|
|
52
|
+
])
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('captain-only tools cannot be reopened through an allow list', () => {
|
|
56
|
+
const filter = resolveMemberToolFilter({ allow: ['read', ...CAPTAIN_TOOL_NAMES] })
|
|
57
|
+
for (const name of CAPTAIN_TOOL_NAMES) {
|
|
58
|
+
assert.ok(filter.deny.includes(name), `${name} stays denied`)
|
|
59
|
+
assert.ok(!filter.allow?.includes(name), `${name} never enters the allow list`)
|
|
60
|
+
}
|
|
61
|
+
assert.deepEqual(filter.allow, ['read', ...MEMBER_TOOL_NAMES])
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('a deny-only policy unions the captain-only deny list', () => {
|
|
65
|
+
const filter = resolveMemberToolFilter({ deny: ['write', 'bash'] })
|
|
66
|
+
assert.equal(filter.allow, undefined)
|
|
67
|
+
assert.deepEqual(filter.deny.slice(0, 2), ['write', 'bash'])
|
|
68
|
+
for (const name of CAPTAIN_TOOL_NAMES) assert.ok(filter.deny.includes(name))
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('the legacy filter of a member without a policy is unchanged', () => {
|
|
72
|
+
const hostNames = new Set(['subagent_fork', 'send_message', 'skill', ...CAPTAIN_TOOL_NAMES])
|
|
73
|
+
assert.deepEqual(resolveMemberToolFilter(undefined, { maxDepth: 0 }), memberToolFilter(0, undefined))
|
|
74
|
+
assert.deepEqual(
|
|
75
|
+
memberToolFilter(0, undefined).deny,
|
|
76
|
+
[...CAPTAIN_TOOL_NAMES, 'subagent', 'send_message'],
|
|
77
|
+
'without a registry view the depth entries pass through verbatim',
|
|
78
|
+
)
|
|
79
|
+
assert.deepEqual(memberToolFilter(0, hostNames).deny, [...CAPTAIN_TOOL_NAMES, 'send_message'])
|
|
80
|
+
assert.deepEqual(memberToolFilter(1, undefined).deny, [...CAPTAIN_TOOL_NAMES])
|
|
81
|
+
assert.deepEqual(resolveMemberToolFilter({ allow: ['read'] }, { maxDepth: 0, knownTools: hostNames }).deny, memberToolFilter(0, hostNames).deny)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test('malformed policies fail before a member could ever be persisted', () => {
|
|
85
|
+
assert.throws(() => normalizeToolPolicy('empty', {}), /must declare "allow" and\/or "deny"/u)
|
|
86
|
+
assert.throws(() => normalizeToolPolicy('empty-allow', { allow: [' '] }), /empty allow list/u)
|
|
87
|
+
assert.throws(() => normalizeToolPolicy('empty-deny', { deny: [] }), /empty deny list/u)
|
|
88
|
+
assert.throws(() => normalizeToolPolicy('no-coordination', { allow: ['read'], deny: ['agent_teams_status'] }), /required member coordination tool/u)
|
|
89
|
+
assert.throws(() => parseToolPolicies({ ' ': { allow: ['read'] } }), /empty policy id/u)
|
|
90
|
+
assert.throws(() => parseToolPolicies({ researcher: { allow: ['read'] }, ' researcher ': { allow: ['glob'] } }), /duplicate policy id/u)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test('an unknown policy id is rejected with the configured ids', () => {
|
|
94
|
+
const policies = parseToolPolicies({ researcher: { allow: ['read'] }, implementer: { deny: ['web_search'] } })
|
|
95
|
+
assert.deepEqual(Object.keys(policies), ['researcher', 'implementer'])
|
|
96
|
+
assert.deepEqual(requireToolPolicy(policies, 'implementer'), { deny: ['web_search'] })
|
|
97
|
+
assert.throws(() => requireToolPolicy(policies, 'typo'), /unknown tool policy "typo".*configured: implementer, researcher/u)
|
|
98
|
+
assert.throws(() => requireToolPolicy({}, 'typo'), /no toolPolicies are configured/u)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('the spawn retry relaxes only the built-in deny entries', async () => {
|
|
102
|
+
const rejection = names => new Error(
|
|
103
|
+
`tools.restrict() names unknown global tool${names.length > 1 ? 's' : ''} ${names.map(name => `"${name}"`).join(', ')}; known global tools: x`,
|
|
104
|
+
)
|
|
105
|
+
assert.deepEqual(BUILTIN_DENY_TOOLS, [...CAPTAIN_TOOL_NAMES, 'subagent', 'send_message'])
|
|
106
|
+
|
|
107
|
+
// The #163/#164 recovery path stays: a host that renamed or dropped a
|
|
108
|
+
// delegation tool still starts the member.
|
|
109
|
+
const attempts = []
|
|
110
|
+
const started = await startMemberWithLenientFilter(async filter => {
|
|
111
|
+
attempts.push([...filter.deny])
|
|
112
|
+
if (attempts.length === 1) throw rejection(['subagent', 'send_message'])
|
|
113
|
+
return 'started'
|
|
114
|
+
}, { deny: [...CAPTAIN_TOOL_NAMES, 'subagent', 'send_message'] })
|
|
115
|
+
assert.equal(started, 'started')
|
|
116
|
+
assert.equal(attempts.length, 2)
|
|
117
|
+
assert.deepEqual(attempts[1], [...CAPTAIN_TOOL_NAMES])
|
|
118
|
+
|
|
119
|
+
// A name an owner policy contributed is never dropped: the member must not
|
|
120
|
+
// silently spawn under a different policy than the owner declared.
|
|
121
|
+
await assert.rejects(
|
|
122
|
+
startMemberWithLenientFilter(async () => { throw rejection(['web_search']) }, { deny: [...CAPTAIN_TOOL_NAMES, 'web_search'] }),
|
|
123
|
+
/unknown global tool/u,
|
|
124
|
+
)
|
|
125
|
+
// Nothing is ever relaxed out of an allow list, so the required coordination
|
|
126
|
+
// tools cannot disappear either.
|
|
127
|
+
await assert.rejects(
|
|
128
|
+
startMemberWithLenientFilter(async () => { throw rejection(['read']) }, { allow: ['read', ...MEMBER_TOOL_NAMES], deny: [...CAPTAIN_TOOL_NAMES] }),
|
|
129
|
+
/unknown global tool/u,
|
|
130
|
+
)
|
|
131
|
+
await assert.rejects(
|
|
132
|
+
startMemberWithLenientFilter(async () => { throw rejection(['agent_teams_status']) }, { allow: [...MEMBER_TOOL_NAMES], deny: [...CAPTAIN_TOOL_NAMES] }),
|
|
133
|
+
/unknown global tool/u,
|
|
134
|
+
)
|
|
135
|
+
// An explicit empty relaxable set makes even the built-in entries strict.
|
|
136
|
+
await assert.rejects(
|
|
137
|
+
startMemberWithLenientFilter(async () => { throw rejection(['subagent']) }, { deny: [...CAPTAIN_TOOL_NAMES, 'subagent'] }, []),
|
|
138
|
+
/unknown global tool/u,
|
|
139
|
+
)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
test('an owner-declared deny name is never relaxable, even when it overlaps a built-in', () => {
|
|
143
|
+
// `send_message` and `subagent` are built-in depth entries; `agent_teams_*`
|
|
144
|
+
// are built-in captain-only entries. A policy that names one of them must not
|
|
145
|
+
// inherit the #163/#164 relaxation for that exact name.
|
|
146
|
+
const policy = normalizeToolPolicy('strict-send', { deny: ['send_message', 'web_search'] })
|
|
147
|
+
const relaxable = memberSpawnRelaxableDeny(policy)
|
|
148
|
+
assert.ok(!relaxable.includes('send_message'), 'the owner-declared built-in name stays strict')
|
|
149
|
+
assert.ok(relaxable.includes('subagent'), 'built-in names the owner did not declare stay relaxable')
|
|
150
|
+
assert.ok(CAPTAIN_TOOL_NAMES.every(name => relaxable.includes(name)))
|
|
151
|
+
assert.ok(!relaxable.includes('web_search'), 'owner-only names were never relaxable')
|
|
152
|
+
|
|
153
|
+
const captainOverlap = memberSpawnRelaxableDeny(normalizeToolPolicy('strict-captain', { deny: ['agent_teams_create'] }))
|
|
154
|
+
assert.ok(!captainOverlap.includes('agent_teams_create'), 'an owner-declared captain-only name stays strict too')
|
|
155
|
+
|
|
156
|
+
// A member without a policy keeps the legacy built-in recovery path, and a
|
|
157
|
+
// selected policy id this deployment no longer declares relaxes nothing.
|
|
158
|
+
assert.deepEqual(memberSpawnRelaxableDeny(undefined), [...BUILTIN_DENY_TOOLS])
|
|
159
|
+
assert.deepEqual(memberSpawnRelaxableDeny(undefined, true), [], 'a selected id with no configured policy relaxes nothing')
|
|
160
|
+
|
|
161
|
+
const policies = parseToolPolicies({ 'strict-send': { deny: ['send_message'] } })
|
|
162
|
+
assert.deepEqual(optionalToolPolicy(policies, 'strict-send'), { deny: ['send_message'] })
|
|
163
|
+
assert.equal(optionalToolPolicy(policies, 'not-configured'), undefined)
|
|
164
|
+
assert.equal(optionalToolPolicy(policies, 'toString'), undefined)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('a relaxed spawn never drops an owner-declared overlap name', async () => {
|
|
168
|
+
const rejection = names => new Error(
|
|
169
|
+
`tools.restrict() names unknown global tool${names.length > 1 ? 's' : ''} ${names.map(name => `"${name}"`).join(', ')}; known global tools: x`,
|
|
170
|
+
)
|
|
171
|
+
const filter = resolveMemberToolFilter(normalizeToolPolicy('strict-send', { deny: ['send_message'] }), { maxDepth: 0 })
|
|
172
|
+
// The host rejects only the owner-declared overlap name: the spawn must fail
|
|
173
|
+
// instead of silently applying a filter the owner did not declare.
|
|
174
|
+
await assert.rejects(
|
|
175
|
+
startMemberWithLenientFilter(
|
|
176
|
+
async () => { throw rejection(['send_message']) },
|
|
177
|
+
filter,
|
|
178
|
+
memberSpawnRelaxableDeny(normalizeToolPolicy('strict-send', { deny: ['send_message'] })),
|
|
179
|
+
),
|
|
180
|
+
/unknown global tool/u,
|
|
181
|
+
)
|
|
182
|
+
// A rejection naming only an undeclared built-in entry is still recovered.
|
|
183
|
+
const attempts = []
|
|
184
|
+
const started = await startMemberWithLenientFilter(
|
|
185
|
+
async current => {
|
|
186
|
+
attempts.push([...current.deny])
|
|
187
|
+
if (attempts.length === 1) throw rejection(['subagent'])
|
|
188
|
+
return 'started'
|
|
189
|
+
},
|
|
190
|
+
filter,
|
|
191
|
+
memberSpawnRelaxableDeny(normalizeToolPolicy('strict-send', { deny: ['send_message'] })),
|
|
192
|
+
)
|
|
193
|
+
assert.equal(started, 'started')
|
|
194
|
+
assert.ok(!attempts[1].includes('subagent'))
|
|
195
|
+
assert.ok(attempts[1].includes('send_message'), 'the owner-declared name is still denied on the retry')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
test('policy ids are data, never prototype members', () => {
|
|
199
|
+
const policies = parseToolPolicies(JSON.parse('{"__proto__": {"allow": ["read"]}, "constructor": {"deny": ["web_search"]}}'))
|
|
200
|
+
assert.equal(Object.getPrototypeOf(policies), null)
|
|
201
|
+
assert.deepEqual(Object.keys(policies).sort(), ['__proto__', 'constructor'])
|
|
202
|
+
assert.deepEqual(requireToolPolicy(policies, '__proto__'), { allow: ['read'] })
|
|
203
|
+
assert.deepEqual(requireToolPolicy(policies, 'constructor'), { deny: ['web_search'] })
|
|
204
|
+
assert.throws(() => requireToolPolicy(policies, 'toString'), /unknown tool policy "toString"/u)
|
|
205
|
+
assert.throws(() => requireToolPolicy(parseToolPolicies({}), 'constructor'), /no toolPolicies are configured/u)
|
|
206
|
+
assert.throws(() => parseToolPolicies({ researcher: { allow: ['run_code'] } }), /reserved presentation transport/u)
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
test('durable member records reject wrong-typed tool policy fields', async () => {
|
|
210
|
+
const root = await mkdtemp(join(tmpdir(), 'agent-teams-policy-boundary-'))
|
|
211
|
+
const write = async (member, id) => {
|
|
212
|
+
await createTeamDir(root, {
|
|
213
|
+
name: 'Policy Boundary Team',
|
|
214
|
+
id,
|
|
215
|
+
captainSessionId: 'captain',
|
|
216
|
+
createdAt: Date.now(),
|
|
217
|
+
members: [member],
|
|
218
|
+
tasks: [],
|
|
219
|
+
taskSeq: 0,
|
|
220
|
+
})
|
|
221
|
+
return join(root, id, 'team.json')
|
|
222
|
+
}
|
|
223
|
+
const base = { id: 'child', name: 'researcher', joinedAt: Date.now(), status: 'idle' }
|
|
224
|
+
try {
|
|
225
|
+
// Legacy records keep working: both fields absent.
|
|
226
|
+
await write(base, 'legacy')
|
|
227
|
+
assert.equal((await readTeam(root, 'legacy'))?.members[0]?.toolPolicy, undefined)
|
|
228
|
+
|
|
229
|
+
// A well-formed policy snapshot round-trips.
|
|
230
|
+
await write({ ...base, toolPolicy: 'researcher', toolFilter: { allow: ['read'], deny: [...CAPTAIN_TOOL_NAMES] } }, 'valid')
|
|
231
|
+
assert.deepEqual((await readTeam(root, 'valid'))?.members[0]?.toolFilter, { allow: ['read'], deny: [...CAPTAIN_TOOL_NAMES] })
|
|
232
|
+
|
|
233
|
+
const rejected = [
|
|
234
|
+
['blank-policy-id', { ...base, toolPolicy: ' ' }],
|
|
235
|
+
['numeric-policy-id', { ...base, toolPolicy: 7 }],
|
|
236
|
+
['filter-without-deny', { ...base, toolPolicy: 'p', toolFilter: { allow: ['read'] } }],
|
|
237
|
+
['string-deny', { ...base, toolPolicy: 'p', toolFilter: { deny: 'write' } }],
|
|
238
|
+
['empty-deny', { ...base, toolPolicy: 'p', toolFilter: { deny: [] } }],
|
|
239
|
+
['empty-allow', { ...base, toolPolicy: 'p', toolFilter: { allow: [], deny: [...CAPTAIN_TOOL_NAMES] } }],
|
|
240
|
+
['numeric-name', { ...base, toolPolicy: 'p', toolFilter: { deny: [7] } }],
|
|
241
|
+
['blank-name', { ...base, toolPolicy: 'p', toolFilter: { deny: [' '] } }],
|
|
242
|
+
['string-filter', { ...base, toolPolicy: 'p', toolFilter: 'deny=write' }],
|
|
243
|
+
]
|
|
244
|
+
for (const [id, member] of rejected) {
|
|
245
|
+
await write(member, id)
|
|
246
|
+
await assert.rejects(readTeam(root, id), /invalid AgentTeams state/u, `${id} must be rejected at the durable boundary`)
|
|
247
|
+
}
|
|
248
|
+
} finally {
|
|
249
|
+
await rm(root, { recursive: true, force: true })
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
test('team.json round-trips the policy id and the resolved filter', async () => {
|
|
254
|
+
const root = await mkdtemp(join(tmpdir(), 'agent-teams-policy-'))
|
|
255
|
+
try {
|
|
256
|
+
const filter = resolveMemberToolFilter({ allow: ['read', 'glob'] }, { maxDepth: 0 })
|
|
257
|
+
await createTeamDir(root, {
|
|
258
|
+
name: 'Policy Team',
|
|
259
|
+
id: 'policy-team',
|
|
260
|
+
captainSessionId: 'captain',
|
|
261
|
+
createdAt: Date.now(),
|
|
262
|
+
members: [{
|
|
263
|
+
id: 'child',
|
|
264
|
+
name: 'researcher',
|
|
265
|
+
role: 'researcher',
|
|
266
|
+
toolPolicy: 'researcher',
|
|
267
|
+
toolFilter: filter,
|
|
268
|
+
joinedAt: Date.now(),
|
|
269
|
+
status: 'idle',
|
|
270
|
+
}],
|
|
271
|
+
tasks: [],
|
|
272
|
+
taskSeq: 0,
|
|
273
|
+
})
|
|
274
|
+
const restored = await readTeam(root, 'policy-team')
|
|
275
|
+
assert.deepEqual(restored?.members[0]?.toolPolicy, 'researcher')
|
|
276
|
+
assert.deepEqual(restored?.members[0]?.toolFilter, filter)
|
|
277
|
+
} finally {
|
|
278
|
+
await rm(root, { recursive: true, force: true })
|
|
279
|
+
}
|
|
280
|
+
})
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Import reviewed upstream skill blobs at an exact commit; preview by default. */
|
|
3
|
+
import { execFileSync } from 'node:child_process'
|
|
4
|
+
import { createHash } from 'node:crypto'
|
|
5
|
+
import { chmodSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { dirname, join, resolve } from 'node:path'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
const projectRoot = resolve(import.meta.dirname, '..')
|
|
10
|
+
const sha256 = data => createHash('sha256').update(data).digest('hex')
|
|
11
|
+
|
|
12
|
+
function filesIn(directory, prefix = '') {
|
|
13
|
+
return readdirSync(join(directory, prefix), { withFileTypes: true }).flatMap(entry => {
|
|
14
|
+
const path = join(prefix, entry.name)
|
|
15
|
+
if (entry.isDirectory()) return filesIn(directory, path)
|
|
16
|
+
if (!entry.isFile()) throw new Error(`Unsupported entry: ${join(directory, path)}`)
|
|
17
|
+
return [path]
|
|
18
|
+
}).sort()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Preview or import only the existing locked skill roster, preserving local ownership. */
|
|
22
|
+
export function updateSkills({ source, commit, apply = false, root = projectRoot }) {
|
|
23
|
+
if (!/^[a-f0-9]{40}$/.test(commit ?? '')) throw new Error('Use a reviewed full 40-character commit SHA.')
|
|
24
|
+
const git = (...args) => execFileSync('git', ['-C', resolve(source), ...args], { maxBuffer: 32 * 1024 * 1024 })
|
|
25
|
+
if (git('rev-parse', `${commit}^{commit}`).toString().trim() !== commit) throw new Error('Commit identity mismatch.')
|
|
26
|
+
const skillRoot = join(root, 'skills')
|
|
27
|
+
const lockPath = join(skillRoot, 'upstream-lock.json')
|
|
28
|
+
const lock = JSON.parse(readFileSync(lockPath, 'utf8'))
|
|
29
|
+
git('merge-base', '--is-ancestor', lock.commit, commit)
|
|
30
|
+
const roster = new Set(lock.skills)
|
|
31
|
+
const entries = git('ls-tree', '-r', '-z', commit, '--', 'skills').toString().split('\0').filter(Boolean)
|
|
32
|
+
const blobs = new Map()
|
|
33
|
+
const upstreamRoster = new Set()
|
|
34
|
+
for (const row of entries) {
|
|
35
|
+
const [metadata, path] = row.split('\t')
|
|
36
|
+
const [mode, type, oid] = metadata.split(' ')
|
|
37
|
+
if (/^skills\/[^/]+\/SKILL\.md$/.test(path)) upstreamRoster.add(path.split('/')[1])
|
|
38
|
+
const relative = path.slice('skills/'.length)
|
|
39
|
+
if (!roster.has(relative.split('/')[0])) continue
|
|
40
|
+
if (type !== 'blob' || !['100644', '100755'].includes(mode)) throw new Error(`Unsupported upstream entry: ${path}`)
|
|
41
|
+
blobs.set(relative, { data: git('cat-file', 'blob', oid), executable: mode === '100755' })
|
|
42
|
+
}
|
|
43
|
+
if ([...roster].some(name => !upstreamRoster.has(name)) || [...upstreamRoster].some(name => !roster.has(name))) {
|
|
44
|
+
throw new Error('Skill roster changed; review additions/removals and discovery links separately.')
|
|
45
|
+
}
|
|
46
|
+
const removed = Object.keys(lock.files).filter(path => !blobs.has(path))
|
|
47
|
+
if (removed.length) throw new Error(`Upstream removed files; review separately: ${removed.join(', ')}`)
|
|
48
|
+
// Complete preflight before any writes, including both copies and discovery links.
|
|
49
|
+
for (const name of roster) {
|
|
50
|
+
const link = join(root, '.agents/skills', name)
|
|
51
|
+
if (!lstatSync(link).isSymbolicLink() || resolve(dirname(link), readlinkSync(link)) !== join(skillRoot, name)) {
|
|
52
|
+
throw new Error(`Unexpected discovery link: ${link}`)
|
|
53
|
+
}
|
|
54
|
+
for (const base of [skillRoot, join(root, '.dsh/skills')]) {
|
|
55
|
+
const directory = join(base, name)
|
|
56
|
+
if (!lstatSync(directory).isDirectory()) throw new Error(`Expected real skill directory: ${directory}`)
|
|
57
|
+
const actual = filesIn(directory).map(path => `${name}/${path}`)
|
|
58
|
+
const expected = Object.keys(lock.files).filter(path => path.startsWith(`${name}/`)).sort()
|
|
59
|
+
if (JSON.stringify(actual) !== JSON.stringify(expected)) throw new Error(`Untracked or missing skill files: ${directory}`)
|
|
60
|
+
for (const path of expected) {
|
|
61
|
+
const target = join(base, path)
|
|
62
|
+
if (sha256(readFileSync(target)) !== lock.files[path]) throw new Error(`Local skill modification: ${target}`)
|
|
63
|
+
if (process.platform !== 'win32' && Boolean(lstatSync(target).mode & 0o111) !== lock.executableFiles.includes(path)) {
|
|
64
|
+
throw new Error(`Local executable mode modification: ${target}`)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const license = git('show', `${commit}:LICENSE`)
|
|
70
|
+
const oldLicense = git('show', `${lock.commit}:LICENSE`)
|
|
71
|
+
if (!readFileSync(join(skillRoot, lock.licenseFile)).equals(oldLicense)) throw new Error('Local license modification.')
|
|
72
|
+
const added = [], changed = []
|
|
73
|
+
const files = {}, executableFiles = []
|
|
74
|
+
for (const [path, blob] of [...blobs].sort(([a], [b]) => a.localeCompare(b))) {
|
|
75
|
+
files[path] = sha256(blob.data)
|
|
76
|
+
if (blob.executable) executableFiles.push(path)
|
|
77
|
+
if (!(path in lock.files)) added.push(path)
|
|
78
|
+
else if (lock.files[path] !== files[path] || lock.executableFiles.includes(path) !== blob.executable) changed.push(path)
|
|
79
|
+
}
|
|
80
|
+
const result = { from: lock.commit, to: commit, skills: roster.size, files: blobs.size, added, changed, licenseChanged: !license.equals(oldLicense), applied: apply }
|
|
81
|
+
if (!apply) return result
|
|
82
|
+
if (result.licenseChanged) throw new Error('License changed; review licensing separately before importing.')
|
|
83
|
+
for (const path of [...added, ...changed]) {
|
|
84
|
+
const blob = blobs.get(path)
|
|
85
|
+
for (const base of [skillRoot, join(root, '.dsh/skills')]) {
|
|
86
|
+
const target = join(base, path)
|
|
87
|
+
mkdirSync(dirname(target), { recursive: true })
|
|
88
|
+
writeFileSync(target, blob.data)
|
|
89
|
+
if (process.platform !== 'win32') chmodSync(target, blob.executable ? 0o755 : 0o644)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (lock.commit !== commit) writeFileSync(lockPath, JSON.stringify({ ...lock, commit, importedAt: new Date().toISOString().slice(0, 10), files, executableFiles }, null, 2) + '\n')
|
|
93
|
+
return result
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
97
|
+
try {
|
|
98
|
+
const [source, commit, ...flags] = process.argv.slice(2)
|
|
99
|
+
if (!source || flags.some(flag => flag !== '--apply') || flags.length > 1) throw new Error('Usage: update-skills.mjs <upstream-checkout> <full-commit> [--apply]')
|
|
100
|
+
console.log(JSON.stringify(updateSkills({ source, commit, apply: flags.includes('--apply') }), null, 2))
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error(error.message)
|
|
103
|
+
process.exitCode = 1
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import test from 'node:test'
|
|
8
|
+
import { updateSkills } from './update-skills.mjs'
|
|
9
|
+
|
|
10
|
+
function fixture(t) {
|
|
11
|
+
const dir = mkdtempSync(join(tmpdir(), 'skill-update-test-'))
|
|
12
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }))
|
|
13
|
+
const source = join(dir, 'upstream'), root = join(dir, 'project')
|
|
14
|
+
mkdirSync(join(source, 'skills/demo'), { recursive: true })
|
|
15
|
+
const git = (...args) => execFileSync('git', ['-C', source, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim()
|
|
16
|
+
git('init')
|
|
17
|
+
git('config', 'user.name', 'Skill update test')
|
|
18
|
+
git('config', 'user.email', 'test@example.invalid')
|
|
19
|
+
git('config', 'commit.gpgsign', 'false')
|
|
20
|
+
writeFileSync(join(source, 'LICENSE'), 'MIT fixture\n')
|
|
21
|
+
writeFileSync(join(source, 'skills/demo/SKILL.md'), 'original\n')
|
|
22
|
+
const commit = () => { git('add', '.'); git('commit', '-m', 'fixture'); return git('rev-parse', 'HEAD') }
|
|
23
|
+
const baseline = commit()
|
|
24
|
+
for (const base of ['skills', '.dsh/skills']) {
|
|
25
|
+
mkdirSync(join(root, base, 'demo'), { recursive: true })
|
|
26
|
+
writeFileSync(join(root, base, 'demo/SKILL.md'), 'original\n')
|
|
27
|
+
chmodSync(join(root, base, 'demo/SKILL.md'), 0o644)
|
|
28
|
+
}
|
|
29
|
+
mkdirSync(join(root, '.agents/skills'), { recursive: true })
|
|
30
|
+
symlinkSync('../../skills/demo', join(root, '.agents/skills/demo'))
|
|
31
|
+
writeFileSync(join(root, 'skills/LICENSE.upstream'), 'MIT fixture\n')
|
|
32
|
+
writeFileSync(join(root, 'skills/upstream-lock.json'), JSON.stringify({
|
|
33
|
+
repository: 'fixture', commit: baseline, skills: ['demo'], licenseFile: 'LICENSE.upstream',
|
|
34
|
+
files: { 'demo/SKILL.md': createHash('sha256').update('original\n').digest('hex') }, executableFiles: [],
|
|
35
|
+
}))
|
|
36
|
+
writeFileSync(join(source, 'skills/demo/SKILL.md'), 'updated\n')
|
|
37
|
+
writeFileSync(join(source, 'skills/demo/probe.mjs'), '// probe\n')
|
|
38
|
+
chmodSync(join(source, 'skills/demo/probe.mjs'), 0o755)
|
|
39
|
+
const target = commit()
|
|
40
|
+
return { source, root, commit: target, save: commit }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test('preview is read-only; apply pins Git blobs and synchronizes content and modes', t => {
|
|
44
|
+
const f = fixture(t)
|
|
45
|
+
const before = readFileSync(join(f.root, 'skills/upstream-lock.json'))
|
|
46
|
+
assert.deepEqual(updateSkills(f).added, ['demo/probe.mjs'])
|
|
47
|
+
assert.deepEqual(readFileSync(join(f.root, 'skills/upstream-lock.json')), before)
|
|
48
|
+
writeFileSync(join(f.source, 'skills/demo/SKILL.md'), 'dirty checkout must not be imported\n')
|
|
49
|
+
updateSkills({ ...f, apply: true })
|
|
50
|
+
for (const base of ['skills', '.dsh/skills', '.agents/skills']) {
|
|
51
|
+
assert.equal(readFileSync(join(f.root, base, 'demo/SKILL.md'), 'utf8'), 'updated\n')
|
|
52
|
+
}
|
|
53
|
+
assert.deepEqual(updateSkills(f).changed, [])
|
|
54
|
+
assert.deepEqual(updateSkills(f).added, [])
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
for (const base of ['skills', '.dsh/skills']) {
|
|
58
|
+
test(`refuses local edits in ${base} before any write`, t => {
|
|
59
|
+
const f = fixture(t)
|
|
60
|
+
writeFileSync(join(f.root, base, 'demo/SKILL.md'), 'local edit\n')
|
|
61
|
+
assert.throws(() => updateSkills({ ...f, apply: true }), /Local skill modification/)
|
|
62
|
+
assert.notEqual(JSON.parse(readFileSync(join(f.root, 'skills/upstream-lock.json'))).commit, f.commit)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
test('refuses moving refs and upstream file deletion', t => {
|
|
67
|
+
const f = fixture(t)
|
|
68
|
+
assert.throws(() => updateSkills({ ...f, commit: 'main' }), /full 40-character/)
|
|
69
|
+
updateSkills({ ...f, apply: true })
|
|
70
|
+
rmSync(join(f.source, 'skills/demo/probe.mjs'))
|
|
71
|
+
assert.throws(() => updateSkills({ ...f, commit: f.save(), apply: true }), /removed files/)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('refuses silently adding a skill to the locked roster', t => {
|
|
75
|
+
const f = fixture(t)
|
|
76
|
+
mkdirSync(join(f.source, 'skills/other'))
|
|
77
|
+
writeFileSync(join(f.source, 'skills/other/SKILL.md'), 'other\n')
|
|
78
|
+
assert.throws(() => updateSkills({ ...f, commit: f.save(), apply: true }), /roster changed/)
|
|
79
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Read-only release visibility. Registry discovery never adds a host to the tested matrix. */
|
|
2
|
+
import { pathToFileURL } from 'node:url'
|
|
3
|
+
import { compareHostVersions, policy, requiredHostPeers, validatePolicy } from './compatibility.mjs'
|
|
4
|
+
|
|
5
|
+
const exactVersion = value => typeof value === 'string' && /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:alpha|beta|rc)\.(0|[1-9]\d*))?$/.test(value) && value.trim() === value
|
|
6
|
+
|
|
7
|
+
// Understands the current `>=x` engines.dsh and `*` peers, and the exact lists of releases
|
|
8
|
+
// up to 0.1.27. Anything else requires review instead of a guessed semver answer.
|
|
9
|
+
function parseDeclaration(value) {
|
|
10
|
+
if (typeof value !== 'string') return undefined
|
|
11
|
+
if (value === '*') return () => true
|
|
12
|
+
const lower = /^>=(\S+)$/.exec(value)
|
|
13
|
+
if (lower && exactVersion(lower[1])) return version => compareHostVersions(version, lower[1]) >= 0
|
|
14
|
+
const versions = value.split('||').map(v => v.trim())
|
|
15
|
+
if (!versions.every(exactVersion) || new Set(versions).size !== versions.length) return undefined
|
|
16
|
+
return version => versions.includes(version)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function inspectUpgradeStatus({ hostTags, pluginManifest }, support = policy) {
|
|
20
|
+
const supported = validatePolicy(support)
|
|
21
|
+
if (!hostTags || !exactVersion(hostTags.latest)
|
|
22
|
+
|| !exactVersion(hostTags.next)) throw new Error('Registry must return exact latest/next host identities')
|
|
23
|
+
if (pluginManifest?.name !== '@nanmicoder/dsh-agent-teams' || !exactVersion(pluginManifest.version)) throw new Error('Registry plugin identity mismatch')
|
|
24
|
+
const channels = Object.fromEntries(['latest', 'next'].filter(tag => hostTags[tag]).map(tag => [tag, hostTags[tag]]))
|
|
25
|
+
const unverifiedChannels = Object.entries(channels).filter(([, version]) => !supported.includes(version)).map(([channel, version]) => ({ channel, version }))
|
|
26
|
+
const fields = Object.hasOwn(pluginManifest.engines ?? {}, 'dsh')
|
|
27
|
+
? { 'engines.dsh': pluginManifest.engines.dsh }
|
|
28
|
+
: Object.fromEntries([
|
|
29
|
+
...requiredHostPeers.filter(name => name.startsWith('@deepseek-ai/dsh-')),
|
|
30
|
+
...Object.keys(pluginManifest.peerDependencies ?? {}).filter(name => name === '@deepseek-ai/dsh' || name.startsWith('@deepseek-ai/dsh-')),
|
|
31
|
+
].map(name => [name, pluginManifest.peerDependencies?.[name]]))
|
|
32
|
+
const declarations = Object.entries(fields).map(([name, value]) => ({ name, accepts: parseDeclaration(value) }))
|
|
33
|
+
const unrecognizedDeclarations = declarations.filter(({ accepts }) => !accepts).map(({ name }) => name)
|
|
34
|
+
const accepted = version => declarations.every(({ accepts }) => accepts(version))
|
|
35
|
+
// Users on these host channels cannot install the published plugin at all.
|
|
36
|
+
const blockedChannels = unrecognizedDeclarations.length ? null
|
|
37
|
+
: Object.entries(channels).filter(([, version]) => !accepted(version)).map(([channel, version]) => ({ channel, version }))
|
|
38
|
+
const unpublishedSupport = unrecognizedDeclarations.length ? null : supported.filter(version => !accepted(version))
|
|
39
|
+
return {
|
|
40
|
+
needsAttention: unverifiedChannels.length > 0 || unrecognizedDeclarations.length > 0 || blockedChannels?.length > 0 || unpublishedSupport?.length > 0,
|
|
41
|
+
hostChannels: channels,
|
|
42
|
+
pluginChannel: 'latest', pluginVersion: pluginManifest.version,
|
|
43
|
+
blockedChannels, unverifiedChannels, unpublishedSupport, unrecognizedDeclarations,
|
|
44
|
+
limits: ['Compares declarations only; does not prove runtime compatibility or publish anything.', 'Checks host latest/next and plugin latest; other tags and untagged releases require an explicit audit.'],
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function fetchUpgradeStatus(fetcher = fetch, support = policy) {
|
|
49
|
+
async function read(path) {
|
|
50
|
+
const response = await fetcher(`https://registry.npmjs.org/${path}`, { signal: AbortSignal.timeout(30000) })
|
|
51
|
+
if (!response.ok) throw new Error(`Registry request failed: ${path}: HTTP ${response.status}`)
|
|
52
|
+
return response.json()
|
|
53
|
+
}
|
|
54
|
+
const [hostTags, pluginManifest] = await Promise.all([
|
|
55
|
+
read('-/package/@deepseek-ai%2Fdsh/dist-tags'),
|
|
56
|
+
read('@nanmicoder%2Fdsh-agent-teams/latest'),
|
|
57
|
+
])
|
|
58
|
+
return inspectUpgradeStatus({ hostTags, pluginManifest }, support)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
62
|
+
if (process.argv.length !== 2) throw new Error('Usage: node scripts/upgrade-status.mjs')
|
|
63
|
+
const result = await fetchUpgradeStatus()
|
|
64
|
+
console.log(JSON.stringify({ checkedAt: new Date().toISOString(), ...result }, null, 2))
|
|
65
|
+
process.exitCode = result.needsAttention ? 1 : 0
|
|
66
|
+
}
|