@myrialabs/clopen 0.4.8 → 0.4.10
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/README.md +10 -7
- package/backend/artifacts/detect.ts +129 -0
- package/backend/artifacts/engine-map.ts +53 -0
- package/backend/artifacts/frontmatter.ts +68 -0
- package/backend/artifacts/generate.ts +105 -0
- package/backend/artifacts/index.ts +34 -0
- package/backend/artifacts/markers.ts +76 -0
- package/backend/artifacts/matrix.ts +247 -0
- package/backend/artifacts/slug.ts +35 -0
- package/backend/artifacts/sync.ts +130 -0
- package/backend/artifacts/types.ts +152 -0
- package/backend/auth/permissions.ts +51 -1
- package/backend/chat/stream-manager.ts +14 -1
- package/backend/commands/detect.ts +25 -0
- package/backend/commands/index.ts +9 -0
- package/backend/commands/service.ts +178 -0
- package/backend/commands/store.ts +45 -0
- package/backend/commands/sync.ts +94 -0
- package/backend/database/migrations/045_create_commands_table.ts +28 -0
- package/backend/database/migrations/046_create_subagents_table.ts +29 -0
- package/backend/database/migrations/047_create_instructions_table.ts +29 -0
- package/backend/database/migrations/048_add_mcp_tool_overrides.ts +23 -0
- package/backend/database/migrations/049_create_permission_sets_table.ts +50 -0
- package/backend/database/migrations/050_create_profiles_tables.ts +57 -0
- package/backend/database/migrations/051_add_profile_to_sessions.ts +20 -0
- package/backend/database/migrations/052_add_default_profile_to_projects.ts +20 -0
- package/backend/database/migrations/053_add_profile_to_permission_sets.ts +37 -0
- package/backend/database/migrations/054_drop_subagent_agent_type.ts +20 -0
- package/backend/database/migrations/055_artifact_model_tools_per_engine.ts +43 -0
- package/backend/database/migrations/index.ts +77 -0
- package/backend/database/queries/command-queries.ts +82 -0
- package/backend/database/queries/index.ts +12 -2
- package/backend/database/queries/instruction-queries.ts +62 -0
- package/backend/database/queries/mcp-server-queries.ts +25 -0
- package/backend/database/queries/permission-set-queries.ts +155 -0
- package/backend/database/queries/profile-queries.ts +118 -0
- package/backend/database/queries/project-queries.ts +14 -0
- package/backend/database/queries/session-queries.ts +21 -0
- package/backend/database/queries/subagent-queries.ts +92 -0
- package/backend/engine/adapters/claude/stream.ts +27 -3
- package/backend/engine/adapters/codex/stream.ts +46 -14
- package/backend/engine/adapters/copilot/stream.ts +58 -4
- package/backend/engine/adapters/opencode/message-converter.ts +22 -2
- package/backend/engine/adapters/opencode/server.ts +166 -210
- package/backend/engine/adapters/opencode/stream.ts +150 -24
- package/backend/engine/adapters/qwen/stream.ts +23 -3
- package/backend/engine/artifact-sync.ts +51 -0
- package/backend/engine/types.ts +6 -0
- package/backend/instructions/index.ts +8 -0
- package/backend/instructions/service.ts +63 -0
- package/backend/instructions/sync.ts +56 -0
- package/backend/mcp/external/config.ts +42 -20
- package/backend/mcp/external/proxy.ts +89 -5
- package/backend/mcp/external/tools.ts +88 -0
- package/backend/mcp/index.ts +38 -15
- package/backend/mcp/internal/config.ts +48 -11
- package/backend/mcp/internal/remote-server.ts +9 -1
- package/backend/permissions/index.ts +27 -0
- package/backend/permissions/materialize.ts +96 -0
- package/backend/permissions/resolve.test.ts +162 -0
- package/backend/permissions/resolve.ts +106 -0
- package/backend/permissions/service.ts +167 -0
- package/backend/profiles/index.ts +10 -0
- package/backend/profiles/service.ts +169 -0
- package/backend/project/status-manager.ts +7 -25
- package/backend/skills/index.ts +1 -1
- package/backend/skills/sync.ts +88 -128
- package/backend/subagents/detect.ts +23 -0
- package/backend/subagents/index.ts +10 -0
- package/backend/subagents/service.ts +166 -0
- package/backend/subagents/store.ts +44 -0
- package/backend/subagents/sync.ts +144 -0
- package/backend/utils/static-curl.ts +12 -54
- package/backend/ws/artifacts/generate.ts +51 -0
- package/backend/ws/artifacts/index.ts +8 -0
- package/backend/ws/chat/stream.ts +33 -2
- package/backend/ws/commands/crud.ts +157 -0
- package/backend/ws/commands/index.ts +8 -0
- package/backend/ws/git/branch.ts +4 -2
- package/backend/ws/git/remote.ts +21 -11
- package/backend/ws/index.ts +17 -1
- package/backend/ws/instructions/crud.ts +53 -0
- package/backend/ws/instructions/index.ts +8 -0
- package/backend/ws/mcp/crud.ts +7 -1
- package/backend/ws/mcp/index.ts +4 -1
- package/backend/ws/mcp/tools.ts +112 -0
- package/backend/ws/permissions/crud.ts +72 -0
- package/backend/ws/permissions/index.ts +8 -0
- package/backend/ws/profiles/crud.ts +149 -0
- package/backend/ws/profiles/index.ts +9 -0
- package/backend/ws/sessions/crud.ts +12 -0
- package/backend/ws/subagents/crud.ts +136 -0
- package/backend/ws/subagents/index.ts +8 -0
- package/dist/assets/{index-jGo0X72U.js → index-C3kp8wpM.js} +1 -1
- package/dist/assets/{index-B_F_OgoC.js → index-cVUk7das.js} +1 -1
- package/dist/assets/main-CuCxUeqZ.js +533 -0
- package/dist/assets/main-D4pdkiQK.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +24 -24
- package/shared/constants/engine-tools.ts +56 -0
- package/shared/types/database/schema.ts +2 -0
- package/shared/types/stores/settings.ts +15 -0
- package/shared/types/unified/stream.ts +7 -0
- package/shared/utils/interactive-input.ts +71 -0
- package/shared/utils/logger.ts +6 -0
- package/dist/assets/main-BkCc3WEB.js +0 -481
- package/dist/assets/main-CWDwET4x.css +0 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in tool catalog per engine — the inventory the Permissions UI offers for
|
|
3
|
+
* allow/deny rules, alongside MCP tools (from Connectors) and subagent tool
|
|
4
|
+
* allowlists.
|
|
5
|
+
*
|
|
6
|
+
* Tool NAMES must match what each engine reports at its permission hook, or a
|
|
7
|
+
* deny rule silently won't match. Only Claude's names are authoritative (the
|
|
8
|
+
* Agent SDK's canonical PascalCase tool names); every other engine is
|
|
9
|
+
* BEST-EFFORT — the runtime hook receives the engine's own casing/aliases, and
|
|
10
|
+
* these lists are a curated starting point the admin can extend with free-text
|
|
11
|
+
* patterns. See {@link ENGINE_TOOLS_BEST_EFFORT}.
|
|
12
|
+
*
|
|
13
|
+
* Copilot is special: its permission hook decides by operation `kind`
|
|
14
|
+
* (`shell` / `write` / `read` / `url` / `memory`), not by a builtin tool name,
|
|
15
|
+
* so its catalog lists those kind tokens (matched in the adapter). MCP/custom
|
|
16
|
+
* tools still match by `toolName`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { EngineType } from '$shared/types/unified';
|
|
20
|
+
|
|
21
|
+
export const ENGINE_BUILTIN_TOOLS: Record<EngineType, string[]> = {
|
|
22
|
+
// Claude Code — canonical Agent SDK tool names (authoritative).
|
|
23
|
+
'claude-code': [
|
|
24
|
+
'Bash',
|
|
25
|
+
'Edit',
|
|
26
|
+
'Write',
|
|
27
|
+
'Read',
|
|
28
|
+
'Glob',
|
|
29
|
+
'Grep',
|
|
30
|
+
'WebFetch',
|
|
31
|
+
'WebSearch',
|
|
32
|
+
'Task',
|
|
33
|
+
'NotebookEdit',
|
|
34
|
+
'TodoWrite'
|
|
35
|
+
],
|
|
36
|
+
// OpenCode — lowercase tool ids (best-effort).
|
|
37
|
+
opencode: ['bash', 'edit', 'write', 'read', 'grep', 'glob', 'list', 'webfetch', 'task', 'todowrite', 'patch'],
|
|
38
|
+
// Copilot — permission KINDS, not tool names (best-effort; matched by kind).
|
|
39
|
+
copilot: ['shell', 'write', 'read', 'url', 'memory'],
|
|
40
|
+
// Codex — custom-prompt / core tool ids (best-effort).
|
|
41
|
+
codex: ['shell', 'apply_patch', 'update_plan', 'read_file', 'web_search'],
|
|
42
|
+
// Qwen Code — snake_case tool names as passed to canUseTool (best-effort).
|
|
43
|
+
qwen: ['run_shell_command', 'read_file', 'write_file', 'read_many_files', 'grep', 'glob', 'ls', 'web_fetch', 'web_search']
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Engines whose permission enforcement is best-effort. Only Codex — it has no
|
|
48
|
+
* per-call permission hook (Claude/Qwen/Copilot/OpenCode all enforce at runtime).
|
|
49
|
+
*/
|
|
50
|
+
export const ENGINE_TOOLS_BEST_EFFORT: Record<EngineType, boolean> = {
|
|
51
|
+
'claude-code': false,
|
|
52
|
+
opencode: false,
|
|
53
|
+
copilot: false,
|
|
54
|
+
codex: true,
|
|
55
|
+
qwen: false
|
|
56
|
+
};
|
|
@@ -11,6 +11,7 @@ export interface Project {
|
|
|
11
11
|
path: string;
|
|
12
12
|
created_at: string;
|
|
13
13
|
last_opened_at: string;
|
|
14
|
+
default_profile_id?: number | null; // Shared per-project default Profile (null = none)
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface ChatSession {
|
|
@@ -28,6 +29,7 @@ export interface ChatSession {
|
|
|
28
29
|
model_name?: string; // Display name (e.g., 'Sonnet 4.6', 'GPT-5.2')
|
|
29
30
|
account_id?: number; // Engine account used for this session
|
|
30
31
|
account_name?: string; // Display name of the selected account
|
|
32
|
+
profile_id?: number | null; // Active Profile bundle for this session (null = use project default / none)
|
|
31
33
|
|
|
32
34
|
// ── HEAD state (re-derived when HEAD changes: undo/redo/restore/branch) ──
|
|
33
35
|
head_message_id?: string; // Git-like HEAD pointer to current branch tip
|
|
@@ -29,6 +29,19 @@ export interface CommitGeneratorSettings {
|
|
|
29
29
|
branchConfig: BranchNameConfig;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* AI authoring model for generating Skills/Commands/Subagents/Instructions from a
|
|
34
|
+
* purpose sentence. Optional — when absent (or `useCustomModel` false), the
|
|
35
|
+
* assistant model (selectedEngine/selectedModel) is used.
|
|
36
|
+
*/
|
|
37
|
+
export interface ArtifactGeneratorSettings {
|
|
38
|
+
useCustomModel: boolean;
|
|
39
|
+
engine: EngineType;
|
|
40
|
+
provider: string;
|
|
41
|
+
modelId: string;
|
|
42
|
+
modelName: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
32
45
|
/** Per-user settings (stored per user) */
|
|
33
46
|
export interface AppSettings {
|
|
34
47
|
selectedEngine: EngineType;
|
|
@@ -54,6 +67,8 @@ export interface AppSettings {
|
|
|
54
67
|
gitDiffSideBySide: boolean;
|
|
55
68
|
/** AI commit message generator configuration */
|
|
56
69
|
commitGenerator: CommitGeneratorSettings;
|
|
70
|
+
/** AI authoring model for artifact generation (optional; falls back to assistant model) */
|
|
71
|
+
artifactGenerator?: ArtifactGeneratorSettings;
|
|
57
72
|
/** Pinned model IDs — shown at top of provider group in model picker */
|
|
58
73
|
pinnedModels: string[];
|
|
59
74
|
}
|
|
@@ -176,4 +176,11 @@ export interface StreamRequest {
|
|
|
176
176
|
prompt: UserMessage;
|
|
177
177
|
engine: MessageEngine;
|
|
178
178
|
sender: MessageSender;
|
|
179
|
+
/**
|
|
180
|
+
* Active Profile chosen for this session (bundle of Skills/Commands/Subagents/
|
|
181
|
+
* MCP/Permissions). `null` = explicit "no profile"; `undefined` = client didn't
|
|
182
|
+
* send one → the stream falls back to the project's default profile. Persisted
|
|
183
|
+
* to `chat_sessions.profile_id` like engine/model.
|
|
184
|
+
*/
|
|
185
|
+
profileId?: number | null;
|
|
179
186
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for the "is this conversation waiting for user input?"
|
|
3
|
+
* derivation. Both the backend presence layer (status-manager) and the frontend
|
|
4
|
+
* chat service consume this so the logic can never drift between them.
|
|
5
|
+
*
|
|
6
|
+
* Historically this logic was duplicated in three places with subtly different
|
|
7
|
+
* rules, which let the "Needs input" status get stuck after an interrupt →
|
|
8
|
+
* continue flow. Keeping one pure function here removes that class of bug.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Tools that block the stream waiting for a user response. */
|
|
12
|
+
export const INTERACTIVE_TOOLS = new Set(['AskUserQuestion']);
|
|
13
|
+
|
|
14
|
+
/** Minimal structural shape shared by UnifiedMessage and its frontend supersets. */
|
|
15
|
+
interface WaitingInputMessage {
|
|
16
|
+
type: string;
|
|
17
|
+
stopReason?: string | null;
|
|
18
|
+
content?: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface WaitingInputBlock {
|
|
22
|
+
type: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
interrupted?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A conversation is "waiting for user input" if and only if its trailing turn
|
|
29
|
+
* contains an unanswered, non-interrupted interactive tool_use.
|
|
30
|
+
*
|
|
31
|
+
* The rule is intentionally derived from message ordering rather than tracked
|
|
32
|
+
* imperatively, so it stays correct across every entry path:
|
|
33
|
+
* - Answered normally → the tool_result (a user message) lands after the
|
|
34
|
+
* question, so the question is no longer trailing.
|
|
35
|
+
* - Interrupted → continue → the follow-up user message lands after the
|
|
36
|
+
* question, so it is no longer trailing (was the bug).
|
|
37
|
+
* - Interrupted, no follow → the question turn is marked interrupted (via the
|
|
38
|
+
* message stopReason or the block flag) and skipped.
|
|
39
|
+
* - Genuinely pending → the question is the trailing turn and counts.
|
|
40
|
+
*
|
|
41
|
+
* Both interrupted representations are honored (message `stopReason` set by the
|
|
42
|
+
* backend, block `interrupted` set by the frontend) so the reader tolerates
|
|
43
|
+
* either signal regardless of which side produced the messages.
|
|
44
|
+
*/
|
|
45
|
+
export function isWaitingForInteractiveInput(messages: readonly WaitingInputMessage[]): boolean {
|
|
46
|
+
// Find the index of the last user message — anything before it has already
|
|
47
|
+
// been superseded by subsequent user activity and cannot be pending.
|
|
48
|
+
let lastUserIndex = -1;
|
|
49
|
+
for (let i = 0; i < messages.length; i++) {
|
|
50
|
+
if (messages[i]?.type === 'user') lastUserIndex = i;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
for (let i = lastUserIndex + 1; i < messages.length; i++) {
|
|
54
|
+
const msg = messages[i];
|
|
55
|
+
if (!msg || msg.type !== 'assistant') continue;
|
|
56
|
+
// An interrupted assistant turn never counts as waiting.
|
|
57
|
+
if (msg.stopReason === 'interrupted') continue;
|
|
58
|
+
if (!Array.isArray(msg.content)) continue;
|
|
59
|
+
|
|
60
|
+
const hasPending = (msg.content as WaitingInputBlock[]).some(
|
|
61
|
+
block =>
|
|
62
|
+
block?.type === 'tool_use' &&
|
|
63
|
+
!!block.name &&
|
|
64
|
+
INTERACTIVE_TOOLS.has(block.name) &&
|
|
65
|
+
!block.interrupted
|
|
66
|
+
);
|
|
67
|
+
if (hasPending) return true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return false;
|
|
71
|
+
}
|