prioritize

package
v0.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PrioritizeCmd = &cobra.Command{
	Use:   "prioritize <REQ-ID> <feature> <priority>",
	Short: "Update priority of a CANARY token",
	Long: `Update the priority of a specific token (1=highest, 10=lowest).

Priority affects ordering in list and search results.`,
	Args: cobra.ExactArgs(3),
	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")
		root, _ := cmd.Flags().GetString("root")
		if root == "" {
			root = "."
		}

		if !cmd.Flags().Changed("db") {
			dbPath = filepath.Join(root, ".canary", "canary.db")
		} else if !filepath.IsAbs(dbPath) {
			dbPath = filepath.Join(root, dbPath)
		}
		reqID := args[0]
		feature := args[1]
		priority, err := strconv.Atoi(args[2])
		if err != nil {
			return fmt.Errorf("invalid priority: %s (must be 1-10)", args[2])
		}

		projectID, err := utils.WriteProjectID(cmd, root)
		if err != nil {
			return err
		}

		if _, err := Apply(root, dbPath, projectID, reqID, feature, priority); err != nil {
			return utils.GuardContract(cmd, err)
		}

		fmt.Printf("✅ Updated priority for %s/%s to %d\n", reqID, feature, priority)
		return nil
	},
}

CANARY: REQ=ENG-4310; FEATURE="PrioritizeCmd"; ASPECT=CLI; STATUS=TESTED; OWNER=canary; TEST=TestAuditR07MutationsSurviveReindex,TestPrioritizePartialFailureLeavesSourceUntouched,TestPrioritizeRespectsRoot,TestPrioritizeDBFailureRestoresSource; UPDATED=2026-09-01

Functions

func Apply added in v0.3.6

func Apply(root, dbPath, projectID, reqID, feature string, priority int) (updated int, err error)

Apply is the one prioritization implementation (C5-05): the CLI's `prioritize` command and the MCP `prioritize` tool both route through it rather than each re-implementing the source-rewrite/DB-update/rollback sequence. feature=="" means every feature under the requirement -- the shape the MCP tool needs, since it has no feature parameter.

It validates reqID and the 1-10 priority range, resolves the matching token rows, rewrites their canonical source PRIORITY field BEFORE the DB write (so a later `canary index`, which rebuilds rows from source, never silently discards the mutation), then updates the derived DB row for each distinct feature found among the matches. If any DB write fails, the source rewrite is rolled back and the error says so.

updated is the number of token rows whose source was rewritten (and, on success, whose DB row was updated).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL