gaunt-sloth 2.0.0-beta.9 → 2.0.1

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 (118) hide show
  1. package/.gsloth.review-discovery.md +19 -0
  2. package/cli.js +49 -0
  3. package/dist/cli.js +42 -7
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/adkEvalRunner.d.ts +7 -6
  6. package/dist/commands/adkEvalRunner.js +3 -3
  7. package/dist/commands/adkEvalRunner.js.map +1 -1
  8. package/dist/commands/agUiEvalRunner.d.ts +4 -4
  9. package/dist/commands/agUiEvalRunner.js +8 -7
  10. package/dist/commands/agUiEvalRunner.js.map +1 -1
  11. package/dist/commands/askCommand.d.ts +15 -2
  12. package/dist/commands/askCommand.js +75 -32
  13. package/dist/commands/askCommand.js.map +1 -1
  14. package/dist/commands/batchCommand.d.ts +6 -2
  15. package/dist/commands/batchCommand.js +13 -7
  16. package/dist/commands/batchCommand.js.map +1 -1
  17. package/dist/commands/chatCommand.js.map +1 -1
  18. package/dist/commands/codeCommand.js.map +1 -1
  19. package/dist/commands/commandIntrospection.d.ts +1 -1
  20. package/dist/commands/commandIntrospection.js +6 -3
  21. package/dist/commands/commandIntrospection.js.map +1 -1
  22. package/dist/commands/configCommand.d.ts +1 -1
  23. package/dist/commands/configCommand.js +1 -1
  24. package/dist/commands/configSetup.d.ts +1 -1
  25. package/dist/commands/discoveryConfigSchemaAgreement.d.ts +45 -0
  26. package/dist/commands/discoveryConfigSchemaAgreement.js +2 -0
  27. package/dist/commands/discoveryConfigSchemaAgreement.js.map +1 -0
  28. package/dist/commands/evalCommand.d.ts +27 -1
  29. package/dist/commands/evalCommand.js +156 -13
  30. package/dist/commands/evalCommand.js.map +1 -1
  31. package/dist/commands/execCommand.d.ts +15 -3
  32. package/dist/commands/execCommand.js +123 -51
  33. package/dist/commands/execCommand.js.map +1 -1
  34. package/dist/commands/firstRunDialog.d.ts +3 -3
  35. package/dist/commands/firstRunDialog.js +2 -2
  36. package/dist/commands/getCommand.js +10 -1
  37. package/dist/commands/getCommand.js.map +1 -1
  38. package/dist/commands/historyCommand.d.ts +16 -8
  39. package/dist/commands/historyCommand.js +190 -72
  40. package/dist/commands/historyCommand.js.map +1 -1
  41. package/dist/commands/insightsCommand.d.ts +4 -2
  42. package/dist/commands/insightsCommand.js +10 -7
  43. package/dist/commands/insightsCommand.js.map +1 -1
  44. package/dist/commands/prCommand.js +45 -16
  45. package/dist/commands/prCommand.js.map +1 -1
  46. package/dist/commands/prDiscovery.d.ts +24 -25
  47. package/dist/commands/prDiscovery.js +55 -132
  48. package/dist/commands/prDiscovery.js.map +1 -1
  49. package/dist/commands/requirementsDiscovery.d.ts +82 -0
  50. package/dist/commands/requirementsDiscovery.js +127 -0
  51. package/dist/commands/requirementsDiscovery.js.map +1 -0
  52. package/dist/commands/resumeOption.d.ts +19 -9
  53. package/dist/commands/resumeOption.js +29 -17
  54. package/dist/commands/resumeOption.js.map +1 -1
  55. package/dist/commands/reviewCommand.js +75 -8
  56. package/dist/commands/reviewCommand.js.map +1 -1
  57. package/dist/commands/reviewDiscovery.d.ts +96 -0
  58. package/dist/commands/reviewDiscovery.js +180 -0
  59. package/dist/commands/reviewDiscovery.js.map +1 -0
  60. package/dist/commands/singleShotResume.d.ts +19 -0
  61. package/dist/commands/singleShotResume.js +37 -0
  62. package/dist/commands/singleShotResume.js.map +1 -0
  63. package/dist/tui/approvalBridges.d.ts +86 -0
  64. package/dist/tui/approvalBridges.js +147 -0
  65. package/dist/tui/approvalBridges.js.map +1 -0
  66. package/dist/tui/components/App.js +278 -29
  67. package/dist/tui/components/App.js.map +1 -1
  68. package/dist/tui/components/DebugPanel.d.ts +6 -3
  69. package/dist/tui/components/DebugPanel.js +32 -10
  70. package/dist/tui/components/DebugPanel.js.map +1 -1
  71. package/dist/tui/components/FetchProgress.d.ts +1 -1
  72. package/dist/tui/components/LaunchBanner.d.ts +4 -3
  73. package/dist/tui/components/LaunchBanner.js +8 -6
  74. package/dist/tui/components/LaunchBanner.js.map +1 -1
  75. package/dist/tui/components/LiveTurn.d.ts +15 -9
  76. package/dist/tui/components/LiveTurn.js +15 -14
  77. package/dist/tui/components/LiveTurn.js.map +1 -1
  78. package/dist/tui/components/PromptInput.d.ts +2 -2
  79. package/dist/tui/components/PromptInput.js +11 -6
  80. package/dist/tui/components/PromptInput.js.map +1 -1
  81. package/dist/tui/components/ResumePicker.d.ts +69 -0
  82. package/dist/tui/components/ResumePicker.js +93 -0
  83. package/dist/tui/components/ResumePicker.js.map +1 -0
  84. package/dist/tui/components/SelectList.d.ts +1 -1
  85. package/dist/tui/components/SelectList.js +1 -1
  86. package/dist/tui/components/SlashCommandMenu.d.ts +1 -1
  87. package/dist/tui/components/SlashCommandMenu.js +1 -1
  88. package/dist/tui/components/StatusBar.d.ts +27 -1
  89. package/dist/tui/components/StatusBar.js +13 -2
  90. package/dist/tui/components/StatusBar.js.map +1 -1
  91. package/dist/tui/debugRender.d.ts +26 -3
  92. package/dist/tui/debugRender.js +233 -2
  93. package/dist/tui/debugRender.js.map +1 -1
  94. package/dist/tui/fixtureAgent.d.ts +2 -2
  95. package/dist/tui/fixtureAgent.js +2 -2
  96. package/dist/tui/keyBindings.js +7 -1
  97. package/dist/tui/keyBindings.js.map +1 -1
  98. package/dist/tui/keyGuards.d.ts +1 -1
  99. package/dist/tui/keyGuards.js +1 -1
  100. package/dist/tui/ruleWidth.d.ts +1 -1
  101. package/dist/tui/ruleWidth.js +1 -1
  102. package/dist/tui/selectCancelled.d.ts +1 -1
  103. package/dist/tui/selectCancelled.js +1 -1
  104. package/dist/tui/transcriptWindow.js +7 -1
  105. package/dist/tui/transcriptWindow.js.map +1 -1
  106. package/dist/tui/tuiSessionModule.js +91 -192
  107. package/dist/tui/tuiSessionModule.js.map +1 -1
  108. package/dist/tui/types.d.ts +79 -19
  109. package/dist/tui/useMouse.d.ts +1 -1
  110. package/dist/tui/useMouse.js +1 -1
  111. package/dist/tui/useSlothAnimation.d.ts +1 -1
  112. package/dist/tui/viewModel.d.ts +64 -12
  113. package/dist/tui/viewModel.js +38 -11
  114. package/dist/tui/viewModel.js.map +1 -1
  115. package/dist/utils/configErrorGuard.d.ts +11 -3
  116. package/dist/utils/configErrorGuard.js +11 -3
  117. package/dist/utils/configErrorGuard.js.map +1 -1
  118. package/package.json +19 -19
