@yahyahammad/venastine 0.2.0 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +19 -14
- package/CONFIG_ARCHITECTURE.md +2002 -0
- package/NOTICE +1 -1
- package/README.md +233 -94
- package/agents/builtin/build.md +73 -0
- package/agents/builtin/general.md +80 -0
- package/agents/builtin/plan.md +23 -5
- package/agents/builtin/test.md +65 -0
- package/agents/builtin/writer.md +67 -0
- package/agents/manager.py +261 -195
- package/agents/subagent_tool.py +277 -43
- package/agents/tui_commands.py +7 -12
- package/bin/venastine.mjs +528 -382
- package/bin/venastine.py +71 -0
- package/cli_commands.py +835 -0
- package/config.py +95 -1198
- package/config.yaml +1090 -0
- package/config_edit.py +1301 -0
- package/config_schema.py +966 -0
- package/config_update.py +749 -0
- package/core/agent_activity.py +158 -20
- package/core/ansi.py +452 -0
- package/core/approval.py +27 -5
- package/core/call_view.py +364 -0
- package/core/cancel.py +121 -0
- package/core/chatgpt_auth.py +747 -0
- package/core/claims_view.py +107 -0
- package/core/client.py +1238 -82
- package/core/commands.py +454 -0
- package/core/compaction.py +830 -66
- package/core/config_loader.py +516 -97
- package/core/connect.py +686 -0
- package/core/events.py +68 -6
- package/core/file_mentions.py +280 -0
- package/core/interaction.py +87 -4
- package/core/line_pattern.py +128 -0
- package/core/loop.py +1516 -440
- package/core/memory.py +120 -8
- package/core/pipeline_models.py +23 -9
- package/core/provider_errors.py +234 -0
- package/core/reasoning/confidence_scoring.py +70 -54
- package/core/reasoning/json_retry.py +19 -1
- package/core/reasoning/orchestrator.py +232 -53
- package/core/reasoning/output_writer.py +90 -31
- package/core/reasoning/payload_validation.py +133 -7
- package/core/reasoning/pipeline_storage.py +427 -361
- package/core/reasoning/review.py +659 -615
- package/core/reasoning/scholar.py +38 -14
- package/core/reasoning/source_corpus.py +110 -4
- package/core/replay.py +158 -26
- package/core/session.py +36 -12
- package/core/session_view.py +259 -0
- package/core/session_wake.py +259 -0
- package/core/shell_sessions.py +1553 -0
- package/core/workspace_trust.py +1 -1
- package/credentials.py +308 -180
- package/database.py +82 -1
- package/{PRIVACY.md → docs/PRIVACY.md} +19 -7
- package/docs/SECURITY.md +108 -0
- package/docs/THIRD_PARTY_NOTICES.md +148 -0
- package/env_secrets.py +118 -77
- package/json_store.py +236 -16
- package/logging_setup.py +121 -11
- package/main.py +1671 -199
- package/mcp_client/client.py +257 -23
- package/mcp_client/config.py +484 -379
- package/mcp_client/registration.py +163 -2
- package/memories/manager.py +15 -0
- package/memories/tui_commands.py +7 -12
- package/package.json +234 -4
- package/project_init/config_files.py +4 -0
- package/project_init/generator.py +201 -37
- package/project_init/manifest.py +418 -406
- package/project_init/tui_commands.py +7 -4
- package/prompts/revalidate.md +1 -1
- package/prompts/revise.md +17 -15
- package/prompts/system_prompts.py +64 -10
- package/providers.json.example +94 -92
- package/pyproject.toml +51 -2
- package/requirements.txt +252 -29
- package/safety/policy_enforcement.py +353 -17
- package/security/askpass.py +419 -0
- package/security/capability.py +37 -7
- package/security/confine.py +484 -0
- package/security/hosted.py +182 -0
- package/security/permissions.py +54 -7
- package/security/posture.py +124 -12
- package/security/protected_paths.py +198 -6
- package/security/sandbox.py +3262 -139
- package/security/secrets.py +855 -0
- package/skills/tui_commands.py +3 -4
- package/storage.py +368 -35
- package/tools/base.py +465 -305
- package/tools/builtin/_math_common.py +306 -16
- package/tools/builtin/_net_common.py +267 -61
- package/tools/builtin/arxiv.py +681 -223
- package/tools/builtin/ask_user.py +231 -213
- package/tools/builtin/discrete_math.py +35 -4
- package/tools/builtin/fetch_url.py +239 -21
- package/tools/builtin/file_ops.py +341 -33
- package/tools/builtin/geometry.py +184 -148
- package/tools/builtin/get_time.py +2 -2
- package/tools/builtin/linear_algebra.py +66 -23
- package/tools/builtin/load_skill.py +10 -0
- package/tools/builtin/logic.py +171 -12
- package/tools/builtin/pin.py +46 -12
- package/tools/builtin/probability_stats.py +224 -228
- package/tools/builtin/project_docs.py +80 -21
- package/tools/builtin/remember.py +21 -4
- package/tools/builtin/shell.py +586 -67
- package/tools/builtin/shell_sessions.py +613 -0
- package/tools/builtin/symbolic_math.py +80 -10
- package/tools/builtin/todo.py +5 -3
- package/tools/builtin/web_search.py +329 -151
- package/tools/context.py +23 -0
- package/tools/isolation.py +387 -314
- package/tools/registry.py +347 -30
- package/tui/app.py +4645 -438
- package/tui/app.tcss +185 -2
- package/tui/commands.py +10 -154
- package/tui/diffs.py +286 -265
- package/tui/hosted_driver.py +102 -0
- package/tui/markdown.py +60 -10
- package/tui/meters.py +103 -7
- package/tui/screens.py +346 -92
- package/tui/themes.py +59 -19
- package/tui/widgets.py +1575 -111
- package/SECURITY.md +0 -88
- package/THIRD_PARTY_NOTICES.md +0 -100
package/core/config_loader.py
CHANGED
|
@@ -32,8 +32,9 @@ from typing import Optional
|
|
|
32
32
|
|
|
33
33
|
import yaml
|
|
34
34
|
|
|
35
|
-
import
|
|
35
|
+
import config_schema
|
|
36
36
|
from core import workspace_trust
|
|
37
|
+
from json_store import read_regular_text
|
|
37
38
|
|
|
38
39
|
logger = logging.getLogger(__name__)
|
|
39
40
|
|
|
@@ -49,7 +50,6 @@ NUMBER_TYPES = (int, float)
|
|
|
49
50
|
# vocabulary is a second thing to keep in step.
|
|
50
51
|
from core.reasoning.base import GROUNDING_STATUSES # noqa: E402
|
|
51
52
|
|
|
52
|
-
|
|
53
53
|
_FRONTMATTER_DELIM = re.compile(r"^---\s*$", re.MULTILINE)
|
|
54
54
|
|
|
55
55
|
_KNOWN_SETTINGS = {
|
|
@@ -140,8 +140,8 @@ _KNOWN_TUI = {
|
|
|
140
140
|
"todo_position": str, # §23 slice 2: one of TODO_POSITIONS below
|
|
141
141
|
# §38 (O6): render a turn's reasoning inline, or collapse it to an
|
|
142
142
|
# animated one-line indicator. Defaults to True in tui/app.py rather
|
|
143
|
-
# than to a config.
|
|
144
|
-
# holds no TUI values
|
|
143
|
+
# than to a config.yaml key, following `animations` above -- config.yaml
|
|
144
|
+
# holds no TUI values.
|
|
145
145
|
"show_thinking": bool,
|
|
146
146
|
}
|
|
147
147
|
|
|
@@ -166,6 +166,9 @@ _KNOWN_CONFIDENCE = {
|
|
|
166
166
|
"grounding_weight_factor": float,
|
|
167
167
|
"critic_weight_factor": float,
|
|
168
168
|
"assumption_flag_penalty": float,
|
|
169
|
+
# Retired by ROADMAP_v3 §90 and still KNOWN, as `ensemble_n` is (E4):
|
|
170
|
+
# unknown keys raise, so dropping it would stop every settings.json
|
|
171
|
+
# that sets it from loading. effective_confidence warns instead.
|
|
169
172
|
"disagreement_penalty_factor": float,
|
|
170
173
|
"non_factual_score_cap": float,
|
|
171
174
|
"source_quality_floor": float,
|
|
@@ -250,13 +253,64 @@ class AgentDef:
|
|
|
250
253
|
# spawnable does not fail, it under-performs, and the parent has
|
|
251
254
|
# no way to tell (which is #69's actual complaint).
|
|
252
255
|
#
|
|
253
|
-
#
|
|
254
|
-
#
|
|
255
|
-
#
|
|
256
|
-
#
|
|
257
|
-
#
|
|
258
|
-
#
|
|
256
|
+
# IT IS A PERMISSION SINCE A16 (ROADMAP_v3 section 62), and this
|
|
257
|
+
# comment said the opposite for as long as it was true. Consulted by
|
|
258
|
+
# prompts.system_prompts.agent_catalog_text AND by
|
|
259
|
+
# agents.subagent_tool.refusal_reason, which refuses a spawn of
|
|
260
|
+
# anything whose value is not True.
|
|
261
|
+
#
|
|
262
|
+
# WHY IT CHANGED. "Advertisement only" meant `spawn_subagent` would
|
|
263
|
+
# spawn any agent the loader had discovered, by name -- including one
|
|
264
|
+
# the asymmetry above had deliberately left off the catalog. So the
|
|
265
|
+
# measured consequence of a stranger's silence was INVISIBLE rather
|
|
266
|
+
# than unreachable: a project-tier agent omitting the field was absent
|
|
267
|
+
# from the prompt a user might read and callable by any text that named
|
|
268
|
+
# it. For the careless author the default was safe; for the adversarial
|
|
269
|
+
# one it was the quieter option, which inverts the ranking the SAFE
|
|
270
|
+
# answer above is reaching for. Its own sibling `spawn_targets` had
|
|
271
|
+
# already chosen refusal for the same class of problem.
|
|
272
|
+
#
|
|
273
|
+
# C6 still caps a child's tools and the depth limit still applies;
|
|
274
|
+
# those were never what this field was about. D24's rule
|
|
275
|
+
# ("advertising an uncallable tool is not harmless: the model keeps
|
|
276
|
+
# choosing it") still applies to the catalog's entries -- and now its
|
|
277
|
+
# mirror applies too: a catalog that hides a REACHABLE agent is the
|
|
278
|
+
# same defect read the other way.
|
|
259
279
|
spawnable: Optional[bool] = None
|
|
280
|
+
# WHICH agents this one may spawn. `spawnable` above is the other
|
|
281
|
+
# half of the same question -- that one is about being spawned, this
|
|
282
|
+
# one about spawning -- and they are separate fields because an agent
|
|
283
|
+
# can be either, both or neither.
|
|
284
|
+
#
|
|
285
|
+
# None means NO OPINION: every spawnable agent, which is what every
|
|
286
|
+
# definition written before this field got and therefore what it has
|
|
287
|
+
# to keep meaning. A list restricts, and only ever restricts: it
|
|
288
|
+
# composes by intersection on ToolContext exactly as allowed_tools
|
|
289
|
+
# does, so it cannot be widened by nesting.
|
|
290
|
+
#
|
|
291
|
+
# It is a REFUSAL, unlike `spawnable`'s advertisement. C6 already
|
|
292
|
+
# narrows a child's tools to the parent's, which is the wrong answer
|
|
293
|
+
# when the parent should not be delegating that work at all: `plan`
|
|
294
|
+
# spawning `build` produced a build stripped of `write` and `edit`,
|
|
295
|
+
# degraded exactly the way A4 describes and invisible from both ends.
|
|
296
|
+
# Read by agents.subagent_tool.refusal_reason (the refusal) and by
|
|
297
|
+
# prompts.system_prompts.agent_catalog_text (D24: an agent that will
|
|
298
|
+
# be refused is not advertised in the first place).
|
|
299
|
+
spawn_targets: Optional[list] = None
|
|
300
|
+
|
|
301
|
+
@property
|
|
302
|
+
def pins_model(self) -> bool:
|
|
303
|
+
"""Whether this file names EITHER half of its model pair.
|
|
304
|
+
|
|
305
|
+
One predicate, because three readers ask it and have to agree:
|
|
306
|
+
the subagent spawn, which takes the `/submodel` pair only for an
|
|
307
|
+
agent that pins neither half (ROADMAP_v3 §57, SM6); the note a
|
|
308
|
+
`/model` switch owes an active agent that pins; and `/submodel`'s
|
|
309
|
+
list of the agents it does not reach. A half pin opts out WHOLE:
|
|
310
|
+
a model name means nothing against the wrong provider, so filling
|
|
311
|
+
the missing half from `/submodel` would build a pair nobody chose.
|
|
312
|
+
"""
|
|
313
|
+
return bool(self.model or self.provider)
|
|
260
314
|
|
|
261
315
|
|
|
262
316
|
def _user_config_dir() -> str:
|
|
@@ -300,10 +354,11 @@ def _catalog_text(value) -> str:
|
|
|
300
354
|
least visible -- so the shipped files are held to it too, and
|
|
301
355
|
tests/test_catalog_text.py asserts they already comply.
|
|
302
356
|
"""
|
|
357
|
+
cap = config_schema.current().max_catalog_text_chars
|
|
303
358
|
text = " ".join(str(value).split())
|
|
304
|
-
if len(text) <=
|
|
359
|
+
if len(text) <= cap:
|
|
305
360
|
return text
|
|
306
|
-
return text[:
|
|
361
|
+
return text[:cap - 1].rstrip() + "\u2026"
|
|
307
362
|
|
|
308
363
|
|
|
309
364
|
def _parse_frontmatter(text: str) -> tuple[dict, str]:
|
|
@@ -340,8 +395,11 @@ def _parse_md_file(path: str, kind: str, tier: str, category: str = ""):
|
|
|
340
395
|
# ^--- no longer sits at position 0 and the file is skipped with
|
|
341
396
|
# the false diagnosis "does not begin with a YAML frontmatter
|
|
342
397
|
# block". utf-8-sig strips a BOM and is a no-op without one.
|
|
343
|
-
|
|
344
|
-
|
|
398
|
+
# Regular files only (batch 219, #214): this runs for the trust
|
|
399
|
+
# prompt's listing, before any grant, and a cloned skill linked to
|
|
400
|
+
# /dev/zero was read until memory ran out. The refusal is an
|
|
401
|
+
# OSError, so it warns and skips below like any broken definition.
|
|
402
|
+
text = read_regular_text(path)
|
|
345
403
|
fm, body = _parse_frontmatter(text)
|
|
346
404
|
except (OSError, ValueError, yaml.YAMLError) as e:
|
|
347
405
|
logger.warning("Skipping %s file %s: %s", kind, path, e)
|
|
@@ -389,10 +447,71 @@ def _parse_md_file(path: str, kind: str, tier: str, category: str = ""):
|
|
|
389
447
|
if allowed is not None and not isinstance(allowed, list):
|
|
390
448
|
logger.warning("Skipping agent file %s: allowed_tools is not a list", path)
|
|
391
449
|
return None
|
|
450
|
+
# ELEMENT TYPES TOO, not just the container. This is the lesson the
|
|
451
|
+
# skills branch above already paid for with `additional_tools`: a
|
|
452
|
+
# non-string element parses cleanly here and fails at first
|
|
453
|
+
# consumption, layers away from the file that caused it. THIS FIELD IS
|
|
454
|
+
# THE ONE THE RULE WAS NEVER APPLIED TO (batch 155) -- it sat under
|
|
455
|
+
# the comment stating it, with the container checked and the elements
|
|
456
|
+
# not.
|
|
457
|
+
#
|
|
458
|
+
# Its two consumers fail in OPPOSITE directions, both measured. A
|
|
459
|
+
# hashable non-string (`[read, 123]`) survives `set()` and then
|
|
460
|
+
# matches nothing, so the whitelist silently holds one fewer entry
|
|
461
|
+
# than it reads as -- the whitelist-typo class
|
|
462
|
+
# tests/test_shipped_roster.py documents for misspelled strings. An
|
|
463
|
+
# unhashable one (`[read, [write]]`, `[read, {write: true}]`) raises
|
|
464
|
+
# `TypeError: unhashable type` out of `AgentManager.active_context`
|
|
465
|
+
# and `child_context`, which are the single place this `Optional[list]`
|
|
466
|
+
# becomes `ToolContext.allowed_tools`'s declared `Optional[set[str]]`.
|
|
467
|
+
#
|
|
468
|
+
# SKIP, NOT DROP THE ELEMENT, for the reason `approval_overrides`
|
|
469
|
+
# states below: half a whitelist is worse than no file at all for a
|
|
470
|
+
# field whose job is deciding what an agent may call.
|
|
471
|
+
if allowed is not None and not all(isinstance(t, str) for t in allowed):
|
|
472
|
+
logger.warning(
|
|
473
|
+
"Skipping agent file %s: allowed_tools is not a list of strings",
|
|
474
|
+
path)
|
|
475
|
+
return None
|
|
476
|
+
# The consumer here is a set membership test against an agent NAME, so
|
|
477
|
+
# a nested list or a mapping raises where that set is built and a
|
|
478
|
+
# hashable non-string sits inert and never matches -- the same pair
|
|
479
|
+
# measured one field up.
|
|
480
|
+
targets = fm.get("spawn_targets")
|
|
481
|
+
if targets is not None and not isinstance(targets, list):
|
|
482
|
+
logger.warning(
|
|
483
|
+
"Skipping agent file %s: spawn_targets is not a list", path)
|
|
484
|
+
return None
|
|
485
|
+
if targets is not None and not all(isinstance(t, str) for t in targets):
|
|
486
|
+
logger.warning(
|
|
487
|
+
"Skipping agent file %s: spawn_targets is not a list of strings",
|
|
488
|
+
path)
|
|
489
|
+
return None
|
|
392
490
|
overrides = fm.get("approval_overrides") or {}
|
|
393
491
|
if not isinstance(overrides, dict):
|
|
394
492
|
logger.warning("Skipping agent file %s: approval_overrides is not a mapping", path)
|
|
395
493
|
return None
|
|
494
|
+
# THE VALUES TOO, not just the mapping (batch 150). The two scalar
|
|
495
|
+
# booleans below are validated for the reason stated there, and this
|
|
496
|
+
# field is the third one a restrictive agent definition uses to opt
|
|
497
|
+
# IN to prompting -- so stopping at the container left
|
|
498
|
+
# `web_search: "false"` parsing to the STRING, and
|
|
499
|
+
# requires_approval() returning 'false' from a function documented to
|
|
500
|
+
# return a bool. Measured: no value widens a gate, because approval
|
|
501
|
+
# ORs and every falsy value is already indistinguishable from the key
|
|
502
|
+
# being absent -- so this is the type boundary, not an escalation.
|
|
503
|
+
# Same warn-and-skip contract as every other typed field here; a
|
|
504
|
+
# per-key repair would leave half a policy, which is worse than no
|
|
505
|
+
# file at all for a field whose job is adding prompts.
|
|
506
|
+
if not all(isinstance(v, bool) for v in overrides.values()):
|
|
507
|
+
bad = sorted(k for k, v in overrides.items()
|
|
508
|
+
if not isinstance(v, bool))
|
|
509
|
+
logger.warning(
|
|
510
|
+
"Skipping agent file %s: approval_overrides values must be "
|
|
511
|
+
"booleans; %s %s not.",
|
|
512
|
+
path, ", ".join(repr(k) for k in bad),
|
|
513
|
+
"is" if len(bad) == 1 else "are")
|
|
514
|
+
return None
|
|
396
515
|
max_steps = fm.get("max_steps")
|
|
397
516
|
# REPAIR, NOT REJECT (#45, batch 16 -- explicit owner decision). This
|
|
398
517
|
# guard used to SKIP the whole file for a bad max_steps, which made it
|
|
@@ -420,7 +539,7 @@ def _parse_md_file(path: str, kind: str, tier: str, category: str = ""):
|
|
|
420
539
|
logger.warning(
|
|
421
540
|
"Agent file %s: max_steps must be a positive integer, got "
|
|
422
541
|
"%r; defaulting to %s (config.MAX_ITERATIONS).",
|
|
423
|
-
path, max_steps,
|
|
542
|
+
path, max_steps, config_schema.current().max_iterations)
|
|
424
543
|
max_steps = None
|
|
425
544
|
# Booleans are VALIDATED, not coerced. bool("false") is True, so
|
|
426
545
|
# `use_memory: "false"` would invert a deliberate opt-out with no
|
|
@@ -440,6 +559,35 @@ def _parse_md_file(path: str, kind: str, tier: str, category: str = ""):
|
|
|
440
559
|
logger.warning(
|
|
441
560
|
"Skipping agent file %s: spawnable is not a boolean", path)
|
|
442
561
|
return None
|
|
562
|
+
# STRINGS OR ABSENT, and these are the other two fields the rule above
|
|
563
|
+
# was never applied to (batch 155). Both were read straight out of
|
|
564
|
+
# frontmatter and handed to code that has always assumed a string, so
|
|
565
|
+
# a well-typed-but-wrong-SHAPED value loaded clean here and failed
|
|
566
|
+
# layers away with nothing naming the file. Measured against the real
|
|
567
|
+
# resolvers, nothing monkeypatched: `provider: 123` reaches
|
|
568
|
+
# `client.api_initialization` and raises `ValueError: Unknown
|
|
569
|
+
# provider: 123`, which names the provider and not the file that
|
|
570
|
+
# supplied it; `model: [a, b]` reaches the effort cache's
|
|
571
|
+
# `(provider_name, model)` key and raises `TypeError: unhashable
|
|
572
|
+
# type: 'list'`, which names neither. Both arrive there through
|
|
573
|
+
# `agents/subagent_tool.py` and `tui/app.py`, which pass
|
|
574
|
+
# `agent.model or ...` through verbatim.
|
|
575
|
+
#
|
|
576
|
+
# SKIP RATHER THAN REPAIR TO None, which is where this parts company
|
|
577
|
+
# with `max_steps` above (#45). None is a REAL value for both fields
|
|
578
|
+
# and means "inherit the session's", so repairing would leave the
|
|
579
|
+
# agent available and running on a model nobody chose for it. A file
|
|
580
|
+
# names a model when being a DIFFERENT model is the point, and §11's
|
|
581
|
+
# critic rationale is the sharpest form of that -- "a model checking
|
|
582
|
+
# its own output for errors shares that model's blind spots". A bad
|
|
583
|
+
# `max_steps` has no honest reading, so repairing it invents nothing;
|
|
584
|
+
# an unreadable `model` has one, and it is the wrong one.
|
|
585
|
+
for key in ("model", "provider"):
|
|
586
|
+
value = fm.get(key)
|
|
587
|
+
if value is not None and not isinstance(value, str):
|
|
588
|
+
logger.warning(
|
|
589
|
+
"Skipping agent file %s: %s is not a string", path, key)
|
|
590
|
+
return None
|
|
443
591
|
return AgentDef(
|
|
444
592
|
name=name,
|
|
445
593
|
description=_catalog_text(fm.get("description", "")),
|
|
@@ -450,6 +598,7 @@ def _parse_md_file(path: str, kind: str, tier: str, category: str = ""):
|
|
|
450
598
|
use_project_context=flags["use_project_context"],
|
|
451
599
|
use_memory=flags["use_memory"],
|
|
452
600
|
spawnable=spawnable,
|
|
601
|
+
spawn_targets=targets,
|
|
453
602
|
max_steps=max_steps,
|
|
454
603
|
body=body,
|
|
455
604
|
tier=tier,
|
|
@@ -643,8 +792,8 @@ def _validate_settings(data, source: str) -> None:
|
|
|
643
792
|
f"settings.json at {source}: ensemble_models is deliberately "
|
|
644
793
|
f"not supported -- a roster chooses which providers N research "
|
|
645
794
|
f"passes call, and a project's settings.json beats the "
|
|
646
|
-
f"user's. Set
|
|
647
|
-
f"(same posture as
|
|
795
|
+
f"user's. Set ensemble_models in config.yaml instead "
|
|
796
|
+
f"(same posture as critic_model).")
|
|
648
797
|
if key == "shell_approval_mode":
|
|
649
798
|
# ROADMAP_v2 §28 (G7), and the third application of R12's rule.
|
|
650
799
|
# Rejected BY NAME for the reason the other two are: the
|
|
@@ -665,7 +814,7 @@ def _validate_settings(data, source: str) -> None:
|
|
|
665
814
|
f"deliberately not supported -- it decides whether shell "
|
|
666
815
|
f"commands are approved at all, and a project's "
|
|
667
816
|
f"settings.json beats the user's. Set "
|
|
668
|
-
f"
|
|
817
|
+
f"shell_approval_mode in config.yaml instead (same "
|
|
669
818
|
f"posture as ensemble_models and research.granted_tools).")
|
|
670
819
|
if key in ("critic_model", "embedder_model"):
|
|
671
820
|
# ROADMAP_v2 §45 (SQ7), and the fourth application of R12's
|
|
@@ -686,7 +835,7 @@ def _validate_settings(data, source: str) -> None:
|
|
|
686
835
|
f"supported -- it names a provider this harness sends "
|
|
687
836
|
f"research content to, and a project's settings.json beats "
|
|
688
837
|
f"the user's. Use /critic or /embedder, or set "
|
|
689
|
-
f"
|
|
838
|
+
f"critic_model / embedder_model in config.yaml "
|
|
690
839
|
f"(same posture as ensemble_models).")
|
|
691
840
|
if key not in _KNOWN_SETTINGS:
|
|
692
841
|
raise ValueError(f"settings.json at {source}: unknown key {key!r}")
|
|
@@ -697,6 +846,16 @@ def _validate_settings(data, source: str) -> None:
|
|
|
697
846
|
raise ValueError(
|
|
698
847
|
f"settings.json at {source}: key {key!r} must be {expected_name}, "
|
|
699
848
|
f"got {type(value).__name__}")
|
|
849
|
+
if key == "max_token_budget" and value is not None and value <= 0:
|
|
850
|
+
# #213. The type gate passes 0 and -5 -- they are ints -- and
|
|
851
|
+
# the loop's check is `used >= cap`, so a cap of zero or less
|
|
852
|
+
# let every turn spend ONE model call and then die reporting a
|
|
853
|
+
# budget problem for what is a typo in this file.
|
|
854
|
+
raise ValueError(
|
|
855
|
+
f"settings.json at {source}: max_token_budget must be a "
|
|
856
|
+
f"positive number of tokens, or null for no cap -- got "
|
|
857
|
+
f"{value}, which would stop every turn after its first "
|
|
858
|
+
f"model call.")
|
|
700
859
|
for section, known_keys in _NESTED_SETTINGS.items():
|
|
701
860
|
block = data.get(section)
|
|
702
861
|
if block is None:
|
|
@@ -749,21 +908,33 @@ def _validate_settings(data, source: str) -> None:
|
|
|
749
908
|
# bad value is a startup error, and called again per compaction so a
|
|
750
909
|
# per-invocation `/compact --strength 4` composes with the same rules.
|
|
751
910
|
|
|
911
|
+
# settings.json key -> the `config.yaml` field it defaults from.
|
|
912
|
+
#
|
|
913
|
+
# THESE ARE SCHEMA FIELD NAMES, NOT STRINGS LOOKED UP ON A MODULE. This map
|
|
914
|
+
# used to hold `"COMPACTION_TRIGGER_TOKENS"` and friends and reach them with
|
|
915
|
+
# `getattr(config, attr)` -- no default, so renaming or dropping any one of
|
|
916
|
+
# the seven turned `shipped_defaults()` into an AttributeError that surfaced
|
|
917
|
+
# through `initialize()` at startup, and nothing but this dictionary tied the
|
|
918
|
+
# two names together. `config_schema.HarnessConfig` is the source of truth
|
|
919
|
+
# now, so a missing field is a validation error naming the key and a renamed
|
|
920
|
+
# one is an AttributeError here at the same moment either way -- but the names
|
|
921
|
+
# below are checked against the model by
|
|
922
|
+
# `tests/test_config_loader.py::test_every_compaction_default_names_a_schema_field`.
|
|
752
923
|
_COMPACTION_DEFAULTS = {
|
|
753
|
-
"trigger_tokens": "
|
|
754
|
-
"warning_margin_tokens": "
|
|
755
|
-
"keep_recent_tokens": "
|
|
756
|
-
"keep_recent_turns": "
|
|
757
|
-
"strength": "
|
|
758
|
-
"max_retries": "
|
|
759
|
-
"strategy": "
|
|
924
|
+
"trigger_tokens": "compaction_trigger_tokens",
|
|
925
|
+
"warning_margin_tokens": "compaction_warning_margin_tokens",
|
|
926
|
+
"keep_recent_tokens": "compaction_keep_recent_tokens",
|
|
927
|
+
"keep_recent_turns": "compaction_keep_recent_turns",
|
|
928
|
+
"strength": "compaction_strength",
|
|
929
|
+
"max_retries": "compaction_max_retries",
|
|
930
|
+
"strategy": "compaction_strategy",
|
|
760
931
|
}
|
|
761
932
|
|
|
762
933
|
|
|
763
934
|
def shipped_defaults() -> dict:
|
|
764
935
|
"""Every nested knob at the value it takes when no settings.json
|
|
765
936
|
speaks. `{section: {key: default}}`, sections only -- the top-level
|
|
766
|
-
scalars are plain `config.
|
|
937
|
+
scalars are plain `config.yaml` keys and need no accessor.
|
|
767
938
|
|
|
768
939
|
EXISTS SO A TEMPLATE CANNOT QUOTE A STALE DEFAULT (§24 I15).
|
|
769
940
|
`/init --config` writes a settings.json of defaults, and a settings
|
|
@@ -776,9 +947,10 @@ def shipped_defaults() -> dict:
|
|
|
776
947
|
resolved at call time, which is why this can sit beside the compaction
|
|
777
948
|
map it also reads.
|
|
778
949
|
"""
|
|
950
|
+
cfg = config_schema.current()
|
|
779
951
|
return {
|
|
780
|
-
"compaction": {key: getattr(
|
|
781
|
-
for key,
|
|
952
|
+
"compaction": {key: getattr(cfg, field)
|
|
953
|
+
for key, field in _COMPACTION_DEFAULTS.items()},
|
|
782
954
|
"confidence": _confidence_defaults(),
|
|
783
955
|
"source_scoring": _source_scoring_defaults(),
|
|
784
956
|
}
|
|
@@ -788,13 +960,18 @@ def effective_compaction(overrides: Optional[dict] = None,
|
|
|
788
960
|
warn: bool = False) -> dict:
|
|
789
961
|
"""The compaction values actually in force.
|
|
790
962
|
|
|
791
|
-
A flat {key: value}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
963
|
+
A flat {key: value}, and DELIBERATELY STILL FLAT. Where each value
|
|
964
|
+
came from is `compaction_sources()` below, beside this rather than
|
|
965
|
+
inside it: twelve call sites subscript what this returns, so
|
|
966
|
+
`{key: (value, tier)}` breaks every one of them and a parallel dict
|
|
967
|
+
breaks none -- TECHNICAL_DEBT 12's first blocker, which is a decision
|
|
968
|
+
about shape and is unchanged by having built the second half.
|
|
796
969
|
|
|
797
|
-
|
|
970
|
+
This docstring used to open "and where they came from" and return a
|
|
971
|
+
flat dict, which is audit #91's finding; then it promised nothing and
|
|
972
|
+
pointed at the register. Now it points at the function that answers.
|
|
973
|
+
|
|
974
|
+
config.yaml default -> user settings.json -> trusted project
|
|
798
975
|
settings.json -> `overrides` (a per-invocation `/compact --strength 4`,
|
|
799
976
|
which applies to that one run and persists nothing). Nearest wins,
|
|
800
977
|
which is the precedence the rest of the config system already uses.
|
|
@@ -813,21 +990,19 @@ def effective_compaction(overrides: Optional[dict] = None,
|
|
|
813
990
|
compaction constantly, and every compaction is a real model call the
|
|
814
991
|
user pays for.
|
|
815
992
|
"""
|
|
816
|
-
|
|
993
|
+
cfg = config_schema.current()
|
|
817
994
|
|
|
818
|
-
values =
|
|
819
|
-
values.update(get_settings().get("compaction") or {})
|
|
820
|
-
values.update({k: v for k, v in (overrides or {}).items() if v is not None})
|
|
995
|
+
values, _ = _compaction_merge(overrides)
|
|
821
996
|
|
|
822
997
|
strength = values["strength"]
|
|
823
|
-
if strength not in
|
|
998
|
+
if strength not in cfg.compaction_target_ratios:
|
|
824
999
|
raise ValueError(
|
|
825
1000
|
f"compaction.strength must be one of "
|
|
826
|
-
f"{sorted(
|
|
827
|
-
if values["strategy"] not in
|
|
1001
|
+
f"{sorted(cfg.compaction_target_ratios)}, got {strength!r}")
|
|
1002
|
+
if values["strategy"] not in cfg.compaction_strategies:
|
|
828
1003
|
raise ValueError(
|
|
829
1004
|
f"compaction.strategy must be one of "
|
|
830
|
-
f"{', '.join(
|
|
1005
|
+
f"{', '.join(cfg.compaction_strategies)}, "
|
|
831
1006
|
f"got {values['strategy']!r}")
|
|
832
1007
|
if values["trigger_tokens"] < 1:
|
|
833
1008
|
raise ValueError(
|
|
@@ -883,13 +1058,64 @@ def effective_compaction(overrides: Optional[dict] = None,
|
|
|
883
1058
|
return values
|
|
884
1059
|
|
|
885
1060
|
|
|
1061
|
+
def _compaction_merge(overrides: Optional[dict] = None) -> tuple[dict, dict]:
|
|
1062
|
+
"""`(values, sources)` for the seven compaction keys -- ONE ladder.
|
|
1063
|
+
|
|
1064
|
+
TECHNICAL_DEBT 12, batch 111. Both halves come out of the same three
|
|
1065
|
+
`update()` calls because the alternative is two ladders that have to
|
|
1066
|
+
agree about precedence, and a provenance report that disagrees with
|
|
1067
|
+
the value it describes is worse than no provenance: it is a confident
|
|
1068
|
+
wrong answer to "why is this number what it is".
|
|
1069
|
+
|
|
1070
|
+
`sources` names a tier for every key, always -- `"config.yaml"` when
|
|
1071
|
+
nothing outranks the file -- where `settings_sources()` records only
|
|
1072
|
+
what a settings file set. The difference is deliberate: that one
|
|
1073
|
+
answers "did anything override this", which absence can express, and
|
|
1074
|
+
this one answers "where did this number come from", which it cannot.
|
|
1075
|
+
"""
|
|
1076
|
+
values = shipped_defaults()["compaction"]
|
|
1077
|
+
sources = dict.fromkeys(values, "config.yaml")
|
|
1078
|
+
|
|
1079
|
+
tiers = settings_sources()
|
|
1080
|
+
for key, value in (get_settings().get("compaction") or {}).items():
|
|
1081
|
+
values[key] = value
|
|
1082
|
+
# The tier that WROTE it, not "settings.json": the merge upstream
|
|
1083
|
+
# kept them apart precisely so this line can tell them apart.
|
|
1084
|
+
sources[key] = tiers.get(f"compaction.{key}", "user")
|
|
1085
|
+
|
|
1086
|
+
for key, value in (overrides or {}).items():
|
|
1087
|
+
if value is not None:
|
|
1088
|
+
values[key] = value
|
|
1089
|
+
sources[key] = "override"
|
|
1090
|
+
|
|
1091
|
+
return values, sources
|
|
1092
|
+
|
|
1093
|
+
|
|
1094
|
+
def compaction_sources(overrides: Optional[dict] = None) -> dict:
|
|
1095
|
+
"""`{key: tier}` for the seven compaction keys -- where each value in
|
|
1096
|
+
force came from. TECHNICAL_DEBT 12, and D27's third implementation
|
|
1097
|
+
note, whose whole argument was that "compaction feels too aggressive"
|
|
1098
|
+
should be a one-line answer rather than a value three files away.
|
|
1099
|
+
|
|
1100
|
+
Tiers: `"config.yaml"`, `"user"`, `"project"`, `"override"` -- nearest
|
|
1101
|
+
wins, the same ladder `effective_compaction` walks, walked once by the
|
|
1102
|
+
function they share.
|
|
1103
|
+
|
|
1104
|
+
NO VALIDATION HERE, and that is not an oversight. This is a display
|
|
1105
|
+
call on a process whose configuration was validated at startup by
|
|
1106
|
+
`initialize()`; raising from a `/config` explanation would replace a
|
|
1107
|
+
sentence about a number with a traceback about a number.
|
|
1108
|
+
"""
|
|
1109
|
+
return _compaction_merge(overrides)[1]
|
|
1110
|
+
|
|
1111
|
+
|
|
886
1112
|
def _read_settings_file(path: str) -> dict:
|
|
887
1113
|
if not os.path.exists(path):
|
|
888
1114
|
return {}
|
|
889
1115
|
# utf-8-sig for the same reason as _parse_md_file: a BOM'd
|
|
890
|
-
# settings.json makes json.load raise at the first character.
|
|
891
|
-
|
|
892
|
-
|
|
1116
|
+
# settings.json makes json.load raise at the first character. And
|
|
1117
|
+
# regular files only, for the same reason too (batch 219).
|
|
1118
|
+
data = json.loads(read_regular_text(path)) # a JSONDecodeError is a ValueError
|
|
893
1119
|
_validate_settings(data, path)
|
|
894
1120
|
return data
|
|
895
1121
|
|
|
@@ -910,9 +1136,10 @@ def user_settings() -> dict:
|
|
|
910
1136
|
os.path.join(_user_config_dir(), "settings.json"))
|
|
911
1137
|
|
|
912
1138
|
|
|
913
|
-
def _load_merged_settings(project_path: str,
|
|
914
|
-
|
|
915
|
-
|
|
1139
|
+
def _load_merged_settings(project_path: str,
|
|
1140
|
+
trusted: bool) -> tuple[dict, dict]:
|
|
1141
|
+
"""`(values, sources)`. Resolution order: project (trusted) > user.
|
|
1142
|
+
Anything absent falls through to config.yaml defaults at the consumer.
|
|
916
1143
|
|
|
917
1144
|
Nested sections (`_NESTED_SETTINGS`) merge one level deeper than the
|
|
918
1145
|
rest. Every other setting is a scalar, so whole-value replacement IS
|
|
@@ -924,8 +1151,24 @@ def _load_merged_settings(project_path: str, trusted: bool) -> dict:
|
|
|
924
1151
|
Driven off _NESTED_SETTINGS rather than naming sections inline: §16
|
|
925
1152
|
added `tui` alongside `compaction`, and a second hardcoded section name
|
|
926
1153
|
here is exactly how the first one came to be missed.
|
|
1154
|
+
|
|
1155
|
+
`sources` MAPS EACH SETTING TO THE TIER THAT LAST WROTE IT, dotted for
|
|
1156
|
+
a nested key: `{"compaction.strength": "project"}`. TECHNICAL_DEBT 12,
|
|
1157
|
+
batch 111. It is built HERE, in the same pass as the merge, because
|
|
1158
|
+
this is the only moment the two tiers are still distinguishable -- the
|
|
1159
|
+
entry's own words for why provenance was missing were that it is "not
|
|
1160
|
+
omitted, it is destroyed by the merge", and a second function
|
|
1161
|
+
re-reading both files to work it out afterwards would be two
|
|
1162
|
+
traversals that must agree, which is the shape this module's own
|
|
1163
|
+
docstrings keep naming as how the first one drifts.
|
|
1164
|
+
|
|
1165
|
+
A value the user set and the project did not keeps `user`, which is
|
|
1166
|
+
the whole point of recording it per key rather than per file: one
|
|
1167
|
+
`settings.json` arriving with a cloned directory does not make every
|
|
1168
|
+
compaction value the project's.
|
|
927
1169
|
"""
|
|
928
1170
|
merged = user_settings()
|
|
1171
|
+
sources = _tier_of(merged, "user")
|
|
929
1172
|
if trusted:
|
|
930
1173
|
project = _read_settings_file(os.path.join(
|
|
931
1174
|
workspace_trust.venastine_dir(project_path), "settings.json"))
|
|
@@ -934,10 +1177,29 @@ def _load_merged_settings(project_path: str, trusted: bool) -> dict:
|
|
|
934
1177
|
for section in _NESTED_SETTINGS
|
|
935
1178
|
}
|
|
936
1179
|
merged.update(project)
|
|
1180
|
+
sources.update(_tier_of(project, "project"))
|
|
937
1181
|
for section, value in deep.items():
|
|
938
1182
|
if value:
|
|
939
1183
|
merged[section] = value
|
|
940
|
-
return merged
|
|
1184
|
+
return merged, sources
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
def _tier_of(settings: dict, tier: str) -> dict:
|
|
1188
|
+
"""`{dotted key: tier}` for everything *settings* actually sets.
|
|
1189
|
+
|
|
1190
|
+
One level deep, for `_NESTED_SETTINGS`' reason and driven off the same
|
|
1191
|
+
table: a section is the only kind of value whose keys are settings in
|
|
1192
|
+
their own right, so a section is the only thing flattened. Its own
|
|
1193
|
+
name is recorded too -- a consumer that reads a whole section, as
|
|
1194
|
+
`tui` does, wants to know who supplied it.
|
|
1195
|
+
"""
|
|
1196
|
+
flat = {}
|
|
1197
|
+
for key, value in settings.items():
|
|
1198
|
+
flat[key] = tier
|
|
1199
|
+
if key in _NESTED_SETTINGS and isinstance(value, dict):
|
|
1200
|
+
for leaf in value:
|
|
1201
|
+
flat[f"{key}.{leaf}"] = tier
|
|
1202
|
+
return flat
|
|
941
1203
|
|
|
942
1204
|
|
|
943
1205
|
_state: Optional[dict] = None
|
|
@@ -954,7 +1216,7 @@ def initialize(project_path: str) -> None:
|
|
|
954
1216
|
"content (agents, skills, settings, AGENTS.md) will not load.",
|
|
955
1217
|
project_path,
|
|
956
1218
|
)
|
|
957
|
-
settings = _load_merged_settings(project_path, trusted)
|
|
1219
|
+
settings, settings_tiers = _load_merged_settings(project_path, trusted)
|
|
958
1220
|
context = None
|
|
959
1221
|
if trusted:
|
|
960
1222
|
# §44: the project ROOT, not .venastine/. The hub is an ordinary
|
|
@@ -972,8 +1234,7 @@ def initialize(project_path: str) -> None:
|
|
|
972
1234
|
# -- including plain chat, which never reads the file. Every
|
|
973
1235
|
# other malformed content file in this module warns and skips.
|
|
974
1236
|
try:
|
|
975
|
-
|
|
976
|
-
context = f.read()
|
|
1237
|
+
context = read_regular_text(context_path)
|
|
977
1238
|
except (OSError, UnicodeDecodeError) as e:
|
|
978
1239
|
logger.warning(
|
|
979
1240
|
"Could not read %s; continuing without project "
|
|
@@ -984,6 +1245,10 @@ def initialize(project_path: str) -> None:
|
|
|
984
1245
|
"agents": _discover("agents", project_path, trusted),
|
|
985
1246
|
"skills": _discover("skills", project_path, trusted),
|
|
986
1247
|
"settings": settings,
|
|
1248
|
+
# Beside the values rather than folded into them, because twelve
|
|
1249
|
+
# call sites subscript that dict and `{key: (value, tier)}` breaks
|
|
1250
|
+
# every one (TECHNICAL_DEBT 12's first blocker, unchanged).
|
|
1251
|
+
"settings_sources": settings_tiers,
|
|
987
1252
|
"context": context,
|
|
988
1253
|
}
|
|
989
1254
|
# §32 A3. Before effective_compaction, because this one is about
|
|
@@ -1062,10 +1327,27 @@ def get_skills() -> dict:
|
|
|
1062
1327
|
|
|
1063
1328
|
def get_settings() -> dict:
|
|
1064
1329
|
if _state is None:
|
|
1065
|
-
return {} # pre-init consumers fall through to config.
|
|
1330
|
+
return {} # pre-init consumers fall through to config.yaml defaults
|
|
1066
1331
|
return dict(_state["settings"])
|
|
1067
1332
|
|
|
1068
1333
|
|
|
1334
|
+
def settings_sources() -> dict:
|
|
1335
|
+
"""`{dotted setting: "user" | "project"}` for everything a settings
|
|
1336
|
+
file actually set. TECHNICAL_DEBT 12.
|
|
1337
|
+
|
|
1338
|
+
A setting absent here was not set by either file, which means the
|
|
1339
|
+
value in force came from `config.yaml` -- so the caller reads the
|
|
1340
|
+
absence rather than needing a third tier name in the mapping.
|
|
1341
|
+
|
|
1342
|
+
Empty pre-init for `get_settings()`'s reason, and the consequence is
|
|
1343
|
+
the same one: a caller that runs before `initialize()` is told nothing
|
|
1344
|
+
outranks the file, which is true of that moment.
|
|
1345
|
+
"""
|
|
1346
|
+
if _state is None:
|
|
1347
|
+
return {}
|
|
1348
|
+
return dict(_state["settings_sources"])
|
|
1349
|
+
|
|
1350
|
+
|
|
1069
1351
|
def spend_cap() -> Optional[int]:
|
|
1070
1352
|
"""The configured per-run spend ceiling (#4), or None for uncapped.
|
|
1071
1353
|
|
|
@@ -1168,16 +1450,29 @@ def skill_catalog_text(active: Optional[list] = None) -> str:
|
|
|
1168
1450
|
return "\n".join(lines)
|
|
1169
1451
|
|
|
1170
1452
|
|
|
1171
|
-
def _catalog_entries(root: str, files: list) -> list:
|
|
1172
|
-
"""(kind, name, description) for every agent/skill in the
|
|
1453
|
+
def _catalog_entries(root: str, files: list, shadows=None) -> list:
|
|
1454
|
+
"""(kind, name, description, reach) for every agent/skill in the
|
|
1455
|
+
listing; `reach` is the lines saying where that description goes.
|
|
1173
1456
|
|
|
1174
1457
|
ROADMAP_v2 §32 A6, #131. The trust prompt's stated criterion is
|
|
1175
1458
|
written in describe_project_content below -- the files shown
|
|
1176
1459
|
verbatim are "the ones whose contents change what runs". An
|
|
1177
|
-
agent's and a skill's `description` meets it exactly: one `y`
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1460
|
+
agent's and a skill's `description` meets it exactly: one `y` lets
|
|
1461
|
+
it into system prompts in this project, with no tool call and no
|
|
1462
|
+
further consent, and the reason they were left out was that nobody
|
|
1463
|
+
had noticed they qualify.
|
|
1464
|
+
|
|
1465
|
+
WHERE EACH ONE GOES, SINCE BATCH 215 (#259, #260, register items
|
|
1466
|
+
112 and 113, the owner's wording). The section used
|
|
1467
|
+
to say every description entered EVERY system prompt. A skill's is
|
|
1468
|
+
listed wherever load_skill is offered; an agent's only if it is
|
|
1469
|
+
spawnable, and the project tier's are not unless they say so (§32
|
|
1470
|
+
A3/A4); and a definition whose name a harness or user one already
|
|
1471
|
+
has never loads at all, D29's precedence being first-wins. Each is
|
|
1472
|
+
still LISTED -- the grant covers its bytes, and renaming the other
|
|
1473
|
+
makes it live with no new prompt -- but no longer described as
|
|
1474
|
+
reaching further than it does. `shadows` is `{kind: {name: tier}}`
|
|
1475
|
+
for the tiers above the project.
|
|
1181
1476
|
|
|
1182
1477
|
PARSED THROUGH _parse_md_file, so what is shown is the NORMALISED
|
|
1183
1478
|
text -- the same value A5 will put in the prompt, not the raw
|
|
@@ -1192,6 +1487,7 @@ def _catalog_entries(root: str, files: list) -> list:
|
|
|
1192
1487
|
'this file is here and I cannot tell you what it says' is a fact
|
|
1193
1488
|
the person answering the prompt needs.
|
|
1194
1489
|
"""
|
|
1490
|
+
shadows = shadows or {}
|
|
1195
1491
|
out = []
|
|
1196
1492
|
for rel in files:
|
|
1197
1493
|
# §44: the listing is PROJECT-relative now, so the .venastine/
|
|
@@ -1211,27 +1507,139 @@ def _catalog_entries(root: str, files: list) -> list:
|
|
|
1211
1507
|
"project")
|
|
1212
1508
|
if defn is None:
|
|
1213
1509
|
out.append((kind, "/".join(parts),
|
|
1214
|
-
"(could not be read -- see the log)"))
|
|
1215
|
-
|
|
1216
|
-
|
|
1510
|
+
"(could not be read -- see the log)", []))
|
|
1511
|
+
continue
|
|
1512
|
+
out.append((kind, defn.name, defn.description,
|
|
1513
|
+
_reach(kind, defn, shadows.get(kind, {}))))
|
|
1217
1514
|
return out
|
|
1218
1515
|
|
|
1219
1516
|
|
|
1220
|
-
|
|
1221
|
-
|
|
1517
|
+
def _reach(kind: str, defn, shadowed_by: dict) -> list:
|
|
1518
|
+
"""Where a project definition's description goes, as the lines the
|
|
1519
|
+
trust prompt prints under it (#259, #260)."""
|
|
1520
|
+
tier = shadowed_by.get(defn.name)
|
|
1521
|
+
if tier is not None:
|
|
1522
|
+
owner = ("the harness's own" if tier == "harness"
|
|
1523
|
+
else "your own (user configuration)")
|
|
1524
|
+
return [f'shadowed by {owner} "{defn.name}", which is what loads;',
|
|
1525
|
+
"this file is used only if that one goes away"]
|
|
1526
|
+
if kind == "skills":
|
|
1527
|
+
return ["listed wherever load_skill is offered"]
|
|
1528
|
+
if defn.spawnable:
|
|
1529
|
+
return ["spawnable: listed wherever spawn_subagent is offered"]
|
|
1530
|
+
return ["not spawnable: in no system prompt; /agent can still pick it"]
|
|
1531
|
+
|
|
1532
|
+
|
|
1533
|
+
def _shadowing_names(project_path: str) -> dict:
|
|
1534
|
+
"""`{kind: {name: tier}}` for the tiers that win over the project's,
|
|
1535
|
+
harness first, in `_discover`'s own order and with its own parser, so
|
|
1536
|
+
the trust prompt and the loader cannot disagree about which loads."""
|
|
1537
|
+
out: dict = {}
|
|
1538
|
+
for kind in ("agents", "skills"):
|
|
1539
|
+
names: dict = {}
|
|
1540
|
+
for tier, directory in _tier_dirs(kind, project_path, False):
|
|
1541
|
+
if not os.path.isdir(directory):
|
|
1542
|
+
continue
|
|
1543
|
+
for path, category in _md_files(directory,
|
|
1544
|
+
recursive=(kind == "skills")):
|
|
1545
|
+
defn = _parse_md_file(path, kind, tier, category)
|
|
1546
|
+
if defn is not None:
|
|
1547
|
+
names.setdefault(defn.name, tier)
|
|
1548
|
+
out[kind] = names
|
|
1549
|
+
return out
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
#: How much of any ONE section of the trust prompt is printed. Enough to
|
|
1553
|
+
#: recognise what a file is for, short enough that the prompt stays
|
|
1222
1554
|
#: readable -- the whole thing is what a grant covers, not what it prints.
|
|
1223
|
-
|
|
1555
|
+
_SECTION_LINES = 60
|
|
1556
|
+
_SECTION_CHARS = 6000
|
|
1557
|
+
|
|
1558
|
+
|
|
1559
|
+
def _bounded(source: list, prefix: str, what: str) -> list:
|
|
1560
|
+
"""`source`'s lines, prefixed and cut to BOTH bounds, with a marker
|
|
1561
|
+
naming what was withheld.
|
|
1562
|
+
|
|
1563
|
+
THE CONSENT PROMPT IS THE ONE PLACE A PROJECT'S CONTENT IS SHOWN TO
|
|
1564
|
+
SOMEONE WHO HAS NOT TRUSTED IT YET (D17), so how long it is must not
|
|
1565
|
+
be the project's choice. Every section goes through here (A54) --
|
|
1566
|
+
the file listing, the hub, the two JSON files and the catalog --
|
|
1567
|
+
because capping some of them leaves the prompt exactly as floodable
|
|
1568
|
+
and the cap stops being worth having.
|
|
1569
|
+
|
|
1570
|
+
TWO BOUNDS, NOT ONE, AND THE PAIR IS THE POINT. §44 gave the hub a
|
|
1571
|
+
LINE bound alone, and measured against it: a 2 MB AGENTS.md written
|
|
1572
|
+
as one line printed all 2 MB in four lines, and twenty 100 KB lines
|
|
1573
|
+
printed 2 MB from inside the cap. A char bound alone fails the other
|
|
1574
|
+
way -- 30,000 short lines are 2.4 MB of prompt. The two JSON files
|
|
1575
|
+
had neither bound: 2 x 2.2 MB rendered as 4.5 MB in 30 lines, with
|
|
1576
|
+
the `mcp.json` command the section exists to show sitting at
|
|
1577
|
+
99.9994% of the way in.
|
|
1578
|
+
|
|
1579
|
+
THE NUMBERS ARE MEASURED AGAINST THE LARGEST LEGITIMATE SHAPES
|
|
1580
|
+
rather than picked. A five-server pretty-printed `mcp.json` is 54
|
|
1581
|
+
lines and 923 characters; a realistic `settings.json` is 14 and 264;
|
|
1582
|
+
this project's own AGENTS.md is 4,033 characters in its first 60
|
|
1583
|
+
lines. All three render whole, which is what keeps the marker
|
|
1584
|
+
meaningful on the files where it does appear.
|
|
1585
|
+
|
|
1586
|
+
THE MARKER IS NOT A COURTESY. A cut nobody is told about turns a
|
|
1587
|
+
bounded prompt into one that misrepresents what it covers, and the
|
|
1588
|
+
grant is over the whole file either way -- which is why the sentence
|
|
1589
|
+
says so rather than stopping at an ellipsis.
|
|
1590
|
+
"""
|
|
1591
|
+
shown: list = []
|
|
1592
|
+
used = 0
|
|
1593
|
+
hidden_chars = 0
|
|
1594
|
+
for line in source:
|
|
1595
|
+
if len(shown) >= _SECTION_LINES or used >= _SECTION_CHARS:
|
|
1596
|
+
hidden_chars += len(line)
|
|
1597
|
+
continue
|
|
1598
|
+
room = _SECTION_CHARS - used
|
|
1599
|
+
if len(line) > room:
|
|
1600
|
+
# CUT WITHIN THE LINE rather than dropping it whole. A file
|
|
1601
|
+
# flooded on one enormous line has exactly one line, and it
|
|
1602
|
+
# is the line the section exists to show.
|
|
1603
|
+
shown.append(line[:room] + "…")
|
|
1604
|
+
used += room
|
|
1605
|
+
hidden_chars += len(line) - room
|
|
1606
|
+
continue
|
|
1607
|
+
shown.append(line)
|
|
1608
|
+
used += len(line)
|
|
1609
|
+
out = [prefix + line for line in shown]
|
|
1610
|
+
hidden_lines = len(source) - len(shown)
|
|
1611
|
+
if hidden_lines or hidden_chars:
|
|
1612
|
+
# Always plural. The grammar is a blemish; a marker whose wording
|
|
1613
|
+
# depends on the count is one a test can match by luck.
|
|
1614
|
+
out.append(
|
|
1615
|
+
f"{prefix}… {hidden_lines} more lines and {hidden_chars} more "
|
|
1616
|
+
f"characters of {what} are not shown here. Trust covers the "
|
|
1617
|
+
f"whole file, not the part printed.")
|
|
1618
|
+
return out
|
|
1224
1619
|
|
|
1225
1620
|
|
|
1226
1621
|
def describe_project_content(project_path: str) -> str:
|
|
1227
1622
|
"""Human-readable summary shown in the trust prompt, so approving
|
|
1228
1623
|
trust is an informed decision -- a project's settings can choose the
|
|
1229
|
-
provider and multiply pipeline cost
|
|
1230
|
-
|
|
1624
|
+
provider and multiply pipeline cost by turning on ensemble_mode over
|
|
1625
|
+
config.yaml's roster (#213: ensemble_n is ignored), and an agent's
|
|
1626
|
+
or a skill's description can reach the system prompt (#131) --
|
|
1627
|
+
where, each entry says (#259, #260).
|
|
1628
|
+
|
|
1629
|
+
EVERY SECTION IS BOUNDED, through `_bounded` above (A54, batch 155).
|
|
1630
|
+
Two of the four used to be pasted whole and the hub was bounded on
|
|
1631
|
+
one axis of two, which let a cloned project decide how long its own
|
|
1632
|
+
consent screen was."""
|
|
1231
1633
|
root = workspace_trust.venastine_dir(project_path)
|
|
1232
1634
|
files = workspace_trust.content_files(project_path)
|
|
1233
1635
|
lines = [f"Project content ({os.path.realpath(project_path)}):"]
|
|
1234
|
-
|
|
1636
|
+
# THE LISTING ITSELF IS BOUNDED TOO. `content_files()` is unchanged
|
|
1637
|
+
# and still returns every covered path -- the hash and
|
|
1638
|
+
# workspace_trust's "the loader must read no file the trust listing
|
|
1639
|
+
# omits" invariant are about that function, not about this rendering.
|
|
1640
|
+
# What is bounded is what the PROMPT prints, and 20,000 padding files
|
|
1641
|
+
# under .venastine/ were 20,001 lines of it.
|
|
1642
|
+
lines += _bounded(files, " - ", "the file listing")
|
|
1235
1643
|
|
|
1236
1644
|
# §44. The hub is shown VERBATIM, and it is the strongest instance of
|
|
1237
1645
|
# this function's own stated criterion -- "the ones whose contents
|
|
@@ -1244,26 +1652,27 @@ def describe_project_content(project_path: str) -> str:
|
|
|
1244
1652
|
hub = os.path.join(os.path.realpath(project_path),
|
|
1245
1653
|
workspace_trust.PROJECT_CONTEXT_FILENAME)
|
|
1246
1654
|
if os.path.exists(hub):
|
|
1655
|
+
# Every read in this function is of content nobody has consented
|
|
1656
|
+
# to yet, so each is regular-files-only (batch 219, #214): a hub
|
|
1657
|
+
# linked to /dev/zero would otherwise be read until memory ran out.
|
|
1247
1658
|
try:
|
|
1248
|
-
|
|
1249
|
-
body = f.read()
|
|
1659
|
+
body = read_regular_text(hub)
|
|
1250
1660
|
except (OSError, UnicodeDecodeError) as e:
|
|
1251
1661
|
lines.append(
|
|
1252
1662
|
f"{workspace_trust.PROJECT_CONTEXT_FILENAME}: could not be "
|
|
1253
1663
|
f"read ({e})")
|
|
1254
1664
|
else:
|
|
1255
|
-
shown = body.splitlines()
|
|
1256
1665
|
lines.append(
|
|
1257
1666
|
f"{workspace_trust.PROJECT_CONTEXT_FILENAME} would enter "
|
|
1258
1667
|
f"every opted-in agent's system prompt; it begins:")
|
|
1259
|
-
lines +=
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
f" | … {len(shown) - _HUB_PREVIEW_LINES} more lines")
|
|
1668
|
+
lines += _bounded(
|
|
1669
|
+
body.splitlines(), " | ",
|
|
1670
|
+
workspace_trust.PROJECT_CONTEXT_FILENAME)
|
|
1263
1671
|
|
|
1264
1672
|
# settings.json and mcp.json are shown VERBATIM, the rest by name.
|
|
1265
1673
|
# These two are the ones whose contents change what runs: settings can
|
|
1266
|
-
# pick the provider and multiply pipeline cost
|
|
1674
|
+
# pick the provider and multiply pipeline cost by turning on
|
|
1675
|
+
# ensemble_mode (ensemble_n is ignored; the roster is config.yaml's), and
|
|
1267
1676
|
# mcp.json names a local command to execute. Approving trust without
|
|
1268
1677
|
# seeing that command is not an informed decision, which is the whole
|
|
1269
1678
|
# reason §17 moved project MCP config under .venastine/ instead of
|
|
@@ -1274,8 +1683,7 @@ def describe_project_content(project_path: str) -> str:
|
|
|
1274
1683
|
if not os.path.exists(path):
|
|
1275
1684
|
continue
|
|
1276
1685
|
try:
|
|
1277
|
-
|
|
1278
|
-
body = f.read()
|
|
1686
|
+
body = read_regular_text(path)
|
|
1279
1687
|
except (OSError, UnicodeDecodeError) as e:
|
|
1280
1688
|
# This function runs ONLY for untrusted projects, i.e. content
|
|
1281
1689
|
# that is adversarial by definition. UnicodeDecodeError is a
|
|
@@ -1286,18 +1694,25 @@ def describe_project_content(project_path: str) -> str:
|
|
|
1286
1694
|
lines.append(f"{fname}: could not be read ({e})")
|
|
1287
1695
|
continue
|
|
1288
1696
|
lines.append(label)
|
|
1289
|
-
lines +=
|
|
1697
|
+
lines += _bounded(body.splitlines(), " | ", fname)
|
|
1290
1698
|
|
|
1291
1699
|
# §32 A6. Shown AFTER the two config files rather than beside the
|
|
1292
1700
|
# file list, because the list answers "what is here" and this
|
|
1293
1701
|
# answers "what would it say to the model" -- the same order the
|
|
1294
1702
|
# two questions are asked in.
|
|
1295
|
-
entries = _catalog_entries(root, files
|
|
1703
|
+
entries = _catalog_entries(root, files,
|
|
1704
|
+
_shadowing_names(project_path))
|
|
1296
1705
|
if entries:
|
|
1297
|
-
lines.append("
|
|
1298
|
-
"
|
|
1299
|
-
|
|
1300
|
-
|
|
1706
|
+
lines.append("what each project agent and skill would tell the "
|
|
1707
|
+
"model:")
|
|
1708
|
+
# A5 bounds each description at `max_catalog_text_chars` and
|
|
1709
|
+
# nothing bounded the NUMBER of them: 3,000 project agents were
|
|
1710
|
+
# 1 MB of prompt in 6,002 lines, every entry individually legal.
|
|
1711
|
+
rows = []
|
|
1712
|
+
for kind, name, description, reach in entries:
|
|
1713
|
+
rows.append(f"{kind[:-1]} {name}: {description}")
|
|
1714
|
+
rows += [f" {line}" for line in reach]
|
|
1715
|
+
lines += _bounded(rows, " | ", "the agent and skill descriptions")
|
|
1301
1716
|
return "\n".join(lines)
|
|
1302
1717
|
|
|
1303
1718
|
|
|
@@ -1326,11 +1741,11 @@ def describe_project_content(project_path: str) -> str:
|
|
|
1326
1741
|
|
|
1327
1742
|
# key -> (module attribute it defaults from, validator)
|
|
1328
1743
|
#
|
|
1329
|
-
# The defaults live BESIDE THE FORMULA rather than in config.
|
|
1744
|
+
# The defaults live BESIDE THE FORMULA rather than in config.yaml: the
|
|
1330
1745
|
# tunable-weights block at the top of confidence_scoring.py documents what
|
|
1331
1746
|
# each number does and why it is that number, and a second copy here is a
|
|
1332
1747
|
# second thing to keep in step. Imported lazily inside the resolver, the
|
|
1333
|
-
# same shape effective_compaction uses for `
|
|
1748
|
+
# same shape effective_compaction uses for `config_schema`.
|
|
1334
1749
|
_UNIT = ("a number between 0 and 1", lambda v: isinstance(v, NUMBER_TYPES)
|
|
1335
1750
|
and not isinstance(v, bool) and 0.0 <= v <= 1.0)
|
|
1336
1751
|
_POSITIVE_INT = ("a positive whole number",
|
|
@@ -1342,7 +1757,6 @@ _CONFIDENCE_KNOBS = {
|
|
|
1342
1757
|
"grounding_weight_factor": _UNIT,
|
|
1343
1758
|
"critic_weight_factor": _UNIT,
|
|
1344
1759
|
"assumption_flag_penalty": _UNIT,
|
|
1345
|
-
"disagreement_penalty_factor": _UNIT,
|
|
1346
1760
|
"non_factual_score_cap": _UNIT,
|
|
1347
1761
|
"source_quality_floor": _UNIT,
|
|
1348
1762
|
"authority_full_credit": _UNIT,
|
|
@@ -1372,7 +1786,6 @@ def _confidence_defaults() -> dict:
|
|
|
1372
1786
|
"grounding_weight_factor": cs.GROUNDING_WEIGHT_FACTOR,
|
|
1373
1787
|
"critic_weight_factor": cs.CRITIC_WEIGHT_FACTOR,
|
|
1374
1788
|
"assumption_flag_penalty": cs.ASSUMPTION_FLAG_PENALTY,
|
|
1375
|
-
"disagreement_penalty_factor": cs.DISAGREEMENT_PENALTY_FACTOR,
|
|
1376
1789
|
"non_factual_score_cap": cs.NON_FACTUAL_SCORE_CAP,
|
|
1377
1790
|
"source_quality_floor": cs.SOURCE_QUALITY_FLOOR,
|
|
1378
1791
|
"authority_full_credit": cs.AUTHORITY_FULL_CREDIT,
|
|
@@ -1382,23 +1795,23 @@ def _confidence_defaults() -> dict:
|
|
|
1382
1795
|
|
|
1383
1796
|
|
|
1384
1797
|
def _source_scoring_defaults() -> dict:
|
|
1385
|
-
import config
|
|
1386
1798
|
from core.reasoning import source_scoring as ss
|
|
1387
1799
|
|
|
1800
|
+
cfg = config_schema.current()
|
|
1388
1801
|
return {
|
|
1389
1802
|
"similarity_floor": None, # None means "use the per-model table"
|
|
1390
1803
|
"similarity_ceiling": None,
|
|
1391
|
-
"authority_adjustment_cap":
|
|
1804
|
+
"authority_adjustment_cap": cfg.authority_adjustment_cap,
|
|
1392
1805
|
"window_chars": ss.WINDOW_CHARS,
|
|
1393
1806
|
"max_windows": ss.MAX_WINDOWS,
|
|
1394
1807
|
"claim_min_chars": ss.CLAIM_MIN_CHARS,
|
|
1395
1808
|
"top_k": ss.TOP_K,
|
|
1396
|
-
"venue_weight":
|
|
1397
|
-
"citation_weight":
|
|
1398
|
-
"author_weight":
|
|
1399
|
-
"h_saturation":
|
|
1400
|
-
"min_cohort_size":
|
|
1401
|
-
"min_citation_age_days":
|
|
1809
|
+
"venue_weight": cfg.scholar_venue_weight,
|
|
1810
|
+
"citation_weight": cfg.scholar_citation_weight,
|
|
1811
|
+
"author_weight": cfg.scholar_author_weight,
|
|
1812
|
+
"h_saturation": cfg.scholar_h_saturation,
|
|
1813
|
+
"min_cohort_size": cfg.scholar_min_cohort_size,
|
|
1814
|
+
"min_citation_age_days": cfg.scholar_min_citation_age_days,
|
|
1402
1815
|
"domain_overrides": {},
|
|
1403
1816
|
}
|
|
1404
1817
|
|
|
@@ -1512,6 +1925,12 @@ def effective_confidence(warn: bool = False) -> dict:
|
|
|
1512
1925
|
"""
|
|
1513
1926
|
values = _confidence_defaults()
|
|
1514
1927
|
supplied = get_settings().get("confidence") or {}
|
|
1928
|
+
if warn and "disagreement_penalty_factor" in supplied:
|
|
1929
|
+
logger.warning(
|
|
1930
|
+
"Ignoring confidence.disagreement_penalty_factor: a claim most "
|
|
1931
|
+
"ensemble candidates did not assert is sent to Pass 6a/6b to be "
|
|
1932
|
+
"checked now, and nothing is subtracted for it (ROADMAP_v3 §90). "
|
|
1933
|
+
"Remove the key from settings.json.")
|
|
1515
1934
|
_apply_scalar_knobs(values, supplied, _CONFIDENCE_KNOBS, "confidence", warn)
|
|
1516
1935
|
_apply_grounding_weights(values, supplied.get("grounding_weights"), warn)
|
|
1517
1936
|
_apply_tier_thresholds(values, supplied.get("tier_thresholds"), warn)
|