engine7 7.1.144 → 7.1.145
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/dist/auth-server.mjs +1 -1
- package/dist/bg-worker.mjs +10932 -2578
- package/dist/cli.mjs +12327 -12456
- package/dist/engine-startup.mjs +6179 -6375
- package/dist/main.mjs +6162 -6358
- package/dist/recall-worker.mjs +4502 -1433
- package/dist/sqlite-maintenance-worker.mjs +43 -29
- package/dist/topics-worker.mjs +324 -209
- package/dist/travel-data.mjs +95 -86
- package/dist/travel-gateway.mjs +768 -477
- package/dist/travel-host.mjs +641 -483
- package/dist/travel-initial-baseline.mjs +63 -54
- package/dist/travel-node-data.mjs +53 -44
- package/dist/travel-node.mjs +403 -299
- package/dist/{travel-oss-return.mjs → travel-oss-bundle-stream.mjs} +313 -240
- package/dist/travel-pairing.mjs +779 -488
- package/dist/travel-sync-worker.mjs +4929 -0
- package/dist/web-console.mjs +819 -303
- package/package.json +7 -6
- package/templates/config.template.json +0 -1
- package/templates/skills/screenshot-annotate/SKILL.md +56 -0
- package/templates/skills/screenshot-annotate/scripts/annotate.py +156 -0
- package/templates/skills/screenshot-annotate/scripts/annotate_test.py +130 -0
- package/dist/travel-oss-pull.mjs +0 -389
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "engine7",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "7.1.
|
|
4
|
+
"version": "7.1.145",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Engine7 — 给助手一个家 / A home for your AI assistant · https://www.twinsun.top",
|
|
7
7
|
"homepage": "https://www.twinsun.top",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"test:session": "tsx src/session/restore-head-align.test.ts && tsx src/session/archive-continuity.test.ts && tsx src/session/responses-reasoning-roundtrip.test.ts && tsx src/session/memory-source-roundtrip.test.ts && tsx src/session/evidence-roundtrip.test.ts && tsx src/session/tool-error-roundtrip.test.ts && tsx src/core/handle-query.history-restore.test.ts && tsx --test src/core/handle-query.prefill-cache.test.ts && tsx src/session/restore-context-integrity.test.ts && tsx src/session/restore-cost.test.ts && tsx src/session/restore-pinned-rules.test.ts && tsx src/core/query.restore-capacity.test.ts && tsx src/session/restore-budget.test.ts && tsx --test src/messages/prompt-history.test.ts src/tools/result-snapshot.test.ts",
|
|
41
41
|
"test:mem7:state": "tsx src/mem7/core/__tests__/migrations.test.ts && tsx src/mem7/core/__tests__/source-store.test.ts && tsx src/mem7/core/__tests__/job-runner.test.ts && tsx src/mem7/core/__tests__/episode.test.ts && tsx src/mem7/core/__tests__/pipeline-recovery.test.ts && tsx src/mem7/core/__tests__/agent-recovery.test.ts && tsx src/mem7/core/__tests__/facts.test.ts && tsx src/mem7/core/__tests__/interpreter.test.ts && tsx src/mem7/core/__tests__/interpretation-backlog.test.ts && tsx src/mem7/core/__tests__/interpretation-input-isolation.test.ts && tsx src/mem7/core/__tests__/provider-cooldown.test.ts && tsx src/mem7/core/__tests__/fact-conflict-classification.test.ts && tsx src/mem7/core/__tests__/interpretation-concurrency.test.ts && tsx src/mem7/core/__tests__/schedule-interpretation.test.ts && tsx src/mem7/core/__tests__/projection-input-sources.test.ts && tsx src/mem7/core/__tests__/change-feed.test.ts && tsx src/mem7/core/__tests__/change-feed-process.test.ts && tsx src/memory/proactive/__tests__/mutation-service.test.ts && tsx src/memory/proactive/__tests__/intent-runs.test.ts && tsx src/memory/proactive/__tests__/intent-lifecycle.test.ts && tsx src/mem7/core/__tests__/projection-runtime.test.ts && tsx src/mem7/core/__tests__/graph-memory-context.test.ts && tsx src/mem7/core/__tests__/scoped-opportunity.test.ts && tsx src/mem7/core/__tests__/interpretation-runtime.test.ts && tsx src/mem7/core/__tests__/basis-check.test.ts && tsx src/mem7/core/__tests__/context-service.test.ts && tsx src/mem7/core/__tests__/context-budget.test.ts && tsx src/memory/memdir/current-context-pending.test.ts && tsx src/mem7/core/__tests__/knowledge-history.test.ts && tsx src/mem7/core/__tests__/projection-read.test.ts && tsx src/mem7/core/__tests__/tombstones.test.ts && tsx src/mem7/core/__tests__/artifact-revalidation.test.ts && tsx src/mem7/core/__tests__/artifact-context.test.ts && tsx src/mem7/core/__tests__/context-time.test.ts && tsx src/mem7/core/__tests__/milestones-e2e.test.ts && tsx src/mem7/core/__tests__/migration-rehearsal.test.ts && tsx src/calendar/memory-binding.test.ts && tsx src/calendar/memory-occurrences.test.ts && tsx src/calendar/delivery-reconciliation.test.ts && tsx src/tools/memory-bridge.test.ts && tsx src/tools/memory-write.test.ts && tsx src/mem-serve/mem7-mcp.test.ts && tsx src/core/message-dispatcher.memory.test.ts && tsx src/core/message-dispatcher.host-context.test.ts && tsx src/session/memory-source-roundtrip.test.ts && tsx src/tools/notification-durable.test.ts && tsx src/tools/notification-state.test.ts && tsx src/channels/memory-send-guard.test.ts && tsx src/mem7/core/__tests__/vector-indexes.test.ts && tsx src/mem7/core/__tests__/vector-publications.test.ts && tsx src/mem7/core/__tests__/project-projections.test.ts && tsx src/memory/proactive/__tests__/host-deliveries.test.ts && tsx src/memory/proactive/__tests__/delivery-reconciliation.test.ts && tsx src/mem7/core/__tests__/host-turns.test.ts && tsx src/mem7/host-turn.test.ts && tsx src/core/handle-query.memory.test.ts && tsx src/core/handle-query.recall.test.ts && tsx src/channels/host-send-guard.test.ts && tsx src/optional/voice-chat/bridge.memory.test.ts && tsx src/mem7/core/__tests__/job-provenance.test.ts && tsx src/mem7/core/__tests__/artifact-history.test.ts && tsx src/mem7/core/__tests__/legacy-recovery.test.ts && tsx src/mem7/core/__tests__/read-visibility.test.ts && tsx src/mem7/core/__tests__/cascade-visibility.test.ts && tsx src/mem7/core/__tests__/entity-redirect-context.test.ts && tsx src/mem7/core/__tests__/projection-visibility.test.ts && tsx src/mem7/core/__tests__/search-visibility.test.ts && tsx src/mem7/core/__tests__/visibility-cache.test.ts && tsx src/mem7/core/__tests__/generation-visibility.test.ts && tsx src/mem7/core/__tests__/artifact-file-inputs.test.ts && tsx src/calendar/memory-read.test.ts && tsx src/memory/proactive/__tests__/consumer-visibility.test.ts && tsx src/memory/memdir/recall-visibility.test.ts && tsx src/memory/memdir/recall-compatibility.test.ts && tsx src/memory/proactive/__tests__/legacy-read-visibility.test.ts && tsx src/mem7/core/__tests__/prose-review-recovery.test.ts && npx tsx src/mem7/core/__tests__/change-feed-baseline.test.ts && npm run test:mem7:person && npm run test:mem7:worker",
|
|
42
42
|
"test:mem7:person": "tsx src/mem7/core/__tests__/person-relations.test.ts && tsx src/mem7/core/__tests__/person-import-cards.test.ts",
|
|
43
|
-
"test:mem7:worker": "tsx src/mem7/core/__tests__/job-claim-liveness.test.ts && tsx src/mem7/core/__tests__/ready-cell-liveness.test.ts && tsx src/mem7/core/__tests__/social-registration-liveness.test.ts && tsx src/mem7/core/__tests__/social-coverage-lifecycle.test.ts && tsx src/mem7/core/__tests__/social-classification-migration.test.ts && tsx src/mem7/core/__tests__/social-conversation-order.test.ts && tsx src/mem7/core/__tests__/social-processing-liveness.test.ts && tsx src/mem7/core/__tests__/social-identity-context.test.ts && tsx src/mem7/core/__tests__/social-structured-identity.test.ts && tsx src/mem7/core/__tests__/social-evidence-retention.test.ts && tsx src/mem7/core/__tests__/social-alias-provenance.test.ts && tsx src/mem7/core/__tests__/social-discovery-budget.test.ts && tsx src/mem7/core/__tests__/social-name-budget.test.ts && tsx src/mem7/core/__tests__/read-budget-diagnostics.test.ts && tsx src/mem7/core/__tests__/relationship-write-budget.test.ts && tsx src/mem7/worker-log.test.ts && tsx src/mem7/foresight-belief.test.ts && tsx src/mem7/intake-queue.test.ts && tsx --test src/mem7/intake-queue-disk-full.test.ts src/mem7/intake-diagnostics.test.ts && tsx src/mem7/sqlite-statistics.test.ts && tsx src/mem7/lance-optimize.test.ts && tsx src/mem7/owner-rpc.test.ts && tsx --test src/mem7/owner-rpc-diagnostics.test.ts && tsx src/mem7/worker-projection.test.ts && tsx src/tools/memory-people-update.test.ts && tsx --test src/tools/memory-people-author.test.ts && tsx src/tools/memory-people-usability.test.ts",
|
|
43
|
+
"test:mem7:worker": "tsx src/mem7/core/__tests__/job-claim-liveness.test.ts && tsx src/mem7/core/__tests__/ready-cell-liveness.test.ts && tsx src/mem7/core/__tests__/social-registration-liveness.test.ts && tsx src/mem7/core/__tests__/social-coverage-lifecycle.test.ts && tsx src/mem7/core/__tests__/social-classification-migration.test.ts && tsx src/mem7/core/__tests__/social-conversation-order.test.ts && tsx src/mem7/core/__tests__/social-processing-liveness.test.ts && tsx src/mem7/core/__tests__/social-identity-context.test.ts && tsx src/mem7/core/__tests__/social-structured-identity.test.ts && tsx src/mem7/core/__tests__/social-evidence-retention.test.ts && tsx src/mem7/core/__tests__/social-alias-provenance.test.ts && tsx src/mem7/core/__tests__/social-discovery-budget.test.ts && tsx src/mem7/core/__tests__/social-name-budget.test.ts && tsx src/mem7/core/__tests__/read-budget-diagnostics.test.ts && tsx src/mem7/core/__tests__/relationship-write-budget.test.ts && tsx src/mem7/worker-log.test.ts && tsx src/mem7/foresight-belief.test.ts && tsx src/mem7/intake-queue.test.ts && tsx --test src/mem7/intake-queue-disk-full.test.ts src/mem7/intake-diagnostics.test.ts && tsx src/mem7/sqlite-statistics.test.ts && tsx src/mem7/lance-optimize.test.ts && tsx src/mem7/owner-rpc.test.ts && tsx --test src/mem7/owner-rpc-diagnostics.test.ts && tsx src/mem7/worker-projection.test.ts && tsx src/tools/memory-people-update.test.ts && tsx --test src/tools/memory-people-author.test.ts && tsx src/tools/memory-people-usability.test.ts && tsx --test src/tools/memory-correct-usability.test.ts",
|
|
44
44
|
"test:mem7:relationships": "tsx src/mem7/core/__tests__/social-sources.test.ts && tsx src/mem7/core/__tests__/provenance-cache.test.ts && tsx --test src/mem7/core/__tests__/provenance-bookkeeping-cache.test.ts && tsx src/mem7/core/__tests__/grounding-liveness.test.ts && tsx src/mem7/core/__tests__/open-relationships.test.ts && tsx src/mem7/core/__tests__/qualified-relationship-guards.test.ts && tsx src/mem7/core/__tests__/social-interpretation.test.ts && tsx src/memory/proactive/__tests__/relationship-projection.test.ts && tsx src/memory/proactive/__tests__/relationship-snapshot.test.ts && tsx src/mem7/core/__tests__/relationship-context.test.ts && tsx src/mem7/core/__tests__/relationship-recall-lightweight.test.ts && tsx src/mem7/core/__tests__/relationship-undated-recall.test.ts && tsx src/mem7/core/__tests__/relationship-history.test.ts && tsx src/inner-voice/reflection-memory.test.ts && tsx src/mem7/core/__tests__/relationship-cognition.test.ts && tsx src/memory/proactive/__tests__/relationship-notifications.test.ts && tsx src/memory/proactive/__tests__/relationship-notification-runtime.test.ts && tsx src/mem7/core/__tests__/relationships-e2e.test.ts && tsx scripts/relations-replay.test.ts && tsx src/core/query.relationship-budget.test.ts && tsx src/core/handle-query.relationship-provenance.test.ts",
|
|
45
45
|
"replay:relationships": "tsx scripts/relations-replay.ts",
|
|
46
46
|
"test:goal": "tsx src/goals/store.test.ts",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"test:goal:calendar": "tsx src/goals/calendar-adapter.test.ts",
|
|
57
57
|
"test:goal:restart": "powershell -NoProfile -Command \"$d = Join-Path ([System.IO.Path]::GetTempPath()) ('engine7-goal-' + [guid]::NewGuid()); New-Item -ItemType Directory -Path $d | Out-Null; $id = (npx tsx src/goals/restart-writer.ts $d); npx tsx src/goals/restart-reader.ts $d $id; Remove-Item -Recurse -Force $d\"",
|
|
58
58
|
"test:goal:e2e": "powershell -NoProfile -Command \"$d = Join-Path ([System.IO.Path]::GetTempPath()) ('engine7-goal-e2e-' + [guid]::NewGuid()); New-Item -ItemType Directory -Path $d | Out-Null; npx tsx src/goals/e2e-phase1.ts $d; if ($LASTEXITCODE -ne 0) { Remove-Item -Recurse -Force $d; exit 1 }; npx tsx src/goals/e2e-phase2.ts $d; $code = $LASTEXITCODE; Remove-Item -Recurse -Force $d; exit $code\"",
|
|
59
|
-
"test:reload": "tsx src/cc-driver/sdk-loading.test.ts && tsx src/reload/orchestrator.test.ts && tsx src/reload/secrets-watch.test.ts && tsx src/hooks/config.test.ts && tsx src/startup/hooks-boot.test.ts && tsx src/channels/manager.reconcile.test.ts && tsx src/channels/cc-bridge.test.ts && tsx src/engine-startup.shouldSkipReload.test.ts && tsx src/optional/voice-chat/plugin.deps.test.ts && tsx src/optional/voice-chat/config.test.ts && tsx src/cron/cron-plugin.resync.test.ts && tsx src/cron/scheduler.renderer.test.ts && tsx src/channels/renderer.test.ts && tsx src/startup/message-pipeline.test.ts && tsx --test src/channels/process-card.test.ts src/channels/tool-progress.test.ts src/channels/feishu-process-card.test.ts src/startup/message-pipeline.folded.test.ts && tsx src/cc-driver/feishu-cards.test.ts && tsx src/utils/sanitize-error.test.ts && tsx src/reload/config-watch-selfwrite.test.ts && tsx src/channels/feishu.typing.test.ts && tsx src/channels/feishu.sendfile-apicheck.test.ts",
|
|
59
|
+
"test:reload": "tsx src/cc-driver/sdk-loading.test.ts && tsx src/reload/orchestrator.test.ts && tsx src/reload/secrets-watch.test.ts && tsx src/hooks/config.test.ts && tsx src/startup/hooks-boot.test.ts && tsx src/channels/manager.reconcile.test.ts && tsx src/channels/cc-bridge.test.ts && tsx src/engine-startup.shouldSkipReload.test.ts && tsx src/optional/voice-chat/plugin.deps.test.ts && tsx src/optional/voice-chat/config.test.ts && tsx src/cron/cron-plugin.resync.test.ts && tsx src/cron/scheduler.renderer.test.ts && tsx src/channels/renderer.test.ts && tsx src/startup/message-pipeline.test.ts && tsx --test src/channels/process-card.test.ts src/channels/tool-progress.test.ts src/channels/feishu-process-card.test.ts src/startup/message-pipeline.folded.test.ts src/startup/message-pipeline.recall.test.ts && tsx src/cc-driver/feishu-cards.test.ts && tsx src/utils/sanitize-error.test.ts && tsx src/reload/config-watch-selfwrite.test.ts && tsx src/channels/feishu.typing.test.ts && tsx src/channels/feishu.sendfile-apicheck.test.ts",
|
|
60
60
|
"test:installer": "tsx src/overwrite-backup.test.ts && tsx src/provision-free.test.ts && tsx src/channels/wechat.qr-backup.test.ts && tsx src/cli-init-doubao-bridge.test.ts && tsx src/cli-events.test.ts && tsx src/cli-init-config.test.ts && tsx src/cli-init-answers.test.ts && tsx src/cli-init.headless.e2e.test.ts && tsx src/cli-reconfig.test.ts && tsx src/cli-doctor.test.ts && tsx src/config/secrets-env.test.ts && tsx src/startup/api-status.test.ts && tsx src/cli-service.test.ts && tsx src/emotion-hook.test.ts && tsx src/emotion-hook.golden.test.ts && tsx src/tools/tavily-pool.test.ts && tsx src/tools/service.test.ts",
|
|
61
61
|
"test:skill-install": "tsx src/installer/installer.test.ts && tsx src/startup/skill-sync.test.ts",
|
|
62
62
|
"test:feishu-card": "tsx src/tools/AskUserQuestionTool/feishu-card.test.ts && tsx src/tools/AskUserQuestionTool/collect.test.ts && tsx src/tools/AskUserQuestionTool/AskUserQuestionTool.test.ts",
|
|
@@ -73,14 +73,14 @@
|
|
|
73
73
|
"test:config": "tsx src/config/registry.test.ts && tsx src/config/writer.test.ts && tsx src/config/secrets-io.test.ts && tsx src/config/secrets-env.test.ts && tsx src/config/migrations/index.test.ts && tsx src/config/migrations/persona.test.ts && tsx src/config/migrations/channel-secrets.test.ts && tsx src/config/cli-config.test.ts && tsx --test src/config/model-services.test.ts && tsx src/config/tts-providers.test.ts && tsx src/config/tts-voices.test.ts && tsx src/free-tier-apply.test.ts && tsx src/startup/free-tier-video-fixup.test.ts && tsx src/startup/free-tier-voice-fixup.test.ts && tsx src/startup/mem7-services-fixup.test.ts && tsx src/startup/emotion-tools-fixup.test.ts && tsx --test src/startup/context-window-fixup.test.ts",
|
|
74
74
|
"test:time": "tsx src/time/tz-matrix.test.ts && tsx src/time/time-discipline.test.ts && tsx src/time/tsc-guard.test.ts && tsx src/memory/memdir/recall-time-label.test.ts && tsx --test src/session/session-history.time.test.ts",
|
|
75
75
|
"test:tts": "tsx src/config/tts-providers.test.ts && tsx src/tools/tts/pick.test.ts && tsx src/tools/tts/route.test.ts && tsx src/tools/tts/relay.test.ts && tsx src/tools/tts/providers.test.ts && tsx src/tools/tts/impl.test.ts && tsx src/tools/tts/usage.test.ts && tsx src/tools/my-voice.dispatch.test.ts && tsx src/tools/opus-encoder.test.ts",
|
|
76
|
-
"test:toolstate": "tsx src/core/names-from-history.test.ts && tsx src/tools/tool-loading.test.ts && tsx src/core/query.deferred.test.ts && tsx src/core/query.toolgate.test.ts && tsx src/tools/read-repeat.test.ts",
|
|
76
|
+
"test:toolstate": "tsx src/core/names-from-history.test.ts && tsx src/tools/tool-loading.test.ts && tsx src/tools/SkillTool/SkillTool.test.ts && tsx src/core/query.deferred.test.ts && tsx src/core/query.toolgate.test.ts && tsx src/tools/read-repeat.test.ts",
|
|
77
77
|
"test:loopbrake": "tsx src/tools/loop-brake.test.ts",
|
|
78
78
|
"test:mcp": "tsx src/mcp/convert-input-schema.test.ts",
|
|
79
79
|
"test:memory-extract": "tsx --test src/memory/memdir/extractMemories.test.ts src/memory/memdir/tool-paths.test.ts src/memory/topics-history/writes.test.ts src/tools/grep.paths.test.ts",
|
|
80
|
-
"test:proactive": "tsx src/memory/proactive/__tests__/blocked-host-action.test.ts && tsx src/memory/proactive/__tests__/backlog-route.test.ts && tsx src/memory/proactive/__tests__/opportunity-large-delivery.test.ts && tsx src/memory/proactive/__tests__/stream-guard-cost.test.ts && tsx src/memory/proactive/__tests__/verdict-parse.test.ts && tsx src/memory/proactive/__tests__/sweep.test.ts && tsx src/memory/proactive/__tests__/persistence.test.ts && tsx src/memory/proactive/__tests__/graph-store-p0.test.ts && tsx src/memory/proactive/__tests__/opportunity.test.ts && tsx --test src/memory/proactive/__tests__/opportunity-outcomes.test.ts && tsx src/memory/proactive/__tests__/opportunity-provider-budget.test.ts && tsx src/memory/proactive/__tests__/opportunity-failure.test.ts && tsx src/memory/proactive/__tests__/planning-context.test.ts && tsx src/memory/proactive/__tests__/calendar-bridge.test.ts && tsx src/memory/proactive/__tests__/timezone-fix.test.ts && tsx src/memory/proactive/__tests__/stale-fix.test.ts && tsx src/memory/proactive/__tests__/completion-evidence.test.ts && tsx src/memory/proactive/__tests__/plugin.test.ts && tsx src/memory/proactive/__tests__/plan-finalization.test.ts && tsx src/memory/proactive/__tests__/host-delivery-status.test.ts && npm run test:memory-extract",
|
|
80
|
+
"test:proactive": "tsx src/memory/proactive/__tests__/blocked-host-action.test.ts && tsx src/memory/proactive/__tests__/backlog-route.test.ts && tsx src/memory/proactive/__tests__/opportunity-large-delivery.test.ts && tsx src/memory/proactive/__tests__/stream-guard-cost.test.ts && tsx src/memory/proactive/__tests__/verdict-parse.test.ts && tsx src/memory/proactive/__tests__/sweep.test.ts && tsx src/memory/proactive/__tests__/persistence.test.ts && tsx src/memory/proactive/__tests__/graph-store-p0.test.ts && tsx src/memory/proactive/__tests__/opportunity.test.ts && tsx --test src/memory/proactive/__tests__/opportunity-outcomes.test.ts && tsx src/memory/proactive/__tests__/opportunity-provider-budget.test.ts && tsx src/memory/proactive/__tests__/opportunity-failure.test.ts && tsx src/memory/proactive/__tests__/planning-context.test.ts && tsx src/memory/proactive/__tests__/calendar-bridge.test.ts && tsx src/memory/proactive/__tests__/timezone-fix.test.ts && tsx src/memory/proactive/__tests__/stale-fix.test.ts && tsx src/memory/proactive/__tests__/completion-evidence.test.ts && tsx src/memory/proactive/__tests__/plugin.test.ts && tsx src/memory/proactive/__tests__/plan-finalization.test.ts && tsx src/memory/proactive/__tests__/host-delivery-status.test.ts && tsx --test src/memory/proactive/__tests__/graph-load-memory.test.ts src/memory/proactive/__tests__/person-index-reopen.test.ts && npm run test:memory-extract",
|
|
81
81
|
"prepack": "node scripts/verify-cpu-router-package.mjs . && npm run test:time && npm run test:proactive && npm run test:persona && npm run test:config && npm run test:toolstate && npm run test:loopbrake && npm run test:mcp && npm run test:tts",
|
|
82
82
|
"test:onboarding": "tsx src/onboarding/state.test.ts && tsx src/onboarding/content.test.ts && tsx src/onboarding/plugin.test.ts && tsx src/onboarding/wechat-first-contact.test.ts && tsx --test src/onboarding/chan7.test.ts",
|
|
83
|
-
"test:runtime-recovery": "tsx --test src/cli-startup.logging.test.ts src/startup/http-api.logs.test.ts src/inner-voice/provider-error.test.ts && tsx src/tools/notification-retry.test.ts && tsx src/tools/notification-state-retry.test.ts && tsx src/tools/notification-durable.test.ts && tsx src/tools/notification-state.test.ts && tsx --test src/tools/notification-scan-cost.test.ts src/core/message-dispatcher.host-context.test.ts",
|
|
83
|
+
"test:runtime-recovery": "tsx --test src/core/query.request-dump.test.ts src/cli-startup.logging.test.ts src/startup/http-api.logs.test.ts src/inner-voice/provider-error.test.ts && tsx src/tools/notification-retry.test.ts && tsx src/tools/notification-state-retry.test.ts && tsx src/tools/notification-durable.test.ts && tsx src/tools/notification-state.test.ts && tsx --test src/tools/notification-scan-cost.test.ts src/core/message-dispatcher.host-context.test.ts",
|
|
84
84
|
"test:memory-continuity": "tsx --test src/core/handle-query.original-continuity.test.ts src/mem7/core/__tests__/recent-conversation-originals.test.ts && tsx --test src/core/handle-query.continuity-stress.test.ts",
|
|
85
85
|
"test:recall-worker": "tsx src/mem7/core/__tests__/read-budget.test.ts && tsx --test --test-concurrency=1 src/mem7/core/__tests__/read-only-store.test.ts src/memory/memdir/recall-worker.test.ts src/memory/memdir/recall-worker.lifecycle.test.ts src/memory/memdir/recall-worker.status.test.ts src/memory/memdir/recall-worker.failure.test.ts src/core/handle-query.async-history.test.ts src/core/query.recall-steer.test.ts",
|
|
86
86
|
"test:recall-worker:bundle": "tsx --test src/memory/memdir/recall-worker.bundle.test.ts",
|
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
"test:desktop-tasks": "tsx --test src/startup/desktop-tasks.test.ts src/startup/desktop-tasks.http.test.ts src/startup/desktop-tasks.review.test.ts src/startup/desktop-task-actions.test.ts",
|
|
92
92
|
"test:chat-stop": "tsx --test src/startup/chat-stop.test.ts src/startup/chat-stop.integration.test.ts src/startup/input-preparation.test.ts",
|
|
93
93
|
"test:console-billing": "node --test web-console/billing-browser.test.mjs",
|
|
94
|
+
"test:console-travel-gate": "node --test web-console/travel-vip-gate.browser.test.mjs",
|
|
94
95
|
"test:chan7-progress": "tsx --test src/channels/chan7-progress.test.ts src/startup/chan7-progress.integration.test.ts"
|
|
95
96
|
},
|
|
96
97
|
"engines": {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: screenshot-annotate
|
|
3
|
+
description: "TRIGGER: 标图/截图标注/圈出来/这个在哪/这个是什么/在图上标/annotate screenshot/red circle/mark up image。给用户发来的截图做圈注、红框、箭头、中文标签,标好直接回传原渠道。PIL 画图 + 视觉校准坐标,不猜位置。"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 截图标注
|
|
7
|
+
|
|
8
|
+
用户发来截图问「这个在哪 / 这个是什么 / 帮我圈出来」时用本技能:**看图 → 定位 → 画 → 用眼睛校准 → 回传**。
|
|
9
|
+
|
|
10
|
+
核心纪律:**坐标不许猜**。画完必须裁一小块出来"看"一眼,确认套中了目标行,再定稿。
|
|
11
|
+
|
|
12
|
+
## 流程
|
|
13
|
+
|
|
14
|
+
### 1. 看图
|
|
15
|
+
- 图片原生块已经在上下文里 → **直接看,不要再调 `my_eyes`**(重复调用 = 同一份图花两遍 token)。
|
|
16
|
+
- 图片只在磁盘上(翻旧文件、调用方只给路径)→ 用 `my_eyes` 看。
|
|
17
|
+
|
|
18
|
+
### 2. 定位
|
|
19
|
+
用 `my_eyes` 问**具体可量的问题**,例如:
|
|
20
|
+
> "红圈套住的是哪一行文字?套得准不准?"
|
|
21
|
+
|
|
22
|
+
坐标按**图片实际像素**(用 PIL 读到的 `im.size`),不是元数据里宣称的尺寸(iPhone 截图常被标成 1080×2336,实际文件可能是 925×2000)。
|
|
23
|
+
|
|
24
|
+
### 3. 画
|
|
25
|
+
```bash
|
|
26
|
+
python3 scripts/annotate.py --src <in> --out <out.png> \
|
|
27
|
+
--circle "x,y" --label "点这个" --label-at "x,y" \
|
|
28
|
+
--arrow "x1,y1,x2,y2" --banner "往上滑" --banner-at "x1,y1,x2,y2"
|
|
29
|
+
```
|
|
30
|
+
参数:`--circle`(可重复)/ `--label` + `--label-at`(成对)/ `--arrow` / `--banner` + `--banner-at` / `--font-size` / `--fill` / `--label-bg` / `--font`(指定字体文件)。
|
|
31
|
+
|
|
32
|
+
### 4. 校准(必做)
|
|
33
|
+
```bash
|
|
34
|
+
python3 -c "import os,tempfile; from PIL import Image; p=os.path.join(tempfile.gettempdir(),'annotate-check.png'); Image.open('<out.png>').convert('RGB').crop((x1,y1,x2,y2)).save(p); print(p)"
|
|
35
|
+
```
|
|
36
|
+
然后用 `my_eyes` 看打印出来的那个路径:圈歪了就挪坐标重画,**最多两轮**。(用系统临时目录而不是 `/tmp`,Windows 上没有 `/tmp`。)
|
|
37
|
+
|
|
38
|
+
### 5. 回传
|
|
39
|
+
用 `media_send`(type=image)发回**原渠道原收件人**,附一句说明(人话,别复述图上每个字)。
|
|
40
|
+
`media_send` 的 to 填当前对话者 ID;渠道为 feishu 时 source="feishu"。
|
|
41
|
+
|
|
42
|
+
## 字体
|
|
43
|
+
脚本自动挑系统自带的中文字体:Linux 用 Noto CJK,macOS 用黑体-简 / 冬青黑体,Windows 用微软雅黑。
|
|
44
|
+
输出里出现「⚠ 没找到中文字体」= 这台机器一个中文字体都没有,标签里的中文会画成方块——装一个(Ubuntu:`sudo apt install fonts-noto-cjk`),或加 `--font <字体文件>` 指定一个带汉字的 `.ttf` / `.ttc` / `.otf`。
|
|
45
|
+
`--font` 指的文件加载不了时脚本直接报错,不会悄悄换一个字体。
|
|
46
|
+
|
|
47
|
+
## 坑
|
|
48
|
+
|
|
49
|
+
- **别把整屏标满**:一张图最多 1–2 个标注,圈要套准"行",不是套准"点"。
|
|
50
|
+
- **红底白字**在浅色截图上最显眼;深色截图用黄框(`--fill 255,220,0`)。
|
|
51
|
+
- 标注文字写**动作**(「点这里」「往下滑」),不要写解释。
|
|
52
|
+
- 涉及**授权码/密码的截图**:不复述、不标注出来;提醒用户打码。
|
|
53
|
+
|
|
54
|
+
## 依赖
|
|
55
|
+
Pillow(`python3 -c "import PIL"`)。没有就 `python3 -m pip install pillow`;提示 `externally-managed-environment`(Homebrew 装的 Python)就在后面加 `--break-system-packages`。
|
|
56
|
+
Windows 上命令里的 `python3` 写成 `python`。
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""截图标注小工具(把"你看图 → 圈重点 → 写说明"这套变成一条命令)
|
|
3
|
+
|
|
4
|
+
用法示例:
|
|
5
|
+
python3 scripts/annotate.py --src in.jpg --out out.png \
|
|
6
|
+
--circle "110,1330" --label "点这里 → 權限" --label-at "300,1240" \
|
|
7
|
+
--arrow "300,1290,175,1330" --banner "往上滑" --banner-at "30,40,895,210"
|
|
8
|
+
|
|
9
|
+
参数:
|
|
10
|
+
--src/--out 输入图 / 输出图
|
|
11
|
+
--circle "x,y" 在 (x,y) 画红圈(可重复)
|
|
12
|
+
--label "文字" 画红底白字标签
|
|
13
|
+
--label-at "x,y" 标签左上角坐标
|
|
14
|
+
--arrow "x1,y1,x2,y2" 画红箭头(带箭头三角)
|
|
15
|
+
--banner "文字" 顶部红底横幅
|
|
16
|
+
--banner-at "x1,y1,x2,y2"
|
|
17
|
+
--font-size / --fill / --label-bg
|
|
18
|
+
--font "字体文件" 指定字体(.ttf / .ttc / .otf);不传=自动找系统自带的中文字体
|
|
19
|
+
坐标按图片原始像素(用 PIL 读到的实际尺寸,不是手机截图的宣称尺寸)。
|
|
20
|
+
"""
|
|
21
|
+
import argparse
|
|
22
|
+
import sys
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
from PIL import Image, ImageDraw, ImageFont
|
|
26
|
+
except ImportError:
|
|
27
|
+
sys.exit("没装 Pillow(画图要用)。装法:python3 -m pip install pillow;"
|
|
28
|
+
"提示 externally-managed-environment 就在后面加 --break-system-packages")
|
|
29
|
+
|
|
30
|
+
# 系统自带的中文字体,按平台分组(本平台的排最前)。.ttc 里装着多国字形,第二项是取第几款。
|
|
31
|
+
# 一个都加载不了时,中文标签会画成方块——那时会退到下面的拉丁字体并提示。
|
|
32
|
+
CJK_FONTS = {
|
|
33
|
+
"linux": [
|
|
34
|
+
("/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc", 0),
|
|
35
|
+
("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", 0),
|
|
36
|
+
("/usr/share/fonts/noto-cjk/NotoSansCJK-Bold.ttc", 0),
|
|
37
|
+
("/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc", 0),
|
|
38
|
+
],
|
|
39
|
+
"darwin": [
|
|
40
|
+
("/System/Library/Fonts/STHeiti Medium.ttc", 1), # 黑体-简 中黑
|
|
41
|
+
("/System/Library/Fonts/Hiragino Sans GB.ttc", 2), # 冬青黑体 简体 W6
|
|
42
|
+
("/System/Library/Fonts/Hiragino Sans GB.ttc", 0), # 冬青黑体 简体 W3
|
|
43
|
+
("/System/Library/Fonts/Supplemental/Arial Unicode.ttf", 0),
|
|
44
|
+
("/Library/Fonts/Arial Unicode.ttf", 0),
|
|
45
|
+
],
|
|
46
|
+
"win32": [
|
|
47
|
+
("C:/Windows/Fonts/msyhbd.ttc", 0), # 微软雅黑 粗
|
|
48
|
+
("C:/Windows/Fonts/msyh.ttc", 0), # 微软雅黑
|
|
49
|
+
("C:/Windows/Fonts/simhei.ttf", 0), # 黑体
|
|
50
|
+
],
|
|
51
|
+
}
|
|
52
|
+
# 不带汉字的拉丁字体:只有上面的全都加载不了时才用
|
|
53
|
+
NON_CJK_FALLBACK = [("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 0)]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def load_face(path, index, size):
|
|
57
|
+
try:
|
|
58
|
+
return ImageFont.truetype(path, size, index=index)
|
|
59
|
+
except Exception:
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def find_cjk_font():
|
|
64
|
+
"""本机第一个能加载的中文字体,返回 (路径, 序号);一个都没有返回 None"""
|
|
65
|
+
mine = [sys.platform] if sys.platform in CJK_FONTS else []
|
|
66
|
+
for key in mine + [k for k in CJK_FONTS if k not in mine]:
|
|
67
|
+
for path, index in CJK_FONTS[key]:
|
|
68
|
+
if load_face(path, index, 20) is not None:
|
|
69
|
+
return (path, index)
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def pick_font(size, path=None):
|
|
74
|
+
"""返回字体。path 是 --font 指定的字体文件:加载不了直接报错退出,不悄悄换一个。
|
|
75
|
+
没指定就用系统自带的中文字体;一个都没有才退到拉丁字体,并提示中文会变方块。"""
|
|
76
|
+
if path:
|
|
77
|
+
font = load_face(path, 0, size)
|
|
78
|
+
if font is None:
|
|
79
|
+
sys.exit(f"ERR: --font 指定的字体加载不了:{path}。换一个 .ttf / .ttc / .otf 文件的完整路径再试")
|
|
80
|
+
return font
|
|
81
|
+
found = find_cjk_font()
|
|
82
|
+
if found:
|
|
83
|
+
font = load_face(found[0], found[1], size)
|
|
84
|
+
if font is not None:
|
|
85
|
+
return font
|
|
86
|
+
font = None
|
|
87
|
+
for candidate, index in NON_CJK_FALLBACK:
|
|
88
|
+
font = load_face(candidate, index, size)
|
|
89
|
+
if font is not None:
|
|
90
|
+
break
|
|
91
|
+
print("⚠ 没找到中文字体:标签里的中文会画成方块。装一个(Ubuntu:sudo apt install fonts-noto-cjk;"
|
|
92
|
+
"macOS / Windows 本该系统自带,没有说明系统被精简过),或用 --font 指定一个带汉字的字体文件",
|
|
93
|
+
file=sys.stderr)
|
|
94
|
+
return font or ImageFont.load_default()
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def xy(s):
|
|
98
|
+
return tuple(int(v) for v in s.split(","))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def main():
|
|
102
|
+
ap = argparse.ArgumentParser()
|
|
103
|
+
ap.add_argument("--src", required=True)
|
|
104
|
+
ap.add_argument("--out", required=True)
|
|
105
|
+
ap.add_argument("--circle", action="append", default=[])
|
|
106
|
+
ap.add_argument("--label", action="append", default=[])
|
|
107
|
+
ap.add_argument("--label-at", action="append", default=[])
|
|
108
|
+
ap.add_argument("--arrow", action="append", default=[])
|
|
109
|
+
ap.add_argument("--banner")
|
|
110
|
+
ap.add_argument("--banner-at")
|
|
111
|
+
ap.add_argument("--font-size", type=int, default=48)
|
|
112
|
+
ap.add_argument("--font", help="字体文件路径(.ttf / .ttc / .otf);不传=自动找系统自带的中文字体")
|
|
113
|
+
ap.add_argument("--fill", default="255,0,0")
|
|
114
|
+
ap.add_argument("--label-bg", default="255,0,0")
|
|
115
|
+
a = ap.parse_args()
|
|
116
|
+
|
|
117
|
+
im = Image.open(a.src).convert("RGB")
|
|
118
|
+
d = ImageDraw.Draw(im)
|
|
119
|
+
f = pick_font(a.font_size, path=a.font)
|
|
120
|
+
fill = tuple(int(v) for v in a.fill.split(","))
|
|
121
|
+
bg = tuple(int(v) for v in a.label_bg.split(","))
|
|
122
|
+
|
|
123
|
+
for c in a.circle:
|
|
124
|
+
x, y = xy(c)
|
|
125
|
+
r = a.font_size // 2 + 22
|
|
126
|
+
d.ellipse((x - r, y - r, x + r, y + r), outline=fill, width=10)
|
|
127
|
+
|
|
128
|
+
for i, text in enumerate(a.label):
|
|
129
|
+
pos = xy(a.label_at[i]) if i < len(a.label_at) else (40, 40 + i * (a.font_size + 20))
|
|
130
|
+
w = int(d.textlength(text, font=f))
|
|
131
|
+
d.rounded_rectangle((pos[0] - 18, pos[1] - 10, pos[0] + w + 18, pos[1] + a.font_size + 14),
|
|
132
|
+
radius=22, fill=bg)
|
|
133
|
+
d.text(pos, text, font=f, fill=(255, 255, 255))
|
|
134
|
+
|
|
135
|
+
for ar in a.arrow:
|
|
136
|
+
x1, y1, x2, y2 = xy(ar)
|
|
137
|
+
d.line((x1, y1, x2, y2), fill=fill, width=10)
|
|
138
|
+
import math
|
|
139
|
+
ang = math.atan2(y2 - y1, x2 - x1)
|
|
140
|
+
L = 34
|
|
141
|
+
for s in (2.6, -2.6):
|
|
142
|
+
d.polygon([(x2, y2),
|
|
143
|
+
(x2 + L * math.cos(ang + s), y2 + L * math.sin(ang + s)),
|
|
144
|
+
(x2 + L * math.cos(ang + s / 2), y2 + L * math.sin(ang + s / 2))], fill=fill)
|
|
145
|
+
|
|
146
|
+
if a.banner:
|
|
147
|
+
box = xy(a.banner_at) if a.banner_at else (30, 40, im.width - 30, 40 + a.font_size * 3)
|
|
148
|
+
d.rounded_rectangle(box, radius=26, fill=fill)
|
|
149
|
+
d.text((box[0] + 28, box[1] + 22), a.banner, font=f, fill=(255, 255, 255))
|
|
150
|
+
|
|
151
|
+
im.save(a.out)
|
|
152
|
+
print(f"saved {a.out} ({im.width}x{im.height})")
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
if __name__ == "__main__":
|
|
156
|
+
main()
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""annotate.py 的自检(不联网、不读用户图片)。用法:python3 scripts/annotate_test.py"""
|
|
4
|
+
import contextlib
|
|
5
|
+
import io
|
|
6
|
+
import os
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
10
|
+
import unittest
|
|
11
|
+
from unittest import mock
|
|
12
|
+
|
|
13
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
14
|
+
import annotate # noqa: E402
|
|
15
|
+
from PIL import Image, ImageDraw # noqa: E402
|
|
16
|
+
|
|
17
|
+
TOFU = "\u0378" # 没有任何字体会给它造字的码位:画出来就是「缺字方块」
|
|
18
|
+
NOWHERE = {"linux": [("/nonexistent/linux.ttc", 0)], "darwin": [("/nonexistent/mac.ttc", 0)],
|
|
19
|
+
"win32": [("/nonexistent/win.ttc", 0)]}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def render(font, ch):
|
|
23
|
+
im = Image.new("L", (200, 200), 0)
|
|
24
|
+
ImageDraw.Draw(im).text((10, 10), ch, font=font, fill=255) # 不指定颜色 Pillow 不上色,画出来永远是空的
|
|
25
|
+
return im.tobytes()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def draws_chinese(font):
|
|
29
|
+
"""画出来的「中」既不能是空白,也不能和缺字方块一个样"""
|
|
30
|
+
return render(font, "中") != render(font, TOFU) and render(font, "中") != Image.new("L", (200, 200), 0).tobytes()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def have_cjk_font(test):
|
|
34
|
+
cjk = annotate.find_cjk_font()
|
|
35
|
+
if not cjk:
|
|
36
|
+
test.skipTest("这台机器没有中文字体,验不了")
|
|
37
|
+
return cjk
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class ExplicitFont(unittest.TestCase):
|
|
41
|
+
def test_missing_font_file_is_an_error_not_a_silent_fallback(self):
|
|
42
|
+
# 坏法:--font 指错了文件,脚本不吭声地换回默认字体,中文画成方块
|
|
43
|
+
with self.assertRaises(SystemExit) as cm, contextlib.redirect_stderr(io.StringIO()):
|
|
44
|
+
annotate.pick_font(40, path="/nonexistent/font.ttf")
|
|
45
|
+
self.assertIn("/nonexistent/font.ttf", str(cm.exception))
|
|
46
|
+
|
|
47
|
+
def test_given_font_is_the_one_used(self):
|
|
48
|
+
# 坏法:--font 传了却被无视,仍然用自动挑的那个
|
|
49
|
+
cjk = have_cjk_font(self)[0]
|
|
50
|
+
with contextlib.redirect_stderr(io.StringIO()):
|
|
51
|
+
font = annotate.pick_font(40, path=cjk)
|
|
52
|
+
self.assertEqual(font.path, cjk)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class AutoFont(unittest.TestCase):
|
|
56
|
+
def test_no_cjk_font_anywhere_warns_and_says_how_to_fix(self):
|
|
57
|
+
# 坏法:机器上没有中文字体,脚本照样出图,中文全是方块,没人知道为什么
|
|
58
|
+
err = io.StringIO()
|
|
59
|
+
with mock.patch.object(annotate, "CJK_FONTS", NOWHERE), \
|
|
60
|
+
mock.patch.object(annotate, "NON_CJK_FALLBACK", [("/nonexistent/latin.ttf", 0)]), \
|
|
61
|
+
contextlib.redirect_stderr(err):
|
|
62
|
+
annotate.pick_font(40)
|
|
63
|
+
self.assertIn("中文字体", err.getvalue())
|
|
64
|
+
self.assertIn("--font", err.getvalue())
|
|
65
|
+
|
|
66
|
+
def test_cjk_font_wins_over_non_cjk_fallback(self):
|
|
67
|
+
# 坏法:明明有中文字体,却先用上了不带汉字的拉丁兜底字体
|
|
68
|
+
cjk = have_cjk_font(self)
|
|
69
|
+
with mock.patch.dict(annotate.CJK_FONTS, {sys.platform: [cjk]}), \
|
|
70
|
+
mock.patch.object(annotate, "NON_CJK_FALLBACK", [("/nonexistent/latin.ttf", 0)]), \
|
|
71
|
+
contextlib.redirect_stderr(io.StringIO()):
|
|
72
|
+
font = annotate.pick_font(40)
|
|
73
|
+
self.assertEqual(font.path, cjk[0])
|
|
74
|
+
|
|
75
|
+
def test_font_found_on_this_machine_really_draws_chinese(self):
|
|
76
|
+
# 坏法:挑到的「中文字体」其实画不出汉字(比如 .ttc 里挑到的是纯拉丁那一款)
|
|
77
|
+
cjk = have_cjk_font(self)
|
|
78
|
+
with contextlib.redirect_stderr(io.StringIO()):
|
|
79
|
+
font = annotate.pick_font(48)
|
|
80
|
+
self.assertTrue(draws_chinese(font), f"{cjk} 画不出「中」")
|
|
81
|
+
|
|
82
|
+
def test_quiet_when_a_cjk_font_exists(self):
|
|
83
|
+
# 坏法:有中文字体也每次嚷嚷「没找到」,把人吓一跳
|
|
84
|
+
have_cjk_font(self)
|
|
85
|
+
err = io.StringIO()
|
|
86
|
+
with contextlib.redirect_stderr(err):
|
|
87
|
+
annotate.pick_font(40)
|
|
88
|
+
self.assertEqual(err.getvalue(), "")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class MissingPillow(unittest.TestCase):
|
|
92
|
+
def test_missing_pillow_says_how_to_install(self):
|
|
93
|
+
# 坏法:没装 Pillow 时甩一段 Python 报错,agent 和用户都不知道该装什么
|
|
94
|
+
code = ("import sys, runpy; sys.modules['PIL'] = None; "
|
|
95
|
+
f"sys.argv = ['annotate.py', '--help']; runpy.run_path({os.path.join(os.path.dirname(os.path.abspath(__file__)), 'annotate.py')!r}, run_name='__main__')")
|
|
96
|
+
r = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True, timeout=60)
|
|
97
|
+
self.assertNotEqual(r.returncode, 0)
|
|
98
|
+
self.assertIn("pip install pillow", r.stderr + r.stdout)
|
|
99
|
+
self.assertNotIn("Traceback", r.stderr)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class Draw(unittest.TestCase):
|
|
103
|
+
def run_main(self, argv):
|
|
104
|
+
with mock.patch.object(sys, "argv", ["annotate.py", *argv]), \
|
|
105
|
+
contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
|
106
|
+
annotate.main()
|
|
107
|
+
|
|
108
|
+
def test_basic_annotation_keeps_image_size(self):
|
|
109
|
+
# 回归守卫:改字体逻辑时别把基本绘制弄坏
|
|
110
|
+
with tempfile.TemporaryDirectory() as d:
|
|
111
|
+
src, out = os.path.join(d, "in.png"), os.path.join(d, "out.png")
|
|
112
|
+
Image.new("RGB", (300, 200), "white").save(src)
|
|
113
|
+
self.run_main(["--src", src, "--out", out, "--circle", "150,100", "--label", "点这里",
|
|
114
|
+
"--arrow", "60,40,140,95", "--banner", "往上滑"])
|
|
115
|
+
with Image.open(out) as im:
|
|
116
|
+
self.assertEqual(im.size, (300, 200))
|
|
117
|
+
|
|
118
|
+
def test_bad_font_flag_stops_before_drawing_and_names_the_file(self):
|
|
119
|
+
# 坏法:--font 指错也照样出一张方块字的图;或者只是含糊地报「参数不认识」
|
|
120
|
+
with tempfile.TemporaryDirectory() as d:
|
|
121
|
+
src, out = os.path.join(d, "in.png"), os.path.join(d, "out.png")
|
|
122
|
+
Image.new("RGB", (300, 200), "white").save(src)
|
|
123
|
+
with self.assertRaises(SystemExit) as cm:
|
|
124
|
+
self.run_main(["--src", src, "--out", out, "--label", "点这里", "--font", "/nonexistent/font.ttf"])
|
|
125
|
+
self.assertIn("/nonexistent/font.ttf", str(cm.exception))
|
|
126
|
+
self.assertFalse(os.path.exists(out))
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if __name__ == "__main__":
|
|
130
|
+
unittest.main(verbosity=2)
|