@@ -0,0 +1,127 @@
1
+ import { GthAgentRunner } from '@gaunt-sloth/core/core/GthAgentRunner.js';
2
+ import { defaultStatusCallback, displayInfo } from '@gaunt-sloth/core/utils/consoleUtils.js';
3
+ import { buildSystemMessages } from '@gaunt-sloth/core/utils/llmUtils.js';
4
+ import { displayTermination } from '@gaunt-sloth/core/core/terminationNotice.js';
5
+ import { HumanMessage } from '@langchain/core/messages';
6
+ import { MemorySaver } from '@langchain/langgraph';
7
+ import { createResolvers } from '@gaunt-sloth/agent/resolvers.js';
8
+ /**
9
+ * Run the requirements discovery agent once, to completion or to whatever ended it. Results come
10
+ * back through the caller's own tools (`set_requirements` and friends), not through the return
11
+ * value. Errors from the run propagate after the termination notice has been printed.
12
+ */
13
+ export async function runDiscoveryAgent(run) {
14
+ const { config, discoveryConfig, owningCommand } = run;
15
+ const runner = new GthAgentRunner(defaultStatusCallback, createDiscoveryResolvers(run.createDiscoveryTools));
16
+ try {
17
+ // `command` stays undefined so the discovery agent runs on the chat prompt and does NOT pick up
18
+ // the owning command's posture; `owningCommand` is label-only, so a notice about this run says
19
+ // "the pr command" (or "the review command") rather than something the user cannot connect to
20
+ // what they typed (GS2-81).
21
+ //
22
+ // **The checkpoint saver is not optional here, even though `init` accepts none.** An unset
23
+ // command answers approvals (`commandAnswersApprovals`), and every helper tool a discovery
24
+ // agent binds — `set_requirements`, and for `pr` also `set_diff`, `gh_pr`, `gh_diff`,
25
+ // `gh_issue` — has no built-in access class, so all of them are in the rung-independent
26
+ // interrupt set whatever the rung. The first tool call therefore suspends the graph on a
27
+ // LangGraph interrupt, and an interrupt with nowhere to checkpoint throws
28
+ // `MISSING_CHECKPOINTER` instead of suspending — which killed the whole discovery run on its
29
+ // first tool call (EXT-120). That is why the saver lives HERE, in the one function both
30
+ // commands call, rather than at each call site where a second copy could forget it.
31
+ //
32
+ // Per run, not per process: this saver's only job is to hold the graph one discovery run
33
+ // suspends on, and that run dies with the runner it is created beside. `MemorySaver` is what
34
+ // every other surface that drives a gating-capable agent hands the runner.
35
+ //
36
+ // GS2-20 — considered for the durable saver and deliberately kept in memory. This is an internal
37
+ // helper run inside `gth pr` / `gth review`, not a conversation the user had; there is nothing
38
+ // here anyone would ask to resume, and persisting it would put rows in the store with no
39
+ // listing entry.
40
+ await runner.init(undefined, getDiscoveryAgentConfig(config, discoveryConfig), new MemorySaver(), {
41
+ owningCommand,
42
+ });
43
+ await runner.processMessages([
44
+ ...buildSystemMessages(config, run.readPrompt()),
45
+ new HumanMessage(run.userMessage),
46
+ ]);
47
+ }
48
+ finally {
49
+ await runner.cleanup();
50
+ // [[EXT-159]] — say why the DISCOVERY run ended, because on the ending that matters nobody
51
+ // else will. Shared for the same reason as the saver above: both commands need it, and it was
52
+ // a defect in the one that had it last.
53
+ //
54
+ // Several endings return from `processMessages` normally rather than throwing — the interrupt
55
+ // drain giving up, the tool-error budget and the tool-loop guard ending the graph with
56
+ // `jumpTo: 'end'`, an Esc or abort closing the stream, a tool exception returned as the turn's
57
+ // answer, and a refusal or truncation classified from the provider's own metadata. Each leaves
58
+ // the caller's state unset; `prCommand` then prints "Change requirements discovery did not
59
+ // produce a diff" and RETURNS — so `review`'s own notice, the surface this run's ending used to
60
+ // be attributed to, is never reached. One sentence that fits a dozen unrelated causes, printed
61
+ // while the discriminating fact sat unread on this runner: the exact shape EXT-159 removed.
62
+ //
63
+ // In the `finally`, so the endings that DO throw are announced too. Note the ORDER that buys:
64
+ // the `finally` unwinds ahead of the command's catch, so the notice prints FIRST and the
65
+ // provider's prose (or the approvals negotiation transcript) follows it — a heading, then the
66
+ // detail, rather than `reviewModule`'s error-then-notice.
67
+ //
68
+ // A successful discovery costs nothing: it classifies `completed`, which
69
+ // `shouldAnnounceTermination` suppresses, so the review that follows is not preceded by a
70
+ // notice about the sub-run that fed it. The one case that does print twice is a discovery that
71
+ // ended abnormally AFTER the agent had already set what the review needs — the command then
72
+ // continues to the review, and the user sees this notice and later the review's own. That is
73
+ // two runs with two different endings, each stating its own, which is the intended reading
74
+ // rather than a duplicate.
75
+ //
76
+ // Read after `cleanup()` for the reason `reviewModule` reads it there: the agent is gone by
77
+ // here and the runner snapshots its innermost classification at cleanup.
78
+ try {
79
+ displayTermination(runner.getTerminationReason());
80
+ }
81
+ catch {
82
+ /* fail-soft: explaining a run must never be what ends it */
83
+ }
84
+ }
85
+ // The discovery agent streams its final text without a trailing newline, so emit a
86
+ // blank line to separate it from the review agent's output that follows.
87
+ displayInfo('');
88
+ }
89
+ /**
90
+ * The config the discovery agent runs with: the command's config with the discovery block's tool
91
+ * overrides applied, and the discovery allow-list in place of every other one.
92
+ */
93
+ export function getDiscoveryAgentConfig(config, discoveryConfig) {
94
+ const baseTools = discoveryConfig?.tools ?? config.tools ?? [];
95
+ const customTools = discoveryConfig && 'customTools' in discoveryConfig
96
+ ? discoveryConfig.customTools
97
+ : config.customTools;
98
+ return {
99
+ ...config,
100
+ filesystem: discoveryConfig?.filesystem ?? config.filesystem,
101
+ builtInTools: discoveryConfig?.builtInTools ?? config.builtInTools,
102
+ customTools: customTools === false ? undefined : customTools,
103
+ tools: baseTools,
104
+ // The discovery agent must never inherit the top-level allow-list (e.g. a global
105
+ // `allowedTools: []` meant to keep review agents tool-free would strip set_requirements
106
+ // and silently neuter discovery). Only the command's `discovery.allowedTools` applies here,
107
+ // always augmented with set_requirements so the agent can record what it found. The
108
+ // agent applies this list after every tool source is resolved, so it also gates tools
109
+ // supplied via `tools` in config.
110
+ allowedTools: discoveryConfig?.allowedTools
111
+ ? [...new Set([...discoveryConfig.allowedTools, 'set_requirements'])]
112
+ : undefined,
113
+ };
114
+ }
115
+ function createDiscoveryResolvers(createDiscoveryTools) {
116
+ const baseResolvers = createResolvers();
117
+ return {
118
+ ...baseResolvers,
119
+ resolveTools: async (effectiveConfig, command) => {
120
+ const baseTools = baseResolvers.resolveTools
121
+ ? await baseResolvers.resolveTools(effectiveConfig, command)
122
+ : [];
123
+ return [...baseTools, ...createDiscoveryTools()];
124
+ },
125
+ };
126
+ }
127
+ //# sourceMappingURL=requirementsDiscovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requirementsDiscovery.js","sourceRoot":"","sources":["../../src/commands/requirementsDiscovery.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AA8DlE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,GAAsB;IAC5D,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC;IACvD,MAAM,MAAM,GAAG,IAAI,cAAc,CAC/B,qBAAqB,EACrB,wBAAwB,CAAC,GAAG,CAAC,oBAAoB,CAAC,CACnD,CAAC;IACF,IAAI,CAAC;QACH,gGAAgG;QAChG,+FAA+F;QAC/F,8FAA8F;QAC9F,4BAA4B;QAC5B,EAAE;QACF,2FAA2F;QAC3F,2FAA2F;QAC3F,sFAAsF;QACtF,wFAAwF;QACxF,yFAAyF;QACzF,0EAA0E;QAC1E,6FAA6F;QAC7F,wFAAwF;QACxF,oFAAoF;QACpF,EAAE;QACF,yFA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AAC,KAAK,IAAI,EAAE,CAAC;IAC/D,MAAM,WAAW,GACf,eAAe,IAAI,aAAa,IAAI,eAAe;QACjD,CAAC,CAAC,eAAe,CAAC,WAAW;QAC7B,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;IACzB,OAAO;QACL,GAAG,MAAM;QACT,UAAU,EAAE,eAAe,EAAE,UAAU,IAAI,MAAM,CAAC,UAAU;QAC5D,YAAY,EAAE,eAAe,EAAE,YAAY,IAAI,MAAM,CAAC,YAAY;QAClE,WAAW,EAAE,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW;QAC5D,KAAK,EAAE,SAAS;QAChB,iFAAiF;QACjF,wFAAwF;QACxF,4FAA4F;QAC5F,oFAAoF;QACpF,sFAAsF;QACtF,kCAAkC;QAClC,YAAY,EAAE,eAAe,EAAE,YAAY;YACzC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,eAAe,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC,CAAC;YACrE,CAAC,CAAC,SAAS;KACd,CAAC;AACJ,CAAC;AAED,SAAS,wBAAwB,CAC/B,oBAAqD;IAErD,MAAM,aAAa,GAAG,eAAe,EAAE,CAAC;IACxC,OAAO;QACL,GAAG,aAAa;QAChB,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,EAAE;YAC/C,MAAM,SAAS,GAAG,aAAa,CAAC,YAAY;gBAC1C,CAAC,CAAC,MAAM,aAAa,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC;gBAC5D,CAAC,CAAC,EAAE,CAAC;YACP,OAAO,CAAC,GAAG,SAAS,EAAE,GAAG,oBAAoB,EAAE,CAAC,CAAC;QACnD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,22 +1,32 @@
1
1
  import { Option, type Command } from 'commander';
