mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-03 13:11:05 +00:00
69 lines
3.1 KiB
Go
69 lines
3.1 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"github.com/Autumn-27/artex/db"
|
|
actool "github.com/Autumn-27/norma/tool"
|
|
"time"
|
|
)
|
|
|
|
func (t *ToolSet) intentContext(ctx context.Context, id, before int64, limit int) (map[string]any, error) {
|
|
if id <= 0 {
|
|
id = t.ownerNode
|
|
}
|
|
intent, err := t.ts.GetNodeContext(ctx, id)
|
|
if err != nil || intent == nil || intent.Kind != db.KindIntent {
|
|
return nil, fmt.Errorf("intent_id must refer to an intent in this task")
|
|
}
|
|
ids, total, more, err := t.ts.IntentReferenceIDs(ctx, id, before, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
refs := make([]map[string]any, 0, len(ids))
|
|
for _, ref := range ids {
|
|
// This resolver enforces the same direct-source read boundary as node_detail.
|
|
n, err := t.ts.GetNodeWithSourcesContext(ctx, ref)
|
|
if err != nil || n == nil {
|
|
refs = append(refs, map[string]any{"id": ref, "unavailable": true})
|
|
continue
|
|
}
|
|
refs = append(refs, compactPlanningContinuation(n))
|
|
}
|
|
out := map[string]any{"intent_id": id, "references": refs, "total": total, "has_more": more, "instruction": "These are the existing evidence/checkpoint nodes explicitly referenced by your assigned intent, fetched independently of the global graph window. Read their complete node_detail before relying on summaries. If a file Read is truncated, that is not proof the source is absent: use the referenced full graph evidence or an available authorized paginated reader. Do not guess alternate filenames, repeat the same truncated read, invent missing input, or broaden scope. Superseded/dismissed evidence needs current validation."}
|
|
if more && len(ids) > 0 {
|
|
out["next_before"] = ids[len(ids)-1]
|
|
}
|
|
return out, nil
|
|
}
|
|
func (t *ToolSet) renderIntentReferences(ctx context.Context, id int64) string {
|
|
if t.ts == nil {
|
|
return ""
|
|
}
|
|
ctx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
|
defer cancel()
|
|
out, err := t.intentContext(ctx, id, 0, 16)
|
|
if err != nil {
|
|
return "\n\n[Referenced intent evidence unavailable: " + err.Error() + ". Do not infer that the input is missing; retry get_intent_context before making that claim.]"
|
|
}
|
|
raw, _ := json.Marshal(out)
|
|
return "\n\n[Evidence explicitly handed to this intent; read without broadening your assigned work]:\n" + string(raw)
|
|
}
|
|
func (t *ToolSet) getIntentContext() actool.CoreTool {
|
|
return t.readExpTool("get_intent_context", "Read the same-task intent's explicitly linked source facts/checkpoints, independently of the large global graph window. Defaults to your assigned intent; use before/limit to page. Full evidence is available through node_detail.", obj(map[string]any{"intent_id": idp("optional intent ID, defaults to your assigned intent"), "before": idp("older reference ID cursor"), "limit": intp("default 16, maximum 50")}), func(ctx context.Context, raw json.RawMessage) (actool.Result, error) {
|
|
var a struct {
|
|
ID int64 `json:"intent_id"`
|
|
Before int64
|
|
Limit int
|
|
}
|
|
if err := json.Unmarshal(raw, &a); err != nil {
|
|
return actool.Errorf("invalid intent context query"), nil
|
|
}
|
|
out, err := t.intentContext(ctx, a.ID, a.Before, a.Limit)
|
|
if err != nil {
|
|
return actool.Errorf(err.Error()), nil
|
|
}
|
|
return jsonResult(out)
|
|
})
|
|
}
|