Applies AX principle 1 (Predictable Names Over Short Names) to function
signatures and local variables: s->input/raw, v->target/value, d->duration,
a,b->left,right, w->writer, r->reader, l->logger, p->part/databasePoint,
fn parameter names left as-is where they are callback conventions.
Co-Authored-By: Charon <charon@lethean.io>
Parameter named `node` shadowed the package name inside package node,
creating semantic ambiguity. AX Principle 1: predictable names over
short names — `nodeManager` matches the field name and the type.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: Predictable names over short names.
`msg` is an abbreviation; `errorMessage` names what it is.
Co-Authored-By: Charon <charon@lethean.io>
Abbreviated variable names `msg` and `smsgMsg` violate AX Principle 1
(predictable names over short names). Renamed to `message` and
`decryptedMessage` for semantic clarity without context switching.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. msg and conn
are abbreviations that require context to decode; message and connection
are self-documenting.
Co-Authored-By: Charon <charon@lethean.io>
The field `node *NodeManager` used an ambiguous single-word name that required
context to understand. Renamed to `nodeManager` to be self-describing per AX
Principle 1: predictable names over short names.
Co-Authored-By: Charon <charon@lethean.io>
`node` is ambiguous in the `node` package — callers cannot distinguish the
field from the package name without tracing. `nodeManager` names the type
it holds and removes all mapping overhead.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names. The abbreviation
`pc` (PeerConnection) in local variable scope is ambiguous — renamed
to `connection` in Connect, Stop, Send, Broadcast, and handleWSUpgrade.
Co-Authored-By: Charon <charon@lethean.io>
encoding/json is a banned import; peer.go used json.MarshalIndent and
json.Unmarshal directly in saveNow/load instead of the package-local
MarshalJSON/UnmarshalJSON wrappers. Removes the encoding/json import.
Co-Authored-By: Charon <charon@lethean.io>
identity.go was calling encoding/json directly (json.MarshalIndent,
json.Unmarshal) despite the package already defining MarshalJSON and
UnmarshalJSON in bufpool.go. Switch to the wrappers and remove the
direct encoding/json import from identity.go.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 10 (CLI tests as artifact validation) requires all three
test categories — Good, Bad, Ugly — to be mandatory. TestMessage_NewMessage
had only _Good; add _Bad (unmarshalable payload returns error) and _Ugly
(empty From/To fields succeed and produce a valid message ID).
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. `ackMsg` and `ackData`
require the reader to expand the abbreviation; `acknowledgementMessage` and
`acknowledgementData` are self-describing in the handshake context.
Co-Authored-By: Charon <charon@lethean.io>
Comment restated what the function does in prose rather than showing
a concrete usage example, violating AX principle 2 (comments as usage
examples). The usage example on the preceding line is sufficient.
Co-Authored-By: Charon <charon@lethean.io>
AX-1 (predictable names over short names): `auth` is an abbreviation
of `authentication`; the full word removes semantic ambiguity for agents
tracing authentication mode through the peer registry.
Co-Authored-By: Charon <charon@lethean.io>
ParsePayload was calling encoding/json.Unmarshal directly, bypassing the
package-local UnmarshalJSON wrapper that already exists in bufpool.go.
Co-Authored-By: Charon <charon@lethean.io>
Short name `mux` requires context to understand; `serveMux` is
self-describing per AX Principle 1 (predictable names over short names).
Co-Authored-By: Charon <charon@lethean.io>
Replace three direct json.Unmarshal calls with the package-level
UnmarshalJSON wrapper defined in bufpool.go, eliminating the
banned encoding/json import from transport.go.
Co-Authored-By: Charon <charon@lethean.io>
AX principle 2 — comments show HOW, not WHAT. The previous comment
restated the type name; replaced with concrete NewMessage/Reply calls.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 10 requires all three categories (Good, Bad, Ugly) for
every test function. TestMessage_Reply had only _Good; adds _Bad
(unmarshalable payload propagates error) and _Ugly (self-to-self
addressing preserves correct From/To reversal).
Co-Authored-By: Charon <charon@lethean.io>
Removes the banned `strings` import from transport.go by extracting
a `joinVersions` helper into message.go alongside SupportedProtocolVersions,
eliminating the single `strings.Join` call in the handshake rejection path.
Co-Authored-By: Charon <charon@lethean.io>
Replace all fmt.Errorf and fmt.Sprintf calls in transport.go with
ProtocolError{} structs and string concatenation, matching the error
pattern already used throughout the node package.
Co-Authored-By: Charon <charon@lethean.io>
Replace all fmt.Errorf calls in bundle.go with ProtocolError structs,
eliminating the banned fmt import. Error messages are preserved via
string concatenation consistent with the rest of the node package.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names. cfg.json →
config.json makes the path self-describing without a comment.
Co-Authored-By: Charon <charon@lethean.io>
Remove banned `encoding/json` import from pkg/mining/version.go; read
response body with io.ReadAll then decode via the package-local
UnmarshalJSON wrapper (bufpool.go). Also complete the partial fmt
removal in pkg/node/identity.go left broken by the previous sweep.
Co-Authored-By: Charon <charon@lethean.io>
Range variables `p` and `k` in peer_test.go require context to decode —
violates AX Principle 1 (predictable names over short names). Renamed to
`peer` and `key` so intent is self-evident without reading the loop body.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. Local variables
declared as `msg` in GetRemoteStats, StartRemoteMiner, StopRemoteMiner,
GetRemoteLogs, and PingPeer renamed to `message`.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. `tt` is an
abbreviated loop variable; `testCase` states the semantic clearly.
Co-Authored-By: Charon <charon@lethean.io>
ValidateResponse wraps type-mismatch in *ProtocolError (correct behaviour).
The docstring example showed the wrong negation and the assertion fired on
every run. Both the comment (AX §2 — comments as accurate usage examples)
and the guard were inverted; corrected to !IsProtocolError.
Co-Authored-By: Charon <charon@lethean.io>
AX principle 10 requires all three test categories (Good, Bad, Ugly).
lethean_test.go only had Bad variants for the three discovery functions;
added Good (happy-path via httptest.Server) and Ugly (edge-case filtering
and malformed JSON) for each, using a local test server to avoid live daemon dependency.
Co-Authored-By: Charon <charon@lethean.io>
The "path" package uses forward-slash separators and is intended for
URL paths; filesystem paths require "path/filepath" for OS-correct
behaviour. Fixes worker.go handleDeploy to use filepath.Join when
constructing the miners installation directory.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1: predictable names over short names. The `nm` shorthand
in seven comment examples was inconsistent with the full `nodeManager`
name used in actual call-site code and the `manager` receiver name
throughout the file.
Co-Authored-By: Charon <charon@lethean.io>
AX-1: predictable names over short names. The variable `ack` is an
abbreviation for `acknowledgement` — renamed in all six callsites
within handleStartMiner, handleStopMiner, and handleDeploy so the
name is self-describing without a comment.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 2: comments show usage, not prose descriptions. The
ProtocolVersion/MinProtocolVersion block comment and SupportedProtocolVersions
doc comment restated what the names already say; replaced with concrete
call-site examples.
Co-Authored-By: Charon <charon@lethean.io>
All fmt.Errorf calls replaced with &ProtocolError{Code, Message} using
the package-native error type, removing the banned fmt import entirely.
Co-Authored-By: Charon <charon@lethean.io>
worker.go imported encoding/json directly and called json.Unmarshal at two
call sites. bufpool.go already provided MarshalJSON as the package wrapper;
add matching UnmarshalJSON and route both worker.go call sites through it,
removing the encoding/json import from worker.go.
Co-Authored-By: Charon <charon@lethean.io>
Replace all fmt.Errorf calls with typed *ProtocolError values using the
native node error type — consistent with how protocol.go was cleaned up.
Error wrapping cases (failed to create message) now surface the original
error directly, preserving the call chain without fmt.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle #1 — predictable names over short names. The `tt` loop variable
is a two-letter abbreviation with no defined exception in the AX naming rules
(only `i`, `_`, `t`, `c` are acceptable short names). Renamed to `testCase`
throughout TestParseComment_{Good,Bad,Ugly}.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 2: comments show usage examples, not prose descriptions.
Five methods (AddPeer, UpdatePeer, RemovePeer, UpdateMetrics, UpdateScore)
had a redundant "Note: Persistence is debounced..." prose line appended
after the usage example. The usage example already communicates intent;
the prose line restated implementation detail without adding value.
Co-Authored-By: Charon <charon@lethean.io>
Score constants had comments restating the name in prose
("Increment for successful interaction") rather than showing
how they are used. AX Principle 2: comments are usage examples,
not descriptions.
Co-Authored-By: Charon <charon@lethean.io>
Mutex name was singular (allowedPublicKeyMutex) while the field it
protects is plural (allowedPublicKeys). AX Principle 1 requires
predictable names — the mutex name must mirror the field it guards.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — predictable names over short names. `buf` is an
abbreviation that requires a comment to understand; `buffer` is
self-describing.
Co-Authored-By: Charon <charon@lethean.io>
Single-letter parameter names w and r violate AX Principle 1
(predictable names over short names). Only i, _, t, and c are
permitted as single-letter names per the AX spec.
Co-Authored-By: Charon <charon@lethean.io>
AX Principle 1 — Predictable names over short names.
The single-letter `p` in `for _, p := range peers` is not listed
in the allowed exceptions (only `i`, `_`, `t`, `c` are permitted).
Rename to `peer` for semantic clarity.
Co-Authored-By: Charon <charon@lethean.io>