deepclause-sdk 0.0.65 → 0.0.67

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 (92) hide show
  1. package/README.md +83 -6
  2. package/dist/agent.d.ts +1 -0
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +153 -30
  5. package/dist/agent.js.map +1 -1
  6. package/dist/cli/commands.d.ts +5 -0
  7. package/dist/cli/commands.d.ts.map +1 -1
  8. package/dist/cli/commands.js +75 -5
  9. package/dist/cli/commands.js.map +1 -1
  10. package/dist/cli/compile.d.ts +3 -0
  11. package/dist/cli/compile.d.ts.map +1 -1
  12. package/dist/cli/compile.js.map +1 -1
  13. package/dist/cli/config.d.ts +177 -8
  14. package/dist/cli/config.d.ts.map +1 -1
  15. package/dist/cli/config.js +128 -2
  16. package/dist/cli/config.js.map +1 -1
  17. package/dist/cli/index.js +34 -7
  18. package/dist/cli/index.js.map +1 -1
  19. package/dist/cli/run.d.ts.map +1 -1
  20. package/dist/cli/run.js +1 -0
  21. package/dist/cli/run.js.map +1 -1
  22. package/dist/cli/tui.d.ts +9 -0
  23. package/dist/cli/tui.d.ts.map +1 -1
  24. package/dist/cli/tui.js +118 -30
  25. package/dist/cli/tui.js.map +1 -1
  26. package/dist/compaction.d.ts +70 -0
  27. package/dist/compaction.d.ts.map +1 -0
  28. package/dist/compaction.js +286 -0
  29. package/dist/compaction.js.map +1 -0
  30. package/dist/compiler.d.ts.map +1 -1
  31. package/dist/compiler.js +6 -8
  32. package/dist/compiler.js.map +1 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js.map +1 -1
  36. package/dist/prolog/bridge.d.ts +10 -1
  37. package/dist/prolog/bridge.d.ts.map +1 -1
  38. package/dist/prolog/bridge.js +26 -1
  39. package/dist/prolog/bridge.js.map +1 -1
  40. package/dist/prolog/loader.d.ts.map +1 -1
  41. package/dist/prolog/loader.js +8 -3
  42. package/dist/prolog/loader.js.map +1 -1
  43. package/dist/prolog-src/deepclause_mi.pl +27 -8
  44. package/dist/runner.d.ts +8 -1
  45. package/dist/runner.d.ts.map +1 -1
  46. package/dist/runner.js +241 -47
  47. package/dist/runner.js.map +1 -1
  48. package/dist/sdk.d.ts.map +1 -1
  49. package/dist/sdk.js +2 -0
  50. package/dist/sdk.js.map +1 -1
  51. package/dist/system/assets/compactors/default-loop-compactor.dml +20 -0
  52. package/dist/system/assets/compactors/default-memory-compactor.dml +6 -0
  53. package/dist/system/assets/compactors/default-session-compactor.dml +20 -0
  54. package/dist/system/assets/docs/CONDUCTOR_PROMPT.md +39 -5
  55. package/dist/system/assets/docs/DML_COMPILER_PROMPT.md +17 -4
  56. package/dist/system/assets/index.d.ts +4 -0
  57. package/dist/system/assets/index.d.ts.map +1 -1
  58. package/dist/system/assets/index.js +19 -0
  59. package/dist/system/assets/index.js.map +1 -1
  60. package/dist/system/assets/recipes/deepclause-coding-workflow/SKILL.md +45 -0
  61. package/dist/system/assets/skills/conductor.dml +20 -14
  62. package/dist/system/runtime/catalog-recipes.d.ts +24 -0
  63. package/dist/system/runtime/catalog-recipes.d.ts.map +1 -0
  64. package/dist/system/runtime/catalog-recipes.js +273 -0
  65. package/dist/system/runtime/catalog-recipes.js.map +1 -0
  66. package/dist/system/runtime/catalog-skills.d.ts +6 -1
  67. package/dist/system/runtime/catalog-skills.d.ts.map +1 -1
  68. package/dist/system/runtime/catalog-skills.js +28 -0
  69. package/dist/system/runtime/catalog-skills.js.map +1 -1
  70. package/dist/system/runtime/conductor.d.ts +29 -0
  71. package/dist/system/runtime/conductor.d.ts.map +1 -1
  72. package/dist/system/runtime/conductor.js +350 -55
  73. package/dist/system/runtime/conductor.js.map +1 -1
  74. package/dist/system/runtime/dml-executor.d.ts +1 -0
  75. package/dist/system/runtime/dml-executor.d.ts.map +1 -1
  76. package/dist/system/runtime/dml-executor.js +4 -1
  77. package/dist/system/runtime/dml-executor.js.map +1 -1
  78. package/dist/system/runtime/runtime-tools.d.ts +6 -0
  79. package/dist/system/runtime/runtime-tools.d.ts.map +1 -1
  80. package/dist/system/runtime/runtime-tools.js +26 -1
  81. package/dist/system/runtime/runtime-tools.js.map +1 -1
  82. package/dist/system/runtime/shell-manager.d.ts.map +1 -1
  83. package/dist/system/runtime/shell-manager.js +112 -29
  84. package/dist/system/runtime/shell-manager.js.map +1 -1
  85. package/dist/system/runtime/skill-creator.d.ts +2 -0
  86. package/dist/system/runtime/skill-creator.d.ts.map +1 -1
  87. package/dist/system/runtime/skill-creator.js +201 -15
  88. package/dist/system/runtime/skill-creator.js.map +1 -1
  89. package/dist/types.d.ts +57 -1
  90. package/dist/types.d.ts.map +1 -1
  91. package/package.json +2 -3
  92. package/src/prolog-src/deepclause_mi.pl +27 -8
