@orion-agents/orion-code 0.4.5 → 0.4.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +7 -7
  3. package/README.zh-CN.md +7 -7
  4. package/dist/commands/context-commands.js +16 -28
  5. package/dist/commands/context-tool-command-handlers.d.ts +2 -3
  6. package/dist/commands/context-tool-command-handlers.js +2 -20
  7. package/dist/commands/registry.js +24 -61
  8. package/dist/commands/retired-commands.d.ts +2 -0
  9. package/dist/commands/retired-commands.js +24 -0
  10. package/dist/commands/session-command-handlers.d.ts +3 -2
  11. package/dist/commands/session-command-handlers.js +41 -42
  12. package/dist/commands/session-commands.js +21 -0
  13. package/dist/commands/system-commands.js +2 -27
  14. package/dist/commands/tool-commands.js +0 -10
  15. package/dist/commands/types.d.ts +6 -4
  16. package/dist/commands/workflow-commands.js +0 -24
  17. package/dist/framework/query.js +1 -1
  18. package/dist/framework/verification-command.d.ts +2 -0
  19. package/dist/framework/verification-command.js +16 -4
  20. package/dist/harness/assembler.d.ts +1 -0
  21. package/dist/harness/assembler.js +5 -2
  22. package/dist/harness/clarification.d.ts +3 -0
  23. package/dist/harness/clarification.js +56 -0
  24. package/dist/harness/context-harness.d.ts +1 -1
  25. package/dist/harness/context-harness.js +33 -5
  26. package/dist/harness/contract.js +36 -10
  27. package/dist/harness/drift-guard.js +12 -4
  28. package/dist/harness/goal-verification.d.ts +2 -0
  29. package/dist/harness/goal-verification.js +42 -0
  30. package/dist/harness/intent.js +10 -12
  31. package/dist/harness/state.js +15 -2
  32. package/dist/harness/stop-controller.js +1 -1
  33. package/dist/harness/task-checklist.js +1 -1
  34. package/dist/harness/verification.d.ts +2 -0
  35. package/dist/harness/verification.js +16 -5
  36. package/dist/runtime/agent-loop.js +49 -27
  37. package/dist/runtime/agent-runtime-controller.d.ts +4 -2
  38. package/dist/runtime/agent-runtime-controller.js +116 -31
  39. package/dist/runtime/orion-session-runner.js +3 -5
  40. package/dist/runtime/plan-review.d.ts +1 -0
  41. package/dist/runtime/plan-review.js +12 -7
  42. package/dist/runtime/product-bootstrap.js +24 -11
  43. package/dist/runtime/product-orion-runtime.js +1 -1
  44. package/dist/runtime/step-snapshot.d.ts +1 -0
  45. package/dist/runtime/step-snapshot.js +2 -1
  46. package/dist/runtime/task-context-recovery.js +15 -7
  47. package/dist/runtime/tool-gateway.js +1 -0
  48. package/dist/runtime/ui-events.d.ts +4 -1
  49. package/dist/runtime/ui-view-model.js +7 -3
  50. package/dist/skills/builtin/security-check/SKILL.md +2 -2
  51. package/dist/skills/builtin/test-gen/SKILL.md +2 -2
  52. package/dist/terminal-ui/launch.js +1 -1
  53. package/dist/tui-ui/launch.js +4 -1
  54. package/dist/tui-ui/layout.d.ts +2 -2
  55. package/dist/tui-ui/layout.js +59 -47
  56. package/dist/tui-ui/pickers.d.ts +3 -1
  57. package/dist/tui-ui/pickers.js +17 -11
  58. package/dist/tui-ui/runner.d.ts +1 -1
  59. package/dist/tui-ui/runner.js +61 -68
  60. package/dist/tui-ui/state.d.ts +4 -0
  61. package/dist/tui-ui/state.js +33 -2
  62. package/docs/cli-guide.md +24 -1
  63. package/npm-shrinkwrap.json +2 -2
  64. package/package.json +1 -1
