feat: complete evidence restructuring worktree
This commit is contained in:
+104
-100
@@ -1,10 +1,10 @@
|
||||
# Configurazione locale dei modelli Pi
|
||||
# Local Pi model configuration
|
||||
|
||||
Pi, l'agente che orchestra il workflow NL→SQL, risolve i modelli integrati e i provider
|
||||
OpenAI-compatible dichiarati nel catalogo locale. ThothII applica una regola più stretta di Pi:
|
||||
un provider o un modello custom non può essere registrato da codice in `harness/.pi/extensions/`.
|
||||
Endpoint, protocollo, compatibilità e identificatori dei modelli appartengono esclusivamente ai file
|
||||
locali `deploy/pi/models.json` e `deploy/pi/settings.json`.
|
||||
Pi orchestrates the NL-to-SQL workflow and resolves built-in models and OpenAI-compatible providers
|
||||
declared in the local catalog. ThothII applies a stricter rule than Pi: code in
|
||||
`harness/.pi/extensions/` cannot register a provider or custom model. Endpoints, protocols,
|
||||
compatibility settings, and model identifiers belong exclusively in the local files
|
||||
`deploy/pi/models.json` and `deploy/pi/settings.json`.
|
||||
|
||||
> **ThothII operator note:** ThothII runs Pi only in Docker Compose. Paths under
|
||||
> `~/.pi/agent/` in this document describe Pi's container-side behavior. Operators edit
|
||||
@@ -12,62 +12,66 @@ locali `deploy/pi/models.json` e `deploy/pi/settings.json`.
|
||||
> the protected host credential file selected by `PI_AUTH_FILE`; they do not edit files inside
|
||||
> the running container.
|
||||
|
||||
## Credenziali nel backend container
|
||||
## Credentials in the backend container
|
||||
|
||||
In produzione configurare una sola sorgente generica: il bundle `THT_SECRETS_FILE` con la voce
|
||||
`THT_MODEL_API_KEY` (predefinito della distribuzione unificata), oppure
|
||||
`THT_MODEL_API_KEY_FILE` come secret file assoluto. Non mettere il valore della chiave in `.env`.
|
||||
`PiProcessManager` rilegge e valida la sorgente per ogni processo, normalizza il provider
|
||||
selezionato e passa al solo child Pi la variabile nativa appropriata
|
||||
(`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, `ZAI_API_KEY`, ecc.). Il percorso generico,
|
||||
le chiavi di provider non selezionati e il vecchio `PI_PROVIDER_API_KEY` vengono rimossi dall'ambiente
|
||||
del child. Per un provider custom, il backend deriva il nome della variabile dal campo dichiarativo
|
||||
`apiKey` di `models.json`; un valore letterale indica che il catalogo è autosufficiente. Non esistono
|
||||
eccezioni per nomi di provider compilate nel codice. Un secret mancante o non sicuro fallisce prima
|
||||
dello spawn con errore sanitizzato.
|
||||
In production, configure one generic source: the `THT_SECRETS_FILE` bundle with the
|
||||
`THT_MODEL_API_KEY` entry, which is the default for the unified distribution, or
|
||||
`THT_MODEL_API_KEY_FILE` as an absolute secret-file path. Do not put the key value in `.env`.
|
||||
For each process, `PiProcessManager` rereads and validates the source, normalizes the selected
|
||||
provider, and passes only the appropriate native variable to the Pi child
|
||||
(`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, `ZAI_API_KEY`, and so on). It removes the
|
||||
generic path, keys for unselected providers, and the old `PI_PROVIDER_API_KEY` from the child
|
||||
environment. For a custom provider, the backend derives the variable name from the declarative
|
||||
`apiKey` field in `models.json`; a literal value means the catalog is self-contained. Provider-name
|
||||
exceptions are not compiled into the code. A missing or insecure secret fails before spawn with a
|
||||
sanitized error.
|
||||
|
||||
La sorgente generica supporta soltanto provider con una singola chiave: `ant-ling`, `anthropic`,
|
||||
`cerebras`, `deepseek`, `fireworks`, `github-copilot`, `google` (anche tramite alias `gemini`),
|
||||
`google-vertex` in modalità API key, `groq`, `huggingface`, `kimi-coding`, `minimax`, `minimax-cn`,
|
||||
The generic source supports only single-key providers: `ant-ling`, `anthropic`,
|
||||
`cerebras`, `deepseek`, `fireworks`, `github-copilot`, `google` (including the `gemini` alias),
|
||||
`google-vertex` in API-key mode, `groq`, `huggingface`, `kimi-coding`, `minimax`, `minimax-cn`,
|
||||
`mistral`, `moonshotai`, `moonshotai-cn`, `nvidia`, `openai`, `opencode`, `opencode-go`,
|
||||
`openrouter`, `together`, `vercel-ai-gateway`, `xai`, i quattro provider `xiaomi*`, `zai` e
|
||||
`openrouter`, `together`, `vercel-ai-gateway`, `xai`, the four `xiaomi*` providers, `zai`, and
|
||||
`zai-coding-cn`.
|
||||
|
||||
I provider composti `amazon-bedrock`, `azure-openai-responses`, `cloudflare-workers-ai` e
|
||||
`cloudflare-ai-gateway` non sono rappresentabili da un solo file. La selezione fallisce prima
|
||||
dello spawn (anche durante l'elenco modelli); tutte le credenziali ambientali AWS, Azure e
|
||||
Cloudflare restano comunque rimosse. Servirà una futura configurazione dedicata per provider per
|
||||
supportare questi bundle senza ambiguità.
|
||||
The composite providers `amazon-bedrock`, `azure-openai-responses`, `cloudflare-workers-ai`, and
|
||||
`cloudflare-ai-gateway` cannot be represented by one file. Selection fails before spawn, including
|
||||
when models are listed. AWS, Azure, and Cloudflare environment credentials are still removed. A
|
||||
future provider-specific configuration will be needed to support these bundles unambiguously.
|
||||
|
||||
## Le fonti di un modello
|
||||
## Model sources
|
||||
|
||||
### 1. Built-in (compilato dentro Pi)
|
||||
### 1. Built-in (compiled into Pi)
|
||||
|
||||
Pi viene distribuito con un elenco di modelli già noti (`models.generated.js` dentro il pacchetto `@earendil-works/pi-ai`): Anthropic, OpenAI, Google, e anche provider di terze parti con API pubblica ben nota come DeepSeek. Per questi **non serve alcuna configurazione**: bastano le credenziali (env var o `pi auth`).
|
||||
Pi ships with a list of known models (`models.generated.js` in the `@earendil-works/pi-ai` package):
|
||||
Anthropic, OpenAI, Google, and third-party providers with well-known public APIs such as DeepSeek.
|
||||
These require **no configuration** beyond credentials, provided through an environment variable or
|
||||
`pi auth`.
|
||||
|
||||
`deepseek/deepseek-v4-pro` è così: è nella build di Pi perché `api.deepseek.com` è un'API pubblica documentata, non un endpoint interno.
|
||||
`deepseek/deepseek-v4-pro` is one of these models. It is included in Pi because `api.deepseek.com`
|
||||
is a documented public API, not an internal endpoint.
|
||||
|
||||
### 2. `models.json` a livello utente (`~/.pi/agent/models.json`)
|
||||
### 2. User-level `models.json` (`~/.pi/agent/models.json`)
|
||||
|
||||
Per un endpoint **OpenAI-compatible** che non è tra i built-in — ma che non richiede nessuna logica di trasporto speciale — basta *dichiararlo*: baseUrl, apiKey, lista modelli. Questo file esiste **solo a livello utente**: non c'è un equivalente project-level (un `./.pi/models.json` non viene letto).
|
||||
For an **OpenAI-compatible** endpoint that is not built in but needs no special transport logic,
|
||||
declare it with its baseUrl, apiKey, and model list. This file exists **only at user level**; there is
|
||||
no project-level equivalent, and `./.pi/models.json` is not read.
|
||||
|
||||
Nelle installazioni gestite da ThothII il file deve essere interamente dichiarativo. ThothII
|
||||
rifiuta ricorsivamente qualsiasi valore JSON che inizi con `!`, anche dentro `headers`, `models`,
|
||||
`modelOverrides`, `compat`, array o campi non ancora conosciuti. Pi 0.80.3 tratterebbe quel prefisso
|
||||
come un comando shell al momento della richiesta; questa forma non è ammessa dall'elenco gestito
|
||||
dei modelli. L'errore restituito è fisso e non include comando, percorso o
|
||||
secret.
|
||||
In ThothII-managed installations, the file must be entirely declarative. ThothII recursively
|
||||
rejects any JSON value that starts with `!`, including values inside `headers`, `models`,
|
||||
`modelOverrides`, `compat`, arrays, or fields it does not yet know. Pi 0.80.3 would treat that
|
||||
prefix as a shell command when making a request, so managed model catalogs do not allow it. The
|
||||
returned error is fixed and contains no command, path, or secret.
|
||||
|
||||
Per i secret usare un riferimento ambiente come `"$ZAI_API_KEY"` o `"${ZAI_API_KEY}"`. Il backend
|
||||
può popolare la variabile nativa del solo provider selezionato leggendo
|
||||
`THT_MODEL_API_KEY_FILE`, oppure dal bundle `THT_SECRETS_FILE` (`THT_MODEL_API_KEY`); in alternativa
|
||||
le credenziali possono arrivare dal file protetto montato con `PI_AUTH_FILE`, omettendo `apiKey` da
|
||||
`models.json`. Non esiste una sintassi di riferimento diretto a un secret file dentro
|
||||
`models.json`: con le sorgenti `THT_MODEL_*` il file viene letto da ThothII e trasformato nella
|
||||
variabile ambiente del child Pi; `PI_AUTH_FILE` viene invece montato come archivio credenziali Pi
|
||||
protetto. Per un punto esclamativo letterale iniziale, la sintassi Pi dichiarativa è `$!`, non `!`.
|
||||
For secrets, use an environment reference such as `"$ZAI_API_KEY"` or `"${ZAI_API_KEY}"`. The
|
||||
backend can populate the native variable for the selected provider by reading
|
||||
`THT_MODEL_API_KEY_FILE`, or from the `THT_SECRETS_FILE` bundle (`THT_MODEL_API_KEY`). Credentials
|
||||
can also come from the protected file mounted through `PI_AUTH_FILE`, with `apiKey` omitted from
|
||||
`models.json`. There is no direct secret-file reference syntax in `models.json`. With `THT_MODEL_*`
|
||||
sources, ThothII reads the file and turns it into the Pi child's environment variable; `PI_AUTH_FILE`
|
||||
is mounted instead as a protected Pi credential store. For a literal leading exclamation mark, Pi's
|
||||
declarative syntax is `$!`, not `!`.
|
||||
|
||||
Esempio reale in uso su questa macchina — GLM (provider `zai`):
|
||||
Real example in use on this machine: GLM (provider `zai`):
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -90,113 +94,113 @@ Esempio reale in uso su questa macchina — GLM (provider `zai`):
|
||||
}
|
||||
```
|
||||
|
||||
Essendo a livello utente, GLM è visibile da **qualsiasi progetto**.
|
||||
Because it is user-level, GLM is visible to **every project**.
|
||||
|
||||
### Provider da estensione: non ammessi in ThothII
|
||||
### Extension providers: not allowed in ThothII
|
||||
|
||||
Pi supporta tecnicamente provider registrati da estensioni JavaScript, ma ThothII non usa questa
|
||||
possibilità. Le estensioni di progetto sono riservate al workflow e ai gate; non devono contenere
|
||||
`registerProvider(...)`. Un endpoint che non può essere descritto dal catalogo OpenAI-compatible
|
||||
non è un provider supportato da questa installazione finché il contratto dichiarativo non viene
|
||||
esteso in modo generico.
|
||||
Pi technically supports providers registered by JavaScript extensions, but ThothII does not use
|
||||
that capability. Project extensions are reserved for the workflow and gates; they must not contain
|
||||
`registerProvider(...)`. An endpoint that cannot be described by the OpenAI-compatible catalog is
|
||||
not supported by this installation until the declarative contract is extended generically.
|
||||
|
||||
## Tabella riassuntiva (stato attuale di questa macchina)
|
||||
## Summary table (current machine state)
|
||||
|
||||
| Modello | Livello | Perché | Visibilità |
|
||||
| Model | Level | Why | Visibility |
|
||||
|---|---|---|---|
|
||||
| `deepseek/deepseek-v4-pro` | Built-in Pi | API pubblica nota, già nella build | Tutti i progetti |
|
||||
| `zai/glm-5.3` | `deploy/pi/models.json` | Endpoint OpenAI-compatible custom | Installazione ThothII |
|
||||
| `local-qwen/qwen3.6-35b-a3b` | `deploy/pi/models.json` | Endpoint OpenAI-compatible configurato localmente | Installazione ThothII |
|
||||
| `deepseek/deepseek-v4-pro` | Built-in Pi | Known public API, already in the build | All projects |
|
||||
| `zai/glm-5.3` | `deploy/pi/models.json` | Custom OpenAI-compatible endpoint | ThothII installation |
|
||||
| `local-qwen/qwen3.6-35b-a3b` | `deploy/pi/models.json` | Locally configured OpenAI-compatible endpoint | ThothII installation |
|
||||
|
||||
## Come scegliere il livello giusto per un nuovo modello
|
||||
## Choosing the right level for a new model
|
||||
|
||||
1. **L'endpoint è un'API pubblica già nota a Pi?** → abilita l'identificatore esatto in `deploy/pi/settings.json`.
|
||||
2. **È OpenAI-compatible ma non built-in?** → dichiaralo in `deploy/pi/models.json`, poi abilitalo in `deploy/pi/settings.json`.
|
||||
3. **Richiede codice di trasporto specifico del provider?** → non aggiungere un'estensione specifica; il provider non è supportato finché manca una capacità dichiarativa generica.
|
||||
1. **Is the endpoint a public API already known to Pi?** Enable the exact identifier in `deploy/pi/settings.json`.
|
||||
2. **Is it OpenAI-compatible but not built in?** Declare it in `deploy/pi/models.json`, then enable it in `deploy/pi/settings.json`.
|
||||
3. **Does it require provider-specific transport code?** Do not add a provider-specific extension. The provider is unsupported until a generic declarative capability exists.
|
||||
|
||||
---
|
||||
|
||||
## Ambito utente vs. progetto — riepilogo generale
|
||||
## User versus project scope: general summary
|
||||
|
||||
Oltre ai modelli, Pi carica altre risorse da due alberi paralleli: `~/.pi/agent/` (utente) e `<cwd>/.pi/` (progetto, risolto in base alla directory da cui viene lanciato `pi`).
|
||||
In addition to models, Pi loads other resources from two parallel trees: `~/.pi/agent/` (user) and
|
||||
`<cwd>/.pi/` (project, resolved from the directory where `pi` is launched).
|
||||
|
||||
| File/Directory | Livello utente | Livello progetto | Auto-discovery | Precedenza |
|
||||
|---|---|---|---|---|
|
||||
| `models.json` | `~/.pi/agent/models.json` | non supportato | no | solo utente |
|
||||
| `settings.json` | `~/.pi/agent/settings.json` | `./.pi/settings.json` | no | progetto sovrascrive utente |
|
||||
| `extensions/` | `~/.pi/agent/extensions/` | `./.pi/extensions/` | sì (`.ts`/`.js`) | uniti (progetto + utente) |
|
||||
| `prompts/` | `~/.pi/agent/prompts/` | `./.pi/prompts/` | sì (`.md`) | uniti |
|
||||
| `themes/` | `~/.pi/agent/themes/` | `./.pi/themes/` | sì (`.json`) | progetto preferito |
|
||||
| `skills/` | `~/.pi/agent/skills/` | `./.pi/skills/` | sì (`.md`) | uniti |
|
||||
| `models.json` | `~/.pi/agent/models.json` | not supported | no | user only |
|
||||
| `settings.json` | `~/.pi/agent/settings.json` | `./.pi/settings.json` | no | project overrides user |
|
||||
| `extensions/` | `~/.pi/agent/extensions/` | `./.pi/extensions/` | yes (`.ts`/`.js`) | merged (project + user) |
|
||||
| `prompts/` | `~/.pi/agent/prompts/` | `./.pi/prompts/` | yes (`.md`) | merged |
|
||||
| `themes/` | `~/.pi/agent/themes/` | `./.pi/themes/` | yes (`.json`) | project preferred |
|
||||
| `skills/` | `~/.pi/agent/skills/` | `./.pi/skills/` | yes (`.md`) | merged |
|
||||
|
||||
### Esempio reale: ThothII
|
||||
### Real example: ThothII
|
||||
|
||||
```
|
||||
harness/.pi/
|
||||
├── extensions/
|
||||
│ ├── tht-gate.js ← gate human-in-the-loop
|
||||
│ ├── tht-gate.js # human-in-the-loop gate
|
||||
│ └── gate/
|
||||
│ ├── core/ ← enforcement e utility condivise del gate
|
||||
│ ├── disambiguation/ ← policy F1/F3
|
||||
│ └── memory/ ← policy F2/F8
|
||||
├── settings.json ← (opzionale) override delle impostazioni utente
|
||||
│ ├── core/ # shared gate enforcement and utilities
|
||||
│ ├── disambiguation/ # F1/F3 policy
|
||||
│ └── memory/ # F2/F8 policy
|
||||
├── settings.json # optional override of user settings
|
||||
└── themes/
|
||||
└── thothii-mono.json ← tema del progetto
|
||||
└── thothii-mono.json # project theme
|
||||
```
|
||||
|
||||
### Comportamento rispetto alla cwd
|
||||
### Behavior relative to cwd
|
||||
|
||||
La directory da cui lanci `pi` determina quali estensioni del workflow vengono trovate, ma non
|
||||
quali modelli ThothII rende disponibili: il catalogo è montato nel Pi agent directory del container.
|
||||
The directory from which you launch `pi` determines which workflow extensions are found, but not
|
||||
which models ThothII makes available. The catalog is mounted in the container's Pi agent directory.
|
||||
|
||||
```bash
|
||||
# Da harness/ — carica il gate di progetto e il catalogo locale montato
|
||||
# From harness/: load the project gate and mounted local catalog
|
||||
cd /path/to/ThothII/harness
|
||||
pi --model local-qwen/qwen3.6-35b-a3b "..."
|
||||
```
|
||||
|
||||
Il backend di ThothII lancia sempre Pi con `cwd: harnessDir` per il workflow; la disponibilità del
|
||||
modello continua a dipendere soltanto da `models.json`, `settings.json` e dalle credenziali locali.
|
||||
The ThothII backend always launches Pi with `cwd: harnessDir` for the workflow. Model availability
|
||||
continues to depend only on `models.json`, `settings.json`, and local credentials.
|
||||
|
||||
---
|
||||
|
||||
## Trappola nell'auto-discovery: `.mjs` viene ignorato
|
||||
## Auto-discovery trap: `.mjs` is ignored
|
||||
|
||||
Il pattern di auto-discovery delle estensioni in Pi è **`/\.(ts|js)$/`** — non include `.mjs`.
|
||||
Pi's extension auto-discovery pattern is **`/\.(ts|js)$/`**; it does not include `.mjs`.
|
||||
|
||||
```
|
||||
.pi/extensions/
|
||||
├── my-extension.js ✅ auto-caricata
|
||||
├── my-extension.ts ✅ auto-caricata
|
||||
├── my-extension.mjs ❌ ignorata silenziosamente (non combacia col pattern)
|
||||
└── shared-module.mjs ✅ va bene per moduli helper (deliberatamente non caricato come estensione)
|
||||
├── my-extension.js ✅ auto-loaded
|
||||
├── my-extension.ts ✅ auto-loaded
|
||||
├── my-extension.mjs ❌ silently ignored (does not match the pattern)
|
||||
└── shared-module.mjs ✅ suitable for helper modules (deliberately not loaded as an extension)
|
||||
```
|
||||
|
||||
Se serve un modulo condiviso importato da un'estensione, usa `.mjs` proprio per evitare che venga trattato come estensione a sé.
|
||||
If an extension imports a shared module, use `.mjs` so Pi does not treat it as an extension on its own.
|
||||
|
||||
---
|
||||
|
||||
## Verifica
|
||||
|
||||
### Elenco modelli
|
||||
### List models
|
||||
```bash
|
||||
pi --list-models
|
||||
```
|
||||
Mostra i built-in e i modelli dichiarati in `models.json`.
|
||||
This shows built-in models and models declared in `models.json`.
|
||||
|
||||
### Verifica il catalogo usato dall'applicazione
|
||||
### Check the catalog used by the application
|
||||
```bash
|
||||
cd harness # o la cwd rilevante per il progetto
|
||||
cd harness # or the project's relevant cwd
|
||||
pi --mode rpc
|
||||
# poi: {"type": "get_available_models", "id": "1"}
|
||||
```
|
||||
La risposta RPC deve includere soltanto modelli built-in o dichiarati nel catalogo locale.
|
||||
The RPC response must include only built-in models or models declared in the local catalog.
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
| Problema | Causa | Soluzione |
|
||||
| Problem | Cause | Solution |
|
||||
|---|---|---|
|
||||
| `Model "X/Y" not found` | Provider/modello assente da `models.json` oppure identificatore assente da `enabledModels` | Correggi i due file locali e ricarica Pi |
|
||||
| Impostazioni di progetto non applicate | `settings.json` di progetto ha errori di sintassi, o si sta lanciando `pi` dalla cwd sbagliata | Valida il JSON, controlla la cwd |
|
||||
| `Model "X/Y" not found` | Provider/model missing from `models.json` or identifier missing from `enabledModels` | Fix the two local files and reload Pi |
|
||||
| Project settings not applied | Project `settings.json` has a syntax error, or `pi` is launched from the wrong cwd | Validate the JSON and check the cwd |
|
||||
|
||||
Reference in New Issue
Block a user