2
+ import { type ConversationRef } from '@gaunt-sloth/core/history/conversationRef.js';
2
3
  import type { InteractiveSessionOptions } from '@gaunt-sloth/agent/modules/interactiveSessionModule.js';
3
4
  /**
4
- * GS2-20 — the `--resume <id>` flag, defined once and attached three times: on `chat`, on `code`,
5
- * and on the root program for the bare `gth` that starts a code session. The value is validated
5
+ * GS2-20 — the `--resume <id>` flag, defined once and attached on `chat`, on `code`, on the root
6
+ * program for the bare `gth` that starts a code session, and (GS2-106) on `ask` and `exec`. The value is validated
6
7
  * here, where commander reports a bad one in its own voice and exits before any config is loaded,
7
8
  * so a typo never reaches the session.
9
+ *
10
+ * GS2-106 — it parses to a reference, not an integer: the run id cannot be resolved to a row here,
11
+ * because the store's path comes from the config and this runs before it is loaded. The session
12
+ * resolves the reference through the resume seam, exactly as it resolves an integer.
8
13
  */
9
14
  export declare function resumeOption(): Option;
10
- /** The subcommands a root `--resume` can ride along with; the bare command is a `code` session. */
15
+ /**
16
+ * The subcommands a root `--resume` can ride along with; the bare command is a `code` session.
17
+ *
18
+ * GS2-106 — derived from the resume matrix's subcommand map in core, the one table every resume
19
+ * surface reads, so a subcommand gains or loses `--resume` in one place.
20
+ */
11
21
  export declare const RESUMABLE_COMMANDS: ReadonlySet<string>;
