mmoussa commited on
Commit
5c318cb
·
verified ·
1 Parent(s): 5e98769

Docs: specialized decision model, ask by id, precise meanings, known weak spots

Browse files
Files changed (2) hide show
  1. README.md +129 -87
  2. knack.py +9 -9
README.md CHANGED
@@ -12,12 +12,12 @@ inference: false
12
 
13
  # CodeSync Knack
14
 
15
- **The free, private judgment model behind CodeSync.**
16
 
17
  Every time you send CodeSync a message or it runs a shell command, it makes dozens of quick
18
  calls: Is this command risky? Will it run forever? Are you asking to continue earlier work?
19
  Is this a question or a task? Which mode fits? Knack makes those calls on your own machine,
20
- in about 10 milliseconds.
21
 
22
  - **Free.** Ships with every CodeSync install. No API key, no account, no usage limits.
23
  - **Private.** Runs locally. Your prompts and commands never leave your machine to be judged.
@@ -27,45 +27,7 @@ in about 10 milliseconds.
27
  rare cases that cost the most when missed: destructive deletes, commands that never exit,
28
  resuming interrupted work, refactor / test / documentation requests.
29
 
30
- ## Try it in one line
31
-
32
- You need [Ollama](https://ollama.com/download) running. Nothing else to install: the script
33
- uses only the Python standard library and pulls the model on first run.
34
-
35
- ```bash
36
- curl -fsSL https://huggingface.co/devshub-ai/knack/resolve/main/knack.py | python3 - "npm run dev"
37
- ```
38
-
39
- ```
40
- risk 1 0.95 0 safe, 1 needs care, 2 destructive / dangerous
41
- long_running yes 0.97 keeps running (server, watch, poll, tail -f)
42
- activity running 0.92 what kind of command it is
43
- verifies no 0.97 checks that work is correct (tests, lint, build)
44
- mutates_repo no 0.97 changes files or git state of the repo
45
- deploys no 0.94 deploys or publishes
46
- runtime_check no 0.95 needs a running app to check
47
- serves yes 0.97 starts a server
48
- ```
49
-
50
- Knack only reads the command you pass and judges it. Nothing is executed, so it is safe
51
- to ask about any command, including destructive ones.
52
-
53
- Judge a user message instead of a command:
54
-
55
- ```bash
56
- curl -fsSL https://huggingface.co/devshub-ai/knack/resolve/main/knack.py | python3 - --turn "fix the failing login test"
57
- ```
58
-
59
- Or save the script and use it as a tool or a local server:
60
-
61
- ```bash
62
- curl -fsSLO https://huggingface.co/devshub-ai/knack/resolve/main/knack.py
63
- python3 knack.py "docker compose up" --json # machine-readable
64
- python3 knack.py --turn "add dark mode" -q route.mode -q task.intent
65
- python3 knack.py serve --port 33727 # POST /v1/systemone (CodeSync format)
66
- ```
67
-
68
- ## Use it with Ollama directly
69
 
70
  ```bash
71
  ollama pull devshub/knack # Q8_0, 817 MB (https://ollama.com/devshub/knack)
@@ -73,30 +35,54 @@ ollama pull devshub/knack:q4_k_m # 516 MB, near-identical accuracy
73
  ollama pull hf.co/devshub-ai/knack:Q8_0 # same model, straight from this repo
74
  ```
75
 
76
- Then use it like any Ollama decision model:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  ```
79
- echo "npm run dev" | ollama run devshub/knack --ask "Will it keep running?"
80
  ```
81
 
82
  ```
83
  yes 97%
84
  ```
85
 
86
- Ask by question id or by its plain phrasing (both listed below). Knack reads the text as a
87
- shell command for the command questions and as a user message for the turn questions:
 
 
 
 
 
 
 
88
 
89
  ```
90
  echo "git push --force" | ollama run devshub/knack --ask risk --level safe --level "needs care" --level destructive
91
- echo "fix the failing login test" | ollama run devshub/knack --ask "Is this a new task?"
92
  echo "fix the failing login test" | ollama run devshub/knack --ask task.intent \
93
  --choice bug_fix --choice feature --choice refactor --choice api_schema --choice config_deploy \
94
  --choice test --choice documentation --choice investigation --choice unknown
95
  ```
96
 
97
- Knack only knows its 29 questions. Anything else ("Is a refund being requested?") is
98
- rejected with the list of what it can answer, rather than guessed. A question asked with
99
- the wrong options gets back the exact flags to use.
 
 
100
 
101
  ### cURL
102
 
@@ -107,18 +93,18 @@ curl http://localhost:11434/v1/systemone \
107
  "model": "devshub/knack",
108
  "state": "npm run dev",
109
  "questions": {
110
- "long_running": {"type": "noul", "instructions": "Will it keep running?"},
111
- "serves": {"type": "noul", "instructions": "Does it start a server?"}
112
  }
113
  }'
