Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var IndexCmd = &cobra.Command{ Use: "index [flags]", Short: "Build or rebuild the CANARY token database", Long: `Scan the codebase for CANARY tokens and store metadata in SQLite database. This enables advanced features like priority ordering, keyword search, and checkpoints. The database is stored at .canary/canary.db by default. The rebuild is one transaction: either the new index fully replaces the old one, or the old one is left exactly as it was. A token the scanner cannot parse fails the run rather than being skipped with a warning.`, RunE: func(cmd *cobra.Command, args []string) error { prompt, _ := cmd.Flags().GetString("prompt") if prompt != "" { if _, err := utils.LoadPrompt(prompt); err != nil { return err } } dbPath, _ := cmd.Flags().GetString("db") rootPath, _ := cmd.Flags().GetString("root") if cmd.Flags().Changed("db") { if !filepath.IsAbs(dbPath) { dbPath = filepath.Join(rootPath, dbPath) } } else { dbPath = filepath.Join(rootPath, ".canary", "canary.db") } if abs, err := filepath.Abs(dbPath); err == nil { dbPath = abs } projectID, err := utils.WriteProjectID(cmd, rootPath) if err != nil { return err } ctx := cmd.Context() if ctx == nil { ctx = context.Background() } return RunContext(ctx, Options{Root: rootPath, DBPath: dbPath, ProjectID: projectID}, cmd.OutOrStdout(), cmd.ErrOrStderr()) }, }
CANARY: REQ=ENG-4307; FEATURE="IndexCmd"; ASPECT=CLI; STATUS=TESTED; TEST=TestAuditF12,TestAuditF12CleanRunCommits,TestCANARY_CP_285_IndexRespectsCanaryIgnore,TestAuditR10_IndexingSecondProjectPreservesFirst,TestIndexRefusesUnreadableTokenFile,TestIndexRefusesOversizedTextFile,TestIndexAcceptsBinariesAsBenign,TestIndexRootsDefaultDB,TestIndexExplicitRelativeDBUnderRoot,TestIndexExplicitAbsoluteDBStaysPut; UPDATED=2026-09-01
Functions ¶
func ComputeScanDigest ¶ added in v0.3.4
ComputeScanDigest returns the content digest of every token-bearing file under root, computed exactly as `canary index` records it in IndexMeta: the same .canary/project.yaml registry (sources.LoadFromRoot), the same .canaryignore (canaryscan.LoadCanaryIgnore), and the same (unrestricted, skip=nil) scan `canary index` passes to ScanTokenRecords.
`canary index` no longer calls this function for its own digest -- RunE above digests the `files` result of its own ScanTokenRecords call directly via canaryscan.ScanDigest, so the recorded digest describes exactly the snapshot the tokens were built from rather than a second, possibly different, scan of the tree. This function still exists for `canary next`'s index-freshness check (openFreshIndex) and for test fixtures, and both paths are required to use the identical scan inputs described above. If they ever diverge, freshness becomes fiction -- an index could describe a tree whose tokens changed and still read as current. CANARY: REQ=CBIN-132; FEATURE="ScanDigestHelper"; ASPECT=Engine; STATUS=TESTED; TEST=TestCANARY_CBIN_132_CLI_UncommittedEditInvalidatesIndex,TestCANARY_CBIN_132_CLI_ProjectYamlEditInvalidatesIndex; UPDATED=2026-08-31
func ComputeScanDigestContext ¶ added in v0.3.9
ComputeScanDigestContext computes canonical token-source freshness with cancellation.