@cjhyy/code-shell-core 0.8.11 → 0.8.12

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 (47) hide show
  1. package/dist/capabilities/index.d.ts +5 -54
  2. package/dist/capabilities/index.js +1 -80
  3. package/dist/cli/agent-server-stdio.js +21 -21
  4. package/dist/composition/compiler.d.ts +7 -0
  5. package/dist/composition/compiler.js +247 -0
  6. package/dist/composition/core-module.d.ts +10 -0
  7. package/dist/composition/core-module.js +19 -0
  8. package/dist/composition/index.d.ts +5 -0
  9. package/dist/composition/index.js +5 -0
  10. package/dist/composition/protocol-attach.d.ts +15 -0
  11. package/dist/composition/protocol-attach.js +21 -0
  12. package/dist/composition/resolve-preset.d.ts +35 -0
  13. package/dist/composition/resolve-preset.js +58 -0
  14. package/dist/composition/snapshot.d.ts +9 -0
  15. package/dist/composition/snapshot.js +48 -0
  16. package/dist/composition/types.d.ts +169 -0
  17. package/dist/composition/types.js +1 -0
  18. package/dist/engine/engine.d.ts +2 -1
  19. package/dist/engine/engine.js +54 -56
  20. package/dist/engine/subagent-spawner.js +2 -2
  21. package/dist/engine/types.d.ts +9 -6
  22. package/dist/exceptions.d.ts +8 -0
  23. package/dist/exceptions.js +11 -0
  24. package/dist/index.d.ts +8 -8
  25. package/dist/index.extension.d.ts +3 -3
  26. package/dist/index.extension.js +0 -1
  27. package/dist/index.js +6 -6
  28. package/dist/preset/index.d.ts +19 -26
  29. package/dist/preset/index.js +26 -66
  30. package/dist/product/define.js +8 -2
  31. package/dist/prompt/section-loader.d.ts +2 -8
  32. package/dist/prompt/section-loader.js +4 -17
  33. package/dist/protocol/client.d.ts +1 -0
  34. package/dist/protocol/server.d.ts +10 -11
  35. package/dist/protocol/server.js +33 -28
  36. package/dist/protocol/types.d.ts +5 -0
  37. package/dist/run/EngineRunner.d.ts +3 -2
  38. package/dist/run/EngineRunner.js +1 -1
  39. package/dist/run/RunManager.d.ts +3 -3
  40. package/dist/run/RunManager.js +6 -8
  41. package/dist/run/factory.d.ts +3 -3
  42. package/dist/run/factory.js +2 -2
  43. package/dist/session/session-manager.d.ts +1 -1
  44. package/dist/session/session-manager.js +3 -6
  45. package/dist/tool-system/capability-module.d.ts +0 -34
  46. package/dist/tool-system/capability-module.js +1 -53
  47. package/package.json +1 -1
@@ -14,7 +14,7 @@ import type { RunStore } from "./RunStore.js";
14
14
  import { type EngineRunnerConfig, type RunExecutor } from "./EngineRunner.js";
15
15
  import { type Evaluator } from "./Evaluator.js";
16
16
  import type { RunSnapshot, RunEvent, SubmitRunInput, ResumeRunInput, ListRunsQuery, RunStreamCallback, DetachFn } from "./types.js";
17
- import { type CapabilityModule } from "../capabilities/index.js";
17
+ import type { AgentModule } from "../composition/types.js";
18
18
  export interface RunManagerConfig {
19
19
  store: RunStore;
20
20
  /**
@@ -36,8 +36,8 @@ export interface RunManagerConfig {
36
36
  defaultTags?: string[];
37
37
  /** Metadata merged into every submitted run. Submit input wins on conflicts. */
38
38
  defaultMetadata?: Record<string, unknown>;
39
- /** Product/domain capabilities used by the built-in runner and artifact tracker. */
40
- capabilities?: readonly CapabilityModule[];
39
+ /** AgentModules installed into the built-in runner and artifact tracker. */
40
+ modules?: readonly AgentModule[];
41
41
  }
