Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

fix(server): recognise the released record_fact descriptions as known defaults

BaaRai5e1c55db4d67
diff --git a/agent/fact_input_legacy.go b/agent/fact_input_legacy.go
index 769c539..e43e24f 100644
--- a/agent/fact_input_legacy.go
+++ b/agent/fact_input_legacy.go
@@ -16,6 +16,17 @@ const recordFactLegacyDescription = "Write an exploration [fact/conclusion] into
" · source = where the content came from: target_response (content the target itself returned: page bodies, headers, error messages, banners, even when a tool fetched it) | tool_output (a tool's own result about the target: port states, scanner verdicts, status codes, timings) | third_party_intel (OSINT, CVE databases, public reports) | operator_input (given by the human operator) | inference (your own reasoning; the default when omitted). Any other value is refused.\n" +
" · **Negative conclusions** (not injectable / port closed / no entry found, etc.) state only \"observation + tentative reading\" — state what you actually saw; whether to abandon the direction is for the planner to decide globally; always provide evidence, mark inferred when the means weren't exhausted or the evidence is weak (including probed only once, looks-like), and mark observed only when truly exhausted and directly seen."
+// recordFactReleasedDescription is the record_fact description seeded by the
+// releases v0.4.0 to v0.6.0 (agent/tools.go at those tags): the text above
+// without the source bullet.
+const recordFactReleasedDescription = "Write an exploration [fact/conclusion] into the exploration graph, linked to the intent that produced it (intent_id). Used to record exploration results — both [positive conclusions] like fingerprinting/enumeration, and [negative conclusions] like 'port closed'/'parameter not injectable'/'no login entry found'.\n" +
+ "⚠️Multiple observations from one exploration must be [consolidated into ONE fact], not split into many; whenever they can be merged into one fact, use one: summary = a one-sentence summary of this conclusion, detail = the related details (may contain multiple concrete items). Example: a fingerprinting intent → one fact {summary:'identified the tech stack and response characteristics of site X', detail:'nginx 1.25 / Vue3 / 200 / title=.. / body_len=..'}, rather than one fact each for status code, fingerprint, and title. One intent usually produces exactly one fact; splitting too finely bloats the graph endlessly.\n" +
+ "★The facts array writes several [mutually distinct] conclusions at once (each may omit intent_id, defaulting to the top-level intent_id). Returns an ids array, same length and order as facts.\n" +
+ "⚠️Write only conclusions you [actually saw] in tool output — don't extrapolate. evidence and confidence keep inaccurate conclusions from polluting the graph:\n" +
+ " · evidence = [one line] of key evidence supporting this conclusion (the command + the one or two most proving output lines), **keep it brief** — details belong in detail; don't paste large output blocks here.\n" +
+ " · confidence = observed (seen directly in output) | inferred (inferred from phenomena).\n" +
+ " · **Negative conclusions** (not injectable / port closed / no entry found, etc.) state only \"observation + tentative reading\" — state what you actually saw; whether to abandon the direction is for the planner to decide globally; always provide evidence, mark inferred when the means weren't exhausted or the evidence is weak (including probed only once, looks-like), and mark observed only when truly exhausted and directly seen."
+
// recordFactLegacyItemDescriptions are the facts[] item descriptions of the
// earlier contract whose wording referred to the top level; the refresh
// replaces exactly these texts with the current ones.
@@ -28,9 +39,16 @@ var recordFactLegacyItemDescriptions = map[string]string{
// earlier contract.
const recordFactLegacyFactsDescription = "A non-empty batch of complete facts. Every item needs its own summary. Only intent_id inherits from the top level. Returned ids match item order; retry only failed indices."
+// recordFactReleasedFactsDescription is the facts property description seeded
+// by the releases v0.4.0 to v0.6.0. RepairRecordFactSchema keeps a stored facts
+// description, so the refresh has to know this text to replace it.
+const recordFactReleasedFactsDescription = "[use when there are several distinct conclusions] array of facts; element fields same as the top-level fields below (summary/detail/evidence/confidence/intent_id/asset_ids); omitting intent_id falls back to the top-level intent_id. The returned ids match this array in length and order."
+
// RecordFactLegacyDescriptions returns the description texts of the earlier
-// contract that the refresh may replace: the tool description, the facts
-// property description and the item descriptions.
-func RecordFactLegacyDescriptions() (tool []string, facts string, items map[string]string) {
- return []string{recordFactLegacyDescription}, recordFactLegacyFactsDescription, recordFactLegacyItemDescriptions
+// contract that the refresh may replace: the tool descriptions, the facts
+// property descriptions and the item descriptions.
+func RecordFactLegacyDescriptions() (tool, facts []string, items map[string]string) {
+ return []string{recordFactLegacyDescription, recordFactReleasedDescription},
+ []string{recordFactLegacyFactsDescription, recordFactReleasedFactsDescription},
+ recordFactLegacyItemDescriptions
}
diff --git a/server/fact_input_released_test.go b/server/fact_input_released_test.go
new file mode 100644
index 0000000..4d2116e
--- /dev/null
+++ b/server/fact_input_released_test.go
@@ -0,0 +1,117 @@
+package server
+
+import (
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "testing"
+)
+
+// The record_fact texts seeded by the releases v0.4.0 to v0.6.0, copied from
+// agent/tools.go at those tags. They are kept here, apart from the agent
+// package's list of known defaults, so the test fails when that list drifts
+// from the released bytes.
+const fix410ReleasedDescription = "Write an exploration [fact/conclusion] into the exploration graph, linked to the intent that produced it (intent_id). Used to record exploration results — both [positive conclusions] like fingerprinting/enumeration, and [negative conclusions] like 'port closed'/'parameter not injectable'/'no login entry found'.\n" +
+ "⚠️Multiple observations from one exploration must be [consolidated into ONE fact], not split into many; whenever they can be merged into one fact, use one: summary = a one-sentence summary of this conclusion, detail = the related details (may contain multiple concrete items). Example: a fingerprinting intent → one fact {summary:'identified the tech stack and response characteristics of site X', detail:'nginx 1.25 / Vue3 / 200 / title=.. / body_len=..'}, rather than one fact each for status code, fingerprint, and title. One intent usually produces exactly one fact; splitting too finely bloats the graph endlessly.\n" +
+ "★The facts array writes several [mutually distinct] conclusions at once (each may omit intent_id, defaulting to the top-level intent_id). Returns an ids array, same length and order as facts.\n" +
+ "⚠️Write only conclusions you [actually saw] in tool output — don't extrapolate. evidence and confidence keep inaccurate conclusions from polluting the graph:\n" +
+ " · evidence = [one line] of key evidence supporting this conclusion (the command + the one or two most proving output lines), **keep it brief** — details belong in detail; don't paste large output blocks here.\n" +
+ " · confidence = observed (seen directly in output) | inferred (inferred from phenomena).\n" +
+ " · **Negative conclusions** (not injectable / port closed / no entry found, etc.) state only \"observation + tentative reading\" — state what you actually saw; whether to abandon the direction is for the planner to decide globally; always provide evidence, mark inferred when the means weren't exhausted or the evidence is weak (including probed only once, looks-like), and mark observed only when truly exhausted and directly seen."
+
+const fix410ReleasedFactsDescription = "[use when there are several distinct conclusions] array of facts; element fields same as the top-level fields below (summary/detail/evidence/confidence/intent_id/asset_ids); omitting intent_id falls back to the top-level intent_id. The returned ids match this array in length and order."
+
+// A database seeded by a release stores the released record_fact description,
+// the released facts property description and facts items without properties.
+// The one-time refresh replaces both texts with the current ones and sets its
+// flag; texts an operator edited match no known default and stay as stored.
+func TestFix410ReleasedDefaultsRefreshed(t *testing.T) {
+ for _, c := range []struct {
+ name, text, sum string
+ size int
+ }{
+ {"description", fix410ReleasedDescription, "0da5cec5cde7f5e6f41343418fcc2a7d132d6520f336efb39fcbf1ab6ac51957", 2038},
+ {"facts description", fix410ReleasedFactsDescription, "eb054843a6b33dd39b94ba0648f292babb9cf9bdd106ee4eff6bf593d3f3edf4", 286},
+ } {
+ sum := sha256.Sum256([]byte(c.text))
+ if len(c.text) != c.size || hex.EncodeToString(sum[:]) != c.sum {
+ t.Fatalf("the released %s in this test is not the released text: %d bytes, sha256 %x", c.name, len(c.text), sum)
+ }
+ }
+ skipWithoutDSN(t)
+ m, err := NewManager(t.TempDir(), "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer m.Close()
+ s := &Server{m: m}
+ const flag = "tool_schema_refresh_record_fact_facts_only"
+ seed := recordFactSeed(t)
+ seedSchema, _ := json.Marshal(seed.Schema)
+ seedAgents, _ := json.Marshal(seed.Agents)
+ defer func() {
+ _ = m.pg.UpsertToolForce("record_fact", seed.Desc, seedSchema, seedAgents)
+ _, _ = m.pg.Exec(`DELETE FROM settings WHERE key=$1`, flag)
+ }()
+ currentFacts := seed.Schema["properties"].(map[string]any)["facts"].(map[string]any)["description"]
+
+ // start stores the row as a release seeded it, with the given two texts,
+ // runs the startup steps and returns the two texts as stored afterwards.
+ start := func(desc, factsDesc string) (string, any) {
+ t.Helper()
+ str := func(d string) map[string]any { return map[string]any{"type": "string", "description": d} }
+ schema, _ := json.Marshal(map[string]any{"type": "object", "properties": map[string]any{
+ "facts": map[string]any{"type": "array", "description": factsDesc, "items": map[string]any{"type": "object"}},
+ "summary": str("a [one-sentence summary] of this exploration's conclusion (a condensation of detail)"),
+ "intent_id": map[string]any{"type": "integer", "description": "the id of the intent that produced this fact (the intent you claimed; the default for each item in batch mode)"},
+ "detail": str("details related to this fact: write all of this exploration's observations here"),
+ "evidence": str("[one line] of key evidence: the command + the one or two most proving output lines. Keep it brief; don't paste large output blocks (details go in detail)."),
+ "confidence": str("observed (seen directly in output) | inferred (inferred from phenomena). Always label negative conclusions honestly."),
+ "asset_ids": map[string]any{"type": "array", "items": map[string]any{"type": "integer"}, "description": "related asset ids (optional, 0/1/many): which assets this fact involves"},
+ }})
+ if err := m.pg.UpsertToolForce("record_fact", desc, schema, seedAgents); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := m.pg.Exec(`DELETE FROM settings WHERE key=$1`, flag); err != nil {
+ t.Fatal(err)
+ }
+ s.seedFactInputSchema()
+ s.seedFactSourceSchema()
+ s.refreshRecordFactContract()
+ if v, _, _ := m.pg.GetSetting(flag); v != "true" {
+ t.Errorf("flag = %q after the refresh, want true", v)
+ }
+ row, err := m.pg.GetTool("record_fact")
+ if err != nil || row == nil {
+ t.Fatalf("row: %v", err)
+ }
+ var stored struct {
+ Properties map[string]map[string]any `json:"properties"`
+ }
+ if err := json.Unmarshal(row.Schema, &stored); err != nil {
+ t.Fatal(err)
+ }
+ if len(stored.Properties) != 1 || stored.Properties["facts"] == nil {
+ t.Fatalf("top level still holds fact fields: %s", row.Schema)
+ }
+ return row.Description, stored.Properties["facts"]["description"]
+ }
+
+ desc, factsDesc := start(fix410ReleasedDescription, fix410ReleasedFactsDescription)
+ if desc != seed.Desc {
+ t.Errorf("released description not replaced by the current one: %.60q", desc)
+ }
+ if factsDesc != currentFacts {
+ t.Errorf("released facts description not replaced by the current one: %v", factsDesc)
+ }
+
+ editedDesc := fix410ReleasedDescription + "\nOperator note: record every negative result."
+ editedFacts := fix410ReleasedFactsDescription + " Operator note: one fact per host."
+ desc, factsDesc = start(editedDesc, editedFacts)
+ if desc != editedDesc {
+ t.Errorf("operator description changed: %.60q", desc)
+ }
+ if factsDesc != editedFacts {
+ t.Errorf("operator facts description changed: %v", factsDesc)
+ }
+}
diff --git a/server/fact_input_schema.go b/server/fact_input_schema.go
index 0b194e6..d6c3a10 100644
--- a/server/fact_input_schema.go
+++ b/server/fact_input_schema.go
@@ -56,7 +56,7 @@ func (s *Server) refreshRecordFactContract() {
case sliceHas(legacyTool, desc):
desc = seed.Desc
default:
- log.Printf("[facts] record_fact description was edited by an operator and still describes the earlier contract; the facts-only schema is published anyway, review the text in the tool catalog")
+ log.Printf("[facts] record_fact description does not match a known default and still describes the earlier contract; the facts-only schema is published anyway, review the text in the tool catalog")
}
var schema map[string]any
if err := json.Unmarshal(row.Schema, &schema); err != nil {
@@ -66,7 +66,7 @@ func (s *Server) refreshRecordFactContract() {
repaired := agent.RepairRecordFactSchema(schema)
facts := repaired["properties"].(map[string]any)["facts"].(map[string]any)
canonFacts := seed.Schema["properties"].(map[string]any)["facts"].(map[string]any)
- if facts["description"] == legacyFacts {
+ if d, ok := facts["description"].(string); ok && sliceHas(legacyFacts, d) {
facts["description"] = canonFacts["description"]
}
items := facts["items"].(map[string]any)["properties"].(map[string]any)
diff --git a/server/fact_input_schema_test.go b/server/fact_input_schema_test.go
index 0425e7d..9596971 100644
--- a/server/fact_input_schema_test.go
+++ b/server/fact_input_schema_test.go
@@ -129,7 +129,7 @@ func recordFactLegacySchema(t *testing.T) (string, map[string]string) {
"intent_id": map[string]any{"type": "integer", "description": legacyItems["intent_id"]},
"detail": map[string]any{"type": "string", "description": "Details of this fact, including all related observations."},
"source": map[string]any{"type": "string", "enum": []string{"inference"}},
- "facts": map[string]any{"type": "array", "minItems": 1, "description": legacyFacts, "items": item},
+ "facts": map[string]any{"type": "array", "minItems": 1, "description": legacyFacts[0], "items": item},
}}
raw, _ := json.Marshal(schema)
return string(raw), legacyItems