12
22
  /**
13
23
  * GS2-20 — the sentence for a root `--resume` typed in front of a subcommand that cannot take it
14
- * (`gth --resume 12 ask "…"`). Commander accepts the root option before every subcommand, and only
15
- * the session commands read it, so without this the intent would be dropped and a fresh `ask`
16
- * would run as if nothing had been asked. Same register as the ordered checks: what applies, what
17
- * does not yet, and that nothing ran.
24
+ * (`gth --resume 12 review`). Commander accepts the root option before every subcommand, and only
25
+ * the resumable ones read it, so without this the intent would be dropped and a fresh run of the
26
+ * other command would start as if nothing had been asked. Same register as the ordered checks:
27
+ * what applies, and that nothing ran.
18
28
  */
19
- export declare function rootResumeRefusalMessage(subcommand: string, id: number): string;
29
+ export declare function rootResumeRefusalMessage(subcommand: string, ref: ConversationRef | number): string;
20
30
  /**
21
31
  * The session options a command starts with: `{ resumeConversationId }` when `--resume` was given
22
32
  * — on the subcommand itself or on the root program, so `gth chat --resume 12` and
@@ -24,5 +34,5 @@ export declare function rootResumeRefusalMessage(subcommand: string, id: number)
24
34
  * without the flag is started exactly as it always was.
25
35
  */
