1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//! # Frame ISA - SAM Instruction Set Architecture
//!
//! Zero-dependency crate defining the 6-byte opcode format for SAM AI systems.
//!
//! ## Overview
//!
//! Frame ISA defines a compact instruction format for AI output:
//!
//! ```text
//! [ACT:2 bytes][SUBJ:2 bytes][MOD:2 bytes] = 6 bytes total (big-endian)
//! ```
//!
//! - **ACT (Action)**: What operation to perform (GREET, RESPOND, CALCULATE, etc.)
//! - **SUBJ (Subject)**: The topic or entity (TIME, USER, WEATHER, RAG reference, etc.)
//! - **MOD (Modifier)**: Style flags (voice, tone, warmth, format, urgency, etc.)
//!
//! ## Usage
//!
//! ```rust
//! use frame_isa::{Action, Subject, Modifier, Instruction};
//!
//! // Create an instruction
//! let instr = Instruction::new(
//! Action::RESPOND,
//! Subject::TIME,
//! Modifier::default(),
//! );
//!
//! // Serialize to bytes
//! let bytes = instr.to_bytes();
//! assert_eq!(bytes.len(), 6);
//!
//! // Parse from bytes
//! let parsed = Instruction::parse_one(&bytes).unwrap();
//! assert_eq!(instr, parsed);
//!
//! // Use the builder
//! use frame_isa::{InstructionBuilder, Voice, Tone};
//!
//! let instr = InstructionBuilder::new(Action::GREET)
//! .subject(Subject::USER)
//! .voice(Voice::Casual)
//! .tone(Tone::Positive)
//! .build();
//! ```
//!
//! ## Action Categories
//!
//! | Range | Category | Examples |
//! |-------|----------|----------|
//! | 0x00xx | System | NOP, HALT, ERROR, STATUS |
//! | 0x01xx | Response | GREET, CONFIRM, DENY, EXPLAIN, RESPOND |
//! | 0x02xx | Query | ASK, REQUEST, SEARCH, RETRIEVE |
//! | 0x03xx | Knowledge | DEFINE, DESCRIBE, COMPARE, SUMMARIZE |
//! | 0x04xx | Skill | CALCULATE, SET_TIMER, KNOWLEDGE_SEARCH |
//! | 0x05xx | Emotion | EMPATHY, CONCERN, ENCOURAGEMENT |
//! | 0x06xx | Template | TEMPLATE_LOAD, TEMPLATE_FILL |
//! | 0x07xx | Chain | CHAIN, FORK, MERGE |
//!
//! ## Subject Categories
//!
//! | Range | Category | Examples |
//! |-------|----------|----------|
//! | 0x00xx | System | NULL, SELF, USER, CONTEXT |
//! | 0x01xx | Common | WEATHER, TIME, DATE, SCHEDULE |
//! | 0x02xx | Math/Science | NUMBER, EQUATION, PHYSICS |
//! | 0x03xx | Technology | COMPUTER, SOFTWARE, AI, API |
//! | 0x04xx | Knowledge | DOCUMENTATION, CONCEPT |
//! | 0x05xx | Emotions | FEELINGS, STRESS, ANXIETY |
//! | 0x06xx | TRM Refs | References to other TRM models |
//! | 0xE0xx | RAG Refs | Dynamic document lookups |
//!
//! ## Modifier Bit Layout
//!
//! ```text
//! Bit: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
//! [--VOICE--] [--TONE--] [-WARM-] [--FORMAT--] [ACCURACY] [URGENCY]
//! ```
//!
//! ## Integration with TRM Models
//!
//! TinyRecursiveModels (TRMs) output predictions that map to these opcodes.
//! The factored prediction approach uses 3 heads:
//!
//! - ACT head → Action code
//! - SUBJ head → Subject code
//! - MOD head → Modifier flags
//!
//! This allows small models (~148K params) to achieve 99%+ accuracy on
//! opcode prediction tasks.
// Re-export main types
pub use Action;
pub use ;
pub use ;
pub use Subject;
/// Current ISA version
pub const ISA_VERSION: &str = "0.1.0";
/// Convenience prelude for common imports