mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-13 11:40:53 +08:00
Comments, doc comments, UI labels, log and error messages, LLM prompt strings, markdown docs, test data and assertions. Identifiers, enum keys, routes, placeholders and code structure are unchanged. Notes: - docs/漏洞流量证据.md renamed to docs/vulnerability-traffic-evidence.md - tests that exercised CJK specific handling (GBK zip names, Chinese full text search) now use ASCII equivalents; go build passes and the test suite matches the pre translation baseline (remaining failures need a PostgreSQL DSN and fail identically on the original) - frontend mention syntax now uses English kinds (finding, asset, ...) matching the backend, chat mentions tests pass
56 lines
2.3 KiB
Go
56 lines
2.3 KiB
Go
package agent
|
|
|
|
import (
|
|
"log"
|
|
"path/filepath"
|
|
|
|
"github.com/Autumn-27/norma/agentcore"
|
|
"github.com/Autumn-27/norma/noaadapter"
|
|
)
|
|
|
|
// noaWarn returns a diagnostics sink tagging non-fatal noa messages with the
|
|
// session, routed through the package logger (agents have no per-instance one).
|
|
func noaWarn(session string) func(string) {
|
|
return func(msg string) { log.Printf("[noa] %s: %s", session, msg) }
|
|
}
|
|
|
|
// noa is the "model-driven context compression" mechanism introduced in norma v0.4.0,
|
|
// exposed as an experimental platform feature toggled by the user in system settings.
|
|
// It is mutually exclusive with the built-in compaction: noaadapter.Enable is the only
|
|
// entry point, and one call attaches the context take-over (Compactor), the Compress
|
|
// tool, and three resident prompt segments; not calling Enable means off (the built-in
|
|
// compaction works as usual). The toggle is resolved per run by the noaEnabledFn each
|
|
// agent injects, so switching only affects runs started afterwards — no need to rebuild
|
|
// the agent.
|
|
|
|
// enableNoa wires noa into opts when the resolver reports enabled. archiveRoot is the
|
|
// persistent base directory for compression originals (the global workDir; all agents
|
|
// uniformly land under <workDir>/noa, not scattered across task/intent directories),
|
|
// and sessionID names the archive subdirectory under it (globally unique, so no
|
|
// conflict within the same base directory).
|
|
//
|
|
// noa is experimental: an integration failure must not interrupt real tasks. On error
|
|
// it reports via onWarn and falls back to the built-in compaction. On success it clears
|
|
// opts.Compaction, avoiding agentcore's "two context managers set at once" warning.
|
|
func enableNoa(opts *agentcore.Options, enabled func() bool, archiveRoot, sessionID string, onWarn func(string)) {
|
|
if enabled == nil || !enabled() {
|
|
return
|
|
}
|
|
if opts.OnWarn == nil {
|
|
opts.OnWarn = onWarn
|
|
}
|
|
if err := noaadapter.Enable(opts, noaadapter.Options{
|
|
ArchiveBaseDir: filepath.Join(archiveRoot, "noa"),
|
|
SessionID: sessionID,
|
|
OnWarn: onWarn,
|
|
}); err != nil {
|
|
if onWarn != nil {
|
|
onWarn("failed to enable noa compression, falling back to built-in compaction: " + err.Error())
|
|
}
|
|
return
|
|
}
|
|
// Compactor overrides Compaction, but agentcore warns on every run when both are
|
|
// set; clear it explicitly.
|
|
opts.Compaction = nil
|
|
}
|