114
  ```
115
 
116
  ```
117
- {"model":"devshub/knack","answers":{"long_running":{"type":"noul","noul":0.9708},"serves":{"type":"noul","noul":0.9701}}}
118
  ```
119
 
120
- The state can also be an object with Knack's own fields, for example
121
- `{"command": "npm run dev", "description": "start the app"}`.
122
 
123
  ### Python
124
 
@@ -132,46 +118,102 @@ import ollama
132
  response = ollama.systemone(
133
  model="devshub/knack",
134
  state="npm run dev",
135
- questions={"long_running": {"type": "noul", "instructions": "Will it keep running?"}},
136
  )
137
- print(response.answers["long_running"].noul) # 0.9708
138
  ```
139
 
140
- ## What it decides
 
 
 
 
 
 
 
141
 
142
- **Every shell command** (state fields: `command`, `description`):
 
 
 
 
 
 
 
 
 
143
 
144
- | id | options | plain question |
145
- |---|---|---|
146
- | `risk` | 0 safe, 1 needs care, 2 destructive | How risky is this command? |
147
- | `long_running` | yes, no | Will it keep running? |
148
- | `activity` | testing, building, installing, git, inspecting, running | What kind of command is this? |
149
- | `verifies` | yes, no | Does it verify the work? |
150
- | `mutates_repo` | yes, no | Does it change the repo? |
151
- | `deploys` | yes, no | Does it deploy? |
152
- | `runtime_check` | yes, no | Does it need a running app? |
153
- | `serves` | yes, no | Does it start a server? |
154
 
155
- **Every user turn** (state fields, in this order: `prompt`, `current_mode`,
156
- `recent_activity`, `conversation_size`, `open_task`, `turns_on_open_task`,
157
- `interrupted_work`, `browser_context`; see `turn_state()` in `knack.py` for defaults):
158
 
159
- | id | options |
160
- |---|---|
161
- | `turn.chat_or_task` | chat, task |
162
- | `turn.actionable` / `turn.question_shaped` / `turn.new_task` / `turn.resume` / `turn.mission` / `turn.plan_authoring` / `turn.demo` / `turn.skip_orientation` | yes, no |
163
- | `turn.change_intent` | create, adjust, enhance, fix, refactor, none |
164
- | `turn.screencast` | start, stop, none |
165
- | `task.intent` | bug_fix, feature, refactor, api_schema, config_deploy, test, documentation, investigation, unknown |
166
- | `task.execution_strategy` | direct, plan, parallel |
167
- | `route.mode` | plan, build, ask, debug |
168
- | `route.tier` | light, medium, heavy |
169
- | `route.thinking` | off, low, medium, high, xhigh, max |
170
- | `route.risk` | low, medium, high |
171
- | `browser` / `messaging` / `delivery.feature_task` / `delivery.slash_task` | yes, no |
172
-
173
- Knack only knows these 29 questions; Ollama rejects any other one instead of guessing.
174
- Inside CodeSync, anything else goes to CodeSync's cloud judgment service.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
  ## Results
177
 
 
12
 
13
  # CodeSync Knack
14
 
15
+ **A specialized decision model: the free, private judgment model behind CodeSync.**
16
 
17
  Every time you send CodeSync a message or it runs a shell command, it makes dozens of quick
18
  calls: Is this command risky? Will it run forever? Are you asking to continue earlier work?
19
  Is this a question or a task? Which mode fits? Knack makes those calls on your own machine,
20
+ in about 10 milliseconds. It answers only those decisions, asked by question id.
21
 
22
  - **Free.** Ships with every CodeSync install. No API key, no account, no usage limits.
23
  - **Private.** Runs locally. Your prompts and commands never leave your machine to be judged.
 
27
  rare cases that cost the most when missed: destructive deletes, commands that never exit,
28
  resuming interrupted work, refactor / test / documentation requests.
29
 
