@doingdev/opencode-claude-manager-plugin 0.1.20 → 0.1.21

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.
Files changed (56) hide show
  1. package/README.md +40 -129
  2. package/dist/index.d.ts +5 -4
  3. package/dist/index.js +5 -4
  4. package/dist/plugin/orchestrator.plugin.d.ts +14 -0
  5. package/dist/plugin/orchestrator.plugin.js +108 -0
  6. package/dist/prompts/registry.d.ts +8 -2
  7. package/dist/prompts/registry.js +30 -159
  8. package/dist/safety/bash-safety.d.ts +21 -0
  9. package/dist/safety/bash-safety.js +62 -0
  10. package/package.json +3 -6
  11. package/dist/claude/claude-agent-sdk-adapter.d.ts +0 -27
  12. package/dist/claude/claude-agent-sdk-adapter.js +0 -520
  13. package/dist/claude/claude-session.service.d.ts +0 -15
  14. package/dist/claude/claude-session.service.js +0 -23
  15. package/dist/claude/delegated-can-use-tool.d.ts +0 -7
  16. package/dist/claude/delegated-can-use-tool.js +0 -178
  17. package/dist/claude/session-live-tailer.d.ts +0 -51
  18. package/dist/claude/session-live-tailer.js +0 -269
  19. package/dist/claude/tool-approval-manager.d.ts +0 -27
  20. package/dist/claude/tool-approval-manager.js +0 -238
  21. package/dist/manager/context-tracker.d.ts +0 -33
  22. package/dist/manager/context-tracker.js +0 -108
  23. package/dist/manager/git-operations.d.ts +0 -12
  24. package/dist/manager/git-operations.js +0 -76
  25. package/dist/manager/manager-orchestrator.d.ts +0 -17
  26. package/dist/manager/manager-orchestrator.js +0 -178
  27. package/dist/manager/parallel-session-job-manager.d.ts +0 -49
  28. package/dist/manager/parallel-session-job-manager.js +0 -177
  29. package/dist/manager/persistent-manager.d.ts +0 -74
  30. package/dist/manager/persistent-manager.js +0 -167
  31. package/dist/manager/session-controller.d.ts +0 -45
  32. package/dist/manager/session-controller.js +0 -147
  33. package/dist/manager/task-planner.d.ts +0 -5
  34. package/dist/manager/task-planner.js +0 -15
  35. package/dist/metadata/claude-metadata.service.d.ts +0 -12
  36. package/dist/metadata/claude-metadata.service.js +0 -38
  37. package/dist/metadata/repo-claude-config-reader.d.ts +0 -7
  38. package/dist/metadata/repo-claude-config-reader.js +0 -154
  39. package/dist/plugin/claude-code-permission-bridge.d.ts +0 -15
  40. package/dist/plugin/claude-code-permission-bridge.js +0 -184
  41. package/dist/plugin/claude-manager.plugin.d.ts +0 -2
  42. package/dist/plugin/claude-manager.plugin.js +0 -627
  43. package/dist/plugin/service-factory.d.ts +0 -12
  44. package/dist/plugin/service-factory.js +0 -41
  45. package/dist/state/file-run-state-store.d.ts +0 -14
  46. package/dist/state/file-run-state-store.js +0 -87
  47. package/dist/state/transcript-store.d.ts +0 -15
  48. package/dist/state/transcript-store.js +0 -44
  49. package/dist/types/contracts.d.ts +0 -215
  50. package/dist/types/contracts.js +0 -1
  51. package/dist/util/fs-helpers.d.ts +0 -2
  52. package/dist/util/fs-helpers.js +0 -12
  53. package/dist/util/transcript-append.d.ts +0 -7
  54. package/dist/util/transcript-append.js +0 -29
  55. package/dist/worktree/worktree-coordinator.d.ts +0 -21
  56. package/dist/worktree/worktree-coordinator.js +0 -64
