Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
461f64c
docs(spec): add issue-3800 GitHub Copilot support in Chainloop Trace
migmartri Nov 10, 2026
d5fe440
docs(spec): drop scope-only decisions from issue-3800 spec
migmartri Nov 10, 2026
669dd15
docs(plan): add issue-3800 GitHub Copilot Trace provider plan
migmartri Nov 10, 2026
35dd51b
feat(trace): add GitHub Copilot provider
migmartri Nov 11, 2026
f5ec9da
fix(trace): record Copilot apply_patch edits and verify end to end
migmartri Nov 11, 2026
be2c5b7
fix(trace): address review comments on the Copilot provider
migmartri Nov 11, 2026
f90d7b5
fix(trace): give Copilot tool calls without arguments an empty input
migmartri Nov 11, 2026
c4463ef
feat(trace): show the Copilot start banner and session link to the user
migmartri Nov 11, 2026
f6b453d
test(trace): check the Claude Code guard with real Copilot payloads
migmartri Nov 11, 2026
79c1c83
chore(trace): drop the Copilot note from trace init
migmartri Nov 11, 2026
5b93361
chore(trace): drop the per-agent notes from the trace init summary
migmartri Nov 11, 2026
215cbca
docs: add random date to CLI readme
migmartri Nov 11, 2026
4fac0a5
fix(trace): skip Copilot patch payloads in the Claude Code hook witho…
migmartri Nov 11, 2026
5d3baf0
fix(trace): show the Copilot session link one time
migmartri Nov 11, 2026
fe4af9f
fix(trace): keep strict decoding of an object tool_input in the Claud…
migmartri Nov 11, 2026
a7cf6ef
docs: remove random date from CLI readme
migmartri Nov 11, 2026
e3d94be
Merge main into issue-3800-spec-copilot-trace-provider
migmartri Nov 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/cli/cmd/trace_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/claude"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/codex"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/config"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/copilot"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/cursor"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/opencode"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/pi"
Expand All @@ -43,6 +44,7 @@ func newTraceHookCmd() *cobra.Command {
newTraceHookCursorCmd(),
newTraceHookOpenCodeCmd(),
newTraceHookCodexCmd(),
newTraceHookCopilotCmd(),
newTraceHookPiCmd(),
)

Expand Down Expand Up @@ -474,6 +476,25 @@ func newTraceHookCodexCmd() *cobra.Command {
return cmd
}

// newTraceHookCopilotCmd handles the hooks of the GitHub Copilot hook file.
// There is no user-prompt-submit hook, because Copilot drops its output.
func newTraceHookCopilotCmd() *cobra.Command {
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
cmd := &cobra.Command{Use: "copilot", Short: "Handle GitHub Copilot hook invocations"}
handlers := []struct {
name, description string
run func(*cobra.Command, []string) error
}{
{"session-start", "Capture the Copilot session", func(cmd *cobra.Command, _ []string) error { return runAgentSessionStart(cmd, copilot.New()) }},
{"pre-tool-use", "Snapshot files before a Copilot tool", func(_ *cobra.Command, _ []string) error { return action.HandleAgentPreToolUse(copilot.New(), logger) }},
{"post-tool-use", "Record changes after a Copilot tool", func(_ *cobra.Command, _ []string) error { return action.HandleAgentPostToolUse(copilot.New(), logger) }},
{"session-end", "Copy the completed Copilot session", func(_ *cobra.Command, _ []string) error { return action.HandleAgentSessionEnd(copilot.New(), logger) }},
}
for _, h := range handlers {
cmd.AddCommand(&cobra.Command{Use: h.name, Short: h.description, Args: cobra.NoArgs, Annotations: map[string]string{skipActionOptsInit: trueString}, RunE: func(cmd *cobra.Command, args []string) error { InitHookLogger(); return h.run(cmd, args) }})
}
return cmd
}

func newTraceHookPiCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pi",
Expand Down
12 changes: 12 additions & 0 deletions app/cli/cmd/trace_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func TestTraceHookPiCommands(t *testing.T) {
}
}

// TestTraceHookCopilotCommands pins the subcommand names that the Copilot hook
// file calls, so a renamed command cannot break recording without notice.
func TestTraceHookCopilotCommands(t *testing.T) {
root := newTraceHookCmd()
for _, name := range []string{"session-start", "pre-tool-use", "post-tool-use", "session-end"} {
command, args, err := root.Find([]string{"copilot", name})
require.NoError(t, err)
assert.Equal(t, name, command.Name())
assert.Empty(t, args)
}
}

