chore: replace 607 em-dashes with double hyphens project-wide

Includes MCP crash-after-init test fix (crash moved from handle() to serve()
entry point so transport sees immediate subprocess death).
This commit is contained in:
sam committed 2026-07-26 09:53:33 +10:00
1 parent 16d6cd62b7
commit f6d51416f0
112 files changed
+587 -582

No files matched your search

+2 -2
View File
@@ -42,7 +42,7 @@ type Config struct {
// By default, the provider captures a frozen snapshot of both files at
// Initialize() time and uses that snapshot for the system prompt block
// (SystemPromptProvider). Writes go to disk immediately but the snapshot is
// not updated mid-session — only the next session (or next Initialize call)
// not updated mid-session -- only the next session (or next Initialize call)
// picks up the changes. Set Config.FrozenSnapshot to false to read live
// content on every SystemPromptBlock() call.
type Provider struct {
@@ -154,7 +154,7 @@ func (p *Provider) snapshotContent() (memory, user string) {
//
// When frozen snapshot is enabled (the default), Initialize captures the
// rendered content of both files for use by SystemPromptBlock(). The snapshot
// is not updated on subsequent writes — only the next Initialize() call (or
// is not updated on subsequent writes -- only the next Initialize() call (or
// the next session) picks up the fresh content.
func (p *Provider) Initialize(sessionID string) error {
if err := p.memory.Reload(); err != nil {
+3 -3
View File
@@ -300,7 +300,7 @@ func TestProvider_FrozenSnapshot_NotUpdatedOnWrite(t *testing.T) {
t.Fatalf("snapshot should be wrapped in <memory> fences, got: %s", firstBlock)
}
// Write after initialization — the snapshot must not change.
// Write after initialization -- the snapshot must not change.
if _, err := p.HandleToolCall(toolName, map[string]any{
"action": "add", "section": "Facts", "content": "new fact after init",
}); err != nil {
@@ -421,7 +421,7 @@ func TestProvider_FrozenSnapshot_ReInitialize(t *testing.T) {
t.Fatalf("expected 'before', got: %s", block1)
}
// Add more content and re-initialize — snapshot should refresh.
// Add more content and re-initialize -- snapshot should refresh.
if _, err := p.HandleToolCall(toolName, map[string]any{
"action": "add", "section": "Facts", "content": "after",
}); err != nil {
@@ -459,7 +459,7 @@ func TestProvider_FrozenSnapshot_DefaultEnabled(t *testing.T) {
block1 := p.SystemPromptBlock()
// Write after init — snapshot should be frozen.
// Write after init -- snapshot should be frozen.
if _, err := p.HandleToolCall(toolName, map[string]any{
"action": "add", "section": "Facts", "content": "post-init",
}); err != nil {
+2 -2
View File
@@ -132,8 +132,8 @@ type AddResult struct {
}
// Add appends content as a new block in the named section, creating the
// section if it does not already exist. The write is rejected — with no
// change to in-memory state or disk — if the resulting file would exceed
// section if it does not already exist. The write is rejected -- with no
// change to in-memory state or disk -- if the resulting file would exceed
// the store's size bound.
func (s *Store) Add(sectionName, content string) (AddResult, error) {
if err := ValidateSectionName(sectionName); err != nil {
+1 -1
View File
@@ -7,7 +7,7 @@ package memory
// and calls them at the appropriate points in the agent lifecycle.
//
// All hooks are called asynchronously (fire-and-forget) to avoid blocking
// the main agent loop. Hook errors and panics are recovered — they must not
// the main agent loop. Hook errors and panics are recovered -- they must not
// interrupt the agent's operation.
// TurnStartHook is called at the beginning of each agent turn. Providers
+8 -8
View File
@@ -39,7 +39,7 @@ var (
// Manager orchestrates the built-in memory provider plus at most one external
// provider. It is the single entry point that agent lifecycle code interacts
// with — callers never address providers directly.
// with -- callers never address providers directly.
//
// Key responsibilities:
// - Provider registration and lifecycle (Initialize, Shutdown)
@@ -130,7 +130,7 @@ type Manager struct {
// that kind is available.
//
// The built-in provider is always present and typically backed by the
// filesystem or NellDB. The external provider is optional — pass nil
// filesystem or NellDB. The external provider is optional -- pass nil
// and call RegisterExternal later, or pass a single external provider
// at construction time.
//
@@ -239,7 +239,7 @@ func (m *Manager) GetToolSchemas() []tools.ToolEntry {
// ToolCallProvider.
//
// Before dispatching, any "content" or "replacement" string argument is
// passed through ScanContent (18.15) — this is the actual integration point
// passed through ScanContent (18.15) -- this is the actual integration point
// for threat scanning, applying uniformly to every provider's write tools.
// A ThreatBlock result rejects the call before it reaches the provider.
//
@@ -317,7 +317,7 @@ func (m *Manager) Initialize(sessionID string) error {
// Each hook fans out to all active providers that implement the
// corresponding sub-interface. Hooks are fire-and-forget: they launch a
// goroutine per provider and return immediately. Hook errors and panics
// are recovered — they must not interrupt the agent loop.
// are recovered -- they must not interrupt the agent loop.
// safeGo runs fn in a goroutine, recovering any panic to prevent a
// misbehaving provider from crashing the process.
@@ -325,7 +325,7 @@ func safeGo(fn func()) {
go func() {
defer func() {
if r := recover(); r != nil {
// A provider panicked — this must not take down the agent.
// A provider panicked -- this must not take down the agent.
// The panic is intentionally swallowed after logging.
_ = r
_ = debug.Stack()
@@ -482,7 +482,7 @@ func (m *Manager) Prefetch(query string) (string, error) {
// is applied if the caller's context does not already have a shorter deadline.
//
// If the target provider is still prefetching from the previous turn, the
// call is skipped — PrefetchContext returns ("", nil) and the skip is logged
// call is skipped -- PrefetchContext returns ("", nil) and the skip is logged
// (18.8). Results from successful prefetches are stored and included in
// SystemPromptBlock() output.
func (m *Manager) PrefetchContext(ctx context.Context, query string) (string, error) {
@@ -674,7 +674,7 @@ func (m *Manager) Shutdown() error {
//
// After ShutdownContext returns, no new sync operations are accepted.
func (m *Manager) ShutdownContext(ctx context.Context) error {
// Signal that we're shutting down — new submissions will be rejected.
// Signal that we're shutting down -- new submissions will be rejected.
m.shuttingDown.Store(true)
// Record the drain deadline so the sync worker can self-abandon any op
@@ -691,7 +691,7 @@ func (m *Manager) ShutdownContext(ctx context.Context) error {
m.pipelineMu.Unlock()
// Wait for the sync worker to finish draining, or the deadline. On
// timeout we don't block further — the worker keeps running in the
// timeout we don't block further -- the worker keeps running in the
// background, but every op still queued after the deadline is now
// abandoned near-instantly by processSyncOp rather than dispatched.
drainDone := make(chan struct{})
+7 -7
View File
@@ -383,7 +383,7 @@ func TestManager_GetToolSchemas_MergesAllProviders(t *testing.T) {
// Verify injected handlers are present (Finding 2 fix)
for _, s := range schemas {
if s.Handler == nil {
t.Errorf("ToolEntry %q has nil Handler — GetToolSchemas must inject handlers", s.Name)
t.Errorf("ToolEntry %q has nil Handler -- GetToolSchemas must inject handlers", s.Name)
}
}
}
@@ -669,7 +669,7 @@ func TestManager_TypeAssertions_DetectsOptionalInterfaces(t *testing.T) {
t.Fatalf("NewManager returned error: %v", err)
}
// The mock implements everything — verify the manager detects this
// The mock implements everything -- verify the manager detects this
if !mgr.HasSystemPrompt() {
t.Error("HasSystemPrompt() = false, want true")
}
@@ -895,7 +895,7 @@ func TestManager_Shutdown_UnavailableProviderStillShutDown(t *testing.T) {
builtin.mu.Lock()
if builtin.shutdownCalls != 1 {
t.Errorf("unavailable provider shutdown was NOT called (shutdownCalls=%d), want 1 — resources may leak",
t.Errorf("unavailable provider shutdown was NOT called (shutdownCalls=%d), want 1 -- resources may leak",
builtin.shutdownCalls)
}
builtin.mu.Unlock()
@@ -1159,7 +1159,7 @@ func (p *panickyProvider) GetToolSchemas() []tools.ToolEntry {
}
}
// Every hook panics — safeGo must recover each one.
// Every hook panics -- safeGo must recover each one.
func (p *panickyProvider) OnTurnStart(sessionID string) error {
panic("OnTurnStart panicked")
}
@@ -1418,7 +1418,7 @@ func TestManager_PrefetchContext_StoresResult(t *testing.T) {
stored := mgr.PrefetchResult("builtin")
if stored == "" {
t.Error("PrefetchResult() returned empty — result was not stored")
t.Error("PrefetchResult() returned empty -- result was not stored")
}
}
@@ -1726,7 +1726,7 @@ func TestManager_ShutdownContext_DrainsPipeline(t *testing.T) {
// New submissions should be rejected.
err = mgr.SubmitSync(SyncOp{})
if err == nil {
t.Error("SubmitSync after shutdown succeeded — wanted ErrShuttingDown")
t.Error("SubmitSync after shutdown succeeded -- wanted ErrShuttingDown")
}
}
@@ -1766,7 +1766,7 @@ func TestManager_ShutdownContext_AbandonedCount(t *testing.T) {
}
}
// Shutdown with a very short deadline — ops won't finish.
// Shutdown with a very short deadline -- ops won't finish.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
defer cancel()
+2 -2
View File
@@ -6,8 +6,8 @@ package memory
import "github.com/samcharles93/archie-core/internal/tools"
// MemoryProvider is the contract that every memory provider — built-in or
// external/plugin — must implement. It covers provider identity, availability,
// MemoryProvider is the contract that every memory provider -- built-in or
// external/plugin -- must implement. It covers provider identity, availability,
// session-scoped initialization, and tool schema export.
type MemoryProvider interface {
// Name returns a unique, human-readable identifier for this provider
+12 -12
View File
@@ -128,19 +128,19 @@ func (s *Scrubber) processNormal(data []byte) []byte {
if len(tail) >= len(openTag) {
// Enough data to check the full tag.
if string(tail[:len(openTag)]) == openTag {
// Found <memory> — write everything before it, then enter memory block.
// Found <memory> -- write everything before it, then enter memory block.
s.writeOutput(data[:idx])
s.depth++
s.blocksStripped++
s.bytesStripped += int64(len(openTag))
return tail[len(openTag):]
}
// Not <memory> — write the '<' and continue after it.
// Not <memory> -- write the '<' and continue after it.
s.writeOutput(data[:idx+1])
return data[idx+1:]
}
// Not enough data to determine — partial tag at end of chunk.
// Not enough data to determine -- partial tag at end of chunk.
// Hold the tail for the next Write call.
if isPrefixOfTag(tail, openTag) {
s.writeOutput(data[:idx])
@@ -148,7 +148,7 @@ func (s *Scrubber) processNormal(data []byte) []byte {
return nil
}
// Not a prefix of <memory> — write everything.
// Not a prefix of <memory> -- write everything.
s.writeOutput(data)
return nil
}
@@ -156,7 +156,7 @@ func (s *Scrubber) processNormal(data []byte) []byte {
// processInMemory handles input when we're inside a memory block (depth > 0).
// It looks for </memory> close tags and strips everything else.
func (s *Scrubber) processInMemory(data []byte) []byte {
// Fast path: no '<' means no possible close tag — strip everything.
// Fast path: no '<' means no possible close tag -- strip everything.
idx := bytes.IndexByte(data, '<')
if idx < 0 {
s.bytesStripped += int64(len(data))
@@ -180,12 +180,12 @@ func (s *Scrubber) processInMemory(data []byte) []byte {
s.depth--
return tail[len(closeTag):]
}
// Not a close tag — skip the '<' and continue stripping.
// Not a close tag -- skip the '<' and continue stripping.
s.bytesStripped += int64(idx + 1)
return data[idx+1:]
}
// Not enough data to determine — partial tag at end of chunk.
// Not enough data to determine -- partial tag at end of chunk.
// Could be the start of </memory> (which would close the block) or
// <memory> (which would nest). Buffer it.
if isPrefixOfTag(tail, closeTag) || isPrefixOfTag(tail, openTag) {
@@ -194,7 +194,7 @@ func (s *Scrubber) processInMemory(data []byte) []byte {
return nil
}
// Not a prefix of any relevant tag — strip everything.
// Not a prefix of any relevant tag -- strip everything.
s.bytesStripped += int64(len(data))
return nil
}
@@ -223,13 +223,13 @@ func (s *Scrubber) writeOutput(data []byte) {
func (s *Scrubber) Flush() error {
if s.depth > 0 {
// Inside an unclosed memory block. Pending bytes are content that
// was buffered as potential tag starts — since no close tag arrives,
// was buffered as potential tag starts -- since no close tag arrives,
// they are memory-block content and should be stripped, not emitted.
s.bytesStripped += int64(len(s.pending))
s.pending = s.pending[:0]
s.depth = 0
} else if len(s.pending) > 0 {
// Outside a memory block — pending bytes are literal text whose
// Outside a memory block -- pending bytes are literal text whose
// partial tag didn't resolve.
s.writeOutput(s.pending)
s.pending = s.pending[:0]
@@ -249,7 +249,7 @@ func (s *Scrubber) Close() error {
// Process is a convenience method that scrubs a single chunk and returns
// the cleaned text. It maintains internal state across calls, so it can
// be used for streaming just like Write. The returned string is only the
// newly scrubbed output from this chunk — not the full accumulated output.
// newly scrubbed output from this chunk -- not the full accumulated output.
//
// For zero-allocation streaming, prefer Write with a pre-allocated writer.
func (s *Scrubber) Process(chunk string) string {
@@ -308,7 +308,7 @@ func (s *Scrubber) Depth() int {
// ── Helpers ────────────────────────────────────────────────────────────
// isPrefixOfTag reports whether data is a prefix of tag — i.e., data could
// isPrefixOfTag reports whether data is a prefix of tag -- i.e., data could
// be the start of tag if more bytes arrive later. Returns false if data is
// longer than tag.
func isPrefixOfTag(data []byte, tag string) bool {
+5 -5
View File
@@ -52,7 +52,7 @@ func TestScrubber_EmptyContent(t *testing.T) {
}
func TestScrubber_OnlyOpenTag(t *testing.T) {
// Missing close tag — block is implicitly closed at end of stream.
// Missing close tag -- block is implicitly closed at end of stream.
s := New(nil)
result := s.ProcessString("Before <memory>stuff")
if result != "Before " {
@@ -61,7 +61,7 @@ func TestScrubber_OnlyOpenTag(t *testing.T) {
}
func TestScrubber_OnlyCloseTag(t *testing.T) {
// Stray close tag with no open — treated as literal text.
// Stray close tag with no open -- treated as literal text.
s := New(nil)
result := s.ProcessString("text </memory> more")
if result != "text </memory> more" {
@@ -110,7 +110,7 @@ func TestScrubber_DeeplyNestedMemoryBlocks(t *testing.T) {
}
func TestScrubber_UnbalancedNested_MoreOpens(t *testing.T) {
// More open tags than close tags — remaining blocks implicitly closed
// More open tags than close tags -- remaining blocks implicitly closed
// at end of stream. Everything after the first <memory> is stripped
// because the outer block never closes.
s := New(nil)
@@ -241,7 +241,7 @@ func TestScrubber_PartialTag_NotActuallyATag(t *testing.T) {
{
name: "partial in memory block not a close tag",
chunk1: "<memory>content </", chunk2: "notmemory> more</memory>",
// "</notmemory>" is not "</memory>" — it doesn't close the block.
// "</notmemory>" is not "</memory>" -- it doesn't close the block.
// Everything inside the memory block is stripped until the real
// </memory> is found.
expected: "",
@@ -903,7 +903,7 @@ func TestScrubber_Write_ZeroLengthChunkWithPending(t *testing.T) {
if len(s.pending) == 0 {
t.Error("pending should not be empty after partial tag")
}
s.Write([]byte("")) // zero-length write — no-op
s.Write([]byte("")) // zero-length write -- no-op
if len(s.pending) == 0 {
t.Error("pending should not be cleared by zero-length Write")
}
+2 -2
View File
@@ -79,7 +79,7 @@ func (m *Manager) syncWorker() {
}
// processSyncOp handles a single sync operation. Errors are logged but never
// crash the pipeline — a misbehaving external provider must not take down
// crash the pipeline -- a misbehaving external provider must not take down
// the agent.
func (m *Manager) processSyncOp(op SyncOp) {
if deadlineNano := m.shutdownDeadlineNano.Load(); deadlineNano != 0 && time.Now().UnixNano() > deadlineNano {
@@ -143,6 +143,6 @@ func (m *Manager) signalDone(done chan error, err error) {
select {
case done <- err:
default:
// Receiver stopped waiting — don't block the pipeline.
// Receiver stopped waiting -- don't block the pipeline.
}
}