refactor(prompts): every model prompt is a file in internal/prompts
deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
ci/woodpecker/push/deploy Pipeline was canceled
deploy / gate (push) Canceled after 2m58s
deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
ci/woodpecker/push/deploy Pipeline was canceled
deploy / gate (push) Canceled after 2m58s
This commit is contained in:
31 files changed
+286
-183
No files matched your search
@@ -35,8 +35,10 @@ and calls its composition root in `internal/app/<service>`.
|
||||
| `archie-agent` | The worker inside each task container | NATS |
|
||||
|
||||
`internal/domain` holds behaviour and interfaces; `internal/infrastructure`
|
||||
implements them. Dashboard work follows `ui/CLAUDE.md`. Workflow YAML and its
|
||||
step vocabulary are in `WORKFLOWS.md`; the server catalogue is authoritative.
|
||||
implements them. Every instruction sent to a model is a file in
|
||||
`internal/prompts`, read through that package; never inline a prompt in code.
|
||||
Dashboard work follows `ui/CLAUDE.md`. Workflow YAML and its step vocabulary
|
||||
are in `WORKFLOWS.md`; the server catalogue is authoritative.
|
||||
|
||||
## Authority
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
)
|
||||
|
||||
// missionWithHistory puts the conversation of an earlier run of the stage
|
||||
@@ -17,8 +18,7 @@ func missionWithHistory(req agentrun.Request) string {
|
||||
return req.Mission
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("<previous_run>\nAn earlier run of this stage stopped at its step budget and was approved to continue. " +
|
||||
"Its conversation follows and its edits are already in the worktree. Continue from where it stopped; do not start over.\n\n")
|
||||
b.WriteString("<previous_run>\n" + prompts.ResumeRun() + "\n\n")
|
||||
for _, e := range entries {
|
||||
switch e.Kind {
|
||||
case agentrun.TranscriptModel:
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/controlplanerpc"
|
||||
"github.com/samcharles93/archie-core/internal/installtype"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
"github.com/samcharles93/archie-core/internal/releaseupdate"
|
||||
"github.com/samcharles93/archie-core/internal/tools"
|
||||
)
|
||||
@@ -369,7 +370,7 @@ func newChatTitleGenerator(s chatSetup) gateway.TitleGenerator {
|
||||
|
||||
func (g *chatTitleGenerator) GenerateTitle(ctx context.Context, sessionID, firstMessage string) (string, error) {
|
||||
messages := []chat.Message{
|
||||
{Role: chat.RoleSystem, Content: gateway.TitleGenerationSystemPrompt},
|
||||
{Role: chat.RoleSystem, Content: prompts.SessionTitle()},
|
||||
{Role: chat.RoleUser, Content: firstMessage},
|
||||
}
|
||||
// No tools: a title is a single completion. The active model is read
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/prreview"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/prreview/bench"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
)
|
||||
|
||||
// modelJudge asks one model, independent of the reviewer's, which posted
|
||||
@@ -29,7 +30,7 @@ func (j *modelJudge) Judge(ctx context.Context, p bench.Problem, comments []prre
|
||||
sub := agent.Subagent{
|
||||
Provider: provider,
|
||||
Model: model,
|
||||
System: judgeSystemPrompt,
|
||||
System: prompts.PRBenchmarkJudge(),
|
||||
Tools: core.ToolSet{"record_verdict": recordVerdictTool(len(p.Goldens), len(comments), &verdicts)},
|
||||
MaxSteps: 2*len(p.Goldens) + 3,
|
||||
}
|
||||
@@ -41,12 +42,6 @@ func (j *modelJudge) Judge(ctx context.Context, p bench.Problem, comments []prre
|
||||
return verdicts, nil
|
||||
}
|
||||
|
||||
const judgeSystemPrompt = `You score a code reviewer against known defects. You are given the pull request's known defects (goldens) and the numbered comments the reviewer posted.
|
||||
|
||||
For each golden, decide whether any posted comment identifies the same underlying defect: the same location and the same root cause. A comment about the same file but a different problem is not a match, and neither is a vague comment that would only be right by coincidence. Wording does not need to match.
|
||||
|
||||
Call record_verdict exactly once per golden. Pass the index of the matching comment, or -1 when no comment matches, and a one-sentence reason. When several comments match, pass the one that states the defect most directly.`
|
||||
|
||||
func judgePrompt(p bench.Problem, comments []prreview.ScoredFinding) string {
|
||||
var b strings.Builder
|
||||
fmt.Fprintf(&b, "Pull request: %s\n\n<goldens>\n", p.PRURL)
|
||||
|
||||
@@ -3,6 +3,8 @@ package agent
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
)
|
||||
|
||||
// MaxSoulBytes bounds a SOUL document. Its body renders into the prompt ahead
|
||||
@@ -24,35 +26,9 @@ func (s Soul) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// archieIdentity is the default agent's identity and reporting style.
|
||||
const archieIdentity = `You are Archie, the operator's assistant for an event-driven automation system. Events start workflows, workflows run agents and tools, and results come back for review or action. A repository is one optional input to a workflow, not the point of the product.
|
||||
|
||||
Be direct without being brusque, and ground what you say in the system's actual state.
|
||||
|
||||
Reporting
|
||||
- Lead with the outcome. For work, say what you found, what you changed, how you checked it, and what remains. For a question, answer it and stop.
|
||||
- Name the workflows, tasks, services and commands involved. Give numbers and exact error text instead of summaries of them.
|
||||
- Explain a failure as what failed and why. If the cause is not established, say so and name what would establish it.
|
||||
- Separate what you verified from what you did not.
|
||||
- Match length to the question.
|
||||
|
||||
Decisions
|
||||
- When a choice is the operator's, ask a specific question and recommend an answer. Ask every open question together. Otherwise decide, act, and say what you chose.
|
||||
- Offer work that was not asked for only as a follow-up. Do not start it.
|
||||
|
||||
Style
|
||||
- Plain, specific words. No flattery, apologies or closing offers of more help.
|
||||
- Do not repeat the request or narrate routine steps.
|
||||
- Never present a guess as a finding.
|
||||
`
|
||||
|
||||
// DefaultSoul is the starter SOUL document: the agent's identity prose in the
|
||||
// system prompt.
|
||||
const DefaultSoul = "# Archie\n\n" + archieIdentity
|
||||
|
||||
// ShippedSoul returns the SOUL document this build ships.
|
||||
func ShippedSoul() string {
|
||||
return DefaultSoul
|
||||
return prompts.Soul()
|
||||
}
|
||||
|
||||
// SoulMatchesShipped reports whether content equals shipped after line-ending
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
"github.com/samcharles93/archie-core/internal/tools"
|
||||
)
|
||||
|
||||
@@ -130,7 +131,7 @@ func definitionMessages(instructions string, built []tools.ToolEntry, reason str
|
||||
|
||||
user := strings.TrimSpace(reason)
|
||||
if user == "" {
|
||||
user = "Run your scheduled pass now."
|
||||
user = prompts.CuratorPass()
|
||||
}
|
||||
return []Message{
|
||||
{Role: "system", Content: system},
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
"github.com/samcharles93/archie-core/internal/skill"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
@@ -382,7 +383,7 @@ func missionWithSkill(tc *TaskContext, mission string) string {
|
||||
if tc.SkillBody == "" {
|
||||
return mission
|
||||
}
|
||||
return "Follow these project-specific guidelines:\n\n" + tc.SkillBody + "\n\n---\n\n" + mission
|
||||
return prompts.SkillGuidelines(tc.SkillBody, mission)
|
||||
}
|
||||
|
||||
// loadSkillBody loads the SKILL.md body for the current workflow, matched by
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
)
|
||||
|
||||
// Byte limits on failing gate output: the tail logged, what the builder sees,
|
||||
@@ -60,20 +61,7 @@ func stageBaselineGateRun(ctx context.Context, tc *TaskContext) error {
|
||||
// failure via TDD and commits the result. It is reached only for a code
|
||||
// failure: an environment failure is parked by the caller before it runs.
|
||||
func runBaselineFix(ctx context.Context, tc *TaskContext, argv []string, out []byte) error {
|
||||
mission := fmt.Sprintf(
|
||||
"The baseline gate check `%s` failed on the repository %s at the base commit "+
|
||||
"(before any feature work). This is a pre-existing issue -- not caused by your work. "+
|
||||
"Fix it using TDD:\n\n"+
|
||||
"1. Write a test that proves the failure exists\n"+
|
||||
"2. Run the test -- it should FAIL (confirming the bug)\n"+
|
||||
"3. Fix the root cause\n"+
|
||||
"4. Run the test -- it should PASS\n"+
|
||||
"5. Repeat until the gate `%s` passes for all packages\n\n"+
|
||||
"Gate output:\n%s\n\n"+
|
||||
"When the gate passes, call finish with status \"passed\".",
|
||||
strings.Join(argv, " "), tc.Repo.FullName(), strings.Join(argv, " "),
|
||||
clip(extractFailingGateOutput(string(out)), baselineMissionBytes),
|
||||
)
|
||||
mission := prompts.BaselineFix(strings.Join(argv, " "), tc.Repo.FullName(), clip(extractFailingGateOutput(string(out)), baselineMissionBytes))
|
||||
|
||||
modelRef, err := config.ResolveModel(tc.Cfg.Models, "", config.PurposeAgent)
|
||||
if err != nil {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/prreview"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
@@ -220,16 +221,7 @@ func scoreAIGenerated(ctx context.Context, tc *TaskContext, meta PRMetadata) (fl
|
||||
},
|
||||
"required": ["confidence"]
|
||||
}`)
|
||||
mission := fmt.Sprintf(
|
||||
"Judge whether this pull request's own description reads as written by an AI "+
|
||||
"coding assistant rather than the human who opened it: generic boilerplate, a "+
|
||||
"summary that oversells the diff, or phrasing typical of an LLM's own commit "+
|
||||
"or PR style. This is about the PR's description, not the code.\n\n"+
|
||||
"Title: %s\n\nDescription:\n%s\n\nCommit messages:\n%s\n\n"+
|
||||
"Call score_ai_generated exactly once with your confidence, then call finish "+
|
||||
"with status \"passed\".",
|
||||
meta.Title, meta.Body, strings.Join(meta.Commits, "\n"),
|
||||
)
|
||||
mission := prompts.PRReviewAIScore(meta.Title, meta.Body, strings.Join(meta.Commits, "\n"))
|
||||
res, err := runPRReviewAgent(ctx, tc, scratch, "intake-ai-score", mission, 6, []agentrun.CaptureTool{{
|
||||
Name: "score_ai_generated", Description: "Record the machine-written confidence. Call exactly once, before finish.",
|
||||
Parameters: params, RequiredFields: []string{"confidence"}, MaxCalls: 1,
|
||||
@@ -268,12 +260,11 @@ func restoreReviewGate(tc *TaskContext) {
|
||||
|
||||
// It is empty -- and therefore absent -- on a run the operator did not
|
||||
// instruct, which is what keeps "a first run's do not" true.
|
||||
func operatorInstructionsBlock(tc *TaskContext) string {
|
||||
if tc.prReview == nil || tc.prReview.operatorInstructions == "" {
|
||||
func operatorInstructions(tc *TaskContext) string {
|
||||
if tc.prReview == nil {
|
||||
return ""
|
||||
}
|
||||
return "Operator instructions for this re-review, written by the operator who read the " +
|
||||
"previous findings. Address them in your work:\n" + tc.prReview.operatorInstructions + "\n\n"
|
||||
return tc.prReview.operatorInstructions
|
||||
}
|
||||
|
||||
func stagePRAnatomy() Stage {
|
||||
@@ -305,15 +296,7 @@ func stagePRAnatomy() Stage {
|
||||
}
|
||||
tc.prReview.highExposure = prreview.HighExposureFiles(exposure)
|
||||
|
||||
mission := fmt.Sprintf(
|
||||
"Read this pull request's diff and enough of the surrounding repository to "+
|
||||
"write a short narrative of the change: what it does, the riskiest surfaces "+
|
||||
"it touches, any change that does not fit the PR's own description, and any "+
|
||||
"gap between what the description claims and what the diff carries out.\n\n"+
|
||||
"Title: %s\n\nDescription:\n%s\n\nDiff:\n%s\n\n"+
|
||||
"Call finish with status \"passed\" and your narrative as the summary.",
|
||||
tc.prReview.metadata.Title, tc.prReview.metadata.Body, clip(tc.prReview.diff, 60000),
|
||||
)
|
||||
mission := prompts.PRReviewAnatomy(tc.prReview.metadata.Title, tc.prReview.metadata.Body, clip(tc.prReview.diff, 60000))
|
||||
if budgetExhausted(tc, "anatomy") {
|
||||
skipPhase(tc, "anatomy")
|
||||
return nil
|
||||
@@ -327,17 +310,6 @@ func stagePRAnatomy() Stage {
|
||||
}}
|
||||
}
|
||||
|
||||
// Each proposes review dimensions from a different angle; code merges, dedups
|
||||
// and caps the result.
|
||||
var prReviewLenses = []struct {
|
||||
name string
|
||||
prompt string
|
||||
}{
|
||||
{name: "behaviour", prompt: "where the old and new code diverge for any input: API contracts, concurrency and state, security, error handling, data flow"},
|
||||
{name: "mechanics", prompt: "whether the code runs at the language and framework level: types, signatures and every caller, decorators and middleware, framework contracts, imports"},
|
||||
{name: "fit", prompt: "patterns, complexity, abstraction, test adequacy, documentation that no longer matches, dependencies, migration completeness"},
|
||||
}
|
||||
|
||||
// The hallucination dimension competes for the same cap as everything else --
|
||||
// "at most N dimensions" is a total, not a total plus one
|
||||
// -- so it is added before MergeDimensions cuts the tail, never after.
|
||||
@@ -347,14 +319,17 @@ func stagePRLenses() Stage {
|
||||
skipPhase(tc, "lenses")
|
||||
return nil
|
||||
}
|
||||
outputs := make([][]prreview.Dimension, len(prReviewLenses))
|
||||
errs := make([]error, len(prReviewLenses))
|
||||
forEachBounded(len(prReviewLenses), len(prReviewLenses), func(i int) {
|
||||
outputs[i], errs[i] = runLens(ctx, tc, prReviewLenses[i].name, prReviewLenses[i].prompt)
|
||||
// Each lens proposes dimensions from its own angle; code merges, dedups
|
||||
// and caps the result.
|
||||
lenses := prompts.PRReviewLenses()
|
||||
outputs := make([][]prreview.Dimension, len(lenses))
|
||||
errs := make([]error, len(lenses))
|
||||
forEachBounded(len(lenses), len(lenses), func(i int) {
|
||||
outputs[i], errs[i] = runLens(ctx, tc, lenses[i])
|
||||
})
|
||||
for i, err := range errs {
|
||||
if err != nil {
|
||||
return fmt.Errorf("lens %s: %w", prReviewLenses[i].name, err)
|
||||
return fmt.Errorf("lens %s: %w", lenses[i].Name, err)
|
||||
}
|
||||
}
|
||||
candidates := outputs
|
||||
@@ -367,7 +342,7 @@ func stagePRLenses() Stage {
|
||||
}
|
||||
|
||||
// runLens runs one phase-3 lens call and decodes its proposed dimensions.
|
||||
func runLens(ctx context.Context, tc *TaskContext, name, angle string) ([]prreview.Dimension, error) {
|
||||
func runLens(ctx context.Context, tc *TaskContext, lens prompts.Lens) ([]prreview.Dimension, error) {
|
||||
params := json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -388,18 +363,8 @@ func runLens(ctx context.Context, tc *TaskContext, name, angle string) ([]prrevi
|
||||
},
|
||||
"required": ["dimensions"]
|
||||
}`)
|
||||
mission := fmt.Sprintf(
|
||||
"You are the %s lens over this pull request: %s.\n\n"+
|
||||
"Title: %s\n\nDescription:\n%s\n\nDiff:\n%s\n\n%s"+
|
||||
"Propose the review dimensions this angle needs, each with a reviewer prompt "+
|
||||
"written for this specific PR, its target files, any context files a reviewer "+
|
||||
"should also read, and a priority (higher runs first when the depth caps how "+
|
||||
"many dimensions survive). Call propose_dimensions exactly once, then call "+
|
||||
"finish with status \"passed\".",
|
||||
name, angle, tc.prReview.metadata.Title, tc.prReview.metadata.Body, clip(tc.prReview.diff, 60000),
|
||||
operatorInstructionsBlock(tc),
|
||||
)
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "lens-"+name, mission, 15, []agentrun.CaptureTool{{
|
||||
mission := prompts.PRReviewLens(lens, tc.prReview.metadata.Title, tc.prReview.metadata.Body, clip(tc.prReview.diff, 60000), operatorInstructions(tc))
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "lens-"+lens.Name, mission, 15, []agentrun.CaptureTool{{
|
||||
Name: "propose_dimensions", Description: "Record this lens's proposed review dimensions. Call exactly once, before finish.",
|
||||
Parameters: params, RequiredFields: []string{"dimensions"}, MaxCalls: 1,
|
||||
}})
|
||||
@@ -408,7 +373,7 @@ func runLens(ctx context.Context, tc *TaskContext, name, angle string) ([]prrevi
|
||||
}
|
||||
calls := res.Captures["propose_dimensions"]
|
||||
if len(calls) != 1 {
|
||||
return nil, fmt.Errorf("lens %s called propose_dimensions %d times (want exactly once)", name, len(calls))
|
||||
return nil, fmt.Errorf("lens %s called propose_dimensions %d times (want exactly once)", lens.Name, len(calls))
|
||||
}
|
||||
var captured struct {
|
||||
Dimensions []struct {
|
||||
@@ -420,7 +385,7 @@ func runLens(ctx context.Context, tc *TaskContext, name, angle string) ([]prrevi
|
||||
} `json:"dimensions"`
|
||||
}
|
||||
if err := json.Unmarshal(calls[0], &captured); err != nil {
|
||||
return nil, fmt.Errorf("decode lens %s dimensions: %w", name, err)
|
||||
return nil, fmt.Errorf("decode lens %s dimensions: %w", lens.Name, err)
|
||||
}
|
||||
out := make([]prreview.Dimension, len(captured.Dimensions))
|
||||
for i, d := range captured.Dimensions {
|
||||
@@ -459,14 +424,7 @@ func stagePRReview() Stage {
|
||||
// runReviewer runs one reviewer call and returns its findings, or none if
|
||||
// it failed.
|
||||
func runReviewer(ctx context.Context, tc *TaskContext, dim prreview.Dimension) []prreview.Finding {
|
||||
mission := fmt.Sprintf(
|
||||
"%s\n\nTarget files: %s\n\n%sRead the target files (and, if useful, the context "+
|
||||
"files) in the snapshot and report every finding for this dimension. Quote the "+
|
||||
"exact evidence for each finding; do not report anything you cannot point at in "+
|
||||
"the code. Call report_findings exactly once (an empty array is a valid, "+
|
||||
"complete report), then call finish with status \"passed\".",
|
||||
dim.Prompt, strings.Join(dim.TargetFiles, ", "), operatorInstructionsBlock(tc),
|
||||
)
|
||||
mission := prompts.PRReviewReviewer(dim.Prompt, strings.Join(dim.TargetFiles, ", "), operatorInstructions(tc))
|
||||
name := "reviewer-" + dim.Name
|
||||
res, runErr := runReviewerAgent(ctx, tc, name, mission, []agentrun.CaptureTool{reportFindingsTool})
|
||||
if runErr != nil || res.Status != agentrun.StatusPassed {
|
||||
@@ -655,13 +613,7 @@ func polishFinding(ctx context.Context, tc *TaskContext, f prreview.ScoredFindin
|
||||
"properties": {"body": {"type": "string", "description": "The tightened finding body."}},
|
||||
"required": ["body"]
|
||||
}`)
|
||||
mission := fmt.Sprintf(
|
||||
"Tighten the wording of this review comment without changing its meaning or "+
|
||||
"dropping any concrete detail (file, line, failure scenario).\n\n"+
|
||||
"Title: %s\nBody: %s\n\nCall polish exactly once with the tightened body, then "+
|
||||
"call finish with status \"passed\".",
|
||||
f.Title, f.Body,
|
||||
)
|
||||
mission := prompts.PRReviewPolish(f.Title, f.Body)
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "polish", mission, 4, []agentrun.CaptureTool{{
|
||||
Name: "polish", Description: "Record the tightened comment body. Call exactly once, before finish.",
|
||||
Parameters: params, RequiredFields: []string{"body"}, MaxCalls: 1,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
"github.com/samcharles93/archie-core/internal/tools"
|
||||
)
|
||||
|
||||
@@ -83,7 +84,7 @@ func pageIndexTool() (tools.ToolEntry, bool) {
|
||||
Description: "List every dashboard page, what it shows, and built-in guidance for creating workflows and using Archie. Use it to tell the operator where to go for something rather than guessing.",
|
||||
Classification: tools.ClassIdempotent,
|
||||
Handler: func(_ context.Context, _ map[string]any) (any, error) {
|
||||
return PageIndexResult{Pages: DashboardPages(), ProductGuide: productGuide}, nil
|
||||
return PageIndexResult{Pages: DashboardPages(), ProductGuide: prompts.ProductGuide()}, nil
|
||||
},
|
||||
}
|
||||
return entry, true
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
)
|
||||
|
||||
//go:embed templates/archie.md.tpl
|
||||
var archiePromptTpl string
|
||||
|
||||
//go:embed templates/product-guide.md
|
||||
var productGuide string
|
||||
|
||||
// ToolSummary is the capability metadata for one registered tool, as it is
|
||||
// advertised to the model.
|
||||
type ToolSummary struct {
|
||||
@@ -73,22 +67,6 @@ type promptData struct {
|
||||
ProductGuide string
|
||||
}
|
||||
|
||||
// escapeXML replaces the three bytes that would otherwise be read as markup
|
||||
// inside a trust="data" block. Exported within the package so callers that
|
||||
// must bound a block's *rendered* size (turn_memory.go's byte cap) measure
|
||||
// the same expansion the template applies, rather than the pre-escape size.
|
||||
var escapeXML = strings.NewReplacer(
|
||||
"&", "&",
|
||||
"<", "<",
|
||||
">", ">",
|
||||
).Replace
|
||||
|
||||
var archiePromptTemplate = template.Must(
|
||||
template.New("archie").
|
||||
Funcs(template.FuncMap{"xml": escapeXML}).
|
||||
Parse(archiePromptTpl),
|
||||
)
|
||||
|
||||
// BuildSystemPrompt renders the chat agent's system prompt.
|
||||
func BuildSystemPrompt(cfg SystemPromptConfig) string {
|
||||
tools := make([]ToolSummary, len(cfg.Tools))
|
||||
@@ -111,14 +89,7 @@ func BuildSystemPrompt(cfg SystemPromptConfig) string {
|
||||
Repos: cfg.Repos,
|
||||
Operator: cfg.Operator,
|
||||
Memory: cfg.Memory,
|
||||
ProductGuide: productGuide,
|
||||
ProductGuide: prompts.ProductGuide(),
|
||||
}
|
||||
var buf strings.Builder
|
||||
if err := archiePromptTemplate.Execute(&buf, data); err != nil {
|
||||
tpl := "You are Archie, a coding and project assistant. " +
|
||||
"Never claim a tool, file, memory, action or result you have not verified. " +
|
||||
"Keep replies short and lead with the answer."
|
||||
return tpl
|
||||
}
|
||||
return strings.TrimSpace(buf.String())
|
||||
return prompts.ChatSystem(data)
|
||||
}
|
||||
@@ -14,21 +14,6 @@ type TitleGenerator interface {
|
||||
GenerateTitle(ctx context.Context, sessionID, firstMessage string) (string, error)
|
||||
}
|
||||
|
||||
// TitleGenerationSystemPrompt instructs the model how to propose a
|
||||
// session title. The title contract (length, shape) is messaging's
|
||||
// concern, so the prompt lives beside the generator, and the result is
|
||||
// still normalised by cleanGeneratedTitle before it is persisted.
|
||||
const TitleGenerationSystemPrompt = `You write short titles for conversation logs.
|
||||
|
||||
Given a user message from a new conversation, write a title for the
|
||||
conversation. Requirements:
|
||||
- 3 to 6 words, under 60 characters
|
||||
- Name the subject: the system, task, error or goal the message is about
|
||||
- Never describe the user's mood or tone
|
||||
- No quotes, no bullet, no trailing period
|
||||
- Reply with the title only, nothing else
|
||||
- If the message names no subject (an exclamation, a greeting), reply NONE`
|
||||
|
||||
// maxTitleRunes caps how long a generated session title may be. Titles
|
||||
// stay short enough to render on one line in a chat bubble.
|
||||
const maxTitleRunes = 60
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
domainmemory "github.com/samcharles93/archie-core/internal/domain/memory"
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
)
|
||||
|
||||
// memoryRecordsPerScope bounds how many records of each scope the read path
|
||||
@@ -71,7 +72,7 @@ func renderMemoryRecords(records []domainmemory.Record, log *slog.Logger) string
|
||||
dropped := 0
|
||||
for _, record := range records {
|
||||
line := fmt.Sprintf("- [%s] (%s, %s) %s\n", record.ID, record.Scope.Kind, record.Kind, record.Content)
|
||||
next := escapedLen + len(escapeXML(line))
|
||||
next := escapedLen + len(prompts.EscapeXML(line))
|
||||
if next > memoryBlockByteCap {
|
||||
dropped++
|
||||
continue
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/curator"
|
||||
domainmemory "github.com/samcharles93/archie-core/internal/domain/memory"
|
||||
"github.com/samcharles93/archie-core/internal/prompts"
|
||||
)
|
||||
|
||||
// Name is the identifier this curator registers under.
|
||||
@@ -233,21 +234,13 @@ func sessionParticipant(msgs []curator.ConversationMessage) (participant, reason
|
||||
return "", fmt.Sprintf("no single participant: %d distinct sender(s)", len(senders))
|
||||
}
|
||||
|
||||
// extractPrompt instructs the model to return a JSON array of short,
|
||||
// durable strings -- facts, preferences, or corrections worth keeping --
|
||||
// or [] if nothing in the excerpt is worth keeping. No prose outside the
|
||||
// array: the response is parsed directly as JSON.
|
||||
const extractPrompt = `Review this conversation excerpt. List any durable facts, preferences, or corrections about the user or their work that are worth remembering for future conversations -- not the flow of the conversation itself, not anything already obvious from context, not one-off task details.
|
||||
|
||||
Respond with ONLY a JSON array of short strings, one per fact. Respond with [] if nothing in this excerpt is worth keeping. No other text.`
|
||||
|
||||
// askModel sends msgs plus the extraction instruction and returns the
|
||||
// model's raw response text. A non-nil error here is a real failure
|
||||
// (provider down, timeout) -- distinct from parseFacts failing on a
|
||||
// response that came back but wasn't valid JSON.
|
||||
func (c *Curator) askModel(ctx context.Context, msgs []curator.ConversationMessage) (string, error) {
|
||||
chatMsgs := make([]curator.Message, 0, len(msgs)+1)
|
||||
chatMsgs = append(chatMsgs, curator.Message{Role: "system", Content: extractPrompt})
|
||||
chatMsgs = append(chatMsgs, curator.Message{Role: "system", Content: prompts.SessionMemory()})
|
||||
for _, m := range msgs {
|
||||
chatMsgs = append(chatMsgs, curator.Message{Role: m.Role, Content: m.Content})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
The baseline gate check `{{.Gate}}` failed on the repository {{.Repository}} at the base commit (before any feature work). This is a pre-existing issue -- not caused by your work. Fix it using TDD:
|
||||
|
||||
1. Write a test that proves the failure exists
|
||||
2. Run the test -- it should FAIL (confirming the bug)
|
||||
3. Fix the root cause
|
||||
4. Run the test -- it should PASS
|
||||
5. Repeat until the gate `{{.Gate}}` passes for all packages
|
||||
|
||||
Gate output:
|
||||
{{.Output}}
|
||||
|
||||
When the gate passes, call finish with status "passed".
|
||||
File renamed without changes.
@@ -0,0 +1 @@
|
||||
Run your scheduled pass now.
|
||||
@@ -0,0 +1,5 @@
|
||||
You score a code reviewer against known defects. You are given the pull request's known defects (goldens) and the numbered comments the reviewer posted.
|
||||
|
||||
For each golden, decide whether any posted comment identifies the same underlying defect: the same location and the same root cause. A comment about the same file but a different problem is not a match, and neither is a vague comment that would only be right by coincidence. Wording does not need to match.
|
||||
|
||||
Call record_verdict exactly once per golden. Pass the index of the matching comment, or -1 when no comment matches, and a one-sentence reason. When several comments match, pass the one that states the defect most directly.
|
||||
@@ -0,0 +1,11 @@
|
||||
Judge whether this pull request's own description reads as written by an AI coding assistant rather than the human who opened it: generic boilerplate, a summary that oversells the diff, or phrasing typical of an LLM's own commit or PR style. This is about the PR's description, not the code.
|
||||
|
||||
Title: {{.Title}}
|
||||
|
||||
Description:
|
||||
{{.Body}}
|
||||
|
||||
Commit messages:
|
||||
{{.Commits}}
|
||||
|
||||
Call score_ai_generated exactly once with your confidence, then call finish with status "passed".
|
||||
@@ -0,0 +1,11 @@
|
||||
Read this pull request's diff and enough of the surrounding repository to write a short narrative of the change: what it does, the riskiest surfaces it touches, any change that does not fit the PR's own description, and any gap between what the description claims and what the diff carries out.
|
||||
|
||||
Title: {{.Title}}
|
||||
|
||||
Description:
|
||||
{{.Body}}
|
||||
|
||||
Diff:
|
||||
{{.Diff}}
|
||||
|
||||
Call finish with status "passed" and your narrative as the summary.
|
||||
@@ -0,0 +1,11 @@
|
||||
You are the {{.Name}} lens over this pull request: {{.Angle}}.
|
||||
|
||||
Title: {{.Title}}
|
||||
|
||||
Description:
|
||||
{{.Body}}
|
||||
|
||||
Diff:
|
||||
{{.Diff}}
|
||||
|
||||
{{template "operator-instructions" .Instructions}}Propose the review dimensions this angle needs, each with a reviewer prompt written for this specific PR, its target files, any context files a reviewer should also read, and a priority (higher runs first when the depth caps how many dimensions survive). Call propose_dimensions exactly once, then call finish with status "passed".
|
||||
@@ -0,0 +1,4 @@
|
||||
{{define "operator-instructions"}}{{with .}}Operator instructions for this re-review, written by the operator who read the previous findings. Address them in your work:
|
||||
{{.}}
|
||||
|
||||
{{end}}{{end}}
|
||||
@@ -0,0 +1,6 @@
|
||||
Tighten the wording of this review comment without changing its meaning or dropping any concrete detail (file, line, failure scenario).
|
||||
|
||||
Title: {{.Title}}
|
||||
Body: {{.Body}}
|
||||
|
||||
Call polish exactly once with the tightened body, then call finish with status "passed".
|
||||
@@ -0,0 +1,5 @@
|
||||
{{.Dimension}}
|
||||
|
||||
Target files: {{.TargetFiles}}
|
||||
|
||||
{{template "operator-instructions" .Instructions}}Read the target files (and, if useful, the context files) in the snapshot and report every finding for this dimension. Quote the exact evidence for each finding; do not report anything you cannot point at in the code. Call report_findings exactly once (an empty array is a valid, complete report), then call finish with status "passed".
|
||||
File renamed without changes.
@@ -0,0 +1,128 @@
|
||||
// Package prompts holds every instruction archie gives a model, one file per
|
||||
// prompt beside this one, so a prompt is found by its file name rather than by
|
||||
// searching the code. A .md file is sent as written; a .tmpl file is a
|
||||
// text/template filled from the caller's values.
|
||||
//
|
||||
// Some prompts are defaults the operator edits in the dashboard: the SOUL
|
||||
// (soul.md), curator instructions and workflow missions. The shipped
|
||||
// workflows' missions are part of their definitions, in
|
||||
// internal/domain/workflow/shipped.
|
||||
package prompts
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
//go:embed *.md *.tmpl
|
||||
var files embed.FS
|
||||
|
||||
var templates = template.Must(
|
||||
template.New("").
|
||||
Funcs(template.FuncMap{"xml": EscapeXML}).
|
||||
ParseFS(files, "*.tmpl"),
|
||||
)
|
||||
|
||||
// EscapeXML replaces the bytes that would be read as markup inside a
|
||||
// trust="data" block. The chat template applies it, so a caller bounding a
|
||||
// block's rendered size measures the same expansion.
|
||||
var EscapeXML = strings.NewReplacer("&", "&", "<", "<", ">", ">").Replace
|
||||
|
||||
// read returns a static prompt without its file's final newline.
|
||||
func read(name string) string {
|
||||
b, err := files.ReadFile(name)
|
||||
if err != nil {
|
||||
panic("prompts: " + err.Error())
|
||||
}
|
||||
return strings.TrimSuffix(string(b), "\n")
|
||||
}
|
||||
|
||||
// render fills a template. The templates are fixed at build time and filled
|
||||
// from typed values, so a failure is a defect in this package, not input.
|
||||
func render(name string, data any) string {
|
||||
var b strings.Builder
|
||||
if err := templates.ExecuteTemplate(&b, name, data); err != nil {
|
||||
panic("prompts: render " + name + ": " + err.Error())
|
||||
}
|
||||
return strings.TrimSuffix(b.String(), "\n")
|
||||
}
|
||||
|
||||
// ChatSystem is the chat agent's system prompt, filled from the gateway's
|
||||
// prompt data.
|
||||
func ChatSystem(data any) string { return strings.TrimSpace(render("chat-system.tmpl", data)) }
|
||||
|
||||
// ProductGuide is the product guide the chat agent reads from the page index.
|
||||
func ProductGuide() string { return read("product-guide.md") }
|
||||
|
||||
// Soul is the shipped SOUL document: the agent's identity and reporting style.
|
||||
func Soul() string { return read("soul.md") + "\n" }
|
||||
|
||||
// SessionTitle instructs the model to title a conversation.
|
||||
func SessionTitle() string { return read("session-title.md") }
|
||||
|
||||
// SessionMemory instructs the session-memory curator to extract durable facts.
|
||||
func SessionMemory() string { return read("session-memory.md") }
|
||||
|
||||
// CuratorPass is the user turn of a curator pass that names no reason.
|
||||
func CuratorPass() string { return read("curator-pass.md") }
|
||||
|
||||
// ResumeRun introduces an earlier run's conversation to a continued stage.
|
||||
func ResumeRun() string { return read("resume-run.md") }
|
||||
|
||||
// SkillGuidelines puts a project's skill guidelines ahead of a mission.
|
||||
func SkillGuidelines(guidelines, mission string) string {
|
||||
return render("skill-guidelines.tmpl", struct{ Guidelines, Mission string }{guidelines, mission})
|
||||
}
|
||||
|
||||
// BaselineFix asks an agent to repair a gate that fails on the base commit.
|
||||
func BaselineFix(gate, repository, output string) string {
|
||||
return render("baseline-fix.tmpl", struct{ Gate, Repository, Output string }{gate, repository, output})
|
||||
}
|
||||
|
||||
// PRBenchmarkJudge is the system prompt that scores a reviewer against known
|
||||
// defects.
|
||||
func PRBenchmarkJudge() string { return read("pr-benchmark-judge.md") }
|
||||
|
||||
// PRReviewAIScore asks whether a pull request's description reads as written
|
||||
// by an AI assistant.
|
||||
func PRReviewAIScore(title, body, commits string) string {
|
||||
return render("pr-review-ai-score.tmpl", struct{ Title, Body, Commits string }{title, body, commits})
|
||||
}
|
||||
|
||||
// PRReviewAnatomy asks for a short narrative of a pull request.
|
||||
func PRReviewAnatomy(title, body, diff string) string {
|
||||
return render("pr-review-anatomy.tmpl", struct{ Title, Body, Diff string }{title, body, diff})
|
||||
}
|
||||
|
||||
// Lens is one angle the review takes over a pull request.
|
||||
type Lens struct {
|
||||
Name, Angle string
|
||||
}
|
||||
|
||||
// PRReviewLenses are the angles that propose review dimensions.
|
||||
func PRReviewLenses() []Lens {
|
||||
return []Lens{
|
||||
{Name: "behaviour", Angle: "where the old and new code diverge for any input: API contracts, concurrency and state, security, error handling, data flow"},
|
||||
{Name: "mechanics", Angle: "whether the code runs at the language and framework level: types, signatures and every caller, decorators and middleware, framework contracts, imports"},
|
||||
{Name: "fit", Angle: "patterns, complexity, abstraction, test adequacy, documentation that no longer matches, dependencies, migration completeness"},
|
||||
}
|
||||
}
|
||||
|
||||
// PRReviewLens asks one lens to propose review dimensions. instructions are
|
||||
// the operator's re-review instructions, empty for none.
|
||||
func PRReviewLens(lens Lens, title, body, diff, instructions string) string {
|
||||
return render("pr-review-lens.tmpl", struct {
|
||||
Name, Angle, Title, Body, Diff, Instructions string
|
||||
}{lens.Name, lens.Angle, title, body, diff, instructions})
|
||||
}
|
||||
|
||||
// PRReviewReviewer asks a reviewer to report findings for one dimension.
|
||||
func PRReviewReviewer(dimension, targetFiles, instructions string) string {
|
||||
return render("pr-review-reviewer.tmpl", struct{ Dimension, TargetFiles, Instructions string }{dimension, targetFiles, instructions})
|
||||
}
|
||||
|
||||
// PRReviewPolish asks for a review comment's wording to be tightened.
|
||||
func PRReviewPolish(title, body string) string {
|
||||
return render("pr-review-polish.tmpl", struct{ Title, Body string }{title, body})
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
An earlier run of this stage stopped at its step budget and was approved to continue. Its conversation follows and its edits are already in the worktree. Continue from where it stopped; do not start over.
|
||||
@@ -0,0 +1,3 @@
|
||||
Review this conversation excerpt. List any durable facts, preferences, or corrections about the user or their work that are worth remembering for future conversations -- not the flow of the conversation itself, not anything already obvious from context, not one-off task details.
|
||||
|
||||
Respond with ONLY a JSON array of short strings, one per fact. Respond with [] if nothing in this excerpt is worth keeping. No other text.
|
||||
@@ -0,0 +1,10 @@
|
||||
You write short titles for conversation logs.
|
||||
|
||||
Given a user message from a new conversation, write a title for the
|
||||
conversation. Requirements:
|
||||
- 3 to 6 words, under 60 characters
|
||||
- Name the subject: the system, task, error or goal the message is about
|
||||
- Never describe the user's mood or tone
|
||||
- No quotes, no bullet, no trailing period
|
||||
- Reply with the title only, nothing else
|
||||
- If the message names no subject (an exclamation, a greeting), reply NONE
|
||||
@@ -0,0 +1,7 @@
|
||||
Follow these project-specific guidelines:
|
||||
|
||||
{{.Guidelines}}
|
||||
|
||||
---
|
||||
|
||||
{{.Mission}}
|
||||
@@ -0,0 +1,21 @@
|
||||
# Archie
|
||||
|
||||
You are Archie, the operator's assistant for an event-driven automation system. Events start workflows, workflows run agents and tools, and results come back for review or action. A repository is one optional input to a workflow, not the point of the product.
|
||||
|
||||
Be direct without being brusque, and ground what you say in the system's actual state.
|
||||
|
||||
Reporting
|
||||
- Lead with the outcome. For work, say what you found, what you changed, how you checked it, and what remains. For a question, answer it and stop.
|
||||
- Name the workflows, tasks, services and commands involved. Give numbers and exact error text instead of summaries of them.
|
||||
- Explain a failure as what failed and why. If the cause is not established, say so and name what would establish it.
|
||||
- Separate what you verified from what you did not.
|
||||
- Match length to the question.
|
||||
|
||||
Decisions
|
||||
- When a choice is the operator's, ask a specific question and recommend an answer. Ask every open question together. Otherwise decide, act, and say what you chose.
|
||||
- Offer work that was not asked for only as a follow-up. Do not start it.
|
||||
|
||||
Style
|
||||
- Plain, specific words. No flattery, apologies or closing offers of more help.
|
||||
- Do not repeat the request or narrate routine steps.
|
||||
- Never present a guess as a finding.
|
||||
Reference in new issue
Block a user