30
+ ## Get it
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  ```bash
33
  ollama pull devshub/knack # Q8_0, 817 MB (https://ollama.com/devshub/knack)
 
35
  ollama pull hf.co/devshub-ai/knack:Q8_0 # same model, straight from this repo
36
  ```
37
 
38
+ ## A specialized decision model
39
+
40
+ General decision models, like clef, read any question you write in plain language. Knack is
41
+ a different kind: a **specialized decision model**. It was trained on one product's fixed
42
+ decisions, the 29 that CodeSync makes on every shell command and every user message, and it
43
+ answers only those. It does not read question text: you ask by **question id**. In exchange
44
+ it is small, private, and answers all 8 command questions in about 17 ms.
45
+
46
+ | | General decision model (clef) | Specialized decision model (Knack) |
47
+ | --- | --- | --- |
48
+ | Questions | anything you write | 29 fixed ones, asked by id |
49
+ | Input | any text or image | a shell command, or a message to a coding assistant |
50
+ | Size | 27B | 0.75B |
51
+ | A question it was not trained on | answers it | rejects it |
52
+
53
+ ## Try it in one line
54
 
55
  ```
56
+ echo "npm run dev" | ollama run devshub/knack --ask serves
57
  ```
58
 
59
  ```
60
  yes 97%
61
  ```
62
 
63
+ `serves` asks whether the command keeps running until someone stops it (a dev server, a
64
+ watcher, `tail -f`). Each id has one precise meaning, listed in the tables below. Read them
65
+ before relying on an answer: `long_running`, for example, means "takes minutes", so a build
66
+ counts.
67
+
68
+ Knack only reads the text and judges it. Nothing is executed, so it is safe to ask about any
69
+ command, including destructive ones.
70
+
71
+ More examples:
72
 
73
  ```
74
  echo "git push --force" | ollama run devshub/knack --ask risk --level safe --level "needs care" --level destructive
75
+ echo "fix the failing login test" | ollama run devshub/knack --ask turn.new_task
76
  echo "fix the failing login test" | ollama run devshub/knack --ask task.intent \
77
  --choice bug_fix --choice feature --choice refactor --choice api_schema --choice config_deploy \
78
  --choice test --choice documentation --choice investigation --choice unknown
79
  ```
80
 
81
+ Ask with an id from the tables. Any other question is rejected rather than guessed. A choice
82
+ or score question needs its options in the order shown; if they do not match, the error
83
+ shows the exact flags to use.
84
+
85
+ ## API
86
 
87
  ### cURL
88
 
 
93
  "model": "devshub/knack",
94
  "state": "npm run dev",
95
  "questions": {
96
+ "serves": {"type": "noul", "instructions": "serves"},
97
+ "long_running": {"type": "noul", "instructions": "long_running"}
98
  }
99
  }'
100
  ```
101
 
102
  ```
103
+ {"model":"devshub/knack","answers":{"serves":{"type":"noul","noul":0.9701},"long_running":{"type":"noul","noul":0.9708}}}
104
  ```
105
 
106
+ The question id goes in `instructions` (or as the key). The state can also be an object
107
+ with Knack's own fields, for example `{"command": "npm run dev", "description": "start the app"}`.
108
 
109
  ### Python
110
 
 
118
  response = ollama.systemone(
119
  model="devshub/knack",
120
  state="npm run dev",
121
+ questions={"serves": {"type": "noul", "instructions": "serves"}},
122
  )
123
+ print(response.answers["serves"].noul) # 0.9701
124
  ```
125
 
126
+ ## Or use the standalone script
127
+
128
+ `knack.py` asks every question of a command or message at once and prints a table. It uses
129
+ only the Python standard library and pulls the model on first run.
130
+
131
+ ```
132
+ curl -fsSL https://huggingface.co/devshub-ai/knack/resolve/main/knack.py | python3 - "npm run dev"
133
+ ```
134
 
135
+ ```
136
+ risk 1 0.95 0 read-only, 1 recoverable change, 2 irreversible / remote
137
+ long_running yes 0.97 takes minutes, blocks, polls, watches or serves
138
+ activity running 0.92 what kind of work it does
139
+ verifies no 0.97 a test, type or lint check whose pass proves the change works
140
+ mutates_repo no 0.97 changes git state (commit, push, merge, rebase, tag)
141
+ deploys no 0.94 publishes, releases or changes a remote environment
142
+ runtime_check no 0.95 a health probe of a running service that fails if unhealthy
143
+ serves yes 0.97 keeps running until stopped (server, watcher, tail -f)
144
+ ```
145
 