26
36
  export declare function sessionOptionsFor(program: Command, own: {
27
- resume?: number;
37
+ resume?: ConversationRef;
28
38
  }): InteractiveSessionOptions | undefined;
@@ -1,33 +1,45 @@
1
1
  import { InvalidArgumentError, Option } from 'commander';
2
- import { parseResumeId } from '@gaunt-sloth/agent/modules/sessionResume.js';
2
+ import { formatConversationRef, parseConversationRef, } from '@gaunt-sloth/core/history/conversationRef.js';
3
+ import { RESUME_SURFACE_OF_SUBCOMMAND } from '@gaunt-sloth/core/history/resumeMatrix.js';
3
4
  /**
4
- * GS2-20 — the `--resume <id>` flag, defined once and attached three times: on `chat`, on `code`,
5
- * and on the root program for the bare `gth` that starts a code session. The value is validated
5
+ * GS2-20 — the `--resume <id>` flag, defined once and attached on `chat`, on `code`, on the root
6
+ * program for the bare `gth` that starts a code session, and (GS2-106) on `ask` and `exec`. The value is validated
6
7
  * here, where commander reports a bad one in its own voice and exits before any config is loaded,
7
8
  * so a typo never reaches the session.
9
+ *
10
+ * GS2-106 — it parses to a reference, not an integer: the run id cannot be resolved to a row here,
11
+ * because the store's path comes from the config and this runs before it is loaded. The session
12
+ * resolves the reference through the resume seam, exactly as it resolves an integer.
8
13
  */