@@ -1,12 +0,0 @@
1
- import type { ClaudeMetadataSnapshot, ClaudeSettingSource } from '../types/contracts.js';
2
- import type { ClaudeAgentSdkAdapter } from '../claude/claude-agent-sdk-adapter.js';
3
- import type { RepoClaudeConfigReader } from './repo-claude-config-reader.js';
4
- export declare class ClaudeMetadataService {
5
- private readonly configReader;
6
- private readonly sdkAdapter;
7
- constructor(configReader: RepoClaudeConfigReader, sdkAdapter: ClaudeAgentSdkAdapter);
8
- collect(cwd: string, options?: {
9
- includeSdkProbe?: boolean;
10
- settingSources?: ClaudeSettingSource[];
11
- }): Promise<ClaudeMetadataSnapshot>;
12
- }
@@ -1,38 +0,0 @@
1
- export class ClaudeMetadataService {
2
- configReader;
3
- sdkAdapter;
4
- constructor(configReader, sdkAdapter) {
5
- this.configReader = configReader;
6
- this.sdkAdapter = sdkAdapter;
7
- }
8
- async collect(cwd, options = {}) {
9
- const baseSnapshot = await this.configReader.read(cwd);
10
- if (!options.includeSdkProbe) {
11
- return dedupeSnapshot(baseSnapshot);
12
- }
13
- const capabilities = await this.sdkAdapter.probeCapabilities(cwd, options.settingSources);
14
- return dedupeSnapshot({
15
- ...baseSnapshot,
16
- commands: [...baseSnapshot.commands, ...capabilities.commands],
17
- agents: capabilities.agents,
18
- });
19
- }
20
- }
21
- function dedupeSnapshot(snapshot) {
22
- return {
23
- ...snapshot,
24
- commands: dedupeByName(snapshot.commands),
25
- skills: dedupeByName(snapshot.skills),
26
- hooks: dedupeByName(snapshot.hooks),
27
- agents: dedupeByName(snapshot.agents),
28
- };
29
- }
30
- function dedupeByName(items) {
31
- const seen = new Map();
32
- for (const item of items) {
33
- if (!seen.has(item.name)) {
34
- seen.set(item.name, item);
35
- }
36
- }
37
- return [...seen.values()].sort((left, right) => left.name.localeCompare(right.name));
38
- }
@@ -1,7 +0,0 @@
1
- import type { ClaudeMetadataSnapshot } from '../types/contracts.js';
2
- export declare class RepoClaudeConfigReader {
3
- read(cwd: string): Promise<ClaudeMetadataSnapshot>;
4
- private readSkills;
5
- private readCommands;
6
- private readSettings;
7
- }
@@ -1,154 +0,0 @@
1
- import { promises as fs } from 'node:fs';
2
- import path from 'node:path';
3
- import JSON5 from 'json5';
4
- export class RepoClaudeConfigReader {
5
- async read(cwd) {
6
- const claudeDirectory = path.join(cwd, '.claude');
7
- const skillsDirectory = path.join(claudeDirectory, 'skills');
8
- const commandsDirectory = path.join(claudeDirectory, 'commands');
9
- const claudeMdCandidates = [
10
- path.join(cwd, 'CLAUDE.md'),
11
- path.join(claudeDirectory, 'CLAUDE.md'),
12
- ];
13
- const collectedAt = new Date().toISOString();
14
- const [skills, commands, settingsResult, claudeMdPath] = await Promise.all([
15
- this.readSkills(skillsDirectory),
16
- this.readCommands(commandsDirectory),
17
- this.readSettings(claudeDirectory),
18
- findFirstExistingPath(claudeMdCandidates),
19
- ]);
20
- return {
21
- collectedAt,
22
- cwd,
23
- commands: [...skillsToCommands(skills), ...commands],
24
- skills,
25
- hooks: settingsResult.hooks,
26
- agents: [],
27
- claudeMdPath: claudeMdPath ?? undefined,
28
- settingsPaths: settingsResult.settingsPaths,
29
- };
30
- }
31
- async readSkills(directory) {
32
- if (!(await pathExists(directory))) {
33
- return [];
34
- }
35
- const entries = await fs.readdir(directory, { withFileTypes: true });
36
- const skills = await Promise.all(entries
37
- .filter((entry) => entry.isDirectory())
38
- .map(async (entry) => {
39
- const skillPath = path.join(directory, entry.name, 'SKILL.md');
40
- if (!(await pathExists(skillPath))) {
41
- return null;
42
- }
43
- const content = await fs.readFile(skillPath, 'utf8');
44
- return {
45
- name: entry.name,
46
- description: extractMarkdownDescription(content),
47
- path: skillPath,
48
- source: 'skill',
49
- };
50
- }));
51
- return skills.filter((skill) => skill !== null);
52
- }
53
- async readCommands(directory) {
54
- if (!(await pathExists(directory))) {
55
- return [];
56
- }
57
- const commandFiles = await collectMarkdownFiles(directory);
58
- const commands = await Promise.all(commandFiles.map(async (commandPath) => {
59
- const content = await fs.readFile(commandPath, 'utf8');
60
- return {
61
- name: path.basename(commandPath, path.extname(commandPath)),
62
- description: extractMarkdownDescription(content),
63
- source: 'command',
64
- path: commandPath,
65
- };
66
- }));
67
- return commands.sort((left, right) => left.name.localeCompare(right.name));
68
- }
69
- async readSettings(claudeDirectory) {
70
- const candidatePaths = [
71
- path.join(claudeDirectory, 'settings.json'),
72
- path.join(claudeDirectory, 'settings.local.json'),
73
- ];
74
- const settingsPaths = [];
75
- const hooks = [];
76
- for (const candidatePath of candidatePaths) {
77
- if (!(await pathExists(candidatePath))) {
78
- continue;
79
- }
80
- settingsPaths.push(candidatePath);
81
- const content = await fs.readFile(candidatePath, 'utf8');
82
- const parsed = JSON5.parse(content);
83
- const hookEntries = Object.entries(parsed.hooks ?? {});
84
- for (const [hookName, hookValue] of hookEntries) {
85
- const hookMatchers = Array.isArray(hookValue) ? hookValue : [hookValue];
86
- for (const hookMatcher of hookMatchers) {
87
- if (!hookMatcher || typeof hookMatcher !== 'object') {
88
- continue;
89
- }
90
- const matcher = typeof hookMatcher.matcher === 'string'
91
- ? hookMatcher.matcher
92
- : undefined;
93
- const commandCount = Array.isArray(hookMatcher.hooks)
94
- ? (hookMatcher.hooks?.length ?? 0)
95
- : 0;
96
- hooks.push({
97
- name: hookName,
98
- matcher,
99
- sourcePath: candidatePath,
100
- commandCount,
101
- });
102
- }
103
- }
104
- }
105
- return {
106
- settingsPaths,
107
- hooks,
108
- };
109
- }
110
- }
111
- function extractMarkdownDescription(markdown) {
112
- const lines = markdown
113
- .split(/\r?\n/)
114
- .map((line) => line.trim())
115
- .filter(Boolean);
116
- const descriptionLine = lines.find((line) => !line.startsWith('#') && !line.startsWith('---'));
117
- return descriptionLine ?? 'No description provided.';
118
- }
119
- async function collectMarkdownFiles(directory) {
120
- const entries = await fs.readdir(directory, { withFileTypes: true });
121
- const files = await Promise.all(entries.map(async (entry) => {
122
- const resolvedPath = path.join(directory, entry.name);
123
- if (entry.isDirectory()) {
124
- return collectMarkdownFiles(resolvedPath);
125
- }
126
- return entry.name.endsWith('.md') ? [resolvedPath] : [];
127
- }));
128
- return files.flat();
129
- }
130
- async function pathExists(candidatePath) {
131
- try {
132
- await fs.access(candidatePath);
133
- return true;
134
- }
135
- catch {
136
- return false;
137
- }
138
- }
139
- async function findFirstExistingPath(candidatePaths) {
140
- for (const candidatePath of candidatePaths) {
141
- if (await pathExists(candidatePath)) {
142
- return candidatePath;
143
- }
144
- }
145
- return null;
146
- }
147
- function skillsToCommands(skills) {
148
- return skills.map((skill) => ({
149
- name: skill.name,
150
- description: skill.description,
151
- source: 'skill',
152
- path: skill.path,
153
- }));
154
- }
@@ -1,15 +0,0 @@
1
- import type { ToolContext } from '@opencode-ai/plugin';
2
- import type { ManagerSessionCanUseToolFactory } from '../types/contracts.js';
3
- export interface ClaudeCodePermissionBridge {
4
- createCanUseTool: ManagerSessionCanUseToolFactory;
5
- }
6
- /**
7
- * Bridges Claude Agent SDK tool permission prompts to OpenCode `ToolContext.ask`.
8
- * Serializes concurrent asks: parallel manager sub-sessions share one OpenCode tool context.
9
- *
10
- * AskUserQuestion: OpenCode `ask` does not return selected labels. After approval we return
11
- * allow with answers set to each question's first option label so the session can proceed;
12
- * the UI should still show full choices — users needing a different option should answer via
13
- * the primary agent and re-run.
14
- */
15
- export declare function createClaudeCodePermissionBridge(context: ToolContext): ClaudeCodePermissionBridge;
@@ -1,184 +0,0 @@
1
- /**
2
- * Bridges Claude Agent SDK tool permission prompts to OpenCode `ToolContext.ask`.
3
- * Serializes concurrent asks: parallel manager sub-sessions share one OpenCode tool context.
4
- *
5
- * AskUserQuestion: OpenCode `ask` does not return selected labels. After approval we return
6
- * allow with answers set to each question's first option label so the session can proceed;
7
- * the UI should still show full choices — users needing a different option should answer via
8
- * the primary agent and re-run.
9
- */
10
- export function createClaudeCodePermissionBridge(context) {
11
- const queue = createPermissionAskQueue();
12
- return {
13
- createCanUseTool(scope) {
14
- return (toolName, input, options) => queue.enqueue(() => bridgeCanUseTool(context, scope, toolName, input, options));
15
- },
16
- };
17
- }
18
- function createPermissionAskQueue() {
19
- let chain = Promise.resolve();
20
- return {
21
- enqueue(operation) {
22
- const resultPromise = chain
23
- .catch(() => undefined)
24
- .then(operation);
25
- chain = resultPromise.then(() => undefined, () => undefined);
26
- return resultPromise;
27
- },
28
- };
29
- }
30
- async function bridgeCanUseTool(context, scope, toolName, input, options) {
31
- if (options.signal.aborted) {
32
- return {
33
- behavior: 'deny',
34
- message: 'Permission request aborted.',
35
- toolUseID: options.toolUseID,
36
- };
37
- }
38
- if (toolName === 'AskUserQuestion') {
39
- return handleAskUserQuestion(context, scope, input, options);
40
- }
41
- const permission = mapClaudeToolToOpenCodePermission(toolName);
42
- const patterns = derivePatterns(toolName, input);
43
- const metadata = buildMetadata(scope, toolName, input, options);
44
- try {
45
- await context.ask({
46
- permission,
47
- patterns,
48
- always: [],
49
- metadata,
50
- });
51
- return {
52
- behavior: 'allow',
53
- updatedInput: input,
54
- toolUseID: options.toolUseID,
55
- };
56
- }
57
- catch (error) {
58
- return {
59
- behavior: 'deny',
60
- message: error instanceof Error
61
- ? error.message
62
- : 'OpenCode permission request was rejected or failed.',
63
- toolUseID: options.toolUseID,
64
- };
65
- }
66
- }
67
- async function handleAskUserQuestion(context, scope, input, options) {
68
- const questions = input.questions;
69
- if (!Array.isArray(questions) || questions.length === 0) {
70
- return {
71
- behavior: 'deny',
72
- message: 'AskUserQuestion invoked without a valid questions array.',
73
- toolUseID: options.toolUseID,
74
- };
75
- }
76
- const metadata = {
77
- ...buildMetadata(scope, 'AskUserQuestion', input, options),
78
- questions,
79
- note: 'Claude Code AskUserQuestion: approving proceeds with the first listed option per question unless the host supplies structured replies.',
80
- };
81
- try {
82
- await context.ask({
83
- permission: 'question',
84
- patterns: [],
85
- always: [],
86
- metadata,
87
- });
88
- const answers = buildDefaultAskUserQuestionAnswers(questions);
89
- return {
90
- behavior: 'allow',
91
- updatedInput: {
92
- ...input,
93
- questions,
94
- answers,
95
- },
96
- toolUseID: options.toolUseID,
97
- };
98
- }
99
- catch (error) {
100
- return {
101
- behavior: 'deny',
102
- message: error instanceof Error
103
- ? error.message
104
- : 'OpenCode declined or failed the clarifying-question prompt.',
105
- toolUseID: options.toolUseID,
106
- };
107
- }
108
- }
109
- function buildDefaultAskUserQuestionAnswers(questions) {
110
- const answers = {};
111
- for (const raw of questions) {
112
- if (!raw || typeof raw !== 'object') {
113
- continue;
114
- }
115
- const entry = raw;
116
- const questionText = typeof entry.question === 'string' ? entry.question : '';
117
- if (!questionText) {
118
- continue;
119
- }
120
- const options = Array.isArray(entry.options) ? entry.options : [];
121
- const first = options[0];
122
- const label = first &&
123
- typeof first === 'object' &&
124
- first !== null &&
125
- typeof first.label === 'string'
126
- ? first.label
127
- : 'Default';
128
- answers[questionText] = label;
129
- }
130
- return answers;
131
- }
132
- function mapClaudeToolToOpenCodePermission(toolName) {
133
- switch (toolName) {
134
- case 'Read':
135
- return 'read';
136
- case 'Write':
137
- case 'Edit':
138
- case 'NotebookEdit':
139
- return 'edit';
140
- case 'Bash':
141
- return 'bash';
142
- case 'Glob':
143
- return 'glob';
144
- case 'Grep':
145
- return 'grep';
146
- case 'Task':
147
- case 'Agent':
148
- return 'task';
149
- case 'WebFetch':
150
- return 'webfetch';
151
- case 'WebSearch':
152
- return 'websearch';
153
- default:
154
- return 'bash';
155
- }
156
- }
157
- function derivePatterns(toolName, input) {
158
- const filePath = input.file_path ?? input.path;
159
- if (typeof filePath === 'string' && filePath.length > 0) {
160
- return [filePath];
161
- }
162
- if (toolName === 'Bash' && typeof input.command === 'string') {
163
- return [input.command];
164
- }
165
- return [];
166
- }
167
- function buildMetadata(scope, toolName, input, options) {
168
- return {
169
- source: 'claude_code',
170
- managerRunId: scope.runId,
171
- managerPlanId: scope.planId,
172
- managerPlanTitle: scope.planTitle,
173
- claudeTool: toolName,
174
- toolInput: input,
175
- toolUseID: options.toolUseID,
176
- agentID: options.agentID,
177
- title: options.title,
178
- displayName: options.displayName,
179
- description: options.description,
180
- blockedPath: options.blockedPath,
181
- decisionReason: options.decisionReason,
182
- sdkSuggestions: options.suggestions,
183
- };
184
- }
@@ -1,2 +0,0 @@
1
- import { type Plugin } from '@opencode-ai/plugin';
2
- export declare const ClaudeManagerPlugin: Plugin;