package/dist/cli/tui.js CHANGED
@@ -7,7 +7,7 @@ import { listCommands } from './commands.js';
7
7
  import { getConfigPath, loadConfig, resolveModelSlot, setModel } from './config.js';
8
8
  import { run } from './run.js';
9
9
  import { formatToolArgs } from './tool-args.js';
10
- import { createLocalSkill, createConductorSession, getConductorSessionDetail, listConductorSessions, runConductorTurn, } from '../system/runtime/conductor.js';
10
+ import { createSessionExecutionLogWriter, createLocalSkill, createConductorSession, getConductorSessionDetail, listConductorSessions, runConductorTurn, } from '../system/runtime/conductor.js';
11
11
  import { getSystemAssetSourcePaths } from '../system/assets/index.js';
12
12
  import { createShellManager } from '../system/runtime/shell-manager.js';
13
13
  import { buildToolCompletionEvent, buildToolFailureEvent, buildToolStartEvent, createShellToolEventBridge, } from '../system/runtime/shell-tool-events.js';
@@ -74,6 +74,9 @@ export class LiveExecutionPrinter {
74
74
  case 'tool_call':
75
75
  this.handleToolCall(logEvent);
76
76
  break;
77
+ case 'memory_compaction':
78
+ this.writeLine(formatMemoryCompactionLine(logEvent));
79
+ break;
77
80
  case 'output':
78
81
  if (event.content) {
79
82
  this.writeLine(`${formatEventPrefix(logEvent)}output ${event.content}`);
@@ -155,6 +158,9 @@ export class ActivityBuffer {
155
158
  case 'tool_call':
156
159
  this.handleToolCall(logEvent);
157
160
  break;
161
+ case 'memory_compaction':
162
+ this.pushLine(formatMemoryCompactionLine(logEvent));
163
+ break;
158
164
  case 'output':
159
165
  if (event.content) {
160
166
  this.pushLine(`${formatEventPrefix(logEvent)}output ${event.content}`);
@@ -917,6 +923,7 @@ class FullscreenTui {
917
923
  this.requestRender();
918
924
  try {
919
925
  const result = await runSkillCommand(this.workspaceRoot, skillName, args, {
926
+ sessionId: this.selectedSessionId || undefined,
920
927
  sandbox: this.options.sandbox,
921
928
  signal: this.currentAbortController.signal,
922
929
  onUserInput: (question) => this.requestClarification(question),
@@ -2507,12 +2514,7 @@ class FullscreenTui {
2507
2514
  for (const entry of visibleEntries) {
2508
2515
  const header = this.formatMessageHeader(entry);
2509
2516
  lines.push(header);
2510
- const bodyLines = entry.content
2511
- ? entry.content.split(/\r?\n/)
2512
- : (entry.pending ? [''] : ['(empty)']);
2513
- if (entry.pending && !entry.content) {
2514
- bodyLines[0] = 'thinking...';
2515
- }
2517
+ const bodyLines = formatDisplayMessageBodyLines(entry);
2516
2518
  for (const line of bodyLines) {
2517
2519
  lines.push(` ${line}`);
2518
2520
  }
@@ -2936,6 +2938,7 @@ async function startLineTui(workspaceRoot = process.cwd(), options = {}) {
2936
2938
  const printer = new LiveExecutionPrinter();
2937
2939
  try {
2938
2940
  await runSkillCommand(workspaceRoot, parsed.name, parsed.args, {
2941
+ sessionId: session.id,
2939
2942
  sandbox: options.sandbox,
2940
2943
  onUserInput: async (question) => {
2941
2944
  printer.finish();
@@ -3010,23 +3013,52 @@ export async function runPromptHeadless(prompt, workspaceRoot = process.cwd(), o
3010
3013
  throw new Error(result.error);
3011
3014
  }
3012
3015
  }
3013
- async function runSkillCommand(workspaceRoot, skillName, args, options = {}) {
3016
+ export async function runSkillCommand(workspaceRoot, skillName, args, options = {}) {
3014
3017
  const commands = await listCommands(workspaceRoot);
3015
3018
  const command = commands.find((entry) => entry.name === skillName);
3016
3019
  if (!command) {
3017
3020
  throw new Error(`Unknown skill: ${skillName}`);
3018
3021
  }
3019
- const result = await run(command.path, args, {
3020
- configRoot: workspaceRoot,
3021
- headless: true,
3022
- stream: true,
3023
- sandbox: options.sandbox,
3024
- signal: options.signal,
3025
- onUserInput: options.onUserInput,
3026
- onEvent: (event) => options.onEvent?.({ scope: 'child', childSlug: skillName, event }),
3027
- onChildEvent: (childSlug, event) => options.onEvent?.({ scope: 'child', childSlug, event }),
3028
- });
3029
- return result;
3022
+ const executionLog = options.sessionId
3023
+ ? createSessionExecutionLogWriter({
3024
+ workspaceRoot,
3025
+ sessionId: options.sessionId,
3026
+ executionKind: 'skill',
3027
+ inputText: `/${skillName}${args.length > 0 ? ` ${args.join(' ')}` : ''}`,
3028
+ skillName,
3029
+ args,
3030
+ })
3031
+ : null;
3032
+ const emitLogEvent = (event) => {
3033
+ executionLog?.recordEvent(event);
3034
+ options.onEvent?.(event);
3035
+ };
3036
+ try {
3037
+ const result = await run(command.path, args, {
3038
+ configRoot: workspaceRoot,
3039
+ headless: true,
3040
+ stream: true,
3041
+ sandbox: options.sandbox,
3042
+ signal: options.signal,
3043
+ onUserInput: options.onUserInput,
3044
+ onEvent: (event) => emitLogEvent({ scope: 'child', childSlug: skillName, event }),
3045
+ onChildEvent: (childSlug, event) => emitLogEvent({ scope: 'child', childSlug, event }),
3046
+ });
3047
+ await executionLog?.finish({
3048
+ status: result.error ? 'error' : 'success',
3049
+ answer: result.answer,
3050
+ error: result.error,
3051
+ outputCount: result.output.length,
3052
+ });
3053
+ return result;
3054
+ }
3055
+ catch (error) {
3056
+ await executionLog?.finish({
3057
+ status: 'error',
3058
+ error: error.message,
3059
+ });
3060
+ throw error;
3061
+ }
3030
3062
  }
3031
3063
  async function runSkillCreatorCommand(workspaceRoot, sessionId, spec, options = {}) {
3032
3064
  const trimmedSpec = spec.trim();
@@ -3036,19 +3068,41 @@ async function runSkillCreatorCommand(workspaceRoot, sessionId, spec, options =
3036
3068
  const config = await loadConfig(workspaceRoot);
3037
3069
  const compileSelection = resolveModelSlot(config, 'compile');
3038
3070
  const runSelection = resolveModelSlot(config, 'run');
3039
- return createLocalSkill({
3040
- spec: trimmedSpec,
3071
+ const executionLog = createSessionExecutionLogWriter({
3041
3072
  workspaceRoot,
3042
- workspacePath: path.resolve(workspaceRoot, config.workspace || './workspace'),
3043
- config,
3044
- compileSelection,
3045
- runSelection,
3046
3073
  sessionId,
3047
- sandbox: options.sandbox ?? false,
3048
- signal: options.signal,
3049
- onUserInput: options.onUserInput ?? (async () => ''),
3050
- onEvent: options.onEvent,
3074
+ executionKind: 'skill-creator',
3075
+ inputText: trimmedSpec,
3076
+ skillName: 'skill-creator',
3051
3077
  });
3078
+ const emitLogEvent = (event) => {
3079
+ executionLog.recordEvent(event);
3080
+ options.onEvent?.(event);
3081
+ };
3082
+ try {
3083
+ const result = await createLocalSkill({
3084
+ spec: trimmedSpec,
3085
+ workspaceRoot,
3086
+ workspacePath: path.resolve(workspaceRoot, config.workspace || './workspace'),
3087
+ config,
3088
+ compileSelection,
3089
+ runSelection,
3090
+ sessionId,
3091
+ sandbox: options.sandbox ?? false,
3092
+ signal: options.signal,
3093
+ onUserInput: options.onUserInput ?? (async () => ''),
3094
+ onEvent: emitLogEvent,
3095
+ });
3096
+ await executionLog.finish({ status: 'success' });
3097
+ return result;
3098
+ }
3099
+ catch (error) {
3100
+ await executionLog.finish({
3101
+ status: 'error',
3102
+ error: error.message,
3103
+ });
3104
+ throw error;
3105
+ }
3052
3106
  }
3053
3107
  async function runShellCommand(workspaceRoot, command, options = {}) {
3054
3108
  const trimmedCommand = command.trim();
@@ -3454,7 +3508,11 @@ export function formatDisplayMessageHeader(entry, spinner = '') {
3454
3508
  case 'user':
3455
3509
  return '[You]';
3456
3510
  case 'assistant': {
3457
- const base = entry.error ? 'Assistant Error' : 'Assistant';
3511
+ const base = entry.error
3512
+ ? 'Assistant Error'
3513
+ : entry.pending
3514
+ ? 'Thinking'
3515
+ : 'Assistant';
3458
3516
  return entry.tag
3459
3517
  ? `[${base}: ${entry.tag}${spinner}]`
3460
3518
  : `[${base}${spinner}]`;
@@ -3463,6 +3521,18 @@ export function formatDisplayMessageHeader(entry, spinner = '') {
3463
3521
  return formatSystemMessageHeader(entry, spinner);
3464
3522
  }
3465
3523
  }
3524
+ export function formatDisplayMessageBodyLines(entry) {
3525
+ const bodyLines = entry.content
3526
+ ? entry.content.split(/\r?\n/)
3527
+ : (entry.pending ? [''] : ['(empty)']);
3528
+ if (!entry.pending) {
3529
+ return bodyLines;
3530
+ }
3531
+ if (!entry.content) {
3532
+ return ['thinking> generating intermediate output...'];
3533
+ }
3534
+ return bodyLines.map((line) => line ? `thinking> ${line}` : 'thinking>');
3535
+ }
3466
3536
  function formatSystemAssetSourcePath(workspaceRoot, filePath) {
3467
3537
  const relativePath = path.relative(workspaceRoot, filePath);
3468
3538
  if (relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath)) {
@@ -3482,6 +3552,18 @@ function formatToolEventLine(logEvent) {
3482
3552
  }
3483
3553
  return `${prefix}tool ${callLabel} ${event.toolState}${formatToolEventDetails(event)}`;
3484
3554
  }
3555
+ function formatMemoryCompactionLine(logEvent) {
3556
+ const { event } = logEvent;
3557
+ const prefix = formatEventPrefix(logEvent);
3558
+ if (event.content) {
3559
+ return `${prefix}${event.content}`;
3560
+ }
3561
+ const action = event.compactionAction ?? 'skipped';
3562
+ const binding = event.compactionBindingName ?? 'compactor';
3563
+ const before = typeof event.beforeTokens === 'number' ? event.beforeTokens : '?';
3564
+ const after = typeof event.afterTokens === 'number' ? event.afterTokens : '?';
3565
+ return `${prefix}compact ${event.compactionScope ?? 'loop'}.${event.compactionTrigger ?? 'before_model_call'} ${action} via ${binding} ${before} -> ${after} tokens`;
3566
+ }
3485
3567
  function formatToolEventDetails(event) {
3486
3568
  const details = [];
3487
3569
  if (typeof event.toolPid === 'number') {
@@ -3874,9 +3956,15 @@ function renderWindowBody(text, innerWidth, kind) {
3874
3956
  if (text.startsWith('[Assistant Error]')) {
3875
3957
  return `${border}${paint(content, ANSI.red, ANSI.bgBlue, ANSI.bold)}${border}`;
3876
3958
  }
3959
+ if (text.startsWith('[Thinking')) {
3960
+ return `${border}${paint(content, ANSI.cyan, ANSI.bgBlue, ANSI.bold)}${border}`;
3961
+ }
3877
3962
  if (text.startsWith('[Assistant')) {
3878
3963
  return `${border}${paint(content, ANSI.brightYellow, ANSI.bgBlue, ANSI.bold)}${border}`;
3879
3964
  }
3965
+ if (text.startsWith(' thinking>')) {
3966
+ return `${border}${paint(content, ANSI.cyan, ANSI.bgBlue, ANSI.dim)}${border}`;
3967
+ }
3880
3968
  if (text.startsWith('[System')) {
3881
3969
  return `${border}${paint(content, ANSI.cyan, ANSI.bgBlue, ANSI.bold)}${border}`;
3882
3970
  }