146
+ ```
147
+ curl -fsSL https://huggingface.co/devshub-ai/knack/resolve/main/knack.py | python3 - --turn "fix the failing login test"
148
+ ```
 
 
 
 
 
 
 
149
 
150
+ ## What it decides
 
 
151
 
152
+ **Every shell command.** Input: the command (state fields `command`, `description`).
153
+
154
+ | id | yes / the answer means | options |
155
+ | --- | --- | --- |
156
+ | `risk` | the worst it can do: 0 read-only or trivially reversible, 1 changes recoverable local state, 2 irreversible loss or reaches beyond the checkout | 0, 1, 2 |
157
+ | `long_running` | takes minutes, blocks, polls, watches or serves, rather than finishing in seconds. A build or test suite counts | yes, no |
158
+ | `serves` | keeps running until it is stopped: server, daemon, watcher, tunnel, `tail -f`. A build that finishes on its own does not | yes, no |
159
+ | `activity` | what kind of work it does | testing, building, installing, git, inspecting, running |
160
+ | `verifies` | a test run, type or lint check whose passing exit is evidence the change works. Builds and plain runs do not count | yes, no |
161
+ | `mutates_repo` | changes version-control state: commit, push, merge, rebase, tag, amend. Editing or deleting files does not count | yes, no |
162
+ | `deploys` | publishes, releases, or changes a remote or runtime environment (deploy, rollout, push an image, bring a service up) | yes, no |
163
+ | `runtime_check` | a health or smoke probe of a running service that fails on an unhealthy response (`curl --fail`) | yes, no |
164
+
165
+ **Every user turn.** Input: the message a user sends to a coding assistant (state fields, in
166
+ this order: `prompt`, `current_mode`, `recent_activity`, `conversation_size`, `open_task`,
167
+ `turns_on_open_task`, `interrupted_work`, `browser_context`; plain text fills the rest with
168
+ defaults).
169
+
170
+ | id | the answer means | options |
171
+ | --- | --- | --- |
172
+ | `turn.chat_or_task` | conversation, or a request for work | chat, task |
173
+ | `turn.actionable` | asks for something to be done | yes, no |
174
+ | `turn.question_shaped` | phrased as a question | yes, no |
175
+ | `turn.change_intent` | kind of code change asked for | create, adjust, enhance, fix, refactor, none |
176
+ | `turn.new_task` | starts new work rather than continuing | yes, no |
177
+ | `turn.resume` | asks to resume interrupted work | yes, no |
178
+ | `turn.mission` | a long, multi-step job | yes, no |
179
+ | `turn.plan_authoring` | asks for a plan to be written | yes, no |
180
+ | `turn.screencast` | start or stop a screen recording | start, stop, none |
181
+ | `turn.demo` | asks for a demo | yes, no |
182
+ | `turn.skip_orientation` | can be done without exploring the codebase | yes, no |
183
+ | `task.intent` | type of task | bug_fix, feature, refactor, api_schema, config_deploy, test, documentation, investigation, unknown |
184
+ | `task.execution_strategy` | how to execute it | direct, plan, parallel |
185
+ | `route.mode` | best assistant mode | plan, build, ask, debug |
186
+ | `route.tier` | size of model needed | light, medium, heavy |
187
+ | `route.thinking` | reasoning effort needed | off, low, medium, high, xhigh, max |
188
+ | `route.risk` | risk of the requested work | low, medium, high |
189
+ | `browser` | needs a web browser | yes, no |
190
+ | `messaging` | needs to send an email or chat message | yes, no |
191
+ | `delivery.feature_task` | a feature delivery task | yes, no |
192
+ | `delivery.slash_task` | a slash-command style task | yes, no |
193
+
194
+ ## What it does not do
195
+
196
+ - **Other questions.** Anything outside these 29, such as "is this log an error?" or "is a
197
+ refund requested?", is rejected. Use a general decision model like clef for those.
198
+ - **Other input.** Logs, emails, tickets, documents or images give meaningless answers,
199
+ even to these 29 questions.
200
+ - **Conversation history.** Through Ollama it sees a single message. Inside CodeSync it also
201
+ gets the session context, which makes the turn questions more reliable.
202
+ - **Text generation.** It returns one pick with a confidence, never sentences.
203
+
204
+ ## Known weak spots
205
+
206
+ Measured with the commands above, so you know where to double-check:
207
+
208
+ | command | question | Knack says | should be |
209
+ | --- | --- | --- | --- |
210
+ | `tail -f app.log` | `serves` | no, 75% | yes |
211
+ | `npm run build` | `serves` | yes, 79% | no |
212
+ | `docker compose up` | `long_running` | 51% yes | yes |
213
+ | `npm test` | `long_running` | 45% yes | unclear, depends on the suite |
214
+
215
+ These come from the model, not the Ollama packaging (the original PyTorch model gives the
216
+ same numbers), and are the next training targets.
217
 