@@ -568,19 +568,16 @@ class TuiRunner {
568
568
  this.completeCommand(overlay.items[overlay.selectedIndex], false);
569
569
  return;
570
570
  case 'enter':
571
- if (/^\/(?:tool-output|redraw)(?:\s|$)/u.test(this.state.prompt.value.trim())) {
572
- this.dispatch({ type: 'closeOverlay' });
573
- this.submitPrompt();
574
- return;
575
- }
576
- if (this.hasRecognizedCommandArguments()) {
577
- this.dispatch({ type: 'closeOverlay' });
578
- this.submitPrompt();
579
- return;
571
+ if (value.trim() !== '/' || overlay.selectedIndex !== 0) {
572
+ const selected = overlay.items[overlay.selectedIndex];
573
+ if (selected)
574
+ this.completeCommand(selected, true);
575
+ else
576
+ this.submitPrompt();
580
577
  }
581
- this.completeCommand(overlay.items[overlay.selectedIndex], true);
582
578
  return;
583
579
  case 'escape':
580
+ this.dismissedCommandToken = (0, pickers_1.getCommandToken)(value);
584
581
  this.dispatch({ type: 'closeOverlay' });
585
582
  return;
586
583
  }
@@ -700,10 +697,10 @@ class TuiRunner {
700
697
  this.updatePrompt(deleteAfterCursor(value, cursor));
701
698
  return;
702
699
  case 'left':
703
- this.dispatch({ type: 'setPrompt', value, cursor: previousBoundary(value, cursor) });
700
+ this.updatePrompt({ value, cursor: previousBoundary(value, cursor) });
704
701
  return;
705
702
  case 'right':
706
- this.dispatch({ type: 'setPrompt', value, cursor: nextBoundary(value, cursor) });
703
+ this.updatePrompt({ value, cursor: nextBoundary(value, cursor) });
707
704
  return;
708
705
  case 'home':
709
706
  this.moveCursorLineHome();
@@ -712,7 +709,7 @@ class TuiRunner {
712
709
  this.moveCursorLineEnd();
713
710
  return;
714
711
  case 'ctrl+u':
715
- this.dispatch({ type: 'setPrompt', value: '', cursor: 0 });
712
+ this.updatePrompt({ value: '', cursor: 0 });
716
713
  this.dispatch({ type: 'closeOverlay' });
717
714
  return;
718
715
  case 'ctrl+w':
@@ -727,16 +724,15 @@ class TuiRunner {
727
724
  this.options.onInterrupt?.();
728
725
  return;
729
726
  case 'tab':
727
+ if ((0, pickers_1.getCommandToken)(value)) {
728
+ this.syncPromptOverlay(value, cursor, true);
729
+ return;
730
+ }
730
731
  if (this.state.processing && value.trim()) {
731
732
  this.queuePrompt();
732
733
  return;
733
734
  }
734
- if (value.startsWith('/')) {
735
- this.syncPromptOverlay(value);
736
- }
737
- else if ((0, pickers_1.getFileQuery)(value)) {
738
- this.syncPromptOverlay(value);
739
- }
735
+ this.syncPromptOverlay(value, cursor);
740
736
  return;
741
737
  case 'up':
742
738
  this.moveCursorUpOrHistory();
@@ -752,14 +748,14 @@ class TuiRunner {
752
748
  }
753
749
  queuePrompt() {
754
750
  const input = this.state.prompt.value.trim();
755
- if (!input)
751
+ if (!input || (0, pickers_1.getCommandToken)(input))
756
752
  return;
757
753
  try {
758
754
  const queued = this.options.onQueueSubmit?.(input);
759
755
  if (queued === false)
760
756
  return;
761
757
  this.history = (0, history_1.pushHistoryEntry)(this.history, input);
762
- this.dispatch({ type: 'setPrompt', value: '', cursor: 0 });
758
+ this.updatePrompt({ value: '', cursor: 0 });
763
759
  this.dispatch({ type: 'closeOverlay' });
764
760
  if (queued instanceof Promise)
765
761
  void queued.catch(() => this.reportSubmitFailure());
@@ -788,7 +784,7 @@ class TuiRunner {
788
784
  const match = matches[this.historySearchIndex % matches.length];
789
785
  this.historySearchIndex += 1;
790
786
  this.historySearchMatch = match;
791
- this.dispatch({ type: 'setPrompt', value: match, cursor: match.length });
787
+ this.updatePrompt({ value: match, cursor: match.length });
792
788
  this.dispatch({
793
789
  type: 'setStatus',
794
790
  message: `History ${((this.historySearchIndex - 1) % matches.length) + 1}/${matches.length}`,
@@ -808,7 +804,7 @@ class TuiRunner {
808
804
  await (0, promises_1.writeFile)(filePath, original, { encoding: 'utf8', mode: 0o600 });
809
805
  await this.options.onOpenExternalEditor(filePath);
810
806
  const next = await (0, promises_1.readFile)(filePath, 'utf8');
811
- this.dispatch({ type: 'setPrompt', value: next, cursor: next.length });
807
+ this.updatePrompt({ value: next, cursor: next.length });
812
808
  }
813
809
  finally {
814
810
  await (0, promises_1.rm)(directory, { recursive: true, force: true });
@@ -852,7 +848,7 @@ class TuiRunner {
852
848
  const { value, cursor } = this.state.prompt;
853
849
  const { line, col } = lineColOfCursor(value, cursor);
854
850
  if (line > 0) {
855
- this.dispatch({ type: 'setPrompt', value, cursor: cursorOfLineCol(value, line - 1, col) });
851
+ this.updatePrompt({ value, cursor: cursorOfLineCol(value, line - 1, col) });
856
852
  }
857
853
  else {
858
854
  this.historyBack();
@@ -869,7 +865,7 @@ class TuiRunner {
869
865
  const lines = value.split('\n');
870
866
  const { line, col } = lineColOfCursor(value, cursor);
871
867
  if (line < lines.length - 1) {
872
- this.dispatch({ type: 'setPrompt', value, cursor: cursorOfLineCol(value, line + 1, col) });
868
+ this.updatePrompt({ value, cursor: cursorOfLineCol(value, line + 1, col) });
873
869
  }
874
870
  else {
875
871
  this.historyForward();
@@ -877,21 +873,16 @@ class TuiRunner {
877
873
  }
878
874
  /** Home: move to the start of the current visual line (not whole buffer). */
879
875
  moveCursorLineHome() {
880
- if (this.state.overlay)
881
- return;
882
876
  const { value, cursor } = this.state.prompt;
883
877
  const { line } = lineColOfCursor(value, cursor);
884
- this.dispatch({ type: 'setPrompt', value, cursor: cursorOfLineCol(value, line, 0) });
878
+ this.updatePrompt({ value, cursor: cursorOfLineCol(value, line, 0) });
885
879
  }
886
880
  /** End: move to the end of the current visual line (not whole buffer). */
887
881
  moveCursorLineEnd() {
888
- if (this.state.overlay)
889
- return;
890
882
  const { value, cursor } = this.state.prompt;
891
883
  const { line } = lineColOfCursor(value, cursor);
892
884
  const lines = value.split('\n');
893
- this.dispatch({
894
- type: 'setPrompt',
885
+ this.updatePrompt({
895
886
  value,
896
887
  cursor: cursorOfLineCol(value, line, lines[line].length),
897
888
  });
@@ -900,11 +891,16 @@ class TuiRunner {
900
891
  const { value: input, cursor } = this.state.prompt;
901
892
  if (!input.trim() && !options.allowEmpty)
902
893
  return;
903
- this.dispatch({ type: 'setPrompt', value: '', cursor: 0 });
894
+ if (input.trim() === '/') {
895
+ this.syncPromptOverlay(input, cursor, true);
896
+ return;
897
+ }
898
+ this.updatePrompt({ value: '', cursor: 0 });
904
899
  try {
905
900
  const submission = this.handleLocalCommand(input) || this.options.onSubmit?.(input);
906
901
  if (submission === false) {
907
- this.dispatch({ type: 'setPrompt', value: input, cursor });
902
+ this.dismissedCommandToken = (0, pickers_1.getCommandToken)(input);
903
+ this.updatePrompt({ value: input, cursor });
908
904
  return;
909
905
  }
910
906
  this.history = (0, history_1.pushHistoryEntry)(this.history, input);
@@ -921,10 +917,6 @@ class TuiRunner {
921
917
  }
922
918
  handleLocalCommand(input) {
923
919
  const command = input.trim();
924
- if (command === '/redraw') {
925
- this.forceOwnedRedraw();
926
- return true;
927
- }
928
920
  if (command === '/queue') {
929
921
  const items = this.state.followupQueue.items;
930
922
  this.dispatch({
@@ -956,7 +948,7 @@ class TuiRunner {
956
948
  });
957
949
  return true;
958
950
  }
959
- if (command.startsWith('/tool-output')) {
951
+ if (/^\/tool-output(?:\s|$)/u.test(command)) {
960
952
  this.dispatch({
961
953
  type: 'setStatus',
962
954
  message: 'Usage: /tool-output adaptive|collapsed|full',
@@ -977,21 +969,30 @@ class TuiRunner {
977
969
  }
978
970
  updatePrompt(next) {
979
971
  this.dispatch({ type: 'setPrompt', value: next.value, cursor: next.cursor });
980
- this.syncPromptOverlay(next.value);
972
+ this.syncPromptOverlay(next.value, next.cursor);
981
973
  }
982
- syncPromptOverlay(value) {
983
- if (this.state.overlay?.type === 'shortcuts' && value.trim()) {
984
- this.dispatch({ type: 'closeOverlay' });
974
+ syncPromptOverlay(value, cursor, reopen = false) {
975
+ const token = (0, pickers_1.getCommandToken)(value);
976
+ if (reopen || token !== this.dismissedCommandToken)
977
+ this.dismissedCommandToken = undefined;
978
+ const overlay = this.state.overlay;
979
+ if (overlay?.type === 'shortcuts') {
980
+ if (value.trim())
981
+ this.dispatch({ type: 'closeOverlay' });
982
+ }
983
+ else if (overlay && overlay.type !== 'commands' && overlay.type !== 'files') {
984
+ return;
985
985
  }
986
- if (value.startsWith('/')) {
986
+ if (token && cursor > 0 && cursor <= token.length && token !== this.dismissedCommandToken) {
987
+ const query = token.slice(1);
987
988
  this.dispatch({
988
989
  type: 'showCommandPalette',
989
- query: value.slice(1),
990
- items: visibleTuiCommandItems(value),
990
+ query,
991
+ items: (0, pickers_1.visibleCommandItems)(query),
991
992
  });
992
993
  return;
993
994
  }
994
- const fileQuery = (0, pickers_1.getFileQuery)(value);
995
+ const fileQuery = cursor === value.length ? (0, pickers_1.getFileQuery)(value) : null;
995
996
  if (fileQuery) {
996
997
  this.dispatch({
997
998
  type: 'showFilePicker',
@@ -1006,27 +1007,22 @@ class TuiRunner {
1006
1007
  }
1007
1008
  }
1008
1009
  completeCommand(item, submitImmediately) {
1009
- if (!item)
1010
+ const { value } = this.state.prompt;
1011
+ const token = (0, pickers_1.getCommandToken)(value);
1012
+ if (!item || !token)
1010
1013
  return;
1011
- const command = (0, commands_1.getCommands)().find(candidate => candidate.name === item.value);
1012
- const needsArgs = item.value === 'tool-output' ||
1013
- Boolean(command?.argumentHint || command?.params?.some(param => param.required));
1014
- const value = `/${item.value}${needsArgs ? ' ' : ''}`;
1015
- const promptAlreadyMatchesCommand = this.state.prompt.value.trim() === `/${item.value}`;
1016
- const nextValue = promptAlreadyMatchesCommand ? `/${item.value}` : value;
1014
+ const command = (0, commands_1.findCommand)(item.value);
1015
+ const tail = value.slice(token.length);
1016
+ const separator = !submitImmediately && !tail && command?.argumentHint ? ' ' : '';
1017
+ this.dismissedCommandToken = item.label;
1017
1018
  this.dispatch({ type: 'closeOverlay' });
1018
- this.dispatch({ type: 'setPrompt', value: nextValue, cursor: nextValue.length });
1019
- if (submitImmediately && (!needsArgs || promptAlreadyMatchesCommand)) {
1019
+ this.dispatch({
1020
+ type: 'setPrompt',
1021
+ value: item.label + separator + tail,
1022
+ cursor: item.label.length + separator.length,
1023
+ });
1024
+ if (submitImmediately)
1020
1025
  this.submitPrompt();
1021
- }
1022
- }
1023
- hasRecognizedCommandArguments() {
1024
- const prompt = this.state.prompt.value.trim();
1025
- const match = prompt.match(/^\/([^\s]+)\s+\S/u);
1026
- if (!match)
1027
- return false;
1028
- const name = match[1].toLowerCase();
1029
- return (0, commands_1.findCommand)(name) !== undefined;
1030
1026
  }
1031
1027
  completeFile(item) {
1032
1028
  if (!item)
@@ -1421,9 +1417,6 @@ function insertAtCursor(value, cursor, text) {
1421
1417
  cursor: safeCursor + text.length,
1422
1418
  };
1423
1419
  }
1424
- function visibleTuiCommandItems(input) {
1425
- return (0, pickers_1.visibleCommandItems)(input);
1426
- }
1427
1420
  function safeFileName(value) {
1428
1421
  return value.replace(/[^a-zA-Z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '') || 'tool';
1429
1422
  }
@@ -123,6 +123,10 @@ export type TuiUiAction = {
123
123
  } | {
124
124
  type: 'replaceTranscript';
125
125
  entries: TranscriptEntry[];
126
+ } | {
127
+ type: 'startSession';
128
+ sessionId: string;
129
+ model?: string;
126
130
  } | {
127
131
  type: 'clearTranscript';
128
132
  } | {
@@ -185,6 +185,24 @@ function tuiUiReducer(state, action) {
185
185
  recentToolDetails: mergeRecentToolDetails([], action.entries.flatMap(toolDetailsFromTranscriptEntry)),
186
186
  });
187
187
  }
188
+ case 'startSession':
189
+ return {
190
+ ...state,
191
+ overlay: null,
192
+ goal: null,
193
+ research: null,
194
+ researchEvents: [],
195
+ subtaskTimeline: [],
196
+ statusMessage: '',
197
+ statusState: {
198
+ ...exports.initialTuiUiState.statusState,
199
+ snapshot: (0, ui_view_model_1.createStatusSnapshot)({
200
+ renderer: 'tui',
201
+ model: action.model,
202
+ sessionId: action.sessionId,
203
+ }),
204
+ },
205
+ };
188
206
  case 'clearTranscript':
189
207
  return {
190
208
  ...state,
@@ -345,16 +363,21 @@ function tuiUiReducer(state, action) {
345
363
  }
346
364
  case 'followupQueueChanged':
347
365
  return { ...state, followupQueue: action.snapshot };
348
- case 'showCommandPalette':
366
+ case 'showCommandPalette': {
367
+ const previous = state.overlay;
368
+ const previousValue = previous?.type === 'commands' && previous.query === action.query
369
+ ? previous.items[previous.selectedIndex]?.value
370
+ : undefined;
349
371
  return {
350
372
  ...state,
351
373
  overlay: {
352
374
  type: 'commands',
353
375
  query: action.query,
354
376
  items: action.items,
355
- selectedIndex: clampNumber(state.overlay?.type === 'commands' ? state.overlay.selectedIndex : 0, 0, Math.max(0, action.items.length - 1)),
377
+ selectedIndex: Math.max(0, action.items.findIndex(item => item.value === previousValue)),
356
378
  },
357
379
  };
380
+ }
358
381
  case 'showFilePicker':
359
382
  return {
360
383
  ...state,
@@ -573,6 +596,14 @@ function createTuiUiEventSink(dispatch, options = {}) {
573
596
  toolFinished: event => dispatch({ type: 'toolFinished', event }),
574
597
  sessionRestored: (event) => {
575
598
  const view = (0, ui_view_model_1.createSessionRestoredView)(event);
599
+ if (event.reason === 'new') {
600
+ dispatch({ type: 'startSession', sessionId: event.sessionId, model: event.model });
601
+ dispatch({
602
+ type: 'appendTranscript',
603
+ entry: { id: idFactory(), role: 'status', title: 'new', content: view.headline },
604
+ });
605
+ return;
606
+ }
576
607
  const lines = [view.headline];
577
608
  if (view.summary)
578
609
  lines.push(`Summary: ${view.summary}`);
package/docs/cli-guide.md CHANGED
@@ -43,10 +43,33 @@ orion doctor
43
43
  `orion commit` 是只读提交计划,不是执行本地提交。阶段完成不隐含授权 push、发布或删除。
44
44
  模型切换、权限、工具和会话帮助以安装版本内 `/help` 为准。
45
45
 
46
- 多步骤修改会在首次写入前建立清单。`/harness explain` 可查看当前步骤、已验证的回执、失败次数和剩余工作。
46
+ 多步骤修改会在首次写入前建立清单。`/context explain` 可查看当前步骤、已验证的回执、失败次数和剩余工作。
47
47
  审批 PLAN 时,`## Execution checklist` 下的未勾选项可直接进入同一执行清单。实际改动和检查的回执决定
48
48
  步骤能否完成。输入“先把第一步做完,其他之后再说”可以限制当前任务的范围,输入“继续”恢复已延期的步骤。
49
49
 
50
+ 从 v0.4.7 起,询问检查原因或当前状态可以在任务进行中得到答复。继续执行原任务时,原清单和验证条件仍然生效。
51
+ 有自定义验证要求时,请给出检查命令和目录,例如“运行 `python3 inspect_fixture.py` 在 `workflow` 中验证样本”。
52
+ 省略目录时使用项目根目录。也可对已有的未指定验证说“把之前的验证改为 `python3 inspect_fixture.py` 在 `workflow` 中”。
53
+
54
+ ## TUI 命令与会话
55
+
56
+ 从 v0.4.6 起,在输入框开头键入 `/` 可查看命令。候选根据命令名和别名筛选,并贴近输入框显示。
57
+ 用方向键选中候选,Tab 补全命令名并保留已经输入的参数,Enter 执行。Esc 关闭候选并保留草稿。
58
+ 光标进入参数区后,可以继续编辑并直接提交。
59
+
60
+ - `/new` 创建独立会话,`/resume` 可回到原会话。进行中的回合结束后即可切换。
61
+ - `/rename <name>` 重命名当前会话,`/session rename` 仍支持指定其他会话。
62
+ - `/quit` 退出,`/memories` 查看本地记忆状态。旧拼写 `/exit` 和 `/memory` 仍可输入。
63
+
64
+ | 旧入口 | 当前入口 |
65
+ | -------------------------- | ------------------------------ |
66
+ | `/clear`、`/context clear` | `/new` |
67
+ | `/redraw` | Ctrl+L |
68
+ | `/harness` | `/context explain` |
69
+ | `/safety` | `/doctor` |
70
+ | `/security`、`/audit` | `/skill security-check <task>` |
71
+ | `/test-gen`、`/tests` | `/skill test-gen <task>` |
72
+
50
73
  ## 非交互任务与 JSONL 事件
51
74
 
52
75
  ```bash
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@orion-agents/orion-code",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@orion-agents/orion-code",
9
- "version": "0.4.5",
9
+ "version": "0.4.7",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@agentclientprotocol/sdk": "2.12.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-agents/orion-code",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Orion Code - local-first goal-driven coding agent for the terminal.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",