42
42
  export declare class RunManager {
43
43
  private readonly store;
@@ -21,8 +21,7 @@ import { Heartbeat } from "./Heartbeat.js";
21
21
  import { NoopEvaluator } from "./Evaluator.js";
22
22
  import { assertSafeRunFileId, assertSafeRunId } from "./ids.js";
23
23
  import { VALID_TRANSITIONS } from "./types.js";
24
- import { composeArtifactDetectors, resolveCapabilities, } from "../capabilities/index.js";
25
- import { resolveAgentPreset } from "../preset/index.js";
24
+ import { compileComposition } from "../composition/compiler.js";
26
25
  function hasOwnString(value, key) {
27
26
  return (value !== undefined &&
28
27
  Object.prototype.hasOwnProperty.call(value, key) &&
@@ -65,13 +64,12 @@ export class RunManager {
65
64
  constructor(config) {
66
65
  this.store = config.store;
67
66
  this.queue = new RunQueue({ concurrency: config.concurrency ?? 1 });
68
- const localCapabilities = config.capabilities ??
69
- (isRunExecutor(config.executor) ? [] : (config.executor.capabilities ?? []));
70
- const capabilities = resolveCapabilities(localCapabilities);
67
+ const localModules = config.modules ?? (isRunExecutor(config.executor) ? [] : (config.executor.modules ?? []));
68
+ const composition = compileComposition({ modules: localModules });
71
69
  // Accept either a RunExecutor instance or an EngineRunnerConfig
72
70
  this.runner = isRunExecutor(config.executor)
73
71
  ? config.executor
74
- : new EngineRunner({ ...config.executor, capabilities });
72
+ : new EngineRunner({ ...config.executor, modules: localModules });
75
73
  this.lock = new RunLock({
76
74
  runsDir: config.runsDir,
77
75
  staleMs: config.staleLockMs,
@@ -83,8 +81,8 @@ export class RunManager {
83
81
  this.evaluator = config.evaluator ?? new NoopEvaluator();
84
82
  this.defaultTags = config.defaultTags ?? [];
85
83
  this.defaultMetadata = config.defaultMetadata ?? {};
86
- this.defaultPreset = resolveAgentPreset(undefined, capabilities).name;
87
- this.artifactDetectors = composeArtifactDetectors(capabilities);
84
+ this.defaultPreset = composition.engine.defaultPreset;
85
+ this.artifactDetectors = composition.engine.artifactDetectors.map((c) => c.value);
88
86
  // Wire queue executor
89
87
  this.queue.setExecutor((runId) => this.executeRun(runId));
90
88
  }
@@ -20,7 +20,7 @@
20
20
  import type { LLMConfig, PermissionMode } from "../types.js";
21
21
  import type { EngineConfig, EngineHookConfig } from "../engine/types.js";
22
22
  import type { Evaluator } from "./Evaluator.js";
23
- import type { CapabilityModule } from "../capabilities/index.js";
23
+ import type { AgentModule } from "../composition/types.js";
24
24
  import { RunManager } from "./RunManager.js";
25
25
  export interface CreateRunManagerOptions {
26
26
  /** LLM configuration (required). */
@@ -64,8 +64,8 @@ export interface CreateRunManagerOptions {
64
64
  * the interactive run-aware backend.
65
65
  */
66
66
  approvalBackend?: import("../tool-system/permission.js").ApprovalBackend;
67
- /** Product/domain capabilities installed into each Engine. */
68
- capabilities?: readonly CapabilityModule[];
67
+ /** AgentModules installed into each Engine. */
68
+ modules?: readonly AgentModule[];
69
69
  }
70
70
  /**
71
71
  * Create a fully configured RunManager with one call.
@@ -41,7 +41,7 @@ export function createRunManager(options) {
41
41
  customSystemPrompt: options.customSystemPrompt,
42
42
  appendSystemPrompt: options.appendSystemPrompt,
43
43
  hooks: options.hooks,
44
- capabilities: options.capabilities,
44
+ modules: options.modules,
45
45
  ...(options.approvalBackend ? { approvalBackend: options.approvalBackend } : {}),
46
46
  },
47
47
  concurrency: options.concurrency ?? 1,
@@ -49,6 +49,6 @@ export function createRunManager(options) {
49
49
  evaluator: options.evaluator,
50
50
  defaultTags: options.defaultTags,
51
51
  defaultMetadata: options.defaultMetadata,
52
- capabilities: options.capabilities,
52
+ modules: options.modules,
53
53
  });
54
54
  }
@@ -4,7 +4,7 @@
4
4
  import type { SessionForkLineage, SessionState, SessionKind, SessionWorkspace, TokenUsage, TranscriptEvent } from "../types.js";
5
5
  import { Transcript } from "./transcript.js";
6
6
  import { type GoalConfig, type PersistedGoalTerminationReason } from "../goal/lifecycle.js";
7
- import { type SessionWorkspaceCapability } from "../capabilities/index.js";
7
+ import type { SessionWorkspaceCapability } from "../capabilities/index.js";
8
8
  /** Non-Goal fields accepted by the generic latest-state merge path. */
9
9
  export type SessionStateFieldPatch = Readonly<Partial<Omit<SessionState, "sessionId" | "goalLifecycle" | "activeGoal" | "goalTerminal" | "goalTerminals">>>;
10
10
  export type GoalTerminalSaveOutcome = "persisted" | "obsolete" | "failed";
@@ -11,7 +11,6 @@ import { SessionError } from "../exceptions.js";
11
11
  import { addCumulativeUsage, addTokenUsage, normalizeCumulativeUsageCounters } from "./usage.js";
12
12
  import { armGoalLifecycle, createGoalLifecycle, decodeGoalLifecycle, deriveLegacyGoalId, goalConfigFromLifecycle, isGoalLifecycleCurrent, isSameGoalVersion, mergeGoalTerminals, terminateGoalLifecycle, waitGoalLifecycle, } from "../goal/lifecycle.js";
13
13
  import { lockSync } from "../utils/lockfile.js";
14
- import { resolveCapabilities } from "../capabilities/index.js";
15
14
  // Shared close epochs for SessionManager instances in this process. Concurrent
16
15
  // Engines bind the same epoch; only close advances it. This intentionally does
17
16
  // not claim cross-process/Worker protection.
@@ -299,11 +298,9 @@ export class SessionManager {
299
298
  workspaceCapability;
300
299
  constructor(storageDir, workspaceCapability) {
301
300
  this.sessionsDir = storageDir ?? sessionsRoot();
302
- this.workspaceCapability =
303
- workspaceCapability ??
304
- resolveCapabilities()
305
- .map((capability) => capability.sessionWorkspace)
306
- .find((candidate) => candidate !== undefined);
301
+ // No process-global fallback: the workspace capability comes from the
302
+ // owner's compiled composition (Engine passes it explicitly).
303
+ this.workspaceCapability = workspaceCapability;
307
304
  mkdirSync(this.sessionsDir, { recursive: true, mode: 0o700 });
308
305
  if (process.platform !== "win32")
309
306
  chmodSync(this.sessionsDir, 0o700);
@@ -1,8 +1,5 @@
1
1
  import type { RegisteredTool, StreamEvent } from "../types.js";
2
2
  import type { ToolContext } from "./context.js";
3
- import type { ToolRegistry } from "./registry.js";
4
- import type { BuiltinTool } from "./builtin/index.js";
5
- import type { RunBehaviorProfile } from "../engine/run-types.js";
6
3
  import type { PendingApprovalMetadata } from "../protocol/types.js";
7
4
  export interface ExtensionTool {
8
5
  definition: RegisteredTool;
@@ -60,34 +57,3 @@ export interface ProtocolObserverHost {
60
57
  /** Register a protocol-method/query alias handled by this extension. */
61
58
  registerQuery: (type: string, handler: ExtensionQueryHandler) => void;
62
59
  }
63
- /**
64
- * Trusted, in-process product extension. Core owns the registration seam while
65
- * optional packages own their tools and diagnostic/query surface.
66
- */
67
- export interface ExtensionModule {
68
- readonly id: string;
69
- readonly tools?: readonly ExtensionTool[];
70
- readonly queries?: Readonly<Record<string, ExtensionQueryHandler>>;
71
- /** Named per-run behavior profiles contributed by this extension. */
72
- readonly behaviorProfiles?: readonly RunBehaviorProfile[];
73
- /** Attach a protocol lifecycle observer to an AgentServer. */
74
- readonly createProtocolObserver?: (host: ProtocolObserverHost) => ProtocolObserver;
75
- /** Extra agent/run params validation. Returns an error message or null. */
76
- readonly validateRunParams?: (params: Record<string, unknown>) => string | null;
77
- /** Session kinds this extension owns that must stay out of generic session lists. */
78
- readonly hiddenSessionKinds?: readonly string[];
79
- /**
80
- * Full-metadata tool contributions (exposure tags, availability guards,
81
- * per-turn definition rewrites, default permission rules). These join the
82
- * engine's composed tool catalog exactly like builtin/capability tools do —
83
- * use this instead of `tools` when the tool needs visibility metadata.
84
- */
85
- readonly catalogTools?: readonly BuiltinTool[];
86
- }
87
- export declare function registerExtensionModules(registry: ToolRegistry, modules: readonly ExtensionModule[]): void;
88
- export declare function queryExtensionModules(modules: readonly ExtensionModule[], type: string, params: Readonly<Record<string, unknown>>): Promise<{
89
- handled: false;
90
- } | {
91
- handled: true;
92
- data: unknown;
93
- }>;
@@ -1,53 +1 @@
1
- import { ConfigError } from "../exceptions.js";
2
- function validateExtensionModules(modules) {
3
- const ids = new Set();
4
- const queries = new Set();
5
- const tools = new Set();
6
- for (const module of modules) {
7
- if (ids.has(module.id)) {
8
- throw new ConfigError(`Duplicate capability module id: ${module.id}`, {
9
- duplicateCapabilityId: module.id,
10
- });
11
- }
12
- ids.add(module.id);
13
- for (const tool of module.tools ?? []) {
14
- if (tools.has(tool.definition.name)) {
15
- throw new ConfigError(`Duplicate capability tool: ${tool.definition.name}`, {
16
- duplicateCapabilityTool: tool.definition.name,
17
- });
18
- }
19
- tools.add(tool.definition.name);
20
- }
21
- for (const query of Object.keys(module.queries ?? {})) {
22
- if (queries.has(query)) {
23
- throw new ConfigError(`Duplicate capability query: ${query}`, {
24
- duplicateCapabilityQuery: query,
25
- });
26
- }
27
- queries.add(query);
28
- }
29
- }
30
- }
31
- export function registerExtensionModules(registry, modules) {
32
- validateExtensionModules(modules);
33
- for (const module of modules) {
34
- for (const tool of module.tools ?? []) {
35
- if (registry.hasTool(tool.definition.name)) {
36
- throw new ConfigError(`Capability tool conflicts with registered tool: ${tool.definition.name}`, {
37
- duplicateCapabilityTool: tool.definition.name,
38
- capabilityId: module.id,
39
- });
40
- }
41
- registry.registerTool(tool.definition, tool.execute);
42
- }
43
- }
44
- }
45
- export async function queryExtensionModules(modules, type, params) {
46
- validateExtensionModules(modules);
47
- for (const module of modules) {
48
- const handler = module.queries?.[type];
49
- if (handler)
50
- return { handled: true, data: await handler(params) };
51
- }
52
- return { handled: false };
53
- }
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjhyy/code-shell-core",
3
- "version": "0.8.11",
3
+ "version": "0.8.12",
4
4
  "description": "Core engine for code-shell — agent orchestration, tool execution, hooks, protocol. UI-agnostic.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",