218
  ## Results
219
 
knack.py CHANGED
@@ -17,7 +17,7 @@ Usage:
17
 
18
  Knack is an Ollama decision model: this script sends all questions of a command or turn in
19
  one ``POST /v1/systemone`` request (needs an Ollama with decision-model support). Without the
20
- script: ``echo "npm run dev" | ollama run devshub/knack --ask long_running``.
21
 
22
  Env: KNACK_OLLAMA_HOST (default http://127.0.0.1:11434),
23
  KNACK_MODEL (default devshub/knack; devshub/knack:q4_k_m is smaller, 516 MB;
@@ -42,15 +42,15 @@ _READY: set[str] = set()
42
  # question id -> (type, option keys in letter order, what it decides)
43
  QUESTIONS: dict[str, tuple[str, list[str], str]] = {
44
  # every shell command (state: command, description)
45
- "risk": ("score", ["0", "1", "2"], "0 safe, 1 needs care, 2 destructive / dangerous"),
46
- "long_running": ("noul", ["yes", "no"], "keeps running (server, watch, poll, tail -f)"),
47
  "activity": ("choice", ["testing", "building", "installing", "git", "inspecting", "running"],
48
- "what kind of command it is"),
49
- "verifies": ("noul", ["yes", "no"], "checks that work is correct (tests, lint, build)"),
50
- "mutates_repo": ("noul", ["yes", "no"], "changes files or git state of the repo"),
51
- "deploys": ("noul", ["yes", "no"], "deploys or publishes"),
52
- "runtime_check": ("noul", ["yes", "no"], "needs a running app to check"),
53
- "serves": ("noul", ["yes", "no"], "starts a server"),
54
  # every user turn (state: prompt, current_mode, ...)
55
  "turn.chat_or_task": ("choice", ["chat", "task"], "conversation or work request"),
56
  "turn.actionable": ("noul", ["yes", "no"], "asks for something to be done"),
 
17
 
18
  Knack is an Ollama decision model: this script sends all questions of a command or turn in
19
  one ``POST /v1/systemone`` request (needs an Ollama with decision-model support). Without the
20
+ script: ``echo "npm run dev" | ollama run devshub/knack --ask serves``.
21
 
22
  Env: KNACK_OLLAMA_HOST (default http://127.0.0.1:11434),
23
  KNACK_MODEL (default devshub/knack; devshub/knack:q4_k_m is smaller, 516 MB;
 
42
  # question id -> (type, option keys in letter order, what it decides)
43
  QUESTIONS: dict[str, tuple[str, list[str], str]] = {
44
  # every shell command (state: command, description)
45
+ "risk": ("score", ["0", "1", "2"], "0 read-only, 1 recoverable change, 2 irreversible / remote"),
46
+ "long_running": ("noul", ["yes", "no"], "takes minutes, blocks, polls, watches or serves"),
47
  "activity": ("choice", ["testing", "building", "installing", "git", "inspecting", "running"],
48
+ "what kind of work it does"),
49
+ "verifies": ("noul", ["yes", "no"], "a test, type or lint check whose pass proves the change works"),
50
+ "mutates_repo": ("noul", ["yes", "no"], "changes git state (commit, push, merge, rebase, tag)"),
51
+ "deploys": ("noul", ["yes", "no"], "publishes, releases or changes a remote environment"),
52
+ "runtime_check": ("noul", ["yes", "no"], "a health probe of a running service that fails if unhealthy"),
53
+ "serves": ("noul", ["yes", "no"], "keeps running until stopped (server, watcher, tail -f)"),
54
  # every user turn (state: prompt, current_mode, ...)
55
  "turn.chat_or_task": ("choice", ["chat", "task"], "conversation or work request"),
56
  "turn.actionable": ("noul", ["yes", "no"], "asks for something to be done"),