MCPcopy Create free account
hub / github.com/JordanCoin/codemap / Build

Function Build

handoff/build.go:60–158  ·  view source on GitHub ↗

Build creates a multi-agent handoff artifact from git + daemon state.

(root string, opts BuildOptions)

Source from the content-addressed store, hash-verified

58
59// Build creates a multi-agent handoff artifact from git + daemon state.
60func Build(root string, opts BuildOptions) (*Artifact, error) {
61 absRoot, err := filepath.Abs(root)
62 if err != nil {
63 return nil, err
64 }
65
66 state := opts.State
67 if state == nil {
68 state = watch.ReadState(absRoot)
69 }
70
71 fileCount := resolveRepoFileCount(absRoot, state)
72 opts = normalizeOptions(opts, fileCount)
73
74 branch, err := gitCurrentBranch(absRoot)
75 if err != nil {
76 return nil, fmt.Errorf("failed to read git branch: %w", err)
77 }
78
79 entries, diffErr := collectChangedEntries(absRoot, opts.BaseRef)
80 if diffErr != nil {
81 return nil, diffErr
82 }
83 changedAll := entryPaths(entries)
84
85 recentEvents := summarizeEvents(state, opts.Since, opts.MaxEvents)
86 if len(changedAll) == 0 && len(recentEvents) > 0 {
87 changedAll = changedFromEvents(recentEvents)
88 sort.Strings(changedAll)
89 entries = make([]changedEntry, 0, len(changedAll))
90 for _, path := range changedAll {
91 entries = append(entries, changedEntry{Path: path, Status: "event"})
92 }
93 }
94
95 importers := dependencyImportersForHandoff(absRoot, state, fileCount)
96 riskFiles := summarizeRiskFiles(changedAll, importers, opts.MaxRisk)
97 selectedPaths := prioritizeChangedPaths(changedAll, riskFiles, opts.MaxChanged)
98 entries = selectEntries(entries, selectedPaths)
99
100 changedStubs := buildFileStubs(absRoot, entries)
101 hubs := summarizeHubs(importers, opts.MaxHubs)
102
103 nextSteps, openQuestions := deriveGuidance(selectedPaths, riskFiles, recentEvents, opts.BaseRef, state != nil, len(importers) > 0)
104
105 prefix := PrefixSnapshot{
106 FileCount: fileCount,
107 Hubs: nonNilHubs(hubs),
108 }
109 delta := DeltaSnapshot{
110 Changed: nonNilStubs(changedStubs),
111 RiskFiles: nonNilRiskFiles(riskFiles),
112 RecentEvents: nonNilEvents(recentEvents),
113 NextSteps: nonNilStrings(nextSteps),
114 OpenQuestions: nonNilStrings(openQuestions),
115 }
116
117 prefixHash, prefixBytes, err := hashCanonical(prefix)

Callers 6

runHandoffSubcommandFunction · 0.92
writeSessionHandoffFunction · 0.92
handleGetHandoffFunction · 0.92
TestBuildWriteReadFunction · 0.85
TestBuildFileDetailFunction · 0.85

Calls 15

ReadStateFunction · 0.92
resolveRepoFileCountFunction · 0.85
normalizeOptionsFunction · 0.85
collectChangedEntriesFunction · 0.85
entryPathsFunction · 0.85
summarizeEventsFunction · 0.85
changedFromEventsFunction · 0.85
summarizeRiskFilesFunction · 0.85
prioritizeChangedPathsFunction · 0.85
selectEntriesFunction · 0.85
buildFileStubsFunction · 0.85

Tested by 3

TestBuildWriteReadFunction · 0.68
TestBuildFileDetailFunction · 0.68