9
14
  export function resumeOption() {
10
15
  return new Option('--resume <id>', 'Pick up a saved conversation where it left off (the id from `gth history list`)').argParser((raw) => {
11
- const id = parseResumeId(raw);
12
- if (id === null) {
13
- throw new InvalidArgumentError('Expected a conversation id — a positive whole number, as printed by `gth history list`.');
16
+ const ref = parseConversationRef(raw);
17
+ if (ref === null) {
18
+ throw new InvalidArgumentError('Expected a conversation id — a positive whole number or a run id, as printed by ' +
19
+ '`gth history list`.');
14
20
  }
15
- return id;
21
+ return ref;
16
22
  });
17
23
  }
18
- /** The subcommands a root `--resume` can ride along with; the bare command is a `code` session. */
19
- export const RESUMABLE_COMMANDS = new Set(['chat', 'code']);
24
+ /**
25
+ * The subcommands a root `--resume` can ride along with; the bare command is a `code` session.
26
+ *
27
+ * GS2-106 — derived from the resume matrix's subcommand map in core, the one table every resume
28
+ * surface reads, so a subcommand gains or loses `--resume` in one place.
29
+ */
30
+ export const RESUMABLE_COMMANDS = new Set(Object.keys(RESUME_SURFACE_OF_SUBCOMMAND));
20
31
  /**
21
32
  * GS2-20 — the sentence for a root `--resume` typed in front of a subcommand that cannot take it
22
- * (`gth --resume 12 ask "…"`). Commander accepts the root option before every subcommand, and only
23
- * the session commands read it, so without this the intent would be dropped and a fresh `ask`
24
- * would run as if nothing had been asked. Same register as the ordered checks: what applies, what
25
- * does not yet, and that nothing ran.
33
+ * (`gth --resume 12 review`). Commander accepts the root option before every subcommand, and only
34
+ * the resumable ones read it, so without this the intent would be dropped and a fresh run of the
35
+ * other command would start as if nothing had been asked. Same register as the ordered checks:
36
+ * what applies, and that nothing ran.
26
37
  */
27
- export function rootResumeRefusalMessage(subcommand, id) {
28
- return (`Cannot resume into \`gth ${subcommand}\`: \`--resume\` applies to \`gth chat\`, \`gth code\` ` +
29
- 'and the bare `gth` command. Resuming a conversation into `ask` or `exec` is not available ' +
30
- `yet (GS2-106). Nothing was run, and conversation #${id} was not touched.`);
38
+ export function rootResumeRefusalMessage(subcommand, ref) {
39
+ const commands = [...RESUMABLE_COMMANDS].map((c) => `\`gth ${c}\``).join(', ');
40
+ return (`Cannot resume into \`gth ${subcommand}\`: \`--resume\` applies to ${commands} and the bare ` +
41
+ `\`gth\` command. Nothing was run, and conversation ${formatConversationRef(ref)} was not ` +
42
+ 'touched.');
31
43
  }
32
44
  /**
33
45
  * The session options a command starts with: `{ resumeConversationId }` when `--resume` was given
@@ -1 +1 @@
1
- {"version":3,"file":"resumeOption.js","sourceRoot":"","sources":["../../src/commands/resumeOption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAgB,MAAM,WAAW,CAAC;AACvE,OAA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oleUtils.js';
3
- import { getStringFromStdin, setExitCode } from '@gaunt-sloth/core/utils/systemUtils.js';
2
+ import { displayError, displayInfo } from '@gaunt-sloth/core/utils/consoleUtils.js';
3
+ import { getStringFromStdin, setExitCode, stdout } from '@gaunt-sloth/core/utils/systemUtils.js';
4
+ import { ApprovalStopError, approvalStopRows } from '@gaunt-sloth/core/core/shell/approvalStop.js';
4
5
  import { getCommandSourceInput, getEffectiveContentSource, getEffectiveRequirementSource, getReviewSystemPrompt, withReviewContentSource, } from '#src/commands/commandIntrospection.js';
5
6
  import { REQUIREMENTS_SOURCES, CONTENT_SOURCES, } from '#src/commands/commandUtils.js';
6
7
  import { wrapContent } from '@gaunt-sloth/core/utils/llmUtils.js';
@@ -8,6 +9,10 @@ import { readMultipleFilesFromProjectDir } from '@gaunt-sloth/review/utils/fileU
8
9
  // From the REVIEW package, not this package's own same-named module: both ship a
9
10
  // `commands/commandUtils`, and this helper lives only in review's (GS2-45).
10
11
  import { resolvePrIdFromArg } from '@gaunt-sloth/review/commands/commandUtils.js';
12
+ import { extractChangedPathsFromDiff } from '@gaunt-sloth/review/utils/diffPaths.js';
13
+ import { writeReviewFailureReport } from '@gaunt-sloth/review/modules/reviewFailureReport.js';
14
+ /** The source label this command passes to `review()`, and therefore names its report file with. */
15
+ const REVIEW_SOURCE = 'REVIEW';
11
16
  export function reviewCommand(program, cliConfigOverrides) {
12
17
  program
13
18
  .command('review')
@@ -38,9 +43,17 @@ export function reviewCommand(program, cliConfigOverrides) {
38
43
  // made on config (the review module's `gth_gh_read_file` gate) can never disagree with where
39
44
  // the diff actually came from.
40
45
  const config = withReviewContentSource(initialConfig, contentSource);
41
- const requirements = await getCommandSourceInput('review', 'requirements', requirementsId, config, requirementSource);
42
- if (requirements) {
43
- content.push(requirements);
46
+ // CFG-80 — discovery runs only when enabled and no `--requirements` was given; an explicit
47
+ // `--requirements` always wins.
48
+ const discoverRequirements = !requirementsId && config.commands?.review?.discovery?.enabled === true;
49
+ // With discovery on and no id, the requirement source is not asked for an id-less lookup:
50
+ // discovery is what finds the id, and the id-less call only warns (the Jira source prints
51
+ // "No issue ID provided") — the same reason `gth pr` skips it in discovery mode.
52
+ if (!discoverRequirements) {
53
+ const requirements = await getCommandSourceInput('review', 'requirements', requirementsId, config, requirementSource);
54
+ if (requirements) {
55
+ content.push(requirements);
56
+ }
44
57
  }
45
58
  // Fail loudly on a content-source error (e.g. the git source outside a repository or with
46
59
  // an empty diff) instead of surfacing a raw unhandled rejection — same shape as `gth pr`.
@@ -49,13 +62,67 @@ export function reviewCommand(program, cliConfigOverrides) {
49
62
  providedContent = await getCommandSourceInput('review', 'content', contentId, config, contentSource);
50
63
  }
51
64
  catch (error) {
52
- displayError(error instanceof Error ? error.message : String(error));
65
+ const message = error instanceof Error ? error.message : String(error);
66
+ displayError(message);
67
+ // REL-20 — `gth review` fails before inference the same way `gth pr` does (the git source
68
+ // outside a repository, the GitHub source on a diff too large to fetch), so it owes the
69
+ // same report. The two commands share this exit; they must not diverge on it.
70
+ writeReviewFailureReport(config, REVIEW_SOURCE, 'review', message);
53
71
  setExitCode(1);
54
72
  return;
55
73
  }
74
+ // CFG-70 — the changed paths come from `providedContent` alone, never from `content`, which
75
+ // by the time it is passed also holds the requirements, the `--file` contents, stdin and
76
+ // `--message`. A requirements document that quotes a diff would otherwise inject paths this
77
+ // change never touched, attaching another module's guidelines to it.
78
+ //
79
+ // Inside the same truthiness guard as the push: `getCommandSourceInput` is TYPED as
80
+ // returning a string but resolves to nothing when a source produces no content, which is
81
+ // what the guard below has always been for.
82
+ let changedPaths = [];
56
83
  if (providedContent) {
84
+ changedPaths = extractChangedPathsFromDiff(providedContent);
57
85
  content.push(providedContent);
58
86
  }
87
+ // CFG-80 — requirements discovery. After the content fetch, so a review that cannot get its
88
+ // diff never spends a discovery agent run; the discovered requirements still go FIRST in the
89
+ // content, where `--requirements` puts them. With discovery off (the default) nothing here
90
+ // runs: no git, no gh, no agent, so the review runs and prints exactly what it did before.
91
+ if (discoverRequirements) {
92
+ const { runReviewDiscovery } = await import('#src/commands/reviewDiscovery.js');
93
+ try {
94
+ // Bound to the same PR id the review tools are bound to below (CFG-54), so a
95
+ // `gth review 42 --content-source github` finds PR 42's requirements rather than the
96
+ // checked-out branch's.
97
+ const discovered = await runReviewDiscovery(config, requirementSource, {
98
+ prId: resolvePrIdFromArg(contentId),
99
+ });
100
+ if (discovered) {
101
+ content.unshift(wrapContent(discovered, 'discovered-requirements', 'requirements'));
102
+ }
103
+ else {
104
+ displayInfo('Requirements discovery found no requirements; reviewing without them.');
105
+ }
106
+ }
107
+ catch (error) {
108
+ // Same handling as `gth pr`'s discovery: the agent runs inside a try/finally with no
109
+ // catch of its own, so an approvals stop or a provider error from it lands here. It fails
110
+ // the run rather than silently reviewing without the requirements the user asked for.
111
+ if (error instanceof ApprovalStopError) {
112
+ for (const row of approvalStopRows(error.parts, { columns: stdout.columns })) {
113
+ displayError(row);
114
+ }
115
+ writeReviewFailureReport(config, REVIEW_SOURCE, 'review', error.message);
116
+ }
117
+ else {
118
+ const message = error instanceof Error ? error.message : String(error);
119
+ displayError(message);
120
+ writeReviewFailureReport(config, REVIEW_SOURCE, 'review', message);
121
+ }
122
+ setExitCode(1);
123
+ return;
124
+ }
125
+ }
59
126
  if (options.file) {
60
127
  content.push(readMultipleFilesFromProjectDir(options.file));
61
128
  }
@@ -68,14 +135,14 @@ export function reviewCommand(program, cliConfigOverrides) {
68
135
  }
69
136
  const { review } = await import('@gaunt-sloth/review/modules/reviewModule.js');
70
137
  const { createResolvers } = await import('@gaunt-sloth/agent/resolvers.js');
71
- await review('REVIEW', getReviewSystemPrompt(config), content.join('\n'), config, 'review', createResolvers(),
138
+ await review(REVIEW_SOURCE, getReviewSystemPrompt(config), content.join('\n'), config, 'review', createResolvers(),
72
139
  // Bind GitHub-only review tools (gth_gh_read_file) to the pull request this run's DIFF
73
140
  // came from. Without it they resolve the PR from the checked-out branch instead, so a
74
141
  // `gth review 42 --content-source github` reviews PR 42's diff against a different pull
75
142
  // request's files, silently. `contentId` is a content id rather than a PR id — a ref
76
143
  // range or a file path under the other sources — so only a bare number is taken as one;
77
144
  // anything else, including no argument at all, keeps the branch-discovery fallback.
78
- { prId: resolvePrIdFromArg(contentId) });
145
+ { prId: resolvePrIdFromArg(contentId), changedPaths });
79
146
  });
80
147
  }
81
148
  //# sourceMappingURL=reviewCommand.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reviewCommand.js","sourceRoot":"","sources":["../../src/commands/reviewCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,oBAAoB,EACpB,eAAe,GAGhB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AACzF,iFAAiF;AACjF,4EAA4E;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AAUlF,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,kBAA8C;IAE9C,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,uCAAuC,CAAC;SACpD,QAAQ,CACP,aAAa,EACb,wEAAwE;QACtE,mFAAmF,CACtF;SACA,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CACL,uBAAuB,EACvB,2FAA2F,CAC5F;SACA,MAAM,CAAC,mCAAmC,EAAE,+BAA+B,CAAC;SAC5E,SAAS,CACR,IAAI,MAAM,CACR,+CAA+C,EAC/C,qCAAqC,CACt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CAAC,CAAC;gBACf,OAAO;YACT,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAC;QAC7C,IAAI,eAAe,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;QAC9D,CAAC;QACD,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,6CAA6C,CAAC,CAAC;QAC/E,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,MAAM,CAAC,iCAAiC,CAAC,CAAC;QAC5E,MAAM,MAAM,CACV,aAAa,EACb,qBAAqB,CAAC,MAAM,CAAC,EAC7B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAClB,MAAM,EACN,QAAQ,EACR,eAAe,EAAE;QACjB,uFAAuF;QACvF,sFAAsF;QACtF,wFAAwF;QACxF,qFAAqF;QACrF,wFAAwF;QACxF,oFAAoF;QACpF,EAAE,IAAI,EAAE,kBAAkB,CAAC,SAAS,CAAC,EAAE,YAAY,EAAE,CACtD,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * CFG-80 — `gth review` finds its own requirements, the way `gth pr` with no arguments does.
3
+ *
4
+ * Runs only when `commands.review.discovery.enabled` is true and no `--requirements` was given.
5
+ * The evidence is exactly what `gth pr`'s discovery reads: the current branch name and, best
6
+ * effort, the current branch's pull request via `gh pr view`. A Jira key in that evidence resolves
7
+ * through the configured Jira requirement source with no agent run; otherwise the discovery agent
8
+ * runs, through the same shared function `gth pr` uses ({@link runDiscoveryAgent}).
9
+ *
10
+ * **Commit subjects are deliberately absent.** They are CFG-80's second step, and when they come
11
+ * they must list the commits from the merge base that `resolveMergeBase` (in
12
+ * `@gaunt-sloth/review/utils/git.js`) computes — the one resolver the git content source diffs
13
+ * against — so the reviewed diff and the evidence beside it can never disagree about the base.
14
+ * Recovering a range any other way (from the diff text, or from `<base>..HEAD` on a branch other
15
+ * people have merged into) would sweep unrelated commits, and the keys in them, into the evidence.
16
+ */
17
+ import type { GthConfig } from '@gaunt-sloth/core/config.js';
18
+ import { type RequirementsDiscoveryConfig } from '#src/commands/requirementsDiscovery.js';
19
+ export declare const GSLOTH_REVIEW_DISCOVERY_PROMPT = ".gsloth.review-discovery.md";
20
+ /**
21
+ * `commands.review.discovery`. The same shape as `commands.pr.discovery` less `deterministicDiff`:
22
+ * the review's diff comes from its content source, so discovery has no diff to fetch.
23
+ */
24
+ export interface ReviewDiscoveryConfig extends RequirementsDiscoveryConfig {
25
+ /**
26
+ * Enable requirements discovery for `gth review` when no `--requirements` is given.
27
+ *
28
+ * Off by default, unlike `commands.pr.discovery`. `gth review` has always run without
29
+ * requirements unless given some; turning discovery on silently would add a `git` and a `gh`
30
+ * call, possibly an issue-tracker call and an agent run, to every review anyone runs. `gth pr`
31
+ * with no arguments is itself the request for discovery, so its default stays on.
32
+ * @default false
33
+ */
34
+ enabled?: boolean;
35
+ }
36
+ declare module '@gaunt-sloth/core/config.js' {
37
+ interface ReviewCommandConfig {
38
+ /** Requirements discovery for `gth review` with no `--requirements`. */
39
+ discovery?: ReviewDiscoveryConfig;
40
+ }
41
+ }
42
+ /**
43
+ * Read the review discovery agent prompt, honouring project / identity-profile overrides and
44
+ * falling back to the default prompt shipped with the assistant package.
45
+ */
46
+ export declare function readReviewDiscoveryPrompt(config: Pick<GthConfig, 'identityProfile' | 'noDefaultPrompts'>): string;
47
+ /** What the review discovery found out about the change, before any agent runs. */
48
+ export interface ReviewDiscoveryEvidence {
49
+ /** The current branch name, or '' on a detached HEAD or outside a repository. */
50
+ branch: string;
51
+ /** The current branch's PR as `gh pr view` formats it, or '' when there is none. */
52
+ prMetadata: string;
53
+ }
54
+ /**
55
+ * The current branch name, from `git rev-parse --abbrev-ref HEAD`.
56
+ *
57
+ * Returns '' — no evidence, never an error — on a detached HEAD (git prints the literal `HEAD`
58
+ * there, on every platform), on an unborn branch or outside a repository (git fails), and when
59
+ * git is not installed.
60
+ */
61
+ export declare function readCurrentBranchName(): Promise<string>;
62
+ /** Which change the review is of, when the command line names one. */
63
+ export interface ReviewDiscoveryTarget {
64
+ /**
65
+ * The pull request the review's diff comes from (`gth review 42 --content-source github`), the
66
+ * same id `reviewCommand` binds the review tools to. When set, the evidence is that PR alone:
67
+ * the checked-out branch may be a different change entirely, and requirements taken from it
68
+ * would grade PR 42 against another ticket.
69
+ */
70
+ prId?: string;
71
+ }
72
+ /**
73
+ * Every distinct Jira key the evidence names: each key in the branch name, and the key `gth pr`'s
74
+ * own rules pick from the PR metadata ({@link extractJiraIssueKey}, unchanged). The fast path
75
+ * takes a key only when this set has exactly one member. Branch and PR disagreeing — a branch
76
+ * named for one ticket whose PR description points at another — is exactly the case where
77
+ * picking either would grade the review against the wrong ticket, so it goes to the agent.
78
+ */
79
+ export declare function collectJiraIssueKeys(evidence: ReviewDiscoveryEvidence): Set<string>;
80
+ /**
81
+ * The user message. The evidence enters here, inside delimited blocks and labelled as data, never
82
+ * in the system prompt: a branch name and a PR description are written by whoever pushed the
83
+ * branch, and the requirements the agent sets are what the review is then graded against.
84
+ */
85
+ export declare function buildReviewDiscoveryUserMessage(evidence: ReviewDiscoveryEvidence): string;
86
+ /**
87
+ * Discover requirements for `gth review`. Returns the requirements text, or '' when none were
88
+ * found. Errors from the discovery agent propagate (the caller reports them as `gth pr` does).
89
+ *
90
+ * @param requirementSource the review's effective requirement source (`-p`, else
91
+ * `commands.review.requirementSource`, else the root `requirementSource`).
92
+ * @param target the change the command line names, if any. A git ref range is not a target: the
93
+ * evidence for it is still the checked-out branch, which is the branch under review in the
94
+ * intended use (`gth review main` on a feature branch).
95
+ */
96
+ export declare function runReviewDiscovery(config: GthConfig, requirementSource: string | undefined, target?: ReviewDiscoveryTarget): Promise<string>;