@jocax/decision-maker
Agent tools that ask a decision model a typed question about a file, the same question about many files at once, or several questions the agent writes itself about one situation — without loading any of it into the agent's context.
What
Three entry points, six tools:
src/index.ts — one file at a time:
ask_decision_file_bool — yes or no
ask_decision_file_choice — pick one of a set of options
ask_decision_file_score — a position on a scale you define
src/index-files.ts — many files at once:
ask_decision_files — the same typed question asked of every file a pattern matches, one call per file, in parallel
ask_decision_files_pick — one choice over a list of paths, to pick which to open first
src/index-general.ts — one situation, several questions:
ask_decision — the agent writes its own questions_json block and state (a note, named file paths, or both) and gets back one answer per question in a single call
A file's text becomes part of the state of a decision call; it is sent to the decision model and never reaches the agent. The agent receives only the JSON answer(s). A consumer's package filter loads any one entry point, or any combination.
Why
Reading a file into context to answer one narrow question ("does this validate tokens?", "which layer is this?") spends context on text the agent will not quote or edit. These tools trade that read for one typed question and a small structured answer.
Install
{
"packages": [
{
"source": "npm:@jocax/decision-maker"
}
]
}
The package declares all three entry points; they are independent and share only their client resolution.
# Try it from a local checkout without installing
pi -e ./src/index.ts
pi -e ./src/index-files.ts
pi -e ./src/index-general.ts
Usage
A tool call and an illustrative result:
// call
{ "name": "ask_decision_file_bool", "params": {
"path": "src/auth/session.ts",
"question": "Does `content` validate authentication tokens?",
"yes": "It verifies a signature, an expiry or an issuer",
"no": "It does not touch tokens"
} }
// result (also the tool's `details`)
{
"path": "src/auth/session.ts",
"answer": true,
"noul": 0.93,
"meta": {
"provider": "typesafe",
"model": "jev-latest",
"requestedModel": "jev-latest",
"elapsedMs": 812,
"attempts": 1,
"usage": { "input_tokens": 512, "output_tokens": 40 }
}
}
The same question as code, with an injected client (see examples/file-questions.ts for more):
import { createDecisionClient, resolveDecisionConfig } from "@jocax/decision-core";
import { askFileBool } from "@jocax/decision-maker/src/ask-file";
const { config } = resolveDecisionConfig({ cwd: process.cwd() });
const client = createDecisionClient(config!);
const result = await askFileBool(
{ client, cwd: process.cwd() },
"src/auth/session.ts",
"Does `content` validate authentication tokens?",
{ yes: "It verifies a signature, an expiry or an issuer", no: "It does not touch tokens" },
);
// result.answer, result.noul, result.meta
The same question over many files, with an illustrative result:
// call
{ "name": "ask_decision_files", "params": {
"patterns": ["src/auth/**/*.ts"],
"question_type": "bool",
"question": "Does `content` take part in authentication?",
"yes": "It issues, verifies or stores credentials, tokens or sessions",
"no": "It does not touch authentication"
} }
// result (illustrative, also the tool's `details`)
{
"type": "bool",
"answers": [
{ "path": "src/auth/login.ts", "type": "bool", "answer": true, "noul": 0.88 },
{ "path": "src/auth/session.ts", "type": "bool", "answer": true, "noul": 0.93 }
],
"skipped": [
{ "path": "src/auth/index.ts", "reason": "empty" }
],
"meta": {
"provider": "typesafe",
"model": "jev-latest",
"requestedModel": "jev-latest",
"elapsedMs": 1340,
"calls": 2,
"attempts": 2,
"concurrency": 16,
"maxFiles": 255,
"usage": { "input_tokens": 1024, "output_tokens": 80 }
}
}
Picking which of the surviving paths to open first, with an illustrative result:
// call
{ "name": "ask_decision_files_pick", "params": {
"question": "Which file should I open first to fix token expiry?",
"candidates": [
{ "path": "src/auth/session.ts", "note": "validates tokens: true" },
{ "path": "src/auth/login.ts", "note": "validates tokens: true" }
]
} }
// result (illustrative, also the tool's `details`)
{
"path": "src/auth/session.ts",
"confidence": 0.81,
"probabilities": { "src/auth/session.ts": 0.81, "src/auth/login.ts": 0.15, "none": 0.04 },
"options": ["src/auth/session.ts", "src/auth/login.ts", "none"],
"skipped": [],
"meta": {
"provider": "typesafe",
"model": "jev-latest",
"requestedModel": "jev-latest",
"elapsedMs": 640,
"attempts": 1,
"usage": { "input_tokens": 220, "output_tokens": 30 }
}
}
The scan as code, with an injected client:
import { createDecisionClient, resolveDecisionConfig } from "@jocax/decision-core";
import { askFiles } from "@jocax/decision-maker/src/ask-files";
const { config } = resolveDecisionConfig({ cwd: process.cwd() });
const client = createDecisionClient(config!);
const result = await askFiles(
{ client, cwd: process.cwd() },
{
patterns: ["src/auth/**/*.ts"],
type: "bool",
question: "Does `content` take part in authentication?",
yes: "It issues, verifies or stores credentials, tokens or sessions",
no: "It does not touch authentication",
},
);
// result.answers, result.skipped, result.meta
One situation, several questions the agent wrote itself, with an illustrative result:
// call
{ "name": "ask_decision", "params": {
"paths": ["src/auth/session.ts"],
"questions_json": "{\"real\":{\"type\":\"noul\",\"instructions\":\"Is files[\\\"src/auth/session.ts\\\"] handling token expiry correctly?\",\"criteria\":{\"true\":\"Checks and rejects an expired token\",\"false\":\"No expiry check, or it is wrong\"}}}"
} }
// result (illustrative, also the tool's `details`)
{
"answers": {
"real": { "type": "noul", "noul": 0.91 }
},
"stateSummary": {
"own_fields": [],
"files": ["src/auth/session.ts"],
"skipped": [],
"tokens": 612,
"budgetTokens": 28601
},
"meta": {
"provider": "typesafe",
"model": "jev-latest",
"requestedModel": "jev-latest",
"elapsedMs": 790,
"attempts": 1,
"usage": { "input_tokens": 640, "output_tokens": 38 }
}
}
The same shape as code, with an injected client (see examples/general-questions.ts for more):
import { createDecisionClient, MOCK_CONFIG } from "@jocax/decision-core";
import { askGeneral } from "@jocax/decision-maker/src/ask-general";
const client = createDecisionClient(MOCK_CONFIG, {
mockAnswers: {
real: { type: "noul", noul: 0.82 },
kind: {
type: "choice",
choice: "bug_in_code",
confidence: 0.7,
probabilities: { bug_in_code: 0.7, wrong_test: 0.2, environment: 0.05, other: 0.05 },
},
},
});
const result = await askGeneral(
{ client, cwd: process.cwd() },
{
state: "CI failed once on main; nothing in the touched files changed since the last green run.",
questionsJson: JSON.stringify({
real: { type: "noul", instructions: "Is this likely a real failure rather than a flaky one?" },
kind: {
type: "choice",
instructions: "What kind of failure is it?",
criteria: {
bug_in_code: "The code under test is wrong",
wrong_test: "The test asserts the wrong thing",
environment: "Something outside the code failed",
other: "None of the above",
},
},
}),
},
);
// result.answers.real, result.answers.kind, result.stateSummary, result.meta
Tools
| Tool |
Parameters |
Returns |
ask_decision_file_bool |
path, question, yes?, no? — what counts as each side |
{ path, answer, noul, meta } — answer is noul > 0.5 |
ask_decision_file_choice |
path, question, options: { name, description }[] |
{ path, choice, confidence, probabilities, options, meta } — options is the array of option ids actually asked about, including an added other |
ask_decision_file_score |
path, question, levels: string[] (low to high) |
{ path, score, top, nearest, normalized, confidence, legend, meta } |
ask_decision_files |
patterns: string[], question_type: "bool" \| "choice" \| "score", question, yes?/no? (bool only), options?: { name, description }[] (choice only), levels?: string[] (score only), recursive?: boolean |
{ type, answers, skipped, options?, legend?, meta } — each answer carries path plus its type's fields: bool → { answer, noul }, choice → { choice, confidence, probabilities }, score → { score, top, nearest, normalized, confidence } |
ask_decision_files_pick |
question, candidates: { path, note? }[] |
{ path, confidence, probabilities, options, skipped, meta } — path is the chosen candidate, or null when the model picks none |
ask_decision |
state? — a note, plain text or a JSON object as a string; paths? — file paths, globs or directories, read into state.files["path"], at most AE_PI_DECISION_MAKER_MAX_STATE_FILES (default 20); questions_json — a JSON object keyed by question id, written by the agent |
{ answers, stateSummary, meta } — answers is keyed by the agent's own question ids; stateSummary names what went into the state (own_fields, files, skipped, tokens, budgetTokens) without sending the content back |
options for the choice tool is an array of { name, description } objects, not a map — a plain object-array schema is accepted by every provider this repo targets, where a string-keyed map is not. When the agent names none of other, none or none_of_the_above, an other option ("None of the above") is added and appears in the returned options.
Every result carries meta: provider, model (as the provider reports it), requestedModel, elapsedMs, attempts, usage.
Configuration
| Variable |
Required |
Description |
AE_PI_DECISION_MAKER_ENABLED |
No |
"false" registers no tool at all. Any other value, including unset, leaves the package on |
AE_PI_DECISION_MAKER_TIMEOUT_MS |
No |
Total time budget for one decision call, retries included. A positive integer of milliseconds; unset uses @jocax/decision-core's own provider default |
AE_PI_DECISION_MAKER_CONCURRENCY |
No |
How many decision calls ask_decision_files keeps in flight. A positive integer from 1 to 64; unset uses a provider-aware default |
AE_PI_DECISION_MAKER_MAX_FILES |
No |
How many files one ask_decision_files or ask_decision_files_pick call may consider. A positive integer; unset uses the provider's own choice-option limit |
AE_PI_DECISION_MAKER_MAX_STATE_FILES |
No |
How many files one ask_decision call may put in its state. A positive integer; unset uses 20 |
AE_PI_DECISION_MAKER_PRICE_INPUT |
No |
USD per million input tokens, used only for the ask_decision spend ledger. Unset reports no money |
AE_PI_DECISION_MAKER_PRICE_OUTPUT |
No |
USD per million output tokens, for the ledger. Both prices must be set together — one alone is treated as neither, and the ledger reports no money |
AE_PI_DECISION_MAKER_NUDGE |
No |
"false" leaves the system prompt alone. Any other value, including unset, adds a short block pointing the agent at ask_decision |
Both of the scale defaults come from the provider, not a constant:
| Provider |
Concurrency default |
File cap default |
| Ollama |
4 |
26 |
| TypeSafe |
16 |
255 |
Provider, model, base URL and API key are not settings of this package — they come from @jocax/decision-core's own AE_PI_DECISION_CORE_* variables. See software/packages/decision-core/README.md.
With no decision provider configured, the extension still loads: it warns once at session start and every tool call fails with a message naming AE_PI_DECISION_CORE_PROVIDER.
Package events
With AE_PI_EVENT_CORE_ENABLED=true (a setting of @jocax/event-core), each of
ask_decision_file_bool, ask_decision_file_choice and ask_decision_file_score also
writes one package event per answer: which decision model read which file, how many
tokens it read, the answer, and that the file stayed out of the agent's context. The tool
result itself is unchanged. The scale and general tools write none.
Scale