@hobin/developer 0.1.5 → 0.1.7

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.
@@ -1,94 +1,100 @@
1
- import type { DeveloperMode } from "./state.ts";
1
+ export type ControlledToolCapability = "shell" | "artifact";
2
2
 
3
- export type ControlledToolCapability = "execute" | "mutate";
4
-
5
- const CONTROLLED_BUILTIN_CAPABILITIES = new Map<string, ControlledToolCapability>([
6
- ["bash", "execute"],
7
- ["edit", "mutate"],
8
- ["write", "mutate"],
3
+ const CONTROLLED_BUILTIN_CAPABILITIES = new Map<
4
+ string,
5
+ ControlledToolCapability
6
+ >([
7
+ ["bash", "shell"],
8
+ ["edit", "artifact"],
9
+ ["write", "artifact"],
9
10
  ]);
10
11
 
11
12
  export interface ToolMetadataLike {
12
- name: string;
13
- sourceInfo: { source: string };
13
+ name: string;
14
+ sourceInfo: { source: string };
14
15
  }
15
16
 
16
17
  export interface ToolPolicyMemory {
17
- withheldBuiltins: Set<string>;
18
+ withheldBuiltins: Set<string>;
18
19
  }
19
20
 
20
21
  export interface ToolPolicyResult {
21
- activeTools: string[];
22
- memory: ToolPolicyMemory;
22
+ activeTools: string[];
23
+ memory: ToolPolicyMemory;
23
24
  }
24
25
 
25
26
  export interface ProtocolToolAccess {
26
- canExecute: boolean;
27
- canMutate: boolean;
28
- hasBeforeDirectGate: boolean;
27
+ allowsShell: boolean;
28
+ allowsArtifactTools: boolean;
29
+ hasBeforeImplementationGate: boolean;
29
30
  }
30
31
 
31
32
  export function builtinControlledToolCapabilities(
32
- tools: ToolMetadataLike[],
33
+ tools: ToolMetadataLike[],
33
34
  ): Map<string, ControlledToolCapability> {
34
- const result = new Map<string, ControlledToolCapability>();
35
- for (const tool of tools) {
36
- if (tool.sourceInfo.source !== "builtin") continue;
37
- const capability = CONTROLLED_BUILTIN_CAPABILITIES.get(tool.name);
38
- if (capability) result.set(tool.name, capability);
39
- }
40
- return result;
35
+ const result = new Map<string, ControlledToolCapability>();
36
+ for (const tool of tools) {
37
+ if (tool.sourceInfo.source !== "builtin") continue;
38
+ const capability = CONTROLLED_BUILTIN_CAPABILITIES.get(tool.name);
39
+ if (capability) result.set(tool.name, capability);
40
+ }
41
+ return result;
41
42
  }
42
43
 
43
44
  export function isControlledToolAllowed(input: {
44
- mode: DeveloperMode;
45
- capability: ControlledToolCapability;
46
- access: ProtocolToolAccess;
45
+ enabled: boolean;
46
+ capability: ControlledToolCapability;
47
+ access: ProtocolToolAccess;
47
48
  }): boolean {
48
- if (input.mode === "off") return true;
49
+ if (!input.enabled) return true;
49
50
 
50
- if (input.access.hasBeforeDirectGate) {
51
- if (input.capability === "mutate") return false;
52
- return input.access.canExecute && !input.access.canMutate;
53
- }
51
+ if (input.access.hasBeforeImplementationGate) {
52
+ if (input.capability === "artifact") return false;
53
+ return input.access.allowsShell && !input.access.allowsArtifactTools;
54
+ }
54
55
 
55
- if (input.mode === "on") return true;
56
- if (input.capability === "execute") return input.access.canExecute;
57
- return input.access.canMutate;
56
+ if (input.capability === "shell") return input.access.allowsShell;
57
+ return input.access.allowsArtifactTools;
58
58
  }
59
59
 
60
60
  export function reconcileProtocolTools(input: {
61
- activeTools: string[];
62
- allTools: ToolMetadataLike[];
63
- mode: DeveloperMode;
64
- access: ProtocolToolAccess;
65
- protocolTools: readonly string[];
66
- memory: ToolPolicyMemory;
61
+ activeTools: string[];
62
+ allTools: ToolMetadataLike[];
63
+ enabled: boolean;
64
+ access: ProtocolToolAccess;
65
+ protocolTools: readonly string[];
66
+ memory: ToolPolicyMemory;
67
67
  }): ToolPolicyResult {
68
- const active = new Set(input.activeTools);
69
- const controlledBuiltins = builtinControlledToolCapabilities(input.allTools);
70
- const withheld = new Set(
71
- [...input.memory.withheldBuiltins].filter((name) => controlledBuiltins.has(name)),
72
- );
68
+ const active = new Set(input.activeTools);
69
+ const controlledBuiltins = builtinControlledToolCapabilities(input.allTools);
70
+ const withheld = new Set(
71
+ [...input.memory.withheldBuiltins].filter((name) =>
72
+ controlledBuiltins.has(name),
73
+ ),
74
+ );
73
75
 
74
- if (input.mode === "off") {
75
- for (const name of withheld) active.add(name);
76
- withheld.clear();
77
- for (const tool of input.protocolTools) active.delete(tool);
78
- } else {
79
- for (const tool of input.protocolTools) active.add(tool);
80
- for (const [name, capability] of controlledBuiltins) {
81
- const allowed = isControlledToolAllowed({ mode: input.mode, capability, access: input.access });
82
- if (allowed) {
83
- if (withheld.delete(name)) active.add(name);
84
- } else if (active.delete(name)) {
85
- withheld.add(name);
86
- }
87
- }
88
- }
76
+ if (!input.enabled) {
77
+ for (const name of withheld) active.add(name);
78
+ withheld.clear();
79
+ for (const tool of input.protocolTools) active.delete(tool);
80
+ } else {
81
+ for (const tool of input.protocolTools) active.add(tool);
82
+ for (const [name, capability] of controlledBuiltins) {
83
+ const allowed = isControlledToolAllowed({
84
+ enabled: input.enabled,
85
+ capability,
86
+ access: input.access,
87
+ });
88
+ if (allowed) {
89
+ if (withheld.delete(name)) active.add(name);
90
+ } else if (active.delete(name)) {
91
+ withheld.add(name);
92
+ }
93
+ }
94
+ }
89
95
 
90
- return {
91
- activeTools: [...active],
92
- memory: { withheldBuiltins: withheld },
93
- };
96
+ return {
97
+ activeTools: [...active],
98
+ memory: { withheldBuiltins: withheld },
99
+ };
94
100
  }