puspa 0.1.0__py3-none-any.whl
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.
- puspa/__init__.py +1 -0
- puspa/__main__.py +7 -0
- puspa/accounts/__init__.py +31 -0
- puspa/accounts/ports.py +372 -0
- puspa/accounts/vault.py +319 -0
- puspa/auth/__init__.py +47 -0
- puspa/auth/email_link.py +96 -0
- puspa/auth/google_oauth.py +353 -0
- puspa/autonomy/__init__.py +49 -0
- puspa/autonomy/controls.py +485 -0
- puspa/autonomy/dial.py +669 -0
- puspa/backup/__init__.py +30 -0
- puspa/backup/local_state.py +174 -0
- puspa/backup/ports.py +85 -0
- puspa/billing/__init__.py +16 -0
- puspa/billing/config.py +264 -0
- puspa/billing/fixture.py +103 -0
- puspa/billing/ports.py +649 -0
- puspa/cassette/__init__.py +1 -0
- puspa/cassette/cassette.py +184 -0
- puspa/channels/__init__.py +119 -0
- puspa/channels/agent.py +112 -0
- puspa/channels/authz.py +221 -0
- puspa/channels/base.py +61 -0
- puspa/channels/cli.py +142 -0
- puspa/channels/config.py +256 -0
- puspa/channels/delivery.py +105 -0
- puspa/channels/discord.py +277 -0
- puspa/channels/engines.py +258 -0
- puspa/channels/engines_bailian.py +113 -0
- puspa/channels/engines_coze.py +192 -0
- puspa/channels/engines_dify.py +104 -0
- puspa/channels/errors.py +38 -0
- puspa/channels/events.py +58 -0
- puspa/channels/heartbeat.py +112 -0
- puspa/channels/inbound.py +194 -0
- puspa/channels/ledger.py +334 -0
- puspa/channels/line.py +253 -0
- puspa/channels/notify.py +34 -0
- puspa/channels/run.py +370 -0
- puspa/channels/slack.py +305 -0
- puspa/channels/telegram.py +273 -0
- puspa/channels/whatsapp.py +216 -0
- puspa/chassis/__init__.py +80 -0
- puspa/chassis/agent_session.py +217 -0
- puspa/chassis/context.py +112 -0
- puspa/chassis/contract.py +62 -0
- puspa/chassis/factory.py +213 -0
- puspa/chassis/hooks.py +474 -0
- puspa/chassis/pin.json +17 -0
- puspa/chassis/pin.py +235 -0
- puspa/chassis/registry.py +137 -0
- puspa/chassis/sandbox_tool.py +144 -0
- puspa/chassis/skill_loader.py +93 -0
- puspa/chassis/tools.py +600 -0
- puspa/check_before_buy/__init__.py +53 -0
- puspa/check_before_buy/answer.py +618 -0
- puspa/check_before_buy/classifier.py +144 -0
- puspa/check_before_buy/outcome.py +93 -0
- puspa/check_before_buy/records.py +161 -0
- puspa/check_before_buy/wiring.py +68 -0
- puspa/cli.py +977 -0
- puspa/computer/__init__.py +182 -0
- puspa/computer/allowlist.py +111 -0
- puspa/computer/audit.py +205 -0
- puspa/computer/backend.py +630 -0
- puspa/computer/cli.py +975 -0
- puspa/computer/fallback.py +534 -0
- puspa/computer/gating.py +65 -0
- puspa/computer/hands.py +1576 -0
- puspa/computer/input.py +669 -0
- puspa/computer/mcp.py +805 -0
- puspa/computer/safety.py +333 -0
- puspa/computer/screenshot.py +275 -0
- puspa/computer/stop.py +133 -0
- puspa/computer/sync.py +225 -0
- puspa/computer/tiers.py +99 -0
- puspa/computer/tree.py +241 -0
- puspa/computer/vision.py +390 -0
- puspa/computer/web.py +815 -0
- puspa/computer/windows.py +417 -0
- puspa/connectors/__init__.py +59 -0
- puspa/connectors/accounts.py +183 -0
- puspa/connectors/aggregator.py +152 -0
- puspa/connectors/allowlist.py +143 -0
- puspa/connectors/google.py +216 -0
- puspa/connectors/grants.py +86 -0
- puspa/connectors/mcp_registry.py +276 -0
- puspa/connectors/native.py +190 -0
- puspa/connectors/token_app_server.py +289 -0
- puspa/connectors/token_apps.py +303 -0
- puspa/connectors/wedges.py +346 -0
- puspa/consent/__init__.py +20 -0
- puspa/consent/account.py +110 -0
- puspa/consent/consent.py +116 -0
- puspa/consistency/__init__.py +28 -0
- puspa/consistency/idempotency.py +33 -0
- puspa/consistency/kill_drill.py +159 -0
- puspa/consistency/rebuild.py +84 -0
- puspa/consistency/reconcile.py +75 -0
- puspa/consistency/runner.py +206 -0
- puspa/consistency/worker.py +103 -0
- puspa/consistency/write_ahead.py +332 -0
- puspa/credentials/__init__.py +12 -0
- puspa/credentials/auth.py +460 -0
- puspa/credentials/pool.py +391 -0
- puspa/credentials/redact.py +292 -0
- puspa/credentials/resolver.py +536 -0
- puspa/credentials/scope.py +224 -0
- puspa/decider/__init__.py +75 -0
- puspa/decider/backends.py +340 -0
- puspa/decider/decider.py +247 -0
- puspa/decider/jobs.py +192 -0
- puspa/decider/keycheck.py +38 -0
- puspa/decider/log.py +93 -0
- puspa/decider/questions.py +251 -0
- puspa/diagnostics/__init__.py +35 -0
- puspa/diagnostics/export.py +413 -0
- puspa/diagnostics/redact.py +73 -0
- puspa/drafting/__init__.py +54 -0
- puspa/drafting/drafting.py +721 -0
- puspa/drafting/errors.py +29 -0
- puspa/drafting/schema.py +40 -0
- puspa/drafting/voice.py +382 -0
- puspa/eval/__init__.py +41 -0
- puspa/eval/attack_harness.py +390 -0
- puspa/eval/bm25.py +75 -0
- puspa/eval/corpus.py +287 -0
- puspa/eval/data/attack_corpus_v1.json +1 -0
- puspa/eval/data/benign_indonesian_v1.json +1 -0
- puspa/eval/data/gold_entity_identity_v1.json +1 -0
- puspa/eval/data/gold_orphan_numbers_v1.json +1 -0
- puspa/eval/data/gold_quoted_numbers_v1.json +1 -0
- puspa/eval/data/public_sources.md +42 -0
- puspa/eval/fuzz.py +165 -0
- puspa/eval/gold_sets.py +243 -0
- puspa/eval/intervals.py +54 -0
- puspa/eval/mutation.py +284 -0
- puspa/eval/reference_tasks.py +381 -0
- puspa/eval/replay.py +137 -0
- puspa/eval/retrieval_sets.py +423 -0
- puspa/eval/scorecard.py +349 -0
- puspa/evidence/__init__.py +1 -0
- puspa/evidence/agentbench_tasks.py +585 -0
- puspa/evidence/bfcl_checker.py +662 -0
- puspa/evidence/bfcl_tasks.py +728 -0
- puspa/evidence/eval_harness.py +531 -0
- puspa/evidence/evidence.py +174 -0
- puspa/evidence/outcomes.py +392 -0
- puspa/evidence/projections.py +134 -0
- puspa/evidence/proof.py +692 -0
- puspa/evidence/renderer.py +120 -0
- puspa/evidence/verifier.py +102 -0
- puspa/feature_flags.py +208 -0
- puspa/gallery/__init__.py +28 -0
- puspa/gallery/store.py +359 -0
- puspa/gallery/support.py +358 -0
- puspa/governor/__init__.py +96 -0
- puspa/governor/budgets.py +368 -0
- puspa/governor/compiler.py +835 -0
- puspa/governor/governor.py +497 -0
- puspa/governor/skills.py +645 -0
- puspa/graphs/__init__.py +58 -0
- puspa/graphs/fraud_patterns.py +282 -0
- puspa/graphs/identity.py +516 -0
- puspa/graphs/service.py +330 -0
- puspa/graphs/shared.py +527 -0
- puspa/graphs/temporal.py +372 -0
- puspa/guardrails/__init__.py +51 -0
- puspa/guardrails/rails.py +849 -0
- puspa/harness/__init__.py +139 -0
- puspa/harness/diff.py +282 -0
- puspa/harness/executor.py +466 -0
- puspa/harness/loop.py +834 -0
- puspa/harness/modes.py +191 -0
- puspa/harness/repo_map.py +283 -0
- puspa/harness/reproduce.py +284 -0
- puspa/harness/sandbox_profiles.py +308 -0
- puspa/hosting/__init__.py +29 -0
- puspa/hosting/errors.py +31 -0
- puspa/hosting/pairing.py +258 -0
- puspa/i18n/__init__.py +46 -0
- puspa/i18n/locales/en.json +64 -0
- puspa/i18n/locales/id.json +64 -0
- puspa/i18n/locales.py +111 -0
- puspa/i18n/server_lines.py +150 -0
- puspa/intent/__init__.py +62 -0
- puspa/intent/act_ask.py +356 -0
- puspa/intent/distribution.py +242 -0
- puspa/intent/inference.py +570 -0
- puspa/intent/turn_wiring.py +192 -0
- puspa/knowledge/__init__.py +29 -0
- puspa/knowledge/cli.py +149 -0
- puspa/knowledge/store.py +421 -0
- puspa/ledger/__init__.py +103 -0
- puspa/ledger/anchor.py +382 -0
- puspa/ledger/audit.py +571 -0
- puspa/ledger/audit_daemon.py +307 -0
- puspa/ledger/audit_writer.py +108 -0
- puspa/ledger/errors.py +16 -0
- puspa/ledger/export.py +227 -0
- puspa/ledger/kill_switch.py +304 -0
- puspa/ledger/ledger.py +633 -0
- puspa/local_data/__init__.py +64 -0
- puspa/local_data/language.py +214 -0
- puspa/local_data/money.py +289 -0
- puspa/local_data/rails.py +187 -0
- puspa/local_data/rates.py +441 -0
- puspa/localexec/__init__.py +30 -0
- puspa/localexec/executor.py +249 -0
- puspa/marketplace/__init__.py +185 -0
- puspa/marketplace/authoring.py +289 -0
- puspa/marketplace/cli.py +160 -0
- puspa/marketplace/discovery.py +950 -0
- puspa/marketplace/errors.py +69 -0
- puspa/marketplace/hub.py +744 -0
- puspa/marketplace/learning.py +309 -0
- puspa/marketplace/manifest.py +346 -0
- puspa/marketplace/narrowing.py +263 -0
- puspa/marketplace/registry.py +358 -0
- puspa/marketplace/share.py +103 -0
- puspa/marketplace/skill_creator.py +846 -0
- puspa/marketplace/store.py +285 -0
- puspa/marketplace/trust.py +216 -0
- puspa/mcp_server/__init__.py +33 -0
- puspa/mcp_server/cli.py +115 -0
- puspa/mcp_server/handlers.py +434 -0
- puspa/mcp_server/server.py +321 -0
- puspa/mcp_server/tools.py +274 -0
- puspa/meetings/__init__.py +112 -0
- puspa/meetings/parse.py +317 -0
- puspa/meetings/reminders.py +254 -0
- puspa/meetings/schema.py +42 -0
- puspa/meetings/store.py +385 -0
- puspa/memory/__init__.py +67 -0
- puspa/memory/amnesia.py +412 -0
- puspa/memory/background_review.py +348 -0
- puspa/memory/commit_turn.py +1090 -0
- puspa/memory/consolidate.py +301 -0
- puspa/memory/curator.py +358 -0
- puspa/memory/curriculum_guardrails.py +336 -0
- puspa/memory/dream.py +272 -0
- puspa/memory/durable.py +942 -0
- puspa/memory/embeddings.py +358 -0
- puspa/memory/episodic.py +495 -0
- puspa/memory/extraction.py +493 -0
- puspa/memory/facts.py +572 -0
- puspa/memory/importer.py +1617 -0
- puspa/memory/journal.py +126 -0
- puspa/memory/learning_graph.py +436 -0
- puspa/memory/learning_loop.py +1216 -0
- puspa/memory/limits.py +93 -0
- puspa/memory/longterm.py +734 -0
- puspa/memory/loop_store.py +260 -0
- puspa/memory/memory_export.py +803 -0
- puspa/memory/ontology_evolve.py +942 -0
- puspa/memory/ontology_review.py +375 -0
- puspa/memory/optimizer.py +256 -0
- puspa/memory/procedural.py +488 -0
- puspa/memory/profile.py +252 -0
- puspa/memory/provider.py +618 -0
- puspa/memory/recall.py +240 -0
- puspa/memory/recall_plan.py +419 -0
- puspa/memory/schema.py +17 -0
- puspa/memory/self_evolution.py +565 -0
- puspa/memory/skill_repair.py +649 -0
- puspa/memory/slices.py +109 -0
- puspa/memory/trust.py +212 -0
- puspa/memory/wiki.py +647 -0
- puspa/memory/working.py +419 -0
- puspa/memory/write_cycle.py +168 -0
- puspa/migrations/__init__.py +31 -0
- puspa/migrations/__main__.py +80 -0
- puspa/migrations/runner.py +272 -0
- puspa/migrations/versions/0001_core.sql +192 -0
- puspa/migrations/versions/0002_memory.sql +223 -0
- puspa/migrations/versions/0003_runtime.sql +174 -0
- puspa/migrations/versions/0004_graphs.sql +244 -0
- puspa/migrations/versions/0005_workflow.sql +138 -0
- puspa/migrations/versions/0006_world.sql +169 -0
- puspa/migrations/versions/0007_learning_loop.sql +70 -0
- puspa/migrations/versions/0008_channels.sql +38 -0
- puspa/migrations/versions/0009_teams.sql +21 -0
- puspa/migrations/versions/0010_rooms.sql +499 -0
- puspa/migrations/versions/0011_meetings.sql +52 -0
- puspa/migrations/versions/0012_drafting.sql +89 -0
- puspa/migrations/versions/0013_payments.sql +52 -0
- puspa/migrations/versions/0014_marketplace.sql +59 -0
- puspa/migrations/versions/0015_mockup.sql +41 -0
- puspa/migrations/versions/0016_model_settings.sql +28 -0
- puspa/migrations/versions/0017_onboarding_hints.sql +26 -0
- puspa/migrations/versions/0018_scheduler.sql +39 -0
- puspa/migrations/versions/0019_conflicts.sql +70 -0
- puspa/migrations/versions/0020_token_revocations.sql +61 -0
- puspa/migrations/versions/0021_mockup_rls_grant.sql +46 -0
- puspa/migrations/versions/0022_embedding_health.sql +114 -0
- puspa/migrations/versions/0023_memory_rights.sql +37 -0
- puspa/migrations/versions/0024_room_job_queue.sql +36 -0
- puspa/migrations/versions/0025_morning_notes.sql +31 -0
- puspa/migrations/versions/0026_takeover_holds.sql +70 -0
- puspa/migrations/versions/0027_takeover_check_dedup.sql +40 -0
- puspa/migrations/versions/0028_runtime_session_states.sql +58 -0
- puspa/migrations/versions/0029_durable_memory.sql +93 -0
- puspa/migrations/versions/0030_turn_commit_retries.sql +71 -0
- puspa/migrations/versions/0031_memory_import.sql +142 -0
- puspa/migrations/versions/0032_user_display_names.sql +44 -0
- puspa/migrations/versions/0033_voice_settings.sql +32 -0
- puspa/migrations/versions/0034_longterm_tiers.sql +68 -0
- puspa/migrations/versions/0035_artifacts.sql +67 -0
- puspa/migrations/versions/0036_telemetry_settings.sql +27 -0
- puspa/migrations/versions/0037_document_knowledge_base.sql +82 -0
- puspa/migrations/versions/0038_capability_routing.sql +33 -0
- puspa/migrations/versions/0039_instance_settings.sql +34 -0
- puspa/migrations/versions/0040_user_language.sql +27 -0
- puspa/migrations/versions/0041_team_workspaces_audit.sql +21 -0
- puspa/migrations/versions/0042_gallery.sql +91 -0
- puspa/migrations/versions/0043_creator_support.sql +63 -0
- puspa/migrations/versions/0044_multi_agent_teams.sql +69 -0
- puspa/migrations/versions/0045_missions.sql +36 -0
- puspa/mind/__init__.py +75 -0
- puspa/mind/felt_state.py +792 -0
- puspa/mind/metacognition.py +449 -0
- puspa/mind/workspace.py +360 -0
- puspa/missions/__init__.py +29 -0
- puspa/missions/missions.py +315 -0
- puspa/missions/runner.py +283 -0
- puspa/missions/webhooks.py +131 -0
- puspa/moat/__init__.py +2 -0
- puspa/moat/library.py +87 -0
- puspa/moat/metrics.py +167 -0
- puspa/moat/reliability.py +98 -0
- puspa/moat/report.py +90 -0
- puspa/mockup/__init__.py +29 -0
- puspa/mockup/doc.py +537 -0
- puspa/mockup/export.py +143 -0
- puspa/mockup/generate.py +388 -0
- puspa/mockup/render.py +310 -0
- puspa/mockup/store.py +149 -0
- puspa/mockup/templates.py +405 -0
- puspa/modules/__init__.py +0 -0
- puspa/modules/bills.py +116 -0
- puspa/modules/manifest.py +413 -0
- puspa/modules/notifications.py +29 -0
- puspa/modules/tables.py +176 -0
- puspa/modules/views.py +127 -0
- puspa/morning/__init__.py +18 -0
- puspa/morning/holidays.py +111 -0
- puspa/morning/notes.py +373 -0
- puspa/morning/prayer.py +159 -0
- puspa/morning/summary.py +442 -0
- puspa/multimodal/__init__.py +73 -0
- puspa/multimodal/attachments.py +371 -0
- puspa/multimodal/generation.py +86 -0
- puspa/multimodal/turns.py +189 -0
- puspa/multimodal/vision.py +124 -0
- puspa/observability/__init__.py +67 -0
- puspa/observability/health.py +45 -0
- puspa/observability/logging.py +111 -0
- puspa/observability/metrics.py +391 -0
- puspa/observability/tracing.py +274 -0
- puspa/onboarding/__init__.py +31 -0
- puspa/onboarding/hints.py +250 -0
- puspa/onboarding/onboarding.py +253 -0
- puspa/persona/__init__.py +85 -0
- puspa/persona/blind_test.py +128 -0
- puspa/persona/files.py +271 -0
- puspa/persona/persona.py +202 -0
- puspa/persona/switcher.py +405 -0
- puspa/plugins/__init__.py +139 -0
- puspa/plugins/adapters.py +180 -0
- puspa/plugins/api_version.py +190 -0
- puspa/plugins/boundary.py +234 -0
- puspa/plugins/builtin/__init__.py +20 -0
- puspa/plugins/builtin/echo.py +42 -0
- puspa/plugins/builtin/memory_inmemory.py +100 -0
- puspa/plugins/builtin/simple_context.py +130 -0
- puspa/plugins/catalog/acme-notes.yaml +13 -0
- puspa/plugins/catalog/local-llm-context.yaml +12 -0
- puspa/plugins/catalog/sqlite-memory.yaml +12 -0
- puspa/plugins/catalog.py +235 -0
- puspa/plugins/context.py +396 -0
- puspa/plugins/context_engine.py +47 -0
- puspa/plugins/errors.py +66 -0
- puspa/plugins/loader.py +489 -0
- puspa/plugins/mcp.py +212 -0
- puspa/plugins/mcp_definitions/http-fetch-mcp.json +1 -0
- puspa/plugins/mcp_definitions/local-files-mcp.json +1 -0
- puspa/plugins/mcp_definitions/sqlite-mcp.json +1 -0
- puspa/plugins/permissions.py +137 -0
- puspa/plugins/plugin_api.json +1 -0
- puspa/plugins/single_select.py +199 -0
- puspa/policy/__init__.py +260 -0
- puspa/policy/agent_scan.py +1070 -0
- puspa/policy/allowlist.py +139 -0
- puspa/policy/approval_cards.py +428 -0
- puspa/policy/approvals.py +1051 -0
- puspa/policy/conflicts.py +984 -0
- puspa/policy/gate.py +368 -0
- puspa/policy/gateway.py +903 -0
- puspa/policy/revocation.py +587 -0
- puspa/policy/revocations.py +226 -0
- puspa/policy/rules.py +301 -0
- puspa/policy/session_modes.py +386 -0
- puspa/policy/signing.py +498 -0
- puspa/policy/sigstore_verify.py +233 -0
- puspa/policy/skill_signing.py +514 -0
- puspa/policy/spending.py +105 -0
- puspa/policy/stop.py +187 -0
- puspa/policy/tokens.py +440 -0
- puspa/policy/trust_root.py +455 -0
- puspa/pricing/__init__.py +2 -0
- puspa/pricing/cache.py +70 -0
- puspa/pricing/catalog.py +169 -0
- puspa/pricing/compare.py +262 -0
- puspa/pricing/credits.py +69 -0
- puspa/pricing/readers.py +312 -0
- puspa/pricing/tos.py +146 -0
- puspa/pricing/watchlist.py +154 -0
- puspa/proactivity/__init__.py +45 -0
- puspa/proactivity/budget.py +464 -0
- puspa/push/__init__.py +1 -0
- puspa/push/ports.py +48 -0
- puspa/pwa/__init__.py +1 -0
- puspa/pwa/admin_api.py +399 -0
- puspa/pwa/admin_settings.py +77 -0
- puspa/pwa/app.py +1400 -0
- puspa/pwa/approval_overlay.py +599 -0
- puspa/pwa/approval_overlay_api.py +356 -0
- puspa/pwa/artifacts.py +256 -0
- puspa/pwa/artifacts_api.py +114 -0
- puspa/pwa/avatar_api.py +222 -0
- puspa/pwa/capability_routing.py +808 -0
- puspa/pwa/capability_routing_api.py +162 -0
- puspa/pwa/chat_cards.py +506 -0
- puspa/pwa/chat_cards_api.py +180 -0
- puspa/pwa/chat_widgets.py +898 -0
- puspa/pwa/chat_widgets_api.py +273 -0
- puspa/pwa/computer_api.py +219 -0
- puspa/pwa/controls_api.py +220 -0
- puspa/pwa/diagnostics_api.py +98 -0
- puspa/pwa/drafts_api.py +218 -0
- puspa/pwa/gallery_api.py +153 -0
- puspa/pwa/graph_api.py +894 -0
- puspa/pwa/health.py +73 -0
- puspa/pwa/hub_api.py +210 -0
- puspa/pwa/insights_api.py +58 -0
- puspa/pwa/knowledge_api.py +187 -0
- puspa/pwa/language.py +126 -0
- puspa/pwa/language_api.py +106 -0
- puspa/pwa/lite.py +277 -0
- puspa/pwa/live_view.py +622 -0
- puspa/pwa/live_view_api.py +283 -0
- puspa/pwa/memory_api.py +757 -0
- puspa/pwa/missions_api.py +231 -0
- puspa/pwa/mockup_api.py +317 -0
- puspa/pwa/model_settings.py +435 -0
- puspa/pwa/morning_api.py +427 -0
- puspa/pwa/multimodal_api.py +172 -0
- puspa/pwa/names_api.py +72 -0
- puspa/pwa/onboarding_api.py +272 -0
- puspa/pwa/personas_api.py +185 -0
- puspa/pwa/proof_api.py +193 -0
- puspa/pwa/provider_login_api.py +230 -0
- puspa/pwa/receipt_api.py +344 -0
- puspa/pwa/replay.py +573 -0
- puspa/pwa/replay_api.py +238 -0
- puspa/pwa/rooms_api.py +825 -0
- puspa/pwa/rooms_jobs.py +221 -0
- puspa/pwa/serve_modes.py +340 -0
- puspa/pwa/share_api.py +194 -0
- puspa/pwa/static/icon-192.png +0 -0
- puspa/pwa/static/puspa-logo.png +0 -0
- puspa/pwa/static/sw.js +55 -0
- puspa/pwa/stop_all.py +184 -0
- puspa/pwa/support_api.py +93 -0
- puspa/pwa/telemetry_api.py +91 -0
- puspa/pwa/templates/admin.html +184 -0
- puspa/pwa/templates/artifacts.html +11 -0
- puspa/pwa/templates/base.html +45 -0
- puspa/pwa/templates/chat.html +41 -0
- puspa/pwa/templates/connectors.html +22 -0
- puspa/pwa/templates/diagnostics.html +15 -0
- puspa/pwa/templates/gallery.html +60 -0
- puspa/pwa/templates/hub.html +95 -0
- puspa/pwa/templates/insights.html +6 -0
- puspa/pwa/templates/knowledge.html +16 -0
- puspa/pwa/templates/live.html +11 -0
- puspa/pwa/templates/login.html +10 -0
- puspa/pwa/templates/memory.html +128 -0
- puspa/pwa/templates/mockup.html +6 -0
- puspa/pwa/templates/modules.html +8 -0
- puspa/pwa/templates/morning.html +6 -0
- puspa/pwa/templates/office.html +23 -0
- puspa/pwa/templates/onboarding.html +6 -0
- puspa/pwa/templates/panel_evidence.html +17 -0
- puspa/pwa/templates/personas.html +186 -0
- puspa/pwa/templates/proof.html +21 -0
- puspa/pwa/templates/replay.html +11 -0
- puspa/pwa/templates/rooms.html +6 -0
- puspa/pwa/templates/settings.html +157 -0
- puspa/pwa/templates/tasks.html +24 -0
- puspa/pwa/templates/trial.html +39 -0
- puspa/pwa/templates/wiki.html +66 -0
- puspa/pwa/voice_api.py +482 -0
- puspa/pwa/voice_settings.py +509 -0
- puspa/pwa/weekly_report.py +192 -0
- puspa/pwa/wiki_api.py +138 -0
- puspa/py.typed +0 -0
- puspa/quarantine/__init__.py +6 -0
- puspa/quarantine/injection.py +296 -0
- puspa/quarantine/reader.py +120 -0
- puspa/receipts/__init__.py +75 -0
- puspa/receipts/accuracy.py +286 -0
- puspa/receipts/documents.py +131 -0
- puspa/receipts/ocr.py +185 -0
- puspa/receipts/parser.py +264 -0
- puspa/receipts/pipeline.py +167 -0
- puspa/retrieval/__init__.py +105 -0
- puspa/retrieval/canary_questions.py +142 -0
- puspa/retrieval/code_graph.py +832 -0
- puspa/retrieval/embedding_health.py +958 -0
- puspa/retrieval/hipporag.py +468 -0
- puspa/retrieval/incremental.py +516 -0
- puspa/retrieval/knowledge_graph.py +528 -0
- puspa/retrieval/modes.py +243 -0
- puspa/retrieval/reranker.py +669 -0
- puspa/retrieval/triple_filter.py +282 -0
- puspa/rooms/__init__.py +183 -0
- puspa/rooms/errors.py +58 -0
- puspa/rooms/memory.py +301 -0
- puspa/rooms/names.py +391 -0
- puspa/rooms/rooms.py +494 -0
- puspa/rooms/schema.py +65 -0
- puspa/rooms/tasks.py +366 -0
- puspa/router/__init__.py +87 -0
- puspa/router/chains.py +214 -0
- puspa/router/complete.py +662 -0
- puspa/router/compression.py +754 -0
- puspa/router/fallback.py +673 -0
- puspa/router/oauth.py +659 -0
- puspa/router/pool.py +1109 -0
- puspa/router/provider_login.py +2468 -0
- puspa/router/quota.py +375 -0
- puspa/router/router.py +306 -0
- puspa/router/translate.py +879 -0
- puspa/runtime/__init__.py +77 -0
- puspa/runtime/agents.py +133 -0
- puspa/runtime/budget.py +109 -0
- puspa/runtime/context_compression.py +533 -0
- puspa/runtime/handoff.py +188 -0
- puspa/runtime/hierarchy.py +860 -0
- puspa/runtime/planner.py +432 -0
- puspa/runtime/prompt_assembly.py +561 -0
- puspa/runtime/prompt_caching.py +168 -0
- puspa/runtime/session_store.py +231 -0
- puspa/runtime/subagents.py +174 -0
- puspa/runtime/tasks.py +637 -0
- puspa/scheduler/__init__.py +40 -0
- puspa/scheduler/claim.py +291 -0
- puspa/scheduler/cron.py +578 -0
- puspa/scheduler/curriculum.py +700 -0
- puspa/scheduler/due.py +84 -0
- puspa/scheduler/execution.py +90 -0
- puspa/scheduler/holds.py +119 -0
- puspa/scheduler/mission_triggers.py +154 -0
- puspa/scheduler/receipts.py +115 -0
- puspa/scheduler/recovery.py +100 -0
- puspa/scheduler/routines.py +248 -0
- puspa/scheduler/scheduler.py +861 -0
- puspa/scheduler/schedules.py +322 -0
- puspa/scheduler/serve.py +143 -0
- puspa/self/__init__.py +80 -0
- puspa/self/initiative.py +950 -0
- puspa/self/repair_loop.py +840 -0
- puspa/sentinel/__init__.py +154 -0
- puspa/sentinel/analytics.py +182 -0
- puspa/sentinel/decision_log.py +162 -0
- puspa/sentinel/detectors.py +607 -0
- puspa/sentinel/failure_taxonomy.py +379 -0
- puspa/sentinel/insights.py +269 -0
- puspa/sentinel/outcome_watcher.py +356 -0
- puspa/sentinel/scanner.py +248 -0
- puspa/sentinel/state.py +248 -0
- puspa/sentinel/thresholds.py +71 -0
- puspa/sentinel/traces.py +223 -0
- puspa/sentinel/trajectory.py +354 -0
- puspa/sentinel/verifier.py +162 -0
- puspa/service/__init__.py +5 -0
- puspa/service/cli.py +214 -0
- puspa/service/manager.py +418 -0
- puspa/sessions/__init__.py +88 -0
- puspa/sessions/assembly.py +69 -0
- puspa/sessions/auto_compress.py +273 -0
- puspa/sessions/errors.py +57 -0
- puspa/sessions/export.py +586 -0
- puspa/sessions/gateway.py +218 -0
- puspa/sessions/home.py +140 -0
- puspa/sessions/housekeeping.py +129 -0
- puspa/sessions/lineage.py +91 -0
- puspa/sessions/schema.py +210 -0
- puspa/sessions/single_writer.py +304 -0
- puspa/sessions/spawner.py +60 -0
- puspa/sessions/store.py +684 -0
- puspa/subagents/__init__.py +68 -0
- puspa/subagents/errors.py +89 -0
- puspa/subagents/handles.py +109 -0
- puspa/subagents/hooks.py +73 -0
- puspa/subagents/host.py +272 -0
- puspa/subagents/lifecycle.py +551 -0
- puspa/subagents/limits.py +87 -0
- puspa/subagents/records.py +42 -0
- puspa/subagents/results.py +70 -0
- puspa/subagents/runner.py +92 -0
- puspa/subagents/states.py +50 -0
- puspa/subagents/toolsets.py +69 -0
- puspa/teams/__init__.py +110 -0
- puspa/teams/conversations.py +270 -0
- puspa/teams/errors.py +41 -0
- puspa/teams/runner.py +184 -0
- puspa/teams/schema.py +60 -0
- puspa/teams/teams.py +427 -0
- puspa/telemetry/__init__.py +35 -0
- puspa/telemetry/client.py +220 -0
- puspa/telemetry/config.py +125 -0
- puspa/telemetry/settings.py +108 -0
- puspa/tools/__init__.py +132 -0
- puspa/tools/approval.py +302 -0
- puspa/tools/browser.py +667 -0
- puspa/tools/builtin.py +115 -0
- puspa/tools/check.py +252 -0
- puspa/tools/footprint.py +121 -0
- puspa/tools/narrowing.py +644 -0
- puspa/tools/registry.py +533 -0
- puspa/tools/toolsets.py +256 -0
- puspa/turns/__init__.py +114 -0
- puspa/turns/budget.py +120 -0
- puspa/turns/config.py +119 -0
- puspa/turns/conflict_wiring.py +65 -0
- puspa/turns/intercepts.py +335 -0
- puspa/turns/interrupt.py +128 -0
- puspa/turns/loop.py +1330 -0
- puspa/turns/messages.py +822 -0
- puspa/turns/todos.py +77 -0
- puspa/turns/turn_api.py +458 -0
- puspa/turns/turn_api_error.py +150 -0
- puspa/turns/turn_overflow.py +86 -0
- puspa/turns/turn_prepare.py +60 -0
- puspa/turns/turn_recover.py +63 -0
- puspa/turns/turn_truncate.py +80 -0
- puspa/voice/__init__.py +57 -0
- puspa/voice/asr.py +124 -0
- puspa/voice/edge_tts.py +186 -0
- puspa/voice/pipeline.py +169 -0
- puspa/voice/transcriber.py +137 -0
- puspa/voice/tts.py +259 -0
- puspa/voice/wer.py +247 -0
- puspa/workflow/__init__.py +0 -0
- puspa/workflow/approvals.py +183 -0
- puspa/workflow/blocks.py +306 -0
- puspa/workflow/composer.py +294 -0
- puspa/workflow/manifest.py +86 -0
- puspa/workflow/metrics.py +57 -0
- puspa/workflow/panel.py +73 -0
- puspa/workflow/runner.py +928 -0
- puspa/workflow/schema.py +41 -0
- puspa/workflow/templates.py +140 -0
- puspa/workflow/triggers.py +176 -0
- puspa/world/__init__.py +171 -0
- puspa/world/agents.py +1047 -0
- puspa/world/beliefs.py +250 -0
- puspa/world/bitemporal.py +451 -0
- puspa/world/causal.py +615 -0
- puspa/world/ignorance.py +482 -0
- puspa/world/model.py +1395 -0
- puspa/world/noisy_simulator.py +221 -0
- puspa/world/planner.py +319 -0
- puspa/world/prediction_surprise.py +420 -0
- puspa/world/simulator.py +195 -0
- puspa/world/speeds.py +323 -0
- puspa/world/store.py +720 -0
- puspa-0.1.0.dist-info/METADATA +49 -0
- puspa-0.1.0.dist-info/RECORD +687 -0
- puspa-0.1.0.dist-info/WHEEL +5 -0
- puspa-0.1.0.dist-info/entry_points.txt +4 -0
- puspa-0.1.0.dist-info/licenses/LICENSE +201 -0
- puspa-0.1.0.dist-info/licenses/NOTICE.md +934 -0
- puspa-0.1.0.dist-info/top_level.txt +1 -0
puspa/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Paket Puspa — Fase 0 MVP."""
|
puspa/__main__.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Public part of Puspa accounts: the local encrypted vault.
|
|
2
|
+
|
|
3
|
+
Split Step 1: the multi-user account code (``users.py``,
|
|
4
|
+
``user_sessions.py``, ``access.py``, ``rls.py``) moved private with
|
|
5
|
+
the hosted accounts. What stays public is the vault only — per-user
|
|
6
|
+
connector tokens encrypted with a master key from the environment.
|
|
7
|
+
The session / user names (``create_session``, ``validate_session``,
|
|
8
|
+
``create_user``, ``delete_user``, ``resolve_dsn`` and friends) move
|
|
9
|
+
to the SessionStore port in Step 3; they are deliberately NOT
|
|
10
|
+
re-exported here.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from .vault import VaultError
|
|
14
|
+
from .vault import delete as vault_delete
|
|
15
|
+
from .vault import derive_user_key as vault_derive_user_key
|
|
16
|
+
from .vault import get as vault_get
|
|
17
|
+
from .vault import list_names as vault_list_names
|
|
18
|
+
from .vault import put as vault_put
|
|
19
|
+
from .vault import rekey_all as vault_rekey_all
|
|
20
|
+
from .vault import rotate_entry as vault_rotate_entry
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"VaultError",
|
|
24
|
+
"vault_delete",
|
|
25
|
+
"vault_derive_user_key",
|
|
26
|
+
"vault_get",
|
|
27
|
+
"vault_list_names",
|
|
28
|
+
"vault_put",
|
|
29
|
+
"vault_rekey_all",
|
|
30
|
+
"vault_rotate_entry",
|
|
31
|
+
]
|
puspa/accounts/ports.py
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
"""Local account ports: DSN resolution and the single-operator session store.
|
|
2
|
+
|
|
3
|
+
This module is the public side of the accounts boundary. It defines
|
|
4
|
+
the two ports the hosted service implements against its own user
|
|
5
|
+
registry and that the local install implements against its own
|
|
6
|
+
Postgres database:
|
|
7
|
+
|
|
8
|
+
- :func:`resolve_dsn` — the canonical DSN resolution (explicit
|
|
9
|
+
argument, then ``PUSPA_DSN`` / ``PUSPA_TEST_DSN``, then the local
|
|
10
|
+
peer-auth default). Every other ``resolve_dsn`` copy in the public
|
|
11
|
+
tree delegates to this one, so there is exactly one resolution
|
|
12
|
+
order to keep correct.
|
|
13
|
+
- the session store — :func:`create_user`, :func:`delete_user`,
|
|
14
|
+
:func:`create_session`, :func:`validate_session`,
|
|
15
|
+
:func:`list_sessions`, :func:`revoke_session`,
|
|
16
|
+
:func:`revoke_all_sessions`, :func:`register_agent`,
|
|
17
|
+
:func:`owner_of`, :func:`owner_of_token`,
|
|
18
|
+
:func:`create_agent_schema`, :func:`create_account_schema`.
|
|
19
|
+
|
|
20
|
+
The local implementations operate on Postgres through
|
|
21
|
+
:func:`resolve_dsn` (the same test database the rest of the suite
|
|
22
|
+
uses). The SQLite backend is a separate future workstream: when it
|
|
23
|
+
lands, these functions gain a SQLite implementation behind the same
|
|
24
|
+
names; nothing here pretends SQLite is live today.
|
|
25
|
+
|
|
26
|
+
Safety properties kept from the original implementation:
|
|
27
|
+
|
|
28
|
+
- Passwords are never stored raw, only as Argon2id hashes; email
|
|
29
|
+
is normalized (strip + lower) and unique.
|
|
30
|
+
- Only the SHA-256 of a session token is stored, never the token
|
|
31
|
+
itself, so a leaked sessions table yields no usable token.
|
|
32
|
+
- ``delete_user`` removes the user row, their sessions, and their
|
|
33
|
+
vault, but never touches the append-only ledger (``events``).
|
|
34
|
+
- ``register_agent`` is idempotent for the same owner and refuses
|
|
35
|
+
with :class:`AccessDeniedError` when an agent already belongs to
|
|
36
|
+
someone else, so an agent cannot be hijacked by re-registering it.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
from __future__ import annotations
|
|
40
|
+
|
|
41
|
+
import hashlib
|
|
42
|
+
import os
|
|
43
|
+
import secrets
|
|
44
|
+
|
|
45
|
+
import psycopg
|
|
46
|
+
from argon2 import PasswordHasher
|
|
47
|
+
from argon2.exceptions import InvalidHash, VerificationError, VerifyMismatchError
|
|
48
|
+
from psycopg import errors as pg_errors
|
|
49
|
+
|
|
50
|
+
DEFAULT_DSN = "dbname=puspa_test user=root host=/var/run/postgresql"
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"DEFAULT_DSN",
|
|
54
|
+
"AccessDeniedError",
|
|
55
|
+
"AuthError",
|
|
56
|
+
"DuplicateEmailError",
|
|
57
|
+
"SessionError",
|
|
58
|
+
"authenticate",
|
|
59
|
+
"create_account_schema",
|
|
60
|
+
"create_agent_schema",
|
|
61
|
+
"create_session",
|
|
62
|
+
"create_user",
|
|
63
|
+
"delete_user",
|
|
64
|
+
"list_sessions",
|
|
65
|
+
"owner_of",
|
|
66
|
+
"owner_of_token",
|
|
67
|
+
"register_agent",
|
|
68
|
+
"resolve_dsn",
|
|
69
|
+
"revoke_all_sessions",
|
|
70
|
+
"revoke_session",
|
|
71
|
+
"revoke_session_by_id",
|
|
72
|
+
"validate_session",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class AuthError(Exception):
|
|
77
|
+
"""Unknown email or wrong password."""
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class DuplicateEmailError(Exception):
|
|
81
|
+
"""Email already registered."""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class SessionError(Exception):
|
|
85
|
+
"""Session token invalid or revoked."""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class AccessDeniedError(Exception):
|
|
89
|
+
"""Reader is not the owner of the data. Always used for ownership
|
|
90
|
+
refusals — never replaced with KeyError/SessionError, so callers
|
|
91
|
+
can tell "data exists but is not yours" from "data does not
|
|
92
|
+
exist"."""
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
_PASSWORD_HASHER = PasswordHasher(time_cost=2, memory_cost=65536, parallelism=1)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def resolve_dsn(dsn: str | None = None) -> str:
|
|
99
|
+
"""Postgres DSN: explicit argument, then env ``PUSPA_DSN`` /
|
|
100
|
+
``PUSPA_TEST_DSN``, then the local peer-auth default."""
|
|
101
|
+
return dsn or os.environ.get("PUSPA_DSN") or os.environ.get("PUSPA_TEST_DSN") or DEFAULT_DSN
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _connect(dsn=None):
|
|
105
|
+
return psycopg.connect(resolve_dsn(dsn))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _normalize_email(email):
|
|
109
|
+
if not isinstance(email, str):
|
|
110
|
+
raise ValueError("email must be a string")
|
|
111
|
+
return email.strip().lower()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def create_user(email, password, dsn=None):
|
|
115
|
+
"""Create a user; return the user id (str UUID).
|
|
116
|
+
|
|
117
|
+
Raise DuplicateEmailError when the (normalized) email already
|
|
118
|
+
exists.
|
|
119
|
+
"""
|
|
120
|
+
email_n = _normalize_email(email)
|
|
121
|
+
if not email_n:
|
|
122
|
+
raise ValueError("email is empty")
|
|
123
|
+
if not password:
|
|
124
|
+
raise ValueError("password is empty")
|
|
125
|
+
password_hash = _PASSWORD_HASHER.hash(password)
|
|
126
|
+
with _connect(dsn) as conn:
|
|
127
|
+
with conn.cursor() as cur:
|
|
128
|
+
try:
|
|
129
|
+
cur.execute(
|
|
130
|
+
"INSERT INTO users (email, password_hash) VALUES (%s, %s) RETURNING id",
|
|
131
|
+
(email_n, password_hash),
|
|
132
|
+
)
|
|
133
|
+
user_id = cur.fetchone()[0]
|
|
134
|
+
except pg_errors.UniqueViolation as err:
|
|
135
|
+
raise DuplicateEmailError(f"email already registered: {email_n}") from err
|
|
136
|
+
conn.commit()
|
|
137
|
+
return str(user_id)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def authenticate(email, password, dsn=None):
|
|
141
|
+
"""Check email + password; return the user id (str UUID).
|
|
142
|
+
|
|
143
|
+
Raise AuthError for an unknown email or a wrong password. The
|
|
144
|
+
message is deliberately the same for both, so it never leaks
|
|
145
|
+
which one was wrong.
|
|
146
|
+
"""
|
|
147
|
+
email_n = _normalize_email(email)
|
|
148
|
+
with _connect(dsn) as conn, conn.cursor() as cur:
|
|
149
|
+
cur.execute(
|
|
150
|
+
"SELECT id, password_hash FROM users WHERE email = %s",
|
|
151
|
+
(email_n,),
|
|
152
|
+
)
|
|
153
|
+
row = cur.fetchone()
|
|
154
|
+
if row is None:
|
|
155
|
+
raise AuthError("email or password is wrong")
|
|
156
|
+
user_id, password_hash = row
|
|
157
|
+
try:
|
|
158
|
+
_PASSWORD_HASHER.verify(password_hash, password)
|
|
159
|
+
except (VerifyMismatchError, VerificationError, InvalidHash) as err:
|
|
160
|
+
raise AuthError("email or password is wrong") from err
|
|
161
|
+
return str(user_id)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def delete_user(user_id, dsn=None):
|
|
165
|
+
"""Delete a user: the user row + all sessions + the whole vault.
|
|
166
|
+
|
|
167
|
+
Ledger events are NOT deleted (append-only audit) — the
|
|
168
|
+
``events`` table is never touched here.
|
|
169
|
+
"""
|
|
170
|
+
with _connect(dsn) as conn:
|
|
171
|
+
with conn.cursor() as cur:
|
|
172
|
+
cur.execute("DELETE FROM vault WHERE user_id = %s", (user_id,))
|
|
173
|
+
cur.execute("DELETE FROM sessions WHERE user_id = %s", (user_id,))
|
|
174
|
+
cur.execute("DELETE FROM users WHERE id = %s", (user_id,))
|
|
175
|
+
conn.commit()
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _token_hash(token):
|
|
179
|
+
return hashlib.sha256(token.encode()).hexdigest()
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def create_session(user_id, device_label, dsn=None):
|
|
183
|
+
"""Create a session for a user; return the raw token (str).
|
|
184
|
+
|
|
185
|
+
The raw token is returned exactly once here — the caller must
|
|
186
|
+
store it safely; the database only keeps its hash.
|
|
187
|
+
"""
|
|
188
|
+
token = secrets.token_urlsafe(32)
|
|
189
|
+
with _connect(dsn) as conn:
|
|
190
|
+
with conn.cursor() as cur:
|
|
191
|
+
cur.execute(
|
|
192
|
+
"INSERT INTO sessions (user_id, token_hash, device_label) VALUES (%s, %s, %s)",
|
|
193
|
+
(user_id, _token_hash(token), device_label),
|
|
194
|
+
)
|
|
195
|
+
conn.commit()
|
|
196
|
+
return token
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def validate_session(token, dsn=None):
|
|
200
|
+
"""Check a token; return the user id (str UUID) while it is valid.
|
|
201
|
+
|
|
202
|
+
Raise SessionError when the token is unknown or revoked. A
|
|
203
|
+
session that validates successfully refreshes ``last_seen_at``.
|
|
204
|
+
"""
|
|
205
|
+
token_h = _token_hash(token)
|
|
206
|
+
with _connect(dsn) as conn:
|
|
207
|
+
with conn.cursor() as cur:
|
|
208
|
+
cur.execute(
|
|
209
|
+
"SELECT user_id FROM sessions WHERE token_hash = %s AND NOT revoked",
|
|
210
|
+
(token_h,),
|
|
211
|
+
)
|
|
212
|
+
row = cur.fetchone()
|
|
213
|
+
if row is None:
|
|
214
|
+
raise SessionError("session is invalid or revoked")
|
|
215
|
+
cur.execute(
|
|
216
|
+
"UPDATE sessions SET last_seen_at = now() WHERE token_hash = %s",
|
|
217
|
+
(token_h,),
|
|
218
|
+
)
|
|
219
|
+
conn.commit()
|
|
220
|
+
return str(row[0])
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def owner_of_token(token, dsn=None):
|
|
224
|
+
"""Return the user id owning a token, WITHOUT side effects.
|
|
225
|
+
|
|
226
|
+
Same as :func:`validate_session` but does NOT refresh
|
|
227
|
+
``last_seen_at``: use this for ownership checks, so a token
|
|
228
|
+
presented by the wrong user leaves no trace on the owner's
|
|
229
|
+
session. Raise SessionError when the token is unknown or
|
|
230
|
+
revoked.
|
|
231
|
+
"""
|
|
232
|
+
token_h = _token_hash(token)
|
|
233
|
+
with _connect(dsn) as conn, conn.cursor() as cur:
|
|
234
|
+
cur.execute(
|
|
235
|
+
"SELECT user_id FROM sessions WHERE token_hash = %s AND NOT revoked",
|
|
236
|
+
(token_h,),
|
|
237
|
+
)
|
|
238
|
+
row = cur.fetchone()
|
|
239
|
+
if row is None:
|
|
240
|
+
raise SessionError("session is invalid or revoked")
|
|
241
|
+
return str(row[0])
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def revoke_session(token, dsn=None):
|
|
245
|
+
"""Revoke one session (log out that device). Idempotent."""
|
|
246
|
+
with _connect(dsn) as conn:
|
|
247
|
+
with conn.cursor() as cur:
|
|
248
|
+
cur.execute(
|
|
249
|
+
"UPDATE sessions SET revoked = true WHERE token_hash = %s",
|
|
250
|
+
(_token_hash(token),),
|
|
251
|
+
)
|
|
252
|
+
conn.commit()
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def revoke_session_by_id(session_id, user_id, dsn=None):
|
|
256
|
+
"""Revoke one session by its row id. Returns True when a
|
|
257
|
+
session of this user was revoked, False when no such session
|
|
258
|
+
exists. An unknown id and another user's id read the same
|
|
259
|
+
(False), so one user's ids cannot probe another user's
|
|
260
|
+
sessions. Idempotent: revoking an already-revoked session
|
|
261
|
+
still returns True. A malformed id raises the database's
|
|
262
|
+
error, which the caller maps to "no such session"."""
|
|
263
|
+
with _connect(dsn) as conn:
|
|
264
|
+
with conn.cursor() as cur:
|
|
265
|
+
cur.execute(
|
|
266
|
+
"UPDATE sessions SET revoked = true WHERE id = %s AND user_id = %s",
|
|
267
|
+
(session_id, user_id),
|
|
268
|
+
)
|
|
269
|
+
revoked = cur.rowcount > 0
|
|
270
|
+
conn.commit()
|
|
271
|
+
return revoked
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def revoke_all_sessions(user_id, dsn=None):
|
|
275
|
+
"""Revoke all sessions of a user (log out every device)."""
|
|
276
|
+
with _connect(dsn) as conn:
|
|
277
|
+
with conn.cursor() as cur:
|
|
278
|
+
cur.execute(
|
|
279
|
+
"UPDATE sessions SET revoked = true WHERE user_id = %s",
|
|
280
|
+
(user_id,),
|
|
281
|
+
)
|
|
282
|
+
conn.commit()
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def list_sessions(user_id, dsn=None):
|
|
286
|
+
"""List all sessions of a user (revoked ones included, with the
|
|
287
|
+
``revoked`` flag), newest first."""
|
|
288
|
+
with _connect(dsn) as conn, conn.cursor() as cur:
|
|
289
|
+
cur.execute(
|
|
290
|
+
"SELECT id, device_label, created_at, last_seen_at, revoked "
|
|
291
|
+
"FROM sessions WHERE user_id = %s ORDER BY created_at DESC",
|
|
292
|
+
(user_id,),
|
|
293
|
+
)
|
|
294
|
+
rows = cur.fetchall()
|
|
295
|
+
return [
|
|
296
|
+
{
|
|
297
|
+
"id": str(r[0]),
|
|
298
|
+
"device_label": r[1],
|
|
299
|
+
"created_at": r[2],
|
|
300
|
+
"last_seen_at": r[3],
|
|
301
|
+
"revoked": r[4],
|
|
302
|
+
}
|
|
303
|
+
for r in rows
|
|
304
|
+
]
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def create_agent_schema(dsn=None):
|
|
308
|
+
"""Apply the agent registry table (migration 0001_core).
|
|
309
|
+
|
|
310
|
+
The ``agents`` table comes from the migration, not from a schema
|
|
311
|
+
file. Idempotent; safe to call before every test.
|
|
312
|
+
"""
|
|
313
|
+
from puspa.migrations import apply_migrations
|
|
314
|
+
|
|
315
|
+
apply_migrations(resolve_dsn(dsn), target="0001")
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def create_account_schema(dsn=None):
|
|
319
|
+
"""Apply the account tables (migration 0001_core).
|
|
320
|
+
|
|
321
|
+
The tables (users, sessions, vault, agents) come from the
|
|
322
|
+
migration, not from a schema file. Idempotent; safe to call
|
|
323
|
+
before every test.
|
|
324
|
+
"""
|
|
325
|
+
from puspa.migrations import apply_migrations
|
|
326
|
+
|
|
327
|
+
apply_migrations(resolve_dsn(dsn), target="0001")
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def register_agent(agent_id, user_id, dsn=None):
|
|
331
|
+
"""Register an agent to its owner. Idempotent when the agent is
|
|
332
|
+
already registered to the same user.
|
|
333
|
+
|
|
334
|
+
Raise AccessDeniedError when the agent id is already registered
|
|
335
|
+
to a DIFFERENT user (an agent cannot be hijacked or moved by
|
|
336
|
+
re-registering it). Raise ValueError for an empty agent_id or
|
|
337
|
+
user_id.
|
|
338
|
+
"""
|
|
339
|
+
if not isinstance(agent_id, str) or not agent_id.strip():
|
|
340
|
+
raise ValueError("agent_id must be a non-empty string")
|
|
341
|
+
if not isinstance(user_id, str) or not user_id.strip():
|
|
342
|
+
raise ValueError("user_id must be a non-empty string")
|
|
343
|
+
agent_id = agent_id.strip()
|
|
344
|
+
user_id = user_id.strip()
|
|
345
|
+
with psycopg.connect(resolve_dsn(dsn)) as conn:
|
|
346
|
+
with conn.cursor() as cur:
|
|
347
|
+
cur.execute("SELECT user_id FROM agents WHERE agent_id = %s", (agent_id,))
|
|
348
|
+
row = cur.fetchone()
|
|
349
|
+
if row is not None:
|
|
350
|
+
if str(row[0]) != user_id:
|
|
351
|
+
raise AccessDeniedError(
|
|
352
|
+
f"agent {agent_id!r} is already registered to another user"
|
|
353
|
+
)
|
|
354
|
+
return # already registered to the same owner: no-op
|
|
355
|
+
cur.execute(
|
|
356
|
+
"INSERT INTO agents (agent_id, user_id) VALUES (%s, %s)",
|
|
357
|
+
(agent_id, user_id),
|
|
358
|
+
)
|
|
359
|
+
conn.commit()
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def owner_of(agent_id, dsn=None):
|
|
363
|
+
"""Return the user id (str UUID) owning an agent, or None when
|
|
364
|
+
the agent is not registered. None means the owner is unknown,
|
|
365
|
+
which owned readers treat as fail-closed (never as owned by
|
|
366
|
+
anyone)."""
|
|
367
|
+
if not isinstance(agent_id, str) or not agent_id.strip():
|
|
368
|
+
return None
|
|
369
|
+
with psycopg.connect(resolve_dsn(dsn)) as conn, conn.cursor() as cur:
|
|
370
|
+
cur.execute("SELECT user_id FROM agents WHERE agent_id = %s", (agent_id.strip(),))
|
|
371
|
+
row = cur.fetchone()
|
|
372
|
+
return str(row[0]) if row is not None else None
|