func TestApplyPrePushPolicy(t *testing.T) {
failure := errors.New("setup failed")
prePush := newTraceHookGitPrePushCmd()
Expand Down
21 changes: 4 additions & 17 deletions app/cli/cmd/trace_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import (

"github.com/chainloop-dev/chainloop/app/cli/internal/repositoryconfig"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/codex"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/config"
tracegit "github.com/chainloop-dev/chainloop/app/cli/internal/trace/git"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/hooks"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/pi"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/providers"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/state"
"github.com/chainloop-dev/chainloop/app/cli/pkg/action"
Expand All @@ -51,6 +49,7 @@ func newTraceInitCmd() *cobra.Command {
opencodeFlag bool
piFlag bool
codexFlag bool
copilotFlag bool
)

cmd := &cobra.Command{
Expand All @@ -76,7 +75,7 @@ named freely; the name is normalized to the lowercase, dash-separated form
Chainloop stores. It then asks which harnesses to trace, with the ones the
repository is already set up for ticked, or Claude Code on a first run; use
space to tick more. Passing --org, --project or a harness flag
(--claude, --cursor, --opencode, --pi, --codex) skips the matching question.
(--claude, --cursor, --opencode, --pi, --codex, --copilot) skips the matching question.

Nothing is asked in CI or when the output is redirected: there --project is
required unless .chainloop.yml carries projectName. Set CHAINLOOP_NO_PROMPT to
Expand Down Expand Up @@ -159,7 +158,7 @@ cannot use them with --local. You can use --require-trace with --local.`,
// so every question is answered up front and an abort leaves the
// repository untouched.
selected, err := resolveTraceProviders(newNamingPrompter(os.LookupEnv),
traceProviderFlags{claude: claudeFlag, cursor: cursorFlag, opencode: opencodeFlag, pi: piFlag, codex: codexFlag},
traceProviderFlags{claude: claudeFlag, cursor: cursorFlag, opencode: opencodeFlag, pi: piFlag, codex: codexFlag, copilot: copilotFlag},
traceInitCanPrompt(), func() []string { return configuredTraceProviders(repoRoot) })
if err != nil {
return stopIfAborted(err)
Expand Down Expand Up @@ -299,6 +298,7 @@ cannot use them with --local. You can use --require-trace with --local.`,
cmd.Flags().BoolVar(&cursorFlag, "cursor", false, "install Cursor hooks")
cmd.Flags().BoolVar(&piFlag, "pi", false, "install Pi extension")
cmd.Flags().BoolVar(&codexFlag, "codex", false, "install Codex hooks")
cmd.Flags().BoolVar(&copilotFlag, "copilot", false, "install GitHub Copilot hooks (Copilot CLI and VS Code)")
cmd.Flags().BoolVar(&opencodeFlag, "opencode", false, "install opencode hooks")

return cmd
Expand Down Expand Up @@ -386,18 +386,6 @@ What's next

Learn more: %s
`, strings.Join(files, " "), joinWithOr(providerNames(installed)), traceDocsURL)
writeTraceHarnessNotes(w, installed)
}

Comment thread
migmartri marked this conversation as resolved.
Resolved
func writeTraceHarnessNotes(w io.Writer, installed []trace.Provider) {
for _, p := range installed {
switch p.Name() {
case codex.Name:
fmt.Fprintln(w, "For Codex, review and trust the installed hooks in Codex before starting work.")
case pi.Name:
fmt.Fprintln(w, "For Pi, review the project extension at .pi/extensions/chainloop-trace.ts before starting work. Interactive Pi asks to trust project files. Non-interactive runs need saved trust or --approve.")
}
}
}

// writeTraceInitLocalSummary reports what a local init set up. It names no
Expand Down Expand Up @@ -455,7 +443,6 @@ What's next

Learn more: %s
`, strings.Join(files, " "), joinWithOr(providerNames(installed)), traceDocsURL)
writeTraceHarnessNotes(w, installed)
}

// providerNames names the harnesses, in the order they were installed.
Expand Down
2 changes: 1 addition & 1 deletion app/cli/cmd/trace_init_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func TestWriteTraceLocalNextSteps(t *testing.T) {
assert.Contains(t, got, chainloopYMLName)
assert.Contains(t, got, claudeSettings)
assert.Contains(t, got, filepath.Join(".pi", "extensions", "chainloop-trace.ts"))
assert.Contains(t, got, "--approve")
assert.NotContains(t, got, "--approve", "the summary has no per-agent notes")
assert.Contains(t, got, "writes the session evidence to disk")
assert.NotContains(t, got, "the push tells you where")
assert.Contains(t, got, traceDocsURL)
Expand Down
10 changes: 7 additions & 3 deletions app/cli/cmd/trace_init_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/chainloop-dev/chainloop/app/cli/internal/trace"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/claude"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/codex"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/copilot"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/cursor"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/opencode"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/pi"
Expand All @@ -31,18 +32,18 @@ const providersPromptTitle = "Harnesses to trace in this repository"

// traceProviderFlags records the harness flags that the user set.
type traceProviderFlags struct {
claude, cursor, opencode, pi, codex bool
claude, cursor, opencode, pi, codex, copilot bool
}

// any reports whether the user named at least one provider.
func (f traceProviderFlags) any() bool {
return f.claude || f.cursor || f.opencode || f.pi || f.codex
return f.claude || f.cursor || f.opencode || f.pi || f.codex || f.copilot
}

// names returns the providers the flags select, in the registry's order rather
// than the order the flags happen to appear in.
func (f traceProviderFlags) names() []string {
out := make([]string, 0, 4)
out := make([]string, 0, 6)
if f.claude {
out = append(out, claude.Name)
}
Expand All @@ -58,6 +59,9 @@ func (f traceProviderFlags) names() []string {
if f.codex {
out = append(out, codex.Name)
}
if f.copilot {
out = append(out, copilot.Name)
}
return out
}

Expand Down
15 changes: 13 additions & 2 deletions app/cli/cmd/trace_init_providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path/filepath"
"testing"

"github.com/chainloop-dev/chainloop/app/cli/internal/trace/copilot"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/pi"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/providers"

Expand Down Expand Up @@ -208,10 +209,20 @@ func TestTraceProviderFlags(t *testing.T) {
})

t.Run("names follow the registry order, not the flag order", func(t *testing.T) {
f := traceProviderFlags{codex: true, pi: true, claude: true}
f := traceProviderFlags{copilot: true, codex: true, pi: true, claude: true}
assert.True(t, f.any())
assert.Equal(t, []string{providerClaudeCode, pi.Name, "codex"}, f.names())
assert.Equal(t, []string{providerClaudeCode, pi.Name, "codex", copilot.Name}, f.names())
})
t.Run("copilot flag", func(t *testing.T) {
f := traceProviderFlags{copilot: true}
assert.True(t, f.any())
assert.Equal(t, []string{copilot.Name}, f.namesOrDefault())
})
}

func TestTraceCommandsExposeCopilotFlag(t *testing.T) {
assert.NotNil(t, newTraceInitCmd().Flags().Lookup(copilot.Name))
assert.NotNil(t, newTraceRunCmd().Flags().Lookup(copilot.Name))
}

func TestTraceCommandsExposePiFlag(t *testing.T) {
Expand Down
13 changes: 7 additions & 6 deletions app/cli/cmd/trace_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"os"
"path/filepath"
"slices"
"strings"
"testing"

"github.com/chainloop-dev/chainloop/app/cli/internal/trace/copilot"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/opencode"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/pi"
"github.com/chainloop-dev/chainloop/app/cli/internal/trace/providers"
Expand Down Expand Up @@ -328,15 +330,15 @@ func TestWriteTraceNextSteps(t *testing.T) {
},
{
name: "every harness",
providers: []string{providerClaudeCode, "cursor", opencode.Name, pi.Name, "codex"},
providers: []string{providerClaudeCode, "cursor", opencode.Name, pi.Name, "codex", copilot.Name},
// Named in full: ".opencode" alone would pass on any file under that
// directory, so it would not catch the plugin being renamed.
wantFiles: []string{
chainloopYMLName, claudeSettings, ".cursor/hooks.json",
".opencode/plugins/chainloop-trace.ts", ".pi/extensions/chainloop-trace.ts",
".codex/hooks.json",
".codex/hooks.json", ".github/hooks/chainloop-trace.json",
},
wantHarnesses: "claude-code, cursor, opencode, pi or codex",
wantHarnesses: "claude-code, cursor, opencode, pi, codex or copilot",
},
}

Expand All @@ -353,9 +355,8 @@ func TestWriteTraceNextSteps(t *testing.T) {

assert.Contains(t, got, tc.wantHarnesses)
assert.Contains(t, got, traceDocsURL)
if slices.Contains(tc.providers, pi.Name) {
assert.Contains(t, got, "--approve")
}
// The summary ends with the docs link: no per-agent notes follow.
assert.True(t, strings.HasSuffix(strings.TrimSpace(got), traceDocsURL), "nothing follows the docs link: %q", got)
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/cli/cmd/trace_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func newTraceRunCmd() *cobra.Command {
opencodeFlag bool
piFlag bool
codexFlag bool
copilotFlag bool
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -167,7 +168,7 @@ func newTraceRunCmd() *cobra.Command {
return action.TraceRun(cmd.Context(), logger, action.TraceRunOpts{
Store: store,
RepoRoot: repoRoot,
Providers: traceProviderFlags{claude: claudeFlag, cursor: cursorFlag, opencode: opencodeFlag, pi: piFlag, codex: codexFlag}.namesOrDefault(),
Providers: traceProviderFlags{claude: claudeFlag, cursor: cursorFlag, opencode: opencodeFlag, pi: piFlag, codex: codexFlag, copilot: copilotFlag}.namesOrDefault(),
Command: args,
ProjectName: projectFlag,
Organization: organization,
Expand All @@ -191,6 +192,7 @@ func newTraceRunCmd() *cobra.Command {
cmd.Flags().BoolVar(&cursorFlag, "cursor", false, "install Cursor hooks")
cmd.Flags().BoolVar(&piFlag, "pi", false, "install Pi extension")
cmd.Flags().BoolVar(&codexFlag, "codex", false, "install Codex hooks")
cmd.Flags().BoolVar(&copilotFlag, "copilot", false, "install GitHub Copilot hooks (Copilot CLI and VS Code)")
cmd.Flags().BoolVar(&opencodeFlag, "opencode", false, "install opencode hooks")

// project and workflow are not required in local mode, so the check is done
Expand Down
4 changes: 3 additions & 1 deletion app/cli/documentation/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3154,7 +3154,7 @@ named freely; the name is normalized to the lowercase, dash-separated form
Chainloop stores. It then asks which harnesses to trace, with the ones the
repository is already set up for ticked, or Claude Code on a first run; use
space to tick more. Passing --org, --project or a harness flag
(--claude, --cursor, --opencode, --pi, --codex) skips the matching question.
(--claude, --cursor, --opencode, --pi, --codex, --copilot) skips the matching question.

Nothing is asked in CI or when the output is redirected: there --project is
required unless .chainloop.yml carries projectName. Set CHAINLOOP_NO_PROMPT to
Expand Down Expand Up @@ -3187,6 +3187,7 @@ Options
--claude[=true|false] install Claude Code hooks (default when no harness flag is set)
--codex[=true|false] install Codex hooks
--contract string workflow contract to attach when creating the workflow; it must already exist and be usable by the project (default: "chainloop-ai-coding-session" when the organization has it, an empty contract otherwise)
--copilot[=true|false] install GitHub Copilot hooks (Copilot CLI and VS Code)
--cursor[=true|false] install Cursor hooks
-h, --help[=true|false] help for init
--local[=true|false] set up local mode, with no control plane, login or workflow. The pre-push hook writes the session evidence to disk
Expand Down Expand Up @@ -3257,6 +3258,7 @@ Options
--claude[=true|false] install Claude Code hooks (default when no provider flag is set)
--codex[=true|false] install Codex hooks
--contract string workflow contract to attach when creating the workflow; it must already exist and be usable by the project (default: "chainloop-ai-coding-session" when the organization has it, an empty contract otherwise)
--copilot[=true|false] install GitHub Copilot hooks (Copilot CLI and VS Code)
--cursor[=true|false] install Cursor hooks
-h, --help[=true|false] help for run
--local[=true|false] store the session on disk, with no control plane, login or workflow
Expand Down
Loading
Loading