indusagi 0.12.18 → 0.12.20
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/README.md +17 -37
- package/dist/agent/agent-loop.d.ts +3 -9
- package/dist/agent/agent-loop.d.ts.map +1 -1
- package/dist/agent/agent-loop.js +19 -58
- package/dist/agent/agent-loop.js.map +1 -1
- package/dist/agent/agent.d.ts +9 -10
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +182 -129
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/error-handler.d.ts.map +1 -1
- package/dist/agent/error-handler.js.map +1 -1
- package/dist/agent/event-bus.d.ts.map +1 -1
- package/dist/agent/event-bus.js +1 -3
- package/dist/agent/event-bus.js.map +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +0 -6
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/messages.d.ts +1 -1
- package/dist/agent/messages.d.ts.map +1 -1
- package/dist/agent/proxy.d.ts +1 -14
- package/dist/agent/proxy.d.ts.map +1 -1
- package/dist/agent/proxy.js +67 -148
- package/dist/agent/proxy.js.map +1 -1
- package/dist/agent/session-manager.d.ts +10 -10
- package/dist/agent/session-manager.d.ts.map +1 -1
- package/dist/agent/session-manager.js +20 -16
- package/dist/agent/session-manager.js.map +1 -1
- package/dist/agent/state-manager.d.ts +1 -1
- package/dist/agent/state-manager.d.ts.map +1 -1
- package/dist/agent/state-manager.js +1 -0
- package/dist/agent/state-manager.js.map +1 -1
- package/dist/agent/telemetry.d.ts.map +1 -1
- package/dist/agent/telemetry.js +1 -3
- package/dist/agent/telemetry.js.map +1 -1
- package/dist/agent/tools/bash.d.ts.map +1 -1
- package/dist/agent/tools/bash.js +143 -118
- package/dist/agent/tools/bash.js.map +1 -1
- package/dist/agent/tools/edit-diff.d.ts +1 -1
- package/dist/agent/tools/edit-diff.d.ts.map +1 -1
- package/dist/agent/tools/edit-diff.js +189 -175
- package/dist/agent/tools/edit-diff.js.map +1 -1
- package/dist/agent/tools/edit.d.ts.map +1 -1
- package/dist/agent/tools/edit.js +137 -121
- package/dist/agent/tools/edit.js.map +1 -1
- package/dist/agent/tools/find.d.ts.map +1 -1
- package/dist/agent/tools/find.js +100 -65
- package/dist/agent/tools/find.js.map +1 -1
- package/dist/agent/tools/grep.d.ts.map +1 -1
- package/dist/agent/tools/grep.js +126 -97
- package/dist/agent/tools/grep.js.map +1 -1
- package/dist/agent/tools/index.d.ts +53 -40
- package/dist/agent/tools/index.d.ts.map +1 -1
- package/dist/agent/tools/index.js +19 -12
- package/dist/agent/tools/index.js.map +1 -1
- package/dist/agent/tools/ls.d.ts +2 -1
- package/dist/agent/tools/ls.d.ts.map +1 -1
- package/dist/agent/tools/ls.js +145 -94
- package/dist/agent/tools/ls.js.map +1 -1
- package/dist/agent/tools/path-utils.d.ts.map +1 -1
- package/dist/agent/tools/path-utils.js +48 -29
- package/dist/agent/tools/path-utils.js.map +1 -1
- package/dist/agent/tools/process-controller.d.ts +15 -0
- package/dist/agent/tools/process-controller.d.ts.map +1 -0
- package/dist/agent/tools/process-controller.js +39 -0
- package/dist/agent/tools/process-controller.js.map +1 -0
- package/dist/agent/tools/process-manager.d.ts +60 -0
- package/dist/agent/tools/process-manager.d.ts.map +1 -0
- package/dist/agent/tools/process-manager.js +485 -0
- package/dist/agent/tools/process-manager.js.map +1 -0
- package/dist/agent/tools/process-types.d.ts +74 -0
- package/dist/agent/tools/process-types.d.ts.map +1 -0
- package/dist/agent/tools/process-types.js +7 -0
- package/dist/agent/tools/process-types.js.map +1 -0
- package/dist/agent/tools/process.d.ts +38 -0
- package/dist/agent/tools/process.d.ts.map +1 -0
- package/dist/agent/tools/process.js +360 -0
- package/dist/agent/tools/process.js.map +1 -0
- package/dist/agent/tools/read.d.ts.map +1 -1
- package/dist/agent/tools/read.js +157 -135
- package/dist/agent/tools/read.js.map +1 -1
- package/dist/agent/tools/registry.js +2 -4
- package/dist/agent/tools/registry.js.map +1 -1
- package/dist/agent/tools/teams/activity-tracker.d.ts +66 -0
- package/dist/agent/tools/teams/activity-tracker.d.ts.map +1 -0
- package/dist/agent/tools/teams/activity-tracker.js +480 -0
- package/dist/agent/tools/teams/activity-tracker.js.map +1 -0
- package/dist/agent/tools/teams/cleanup.d.ts +51 -0
- package/dist/agent/tools/teams/cleanup.d.ts.map +1 -0
- package/dist/agent/tools/teams/cleanup.js +219 -0
- package/dist/agent/tools/teams/cleanup.js.map +1 -0
- package/dist/agent/tools/teams/fs-lock.d.ts +12 -0
- package/dist/agent/tools/teams/fs-lock.d.ts.map +1 -0
- package/dist/agent/tools/teams/fs-lock.js +74 -0
- package/dist/agent/tools/teams/fs-lock.js.map +1 -0
- package/dist/agent/tools/teams/index.d.ts +12 -0
- package/dist/agent/tools/teams/index.d.ts.map +1 -0
- package/dist/agent/tools/teams/index.js +12 -0
- package/dist/agent/tools/teams/index.js.map +1 -0
- package/dist/agent/tools/teams/mailbox.d.ts +21 -0
- package/dist/agent/tools/teams/mailbox.d.ts.map +1 -0
- package/dist/agent/tools/teams/mailbox.js +106 -0
- package/dist/agent/tools/teams/mailbox.js.map +1 -0
- package/dist/agent/tools/teams/model-policy.d.ts +23 -0
- package/dist/agent/tools/teams/model-policy.d.ts.map +1 -0
- package/dist/agent/tools/teams/model-policy.js +113 -0
- package/dist/agent/tools/teams/model-policy.js.map +1 -0
- package/dist/agent/tools/teams/names.d.ts +28 -0
- package/dist/agent/tools/teams/names.d.ts.map +1 -0
- package/dist/agent/tools/teams/names.js +109 -0
- package/dist/agent/tools/teams/names.js.map +1 -0
- package/dist/agent/tools/teams/protocol.d.ts +75 -0
- package/dist/agent/tools/teams/protocol.d.ts.map +1 -0
- package/dist/agent/tools/teams/protocol.js +205 -0
- package/dist/agent/tools/teams/protocol.js.map +1 -0
- package/dist/agent/tools/teams/task-store.d.ts +89 -0
- package/dist/agent/tools/teams/task-store.d.ts.map +1 -0
- package/dist/agent/tools/teams/task-store.js +445 -0
- package/dist/agent/tools/teams/task-store.js.map +1 -0
- package/dist/agent/tools/teams/team-attach-claim.d.ts +36 -0
- package/dist/agent/tools/teams/team-attach-claim.d.ts.map +1 -0
- package/dist/agent/tools/teams/team-attach-claim.js +144 -0
- package/dist/agent/tools/teams/team-attach-claim.js.map +1 -0
- package/dist/agent/tools/teams/team-config.d.ts +55 -0
- package/dist/agent/tools/teams/team-config.d.ts.map +1 -0
- package/dist/agent/tools/teams/team-config.js +252 -0
- package/dist/agent/tools/teams/team-config.js.map +1 -0
- package/dist/agent/tools/teams/worktree.d.ts +40 -0
- package/dist/agent/tools/teams/worktree.d.ts.map +1 -0
- package/dist/agent/tools/teams/worktree.js +213 -0
- package/dist/agent/tools/teams/worktree.js.map +1 -0
- package/dist/agent/tools/todo-store.js +2 -1
- package/dist/agent/tools/todo-store.js.map +1 -1
- package/dist/agent/tools/todo.d.ts +2 -2
- package/dist/agent/tools/todo.js +2 -2
- package/dist/agent/tools/truncate.d.ts.map +1 -1
- package/dist/agent/tools/truncate.js +150 -134
- package/dist/agent/tools/truncate.js.map +1 -1
- package/dist/agent/tools/utils/hook-runner.d.ts +9 -10
- package/dist/agent/tools/utils/hook-runner.d.ts.map +1 -1
- package/dist/agent/tools/utils/hook-runner.js +18 -16
- package/dist/agent/tools/utils/hook-runner.js.map +1 -1
- package/dist/agent/tools/utils/image-resize.d.ts +1 -14
- package/dist/agent/tools/utils/image-resize.d.ts.map +1 -1
- package/dist/agent/tools/utils/image-resize.js +80 -34
- package/dist/agent/tools/utils/image-resize.js.map +1 -1
- package/dist/agent/tools/utils/mime.d.ts +0 -8
- package/dist/agent/tools/utils/mime.d.ts.map +1 -1
- package/dist/agent/tools/utils/mime.js +43 -32
- package/dist/agent/tools/utils/mime.js.map +1 -1
- package/dist/agent/tools/utils/shell.d.ts +1 -23
- package/dist/agent/tools/utils/shell.d.ts.map +1 -1
- package/dist/agent/tools/utils/shell.js +43 -86
- package/dist/agent/tools/utils/shell.js.map +1 -1
- package/dist/agent/tools/write.d.ts.map +1 -1
- package/dist/agent/tools/write.js +105 -62
- package/dist/agent/tools/write.js.map +1 -1
- package/dist/agent/types.d.ts +69 -64
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js +38 -23
- package/dist/agent/types.js.map +1 -1
- package/dist/agent.d.ts +4 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +4 -0
- package/dist/agent.js.map +1 -1
- package/dist/ai/api-registry.d.ts.map +1 -1
- package/dist/ai/api-registry.js +3 -4
- package/dist/ai/api-registry.js.map +1 -1
- package/dist/ai/cli.js +62 -82
- package/dist/ai/cli.js.map +1 -1
- package/dist/ai/env-api-keys.d.ts.map +1 -1
- package/dist/ai/env-api-keys.js +78 -81
- package/dist/ai/env-api-keys.js.map +1 -1
- package/dist/ai/index.d.ts +6 -0
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +6 -0
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/models.d.ts +7 -17
- package/dist/ai/models.d.ts.map +1 -1
- package/dist/ai/models.generated.d.ts +87 -244
- package/dist/ai/models.generated.d.ts.map +1 -1
- package/dist/ai/models.generated.js +82 -241
- package/dist/ai/models.generated.js.map +1 -1
- package/dist/ai/models.js +17 -11
- package/dist/ai/models.js.map +1 -1
- package/dist/ai/providers/amazon-bedrock.d.ts.map +1 -1
- package/dist/ai/providers/amazon-bedrock.js +319 -248
- package/dist/ai/providers/amazon-bedrock.js.map +1 -1
- package/dist/ai/providers/anthropic.d.ts.map +1 -1
- package/dist/ai/providers/anthropic.js +378 -324
- package/dist/ai/providers/anthropic.js.map +1 -1
- package/dist/ai/providers/azure-openai-responses.d.ts.map +1 -1
- package/dist/ai/providers/azure-openai-responses.js +164 -123
- package/dist/ai/providers/azure-openai-responses.js.map +1 -1
- package/dist/ai/providers/google-shared.d.ts +0 -18
- package/dist/ai/providers/google-shared.d.ts.map +1 -1
- package/dist/ai/providers/google-shared.js +224 -225
- package/dist/ai/providers/google-shared.js.map +1 -1
- package/dist/ai/providers/google-vertex.d.ts.map +1 -1
- package/dist/ai/providers/google-vertex.js +244 -226
- package/dist/ai/providers/google-vertex.js.map +1 -1
- package/dist/ai/providers/google.d.ts +3 -0
- package/dist/ai/providers/google.d.ts.map +1 -1
- package/dist/ai/providers/google.js +232 -210
- package/dist/ai/providers/google.js.map +1 -1
- package/dist/ai/providers/kimi.js +1 -0
- package/dist/ai/providers/kimi.js.map +1 -1
- package/dist/ai/providers/mock.d.ts +10 -0
- package/dist/ai/providers/mock.d.ts.map +1 -0
- package/dist/ai/providers/mock.js +64 -0
- package/dist/ai/providers/mock.js.map +1 -0
- package/dist/ai/providers/openai-codex-responses.d.ts.map +1 -1
- package/dist/ai/providers/openai-codex-responses.js +178 -133
- package/dist/ai/providers/openai-codex-responses.js.map +1 -1
- package/dist/ai/providers/openai-completions.d.ts.map +1 -1
- package/dist/ai/providers/openai-completions.js +468 -387
- package/dist/ai/providers/openai-completions.js.map +1 -1
- package/dist/ai/providers/openai-responses-shared.d.ts.map +1 -1
- package/dist/ai/providers/openai-responses-shared.js +187 -166
- package/dist/ai/providers/openai-responses-shared.js.map +1 -1
- package/dist/ai/providers/openai-responses.d.ts.map +1 -1
- package/dist/ai/providers/openai-responses.js +108 -85
- package/dist/ai/providers/openai-responses.js.map +1 -1
- package/dist/ai/providers/openai-scaffold.d.ts +4 -0
- package/dist/ai/providers/openai-scaffold.d.ts.map +1 -0
- package/dist/ai/providers/openai-scaffold.js +33 -0
- package/dist/ai/providers/openai-scaffold.js.map +1 -0
- package/dist/ai/providers/register-builtins.d.ts.map +1 -1
- package/dist/ai/providers/register-builtins.js +109 -42
- package/dist/ai/providers/register-builtins.js.map +1 -1
- package/dist/ai/providers/simple-options.js +2 -0
- package/dist/ai/providers/simple-options.js.map +1 -1
- package/dist/ai/providers/transform-messages.js +3 -9
- package/dist/ai/providers/transform-messages.js.map +1 -1
- package/dist/ai/stream.d.ts +4 -14
- package/dist/ai/stream.d.ts.map +1 -1
- package/dist/ai/stream.js +0 -36
- package/dist/ai/stream.js.map +1 -1
- package/dist/ai/types.d.ts +22 -3
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/types.js +154 -77
- package/dist/ai/types.js.map +1 -1
- package/dist/ai/utils/base-stream-handler.js +1 -0
- package/dist/ai/utils/base-stream-handler.js.map +1 -1
- package/dist/ai/utils/event-stream.d.ts +2 -0
- package/dist/ai/utils/event-stream.d.ts.map +1 -1
- package/dist/ai/utils/event-stream.js +22 -5
- package/dist/ai/utils/event-stream.js.map +1 -1
- package/dist/ai/utils/json-parse.d.ts +3 -0
- package/dist/ai/utils/json-parse.d.ts.map +1 -1
- package/dist/ai/utils/json-parse.js +8 -5
- package/dist/ai/utils/json-parse.js.map +1 -1
- package/dist/ai/utils/oauth/anthropic.d.ts.map +1 -1
- package/dist/ai/utils/oauth/anthropic.js +110 -65
- package/dist/ai/utils/oauth/anthropic.js.map +1 -1
- package/dist/ai/utils/oauth/github-copilot.d.ts +8 -16
- package/dist/ai/utils/oauth/github-copilot.d.ts.map +1 -1
- package/dist/ai/utils/oauth/github-copilot.js +218 -227
- package/dist/ai/utils/oauth/github-copilot.js.map +1 -1
- package/dist/ai/utils/oauth/openai-codex.d.ts +4 -2
- package/dist/ai/utils/oauth/openai-codex.d.ts.map +1 -1
- package/dist/ai/utils/oauth/openai-codex.js +221 -236
- package/dist/ai/utils/oauth/openai-codex.js.map +1 -1
- package/dist/ai/utils/oauth/pkce.d.ts +6 -5
- package/dist/ai/utils/oauth/pkce.d.ts.map +1 -1
- package/dist/ai/utils/oauth/pkce.js +24 -21
- package/dist/ai/utils/oauth/pkce.js.map +1 -1
- package/dist/ai/utils/oauth/types.d.ts +31 -12
- package/dist/ai/utils/oauth/types.d.ts.map +1 -1
- package/dist/ai/utils/oauth/types.js +10 -1
- package/dist/ai/utils/oauth/types.js.map +1 -1
- package/dist/ai/utils/overflow.d.ts.map +1 -1
- package/dist/ai/utils/overflow.js +49 -21
- package/dist/ai/utils/overflow.js.map +1 -1
- package/dist/ai/utils/provider-adapter.js +9 -0
- package/dist/ai/utils/provider-adapter.js.map +1 -1
- package/dist/ai/utils/provider-client-builder.js +1 -1
- package/dist/ai/utils/provider-client-builder.js.map +1 -1
- package/dist/ai/utils/provider-errors.js +2 -0
- package/dist/ai/utils/provider-errors.js.map +1 -1
- package/dist/ai/utils/sanitize-unicode.d.ts +0 -20
- package/dist/ai/utils/sanitize-unicode.d.ts.map +1 -1
- package/dist/ai/utils/sanitize-unicode.js +35 -17
- package/dist/ai/utils/sanitize-unicode.js.map +1 -1
- package/dist/ai/utils/stream-event-helper.js +3 -0
- package/dist/ai/utils/stream-event-helper.js.map +1 -1
- package/dist/ai/utils/stream-handler-types.js +5 -0
- package/dist/ai/utils/stream-handler-types.js.map +1 -1
- package/dist/ai/utils/streaming-state-manager.js +4 -2
- package/dist/ai/utils/streaming-state-manager.js.map +1 -1
- package/dist/ai/utils/typebox-helpers.d.ts +6 -4
- package/dist/ai/utils/typebox-helpers.d.ts.map +1 -1
- package/dist/ai/utils/typebox-helpers.js +25 -7
- package/dist/ai/utils/typebox-helpers.js.map +1 -1
- package/dist/ai/utils/validation.d.ts.map +1 -1
- package/dist/ai/utils/validation.js +67 -34
- package/dist/ai/utils/validation.js.map +1 -1
- package/dist/ai.d.ts +4 -0
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js +4 -0
- package/dist/ai.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/client-pool.js +3 -2
- package/dist/mcp/client-pool.js.map +1 -1
- package/dist/mcp/client.js +19 -6
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/config.d.ts +6 -6
- package/dist/mcp/config.js +17 -17
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/errors.js +8 -0
- package/dist/mcp/errors.js.map +1 -1
- package/dist/mcp/index.d.ts +5 -5
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/schema-converter.d.ts +1 -1
- package/dist/mcp/schema-converter.js +1 -1
- package/dist/mcp/server.d.ts +4 -4
- package/dist/mcp/server.js +12 -7
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-factory.d.ts +2 -2
- package/dist/mcp/tool-factory.js +2 -2
- package/dist/mcp.d.ts +0 -4
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +0 -4
- package/dist/mcp.js.map +1 -1
- package/dist/observability.d.ts +2 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +2 -0
- package/dist/observability.js.map +1 -0
- package/dist/tui/autocomplete.d.ts +14 -18
- package/dist/tui/autocomplete.d.ts.map +1 -1
- package/dist/tui/autocomplete.js +290 -402
- package/dist/tui/autocomplete.js.map +1 -1
- package/dist/tui/components/box.d.ts +1 -6
- package/dist/tui/components/box.d.ts.map +1 -1
- package/dist/tui/components/box.js +98 -67
- package/dist/tui/components/box.js.map +1 -1
- package/dist/tui/components/cancellable-loader.d.ts +6 -3
- package/dist/tui/components/cancellable-loader.d.ts.map +1 -1
- package/dist/tui/components/cancellable-loader.js +8 -9
- package/dist/tui/components/cancellable-loader.js.map +1 -1
- package/dist/tui/components/editor.d.ts +18 -0
- package/dist/tui/components/editor.d.ts.map +1 -1
- package/dist/tui/components/editor.js +356 -354
- package/dist/tui/components/editor.js.map +1 -1
- package/dist/tui/components/image.d.ts +2 -0
- package/dist/tui/components/image.d.ts.map +1 -1
- package/dist/tui/components/image.js +79 -37
- package/dist/tui/components/image.js.map +1 -1
- package/dist/tui/components/input.d.ts +4 -8
- package/dist/tui/components/input.d.ts.map +1 -1
- package/dist/tui/components/input.js +236 -232
- package/dist/tui/components/input.js.map +1 -1
- package/dist/tui/components/loader.d.ts +5 -5
- package/dist/tui/components/loader.d.ts.map +1 -1
- package/dist/tui/components/loader.js +22 -19
- package/dist/tui/components/loader.js.map +1 -1
- package/dist/tui/components/markdown.d.ts +2 -32
- package/dist/tui/components/markdown.d.ts.map +1 -1
- package/dist/tui/components/markdown.js +338 -357
- package/dist/tui/components/markdown.js.map +1 -1
- package/dist/tui/components/select-list.d.ts +1 -0
- package/dist/tui/components/select-list.d.ts.map +1 -1
- package/dist/tui/components/select-list.js +83 -82
- package/dist/tui/components/select-list.js.map +1 -1
- package/dist/tui/components/settings-list.d.ts +10 -10
- package/dist/tui/components/settings-list.d.ts.map +1 -1
- package/dist/tui/components/settings-list.js +48 -40
- package/dist/tui/components/settings-list.js.map +1 -1
- package/dist/tui/components/spacer.d.ts +1 -0
- package/dist/tui/components/spacer.d.ts.map +1 -1
- package/dist/tui/components/spacer.js +20 -5
- package/dist/tui/components/spacer.js.map +1 -1
- package/dist/tui/components/text.d.ts.map +1 -1
- package/dist/tui/components/text.js +47 -20
- package/dist/tui/components/text.js.map +1 -1
- package/dist/tui/components/truncated-text.d.ts +8 -4
- package/dist/tui/components/truncated-text.d.ts.map +1 -1
- package/dist/tui/components/truncated-text.js +15 -12
- package/dist/tui/components/truncated-text.js.map +1 -1
- package/dist/tui/editor-component.d.ts +87 -23
- package/dist/tui/editor-component.d.ts.map +1 -1
- package/dist/tui/fuzzy.d.ts.map +1 -1
- package/dist/tui/fuzzy.js +101 -50
- package/dist/tui/fuzzy.js.map +1 -1
- package/dist/tui/keybindings.d.ts +3 -3
- package/dist/tui/keybindings.d.ts.map +1 -1
- package/dist/tui/keybindings.js +137 -111
- package/dist/tui/keybindings.js.map +1 -1
- package/dist/tui/keys.d.ts +46 -43
- package/dist/tui/keys.d.ts.map +1 -1
- package/dist/tui/keys.js +493 -411
- package/dist/tui/keys.js.map +1 -1
- package/dist/tui/stdin-buffer.d.ts.map +1 -1
- package/dist/tui/stdin-buffer.js +162 -159
- package/dist/tui/stdin-buffer.js.map +1 -1
- package/dist/tui/terminal-image.d.ts +10 -5
- package/dist/tui/terminal-image.d.ts.map +1 -1
- package/dist/tui/terminal-image.js +53 -51
- package/dist/tui/terminal-image.js.map +1 -1
- package/dist/tui/terminal.d.ts +4 -27
- package/dist/tui/terminal.d.ts.map +1 -1
- package/dist/tui/terminal.js +123 -121
- package/dist/tui/terminal.js.map +1 -1
- package/dist/tui/tui.d.ts +14 -1
- package/dist/tui/tui.d.ts.map +1 -1
- package/dist/tui/tui.js +185 -145
- package/dist/tui/tui.js.map +1 -1
- package/dist/tui/utils.d.ts.map +1 -1
- package/dist/tui/utils.js +235 -216
- package/dist/tui/utils.js.map +1 -1
- package/dist/tui.d.ts +4 -0
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +4 -0
- package/dist/tui.js.map +1 -1
- package/package.json +23 -43
- package/LICENSE.md +0 -22
- package/dist/agent/tools/task-types.d.ts +0 -74
- package/dist/agent/tools/task-types.d.ts.map +0 -1
- package/dist/agent/tools/task-types.js +0 -8
- package/dist/agent/tools/task-types.js.map +0 -1
- package/dist/agent/tools/task.d.ts +0 -84
- package/dist/agent/tools/task.d.ts.map +0 -1
- package/dist/agent/tools/task.js +0 -184
- package/dist/agent/tools/task.js.map +0 -1
- package/dist/memory/embedder/base.d.ts +0 -41
- package/dist/memory/embedder/base.d.ts.map +0 -1
- package/dist/memory/embedder/base.js +0 -10
- package/dist/memory/embedder/base.js.map +0 -1
- package/dist/memory/embedder/index.d.ts +0 -8
- package/dist/memory/embedder/index.d.ts.map +0 -1
- package/dist/memory/embedder/index.js +0 -6
- package/dist/memory/embedder/index.js.map +0 -1
- package/dist/memory/embedder/openai.d.ts +0 -35
- package/dist/memory/embedder/openai.d.ts.map +0 -1
- package/dist/memory/embedder/openai.js +0 -103
- package/dist/memory/embedder/openai.js.map +0 -1
- package/dist/memory/index.d.ts +0 -33
- package/dist/memory/index.d.ts.map +0 -1
- package/dist/memory/index.js +0 -31
- package/dist/memory/index.js.map +0 -1
- package/dist/memory/memory.d.ts +0 -126
- package/dist/memory/memory.d.ts.map +0 -1
- package/dist/memory/memory.js +0 -280
- package/dist/memory/memory.js.map +0 -1
- package/dist/memory/processors/base.d.ts +0 -42
- package/dist/memory/processors/base.d.ts.map +0 -1
- package/dist/memory/processors/base.js +0 -6
- package/dist/memory/processors/base.js.map +0 -1
- package/dist/memory/processors/index.d.ts +0 -16
- package/dist/memory/processors/index.d.ts.map +0 -1
- package/dist/memory/processors/index.js +0 -18
- package/dist/memory/processors/index.js.map +0 -1
- package/dist/memory/processors/message-history.d.ts +0 -35
- package/dist/memory/processors/message-history.d.ts.map +0 -1
- package/dist/memory/processors/message-history.js +0 -51
- package/dist/memory/processors/message-history.js.map +0 -1
- package/dist/memory/processors/observational-memory/index.d.ts +0 -82
- package/dist/memory/processors/observational-memory/index.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/index.js +0 -234
- package/dist/memory/processors/observational-memory/index.js.map +0 -1
- package/dist/memory/processors/observational-memory/observer-agent.d.ts +0 -64
- package/dist/memory/processors/observational-memory/observer-agent.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/observer-agent.js +0 -362
- package/dist/memory/processors/observational-memory/observer-agent.js.map +0 -1
- package/dist/memory/processors/observational-memory/reflector-agent.d.ts +0 -38
- package/dist/memory/processors/observational-memory/reflector-agent.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/reflector-agent.js +0 -213
- package/dist/memory/processors/observational-memory/reflector-agent.js.map +0 -1
- package/dist/memory/processors/observational-memory/token-counter.d.ts +0 -35
- package/dist/memory/processors/observational-memory/token-counter.d.ts.map +0 -1
- package/dist/memory/processors/observational-memory/token-counter.js +0 -90
- package/dist/memory/processors/observational-memory/token-counter.js.map +0 -1
- package/dist/memory/processors/semantic-recall.d.ts +0 -55
- package/dist/memory/processors/semantic-recall.d.ts.map +0 -1
- package/dist/memory/processors/semantic-recall.js +0 -143
- package/dist/memory/processors/semantic-recall.js.map +0 -1
- package/dist/memory/processors/working-memory.d.ts +0 -41
- package/dist/memory/processors/working-memory.d.ts.map +0 -1
- package/dist/memory/processors/working-memory.js +0 -82
- package/dist/memory/processors/working-memory.js.map +0 -1
- package/dist/memory/storage/base.d.ts +0 -288
- package/dist/memory/storage/base.d.ts.map +0 -1
- package/dist/memory/storage/base.js +0 -211
- package/dist/memory/storage/base.js.map +0 -1
- package/dist/memory/storage/index.d.ts +0 -9
- package/dist/memory/storage/index.d.ts.map +0 -1
- package/dist/memory/storage/index.js +0 -7
- package/dist/memory/storage/index.js.map +0 -1
- package/dist/memory/storage/inmemory.d.ts +0 -93
- package/dist/memory/storage/inmemory.d.ts.map +0 -1
- package/dist/memory/storage/inmemory.js +0 -646
- package/dist/memory/storage/inmemory.js.map +0 -1
- package/dist/memory/tools/working-memory.d.ts +0 -100
- package/dist/memory/tools/working-memory.d.ts.map +0 -1
- package/dist/memory/tools/working-memory.js +0 -237
- package/dist/memory/tools/working-memory.js.map +0 -1
- package/dist/memory/types.d.ts +0 -386
- package/dist/memory/types.d.ts.map +0 -1
- package/dist/memory/types.js +0 -58
- package/dist/memory/types.js.map +0 -1
- package/dist/memory/vector/base.d.ts +0 -145
- package/dist/memory/vector/base.d.ts.map +0 -1
- package/dist/memory/vector/base.js +0 -83
- package/dist/memory/vector/base.js.map +0 -1
- package/dist/memory/vector/index.d.ts +0 -8
- package/dist/memory/vector/index.d.ts.map +0 -1
- package/dist/memory/vector/index.js +0 -7
- package/dist/memory/vector/index.js.map +0 -1
- package/dist/memory/vector/inmemory.d.ts +0 -47
- package/dist/memory/vector/inmemory.d.ts.map +0 -1
- package/dist/memory/vector/inmemory.js +0 -234
- package/dist/memory/vector/inmemory.js.map +0 -1
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Observational Memory Processor
|
|
3
|
-
* Based on Mastra ObservationalMemory
|
|
4
|
-
*/
|
|
5
|
-
import { TokenCounter } from "./token-counter.js";
|
|
6
|
-
import { buildObserverSystemPrompt, buildObserverPrompt, parseObserverOutput, } from "./observer-agent.js";
|
|
7
|
-
import { buildReflectorSystemPrompt, buildReflectorPrompt, parseReflectorOutput, validateCompression, } from "./reflector-agent.js";
|
|
8
|
-
/**
|
|
9
|
-
* Default observational memory configuration
|
|
10
|
-
*/
|
|
11
|
-
export const OBSERVATIONAL_MEMORY_DEFAULTS = {
|
|
12
|
-
observation: {
|
|
13
|
-
model: "google/gemini-2.5-flash",
|
|
14
|
-
messageTokens: 30_000,
|
|
15
|
-
modelSettings: { temperature: 0.3, maxOutputTokens: 100_000 },
|
|
16
|
-
maxTokensPerBatch: 10_000,
|
|
17
|
-
bufferTokens: 0.2,
|
|
18
|
-
bufferActivation: 0.8,
|
|
19
|
-
},
|
|
20
|
-
reflection: {
|
|
21
|
-
model: "google/gemini-2.5-flash",
|
|
22
|
-
observationTokens: 40_000,
|
|
23
|
-
modelSettings: { temperature: 0, maxOutputTokens: 100_000 },
|
|
24
|
-
bufferActivation: 0.5,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Continuation hint for observation batches
|
|
29
|
-
*/
|
|
30
|
-
export const OBSERVATION_CONTINUATION_HINT = `This message is not from the user...`;
|
|
31
|
-
/**
|
|
32
|
-
* Observational Memory Processor
|
|
33
|
-
*
|
|
34
|
-
* Implements a three-tier memory system:
|
|
35
|
-
* 1. Observer: Extracts observations from messages
|
|
36
|
-
* 2. Reflector: Consolidates observations when they grow too large
|
|
37
|
-
* 3. Actor: Uses observations as context for responses
|
|
38
|
-
*/
|
|
39
|
-
export class ObservationalMemory {
|
|
40
|
-
constructor(config) {
|
|
41
|
-
this.id = "observational-memory";
|
|
42
|
-
this.name = "Observational Memory Processor";
|
|
43
|
-
this.storage = config.storage;
|
|
44
|
-
this.config = config.config;
|
|
45
|
-
this.model = config.model;
|
|
46
|
-
this.callLLM = config.callLLM;
|
|
47
|
-
this.tokenCounter = new TokenCounter();
|
|
48
|
-
}
|
|
49
|
-
// ========================================================================
|
|
50
|
-
// Input Processing
|
|
51
|
-
// ========================================================================
|
|
52
|
-
async processInputStep(args) {
|
|
53
|
-
const { messages, context } = args;
|
|
54
|
-
// Get or initialize observational memory record
|
|
55
|
-
const record = await this.getOrCreateRecord(context);
|
|
56
|
-
// Build context with observations
|
|
57
|
-
const contextMessages = [];
|
|
58
|
-
// Add observations if available
|
|
59
|
-
if (record.activeObservations) {
|
|
60
|
-
const observationsMessage = {
|
|
61
|
-
id: `observations-${Date.now()}`,
|
|
62
|
-
role: "system",
|
|
63
|
-
content: `<observational_memory>\n${record.activeObservations}\n</observational_memory>`,
|
|
64
|
-
createdAt: new Date(),
|
|
65
|
-
};
|
|
66
|
-
contextMessages.push(observationsMessage);
|
|
67
|
-
}
|
|
68
|
-
// Get recent messages from storage
|
|
69
|
-
const { messages: storedMessages } = await this.storage.listMessages({
|
|
70
|
-
threadId: context.threadId,
|
|
71
|
-
perPage: 50,
|
|
72
|
-
orderBy: { field: "createdAt", direction: "DESC" },
|
|
73
|
-
});
|
|
74
|
-
// Reverse to get chronological order
|
|
75
|
-
const chronologicalMessages = storedMessages.reverse();
|
|
76
|
-
// Combine: observations + stored messages + new messages
|
|
77
|
-
return [...contextMessages, ...chronologicalMessages, ...messages];
|
|
78
|
-
}
|
|
79
|
-
// ========================================================================
|
|
80
|
-
// Output Processing
|
|
81
|
-
// ========================================================================
|
|
82
|
-
async processOutputResult(args) {
|
|
83
|
-
const { messages, context } = args;
|
|
84
|
-
// Check if read-only
|
|
85
|
-
if (context.memoryConfig?.readOnly) {
|
|
86
|
-
return messages;
|
|
87
|
-
}
|
|
88
|
-
// Save new messages
|
|
89
|
-
await this.storage.saveMessages({ messages });
|
|
90
|
-
// Check if observation is needed
|
|
91
|
-
const record = await this.getOrCreateRecord(context);
|
|
92
|
-
const newTokens = this.tokenCounter.countMessages(messages);
|
|
93
|
-
const totalPendingTokens = record.pendingMessageTokens + newTokens;
|
|
94
|
-
const observationConfig = this.getObservationConfig();
|
|
95
|
-
const threshold = observationConfig.messageTokens ?? 30_000;
|
|
96
|
-
if (totalPendingTokens >= threshold) {
|
|
97
|
-
// Trigger observation
|
|
98
|
-
await this.runObservation(context, record, totalPendingTokens);
|
|
99
|
-
}
|
|
100
|
-
return messages;
|
|
101
|
-
}
|
|
102
|
-
// ========================================================================
|
|
103
|
-
// Observation
|
|
104
|
-
// ========================================================================
|
|
105
|
-
async runObservation(context, record, pendingTokens) {
|
|
106
|
-
const observationConfig = this.getObservationConfig();
|
|
107
|
-
// Get unobserved messages
|
|
108
|
-
const { messages } = await this.storage.listMessages({
|
|
109
|
-
threadId: context.threadId,
|
|
110
|
-
perPage: 100,
|
|
111
|
-
});
|
|
112
|
-
// Build prompt
|
|
113
|
-
const systemPrompt = buildObserverSystemPrompt(false, observationConfig.instruction);
|
|
114
|
-
const userPrompt = buildObserverPrompt(record.activeObservations || undefined, messages);
|
|
115
|
-
// Call LLM
|
|
116
|
-
if (!this.callLLM) {
|
|
117
|
-
console.warn("ObservationalMemory: No LLM call function provided, skipping observation");
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
const output = await this.callLLM({
|
|
122
|
-
systemPrompt,
|
|
123
|
-
userPrompt,
|
|
124
|
-
model: observationConfig.model ?? this.model,
|
|
125
|
-
modelSettings: observationConfig.modelSettings,
|
|
126
|
-
});
|
|
127
|
-
const result = parseObserverOutput(output);
|
|
128
|
-
if (result.degenerate) {
|
|
129
|
-
console.warn("ObservationalMemory: Degenerate output detected, skipping");
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
// Update record with new observations
|
|
133
|
-
const newObservations = record.activeObservations
|
|
134
|
-
? `${record.activeObservations}\n\n${result.observations}`
|
|
135
|
-
: result.observations;
|
|
136
|
-
const newTokenCount = this.tokenCounter.countObservations(newObservations);
|
|
137
|
-
await this.storage.updateActiveObservations({
|
|
138
|
-
id: record.id,
|
|
139
|
-
observations: newObservations,
|
|
140
|
-
tokenCount: newTokenCount,
|
|
141
|
-
lastObservedAt: new Date(),
|
|
142
|
-
});
|
|
143
|
-
// Check if reflection is needed
|
|
144
|
-
const reflectionConfig = this.getReflectionConfig();
|
|
145
|
-
const reflectionThreshold = reflectionConfig.observationTokens ?? 40_000;
|
|
146
|
-
if (newTokenCount >= reflectionThreshold) {
|
|
147
|
-
await this.runReflection(context, newObservations);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
console.error("ObservationalMemory: Observation failed:", error);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// ========================================================================
|
|
155
|
-
// Reflection
|
|
156
|
-
// ========================================================================
|
|
157
|
-
async runReflection(context, observations) {
|
|
158
|
-
const reflectionConfig = this.getReflectionConfig();
|
|
159
|
-
if (!this.callLLM) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const systemPrompt = buildReflectorSystemPrompt(reflectionConfig.instruction);
|
|
163
|
-
const userPrompt = buildReflectorPrompt(observations);
|
|
164
|
-
try {
|
|
165
|
-
let output = await this.callLLM({
|
|
166
|
-
systemPrompt,
|
|
167
|
-
userPrompt,
|
|
168
|
-
model: reflectionConfig.model ?? this.model,
|
|
169
|
-
modelSettings: reflectionConfig.modelSettings,
|
|
170
|
-
});
|
|
171
|
-
let result = parseReflectorOutput(output);
|
|
172
|
-
// Try compression if needed
|
|
173
|
-
const targetThreshold = reflectionConfig.observationTokens ?? 40_000;
|
|
174
|
-
let compressionLevel = 0;
|
|
175
|
-
while (!result.degenerate &&
|
|
176
|
-
compressionLevel < 3 &&
|
|
177
|
-
!validateCompression(this.tokenCounter.countObservations(result.observations), targetThreshold)) {
|
|
178
|
-
compressionLevel = Math.min(3, compressionLevel + 1);
|
|
179
|
-
const retryPrompt = buildReflectorPrompt(observations, undefined, compressionLevel);
|
|
180
|
-
output = await this.callLLM({
|
|
181
|
-
systemPrompt,
|
|
182
|
-
userPrompt: retryPrompt,
|
|
183
|
-
model: reflectionConfig.model ?? this.model,
|
|
184
|
-
modelSettings: reflectionConfig.modelSettings,
|
|
185
|
-
});
|
|
186
|
-
result = parseReflectorOutput(output);
|
|
187
|
-
}
|
|
188
|
-
if (result.degenerate) {
|
|
189
|
-
console.warn("ObservationalMemory: Degenerate reflection output, keeping original observations");
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
// Create new generation with reflected observations
|
|
193
|
-
const record = await this.getOrCreateRecord(context);
|
|
194
|
-
await this.storage.createReflectionGeneration({
|
|
195
|
-
currentRecord: record,
|
|
196
|
-
reflection: result.observations,
|
|
197
|
-
tokenCount: this.tokenCounter.countObservations(result.observations),
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
catch (error) {
|
|
201
|
-
console.error("ObservationalMemory: Reflection failed:", error);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
// ========================================================================
|
|
205
|
-
// Helpers
|
|
206
|
-
// ========================================================================
|
|
207
|
-
async getOrCreateRecord(context) {
|
|
208
|
-
const scope = this.config.scope ?? "thread";
|
|
209
|
-
const threadId = scope === "thread" ? context.threadId : null;
|
|
210
|
-
let record = await this.storage.getObservationalMemory(threadId, context.resourceId);
|
|
211
|
-
if (!record) {
|
|
212
|
-
record = await this.storage.initializeObservationalMemory({
|
|
213
|
-
threadId,
|
|
214
|
-
resourceId: context.resourceId,
|
|
215
|
-
scope,
|
|
216
|
-
config: this.config,
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
return record;
|
|
220
|
-
}
|
|
221
|
-
getObservationConfig() {
|
|
222
|
-
return {
|
|
223
|
-
...OBSERVATIONAL_MEMORY_DEFAULTS.observation,
|
|
224
|
-
...this.config.observation,
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
getReflectionConfig() {
|
|
228
|
-
return {
|
|
229
|
-
...OBSERVATIONAL_MEMORY_DEFAULTS.reflection,
|
|
230
|
-
...this.config.reflection,
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":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AsB,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;QAErF,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,6BAA6B,CAAC;gBACxD,QAAQ;gBACR,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,KAAK;gBACL,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,oBAAoB;QAC1B,OAAO;YACL,GAAG,6BAA6B,CAAC,WAAW;YAC5C,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW;SAC3B,CAAC;IACJ,CAAC;IAEO,mBAAmB;QACzB,OAAO;YACL,GAAG,6BAA6B,CAAC,UAAU;YAC3C,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU;SAC1B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Observer Agent - Prompts and Parsing
|
|
3
|
-
* Based on Mastra ObserverAgent
|
|
4
|
-
*/
|
|
5
|
-
import type { CoreMessage } from "../../types.js";
|
|
6
|
-
/**
|
|
7
|
-
* Core extraction instructions for the Observer
|
|
8
|
-
*/
|
|
9
|
-
export declare const OBSERVER_EXTRACTION_INSTRUCTIONS = "CRITICAL: DISTINGUISH USER ASSERTIONS FROM QUESTIONS\n\nWhen the user TELLS you something about themselves, mark it as an assertion:\n- \"I have two kids\" \u2192 \uD83D\uDD34 (14:30) User stated has two kids\n- \"I work at Acme Corp\" \u2192 \uD83D\uDD34 (14:31) User stated works at Acme Corp\n\nWhen the user ASKS about something, mark it as a question/request:\n- \"Can you help me with X?\" \u2192 \uD83D\uDD34 (15:00) User asked help with X\n- \"What's the best way to do Y?\" \u2192 \uD83D\uDD34 (15:01) User asked best way to do Y\n\nSTATE CHANGES AND UPDATES:\nWhen a user indicates they are changing something, frame it as a state change:\n- \"I'm going to start doing X instead of Y\" \u2192 \"User will start doing X (changing from Y)\"\n- \"I'm switching from A to B\" \u2192 \"User is switching from A to B\"\n\nTEMPORAL ANCHORING:\nEach observation has TWO potential timestamps:\n1. BEGINNING: The time the statement was made - ALWAYS include this\n2. END: The time being REFERENCED, if different - ONLY when there's a relative time reference\n\nFORMAT:\n- With time reference: (TIME) [observation]. (meaning/estimated DATE)\n- Without time reference: (TIME) [observation].\n\nCONVERSATION CONTEXT:\n- What the user is working on or asking about\n- Previous topics and their outcomes\n- User preferences (likes, dislikes, etc.)\n- Any specifically formatted text that needs to be reproduced later\n- When who/what/where/when is mentioned, note all details\n\nUSER MESSAGE CAPTURE:\n- Short and medium-length user messages should be captured nearly verbatim\n- For very long user messages, summarize but quote key phrases\n\nAVOIDING REPETITIVE OBSERVATIONS:\n- Do NOT repeat the same observation across multiple turns\n- Group repeated similar actions into a single parent observation";
|
|
10
|
-
/**
|
|
11
|
-
* Output format for Observer
|
|
12
|
-
*/
|
|
13
|
-
export declare const OBSERVER_OUTPUT_FORMAT_BASE = "Use priority levels:\n- \uD83D\uDD34 High: explicit user facts, preferences, goals achieved, critical context\n- \uD83D\uDFE1 Medium: project details, learned information, tool results\n- \uD83D\uDFE2 Low: minor details, uncertain observations\n\nGroup related observations by indenting:\n* \uD83D\uDD34 (14:33) Agent debugging auth issue\n * -> ran git status, found 3 modified files\n * -> viewed auth.ts, found missing null check\n\nGroup observations by date, then list each with 24-hour time.\n\n<observations>\nDate: Dec 4, 2025\n* \uD83D\uDD34 (14:30) User prefers direct answers\n* \uD83D\uDD34 (14:31) Working on feature X\n* \uD83D\uDFE1 (14:32) User might prefer dark mode\n\nDate: Dec 5, 2025\n* \uD83D\uDD34 (09:15) Continued work on feature X\n</observations>\n\n<current-task>\nState the current task(s) explicitly.\n</current-task>\n\n<suggested-response>\nHint for the agent's immediate next message.\n</suggested-response>";
|
|
14
|
-
/**
|
|
15
|
-
* Observer guidelines
|
|
16
|
-
*/
|
|
17
|
-
export declare const OBSERVER_GUIDELINES = "- Be specific enough for the assistant to act on\n- Add 1 to 5 observations per exchange\n- Use terse language to save tokens\n- Do not add repetitive observations\n- If the agent calls tools, observe what was called and what was learned\n- Make sure you start each observation with a priority emoji (\uD83D\uDD34, \uD83D\uDFE1, \uD83D\uDFE2)\n- User messages are always \uD83D\uDD34 priority";
|
|
18
|
-
/**
|
|
19
|
-
* Result from Observer agent
|
|
20
|
-
*/
|
|
21
|
-
export interface ObserverResult {
|
|
22
|
-
observations: string;
|
|
23
|
-
currentTask?: string;
|
|
24
|
-
suggestedContinuation?: string;
|
|
25
|
-
rawOutput?: string;
|
|
26
|
-
degenerate?: boolean;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Build the Observer system prompt
|
|
30
|
-
*/
|
|
31
|
-
export declare function buildObserverSystemPrompt(multiThread?: boolean, instruction?: string): string;
|
|
32
|
-
/**
|
|
33
|
-
* Default Observer system prompt
|
|
34
|
-
*/
|
|
35
|
-
export declare const OBSERVER_SYSTEM_PROMPT: string;
|
|
36
|
-
/**
|
|
37
|
-
* Format messages for Observer input
|
|
38
|
-
*/
|
|
39
|
-
export declare function formatMessagesForObserver(messages: CoreMessage[], options?: {
|
|
40
|
-
maxPartLength?: number;
|
|
41
|
-
}): string;
|
|
42
|
-
/**
|
|
43
|
-
* Build the Observer prompt
|
|
44
|
-
*/
|
|
45
|
-
export declare function buildObserverPrompt(existingObservations: string | undefined, messagesToObserve: CoreMessage[], options?: {
|
|
46
|
-
skipContinuationHints?: boolean;
|
|
47
|
-
}): string;
|
|
48
|
-
/**
|
|
49
|
-
* Parse Observer output
|
|
50
|
-
*/
|
|
51
|
-
export declare function parseObserverOutput(output: string): ObserverResult;
|
|
52
|
-
/**
|
|
53
|
-
* Truncate observation lines that exceed max length
|
|
54
|
-
*/
|
|
55
|
-
export declare function sanitizeObservationLines(observations: string): string;
|
|
56
|
-
/**
|
|
57
|
-
* Detect degenerate repetition in output
|
|
58
|
-
*/
|
|
59
|
-
export declare function detectDegenerateRepetition(text: string): boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Optimize observations for token efficiency
|
|
62
|
-
*/
|
|
63
|
-
export declare function optimizeObservationsForContext(observations: string): string;
|
|
64
|
-
//# sourceMappingURL=observer-agent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observer-agent.d.ts","sourceRoot":"","sources":["../../../../src/memory/processors/observational-memory/observer-agent.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,gCAAgC,4wDAqCqB,CAAC;AAEnE;;GAEG;AACH,eAAO,MAAM,2BAA2B,m7BA4BlB,CAAC;AAEvB;;GAEG;AACH,eAAO,MAAM,mBAAmB,6YAMO,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,GAAE,OAAe,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CA0DpG;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,QAA8B,CAAC;AAElE;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CA8C/G;AAUD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,oBAAoB,EAAE,MAAM,GAAG,SAAS,EACxC,iBAAiB,EAAE,WAAW,EAAE,EAChC,OAAO,CAAC,EAAE;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5C,MAAM,CAoBR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,CAmBlE;AAqED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAWrE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CA4BhE;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAoB3E"}
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Observer Agent - Prompts and Parsing
|
|
3
|
-
* Based on Mastra ObserverAgent
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Core extraction instructions for the Observer
|
|
7
|
-
*/
|
|
8
|
-
export const OBSERVER_EXTRACTION_INSTRUCTIONS = `CRITICAL: DISTINGUISH USER ASSERTIONS FROM QUESTIONS
|
|
9
|
-
|
|
10
|
-
When the user TELLS you something about themselves, mark it as an assertion:
|
|
11
|
-
- "I have two kids" → 🔴 (14:30) User stated has two kids
|
|
12
|
-
- "I work at Acme Corp" → 🔴 (14:31) User stated works at Acme Corp
|
|
13
|
-
|
|
14
|
-
When the user ASKS about something, mark it as a question/request:
|
|
15
|
-
- "Can you help me with X?" → 🔴 (15:00) User asked help with X
|
|
16
|
-
- "What's the best way to do Y?" → 🔴 (15:01) User asked best way to do Y
|
|
17
|
-
|
|
18
|
-
STATE CHANGES AND UPDATES:
|
|
19
|
-
When a user indicates they are changing something, frame it as a state change:
|
|
20
|
-
- "I'm going to start doing X instead of Y" → "User will start doing X (changing from Y)"
|
|
21
|
-
- "I'm switching from A to B" → "User is switching from A to B"
|
|
22
|
-
|
|
23
|
-
TEMPORAL ANCHORING:
|
|
24
|
-
Each observation has TWO potential timestamps:
|
|
25
|
-
1. BEGINNING: The time the statement was made - ALWAYS include this
|
|
26
|
-
2. END: The time being REFERENCED, if different - ONLY when there's a relative time reference
|
|
27
|
-
|
|
28
|
-
FORMAT:
|
|
29
|
-
- With time reference: (TIME) [observation]. (meaning/estimated DATE)
|
|
30
|
-
- Without time reference: (TIME) [observation].
|
|
31
|
-
|
|
32
|
-
CONVERSATION CONTEXT:
|
|
33
|
-
- What the user is working on or asking about
|
|
34
|
-
- Previous topics and their outcomes
|
|
35
|
-
- User preferences (likes, dislikes, etc.)
|
|
36
|
-
- Any specifically formatted text that needs to be reproduced later
|
|
37
|
-
- When who/what/where/when is mentioned, note all details
|
|
38
|
-
|
|
39
|
-
USER MESSAGE CAPTURE:
|
|
40
|
-
- Short and medium-length user messages should be captured nearly verbatim
|
|
41
|
-
- For very long user messages, summarize but quote key phrases
|
|
42
|
-
|
|
43
|
-
AVOIDING REPETITIVE OBSERVATIONS:
|
|
44
|
-
- Do NOT repeat the same observation across multiple turns
|
|
45
|
-
- Group repeated similar actions into a single parent observation`;
|
|
46
|
-
/**
|
|
47
|
-
* Output format for Observer
|
|
48
|
-
*/
|
|
49
|
-
export const OBSERVER_OUTPUT_FORMAT_BASE = `Use priority levels:
|
|
50
|
-
- 🔴 High: explicit user facts, preferences, goals achieved, critical context
|
|
51
|
-
- 🟡 Medium: project details, learned information, tool results
|
|
52
|
-
- 🟢 Low: minor details, uncertain observations
|
|
53
|
-
|
|
54
|
-
Group related observations by indenting:
|
|
55
|
-
* 🔴 (14:33) Agent debugging auth issue
|
|
56
|
-
* -> ran git status, found 3 modified files
|
|
57
|
-
* -> viewed auth.ts, found missing null check
|
|
58
|
-
|
|
59
|
-
Group observations by date, then list each with 24-hour time.
|
|
60
|
-
|
|
61
|
-
<observations>
|
|
62
|
-
Date: Dec 4, 2025
|
|
63
|
-
* 🔴 (14:30) User prefers direct answers
|
|
64
|
-
* 🔴 (14:31) Working on feature X
|
|
65
|
-
* 🟡 (14:32) User might prefer dark mode
|
|
66
|
-
|
|
67
|
-
Date: Dec 5, 2025
|
|
68
|
-
* 🔴 (09:15) Continued work on feature X
|
|
69
|
-
</observations>
|
|
70
|
-
|
|
71
|
-
<current-task>
|
|
72
|
-
State the current task(s) explicitly.
|
|
73
|
-
</current-task>
|
|
74
|
-
|
|
75
|
-
<suggested-response>
|
|
76
|
-
Hint for the agent's immediate next message.
|
|
77
|
-
</suggested-response>`;
|
|
78
|
-
/**
|
|
79
|
-
* Observer guidelines
|
|
80
|
-
*/
|
|
81
|
-
export const OBSERVER_GUIDELINES = `- Be specific enough for the assistant to act on
|
|
82
|
-
- Add 1 to 5 observations per exchange
|
|
83
|
-
- Use terse language to save tokens
|
|
84
|
-
- Do not add repetitive observations
|
|
85
|
-
- If the agent calls tools, observe what was called and what was learned
|
|
86
|
-
- Make sure you start each observation with a priority emoji (🔴, 🟡, 🟢)
|
|
87
|
-
- User messages are always 🔴 priority`;
|
|
88
|
-
/**
|
|
89
|
-
* Build the Observer system prompt
|
|
90
|
-
*/
|
|
91
|
-
export function buildObserverSystemPrompt(multiThread = false, instruction) {
|
|
92
|
-
const outputFormat = OBSERVER_OUTPUT_FORMAT_BASE;
|
|
93
|
-
if (multiThread) {
|
|
94
|
-
return `You are the memory consciousness of an AI assistant. Your observations will be the ONLY information the assistant has about past interactions with this user.
|
|
95
|
-
|
|
96
|
-
Extract observations that will help the assistant remember:
|
|
97
|
-
|
|
98
|
-
${OBSERVER_EXTRACTION_INSTRUCTIONS}
|
|
99
|
-
|
|
100
|
-
=== MULTI-THREAD INPUT ===
|
|
101
|
-
|
|
102
|
-
You will receive messages from MULTIPLE conversation threads, each wrapped in <thread id="..."> tags.
|
|
103
|
-
Process each thread separately and output observations for each thread.
|
|
104
|
-
|
|
105
|
-
=== OUTPUT FORMAT ===
|
|
106
|
-
|
|
107
|
-
<observations>
|
|
108
|
-
<thread id="thread_id_1">
|
|
109
|
-
Date: Dec 4, 2025
|
|
110
|
-
* 🔴 (14:30) User prefers direct answers
|
|
111
|
-
|
|
112
|
-
<current-task>
|
|
113
|
-
What the agent is currently working on
|
|
114
|
-
</current-task>
|
|
115
|
-
|
|
116
|
-
<suggested-response>
|
|
117
|
-
Hint for the agent's next message
|
|
118
|
-
</suggested-response>
|
|
119
|
-
</thread>
|
|
120
|
-
</observations>
|
|
121
|
-
|
|
122
|
-
Use priority levels: 🔴 High, 🟡 Medium, 🟢 Low
|
|
123
|
-
|
|
124
|
-
=== GUIDELINES ===
|
|
125
|
-
|
|
126
|
-
${OBSERVER_GUIDELINES}
|
|
127
|
-
|
|
128
|
-
Remember: These observations are the assistant's ONLY memory. Make them count.${instruction ? `\n\n=== CUSTOM INSTRUCTIONS ===\n\n${instruction}` : ""}`;
|
|
129
|
-
}
|
|
130
|
-
return `You are the memory consciousness of an AI assistant. Your observations will be the ONLY information the assistant has about past interactions with this user.
|
|
131
|
-
|
|
132
|
-
Extract observations that will help the assistant remember:
|
|
133
|
-
|
|
134
|
-
${OBSERVER_EXTRACTION_INSTRUCTIONS}
|
|
135
|
-
|
|
136
|
-
=== OUTPUT FORMAT ===
|
|
137
|
-
|
|
138
|
-
Your output MUST use XML tags to structure the response.
|
|
139
|
-
|
|
140
|
-
${outputFormat}
|
|
141
|
-
|
|
142
|
-
=== GUIDELINES ===
|
|
143
|
-
|
|
144
|
-
${OBSERVER_GUIDELINES}
|
|
145
|
-
|
|
146
|
-
Remember: These observations are the assistant's ONLY memory. Make them count.${instruction ? `\n\n=== CUSTOM INSTRUCTIONS ===\n\n${instruction}` : ""}`;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Default Observer system prompt
|
|
150
|
-
*/
|
|
151
|
-
export const OBSERVER_SYSTEM_PROMPT = buildObserverSystemPrompt();
|
|
152
|
-
/**
|
|
153
|
-
* Format messages for Observer input
|
|
154
|
-
*/
|
|
155
|
-
export function formatMessagesForObserver(messages, options) {
|
|
156
|
-
const maxLen = options?.maxPartLength;
|
|
157
|
-
return messages
|
|
158
|
-
.map(msg => {
|
|
159
|
-
const timestamp = msg.createdAt
|
|
160
|
-
? new Date(msg.createdAt).toLocaleString("en-US", {
|
|
161
|
-
year: "numeric",
|
|
162
|
-
month: "short",
|
|
163
|
-
day: "numeric",
|
|
164
|
-
hour: "numeric",
|
|
165
|
-
minute: "2-digit",
|
|
166
|
-
hour12: true,
|
|
167
|
-
})
|
|
168
|
-
: "";
|
|
169
|
-
const role = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);
|
|
170
|
-
const timestampStr = timestamp ? ` (${timestamp})` : "";
|
|
171
|
-
let content = "";
|
|
172
|
-
if (typeof msg.content === "string") {
|
|
173
|
-
content = maybeTruncate(msg.content, maxLen);
|
|
174
|
-
}
|
|
175
|
-
else if (msg.content && typeof msg.content === "object") {
|
|
176
|
-
const contentObj = msg.content;
|
|
177
|
-
if (contentObj.parts && Array.isArray(contentObj.parts) && contentObj.parts.length > 0) {
|
|
178
|
-
content = contentObj.parts
|
|
179
|
-
.map(part => {
|
|
180
|
-
if (part.type === "text")
|
|
181
|
-
return maybeTruncate(part.text, maxLen);
|
|
182
|
-
if (part.type === "tool-call") {
|
|
183
|
-
return `[Tool Call: ${part.toolName}]\n${maybeTruncate(JSON.stringify(part.args, null, 2), maxLen)}`;
|
|
184
|
-
}
|
|
185
|
-
if (part.type === "tool-result") {
|
|
186
|
-
return `[Tool Result: ${part.toolName}]\n${maybeTruncate(JSON.stringify(part.result, null, 2), maxLen)}`;
|
|
187
|
-
}
|
|
188
|
-
return "";
|
|
189
|
-
})
|
|
190
|
-
.filter(Boolean)
|
|
191
|
-
.join("\n");
|
|
192
|
-
}
|
|
193
|
-
else if (contentObj.content) {
|
|
194
|
-
content = maybeTruncate(contentObj.content, maxLen);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return `**${role}${timestampStr}:**\n${content}`;
|
|
198
|
-
})
|
|
199
|
-
.join("\n\n---\n\n");
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Truncate string if needed
|
|
203
|
-
*/
|
|
204
|
-
function maybeTruncate(str, maxLen) {
|
|
205
|
-
if (!maxLen || str.length <= maxLen)
|
|
206
|
-
return str;
|
|
207
|
-
return `${str.slice(0, maxLen)}\n... [truncated ${str.length - maxLen} characters]`;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Build the Observer prompt
|
|
211
|
-
*/
|
|
212
|
-
export function buildObserverPrompt(existingObservations, messagesToObserve, options) {
|
|
213
|
-
const formattedMessages = formatMessagesForObserver(messagesToObserve);
|
|
214
|
-
let prompt = "";
|
|
215
|
-
if (existingObservations) {
|
|
216
|
-
prompt += `## Previous Observations\n\n${existingObservations}\n\n---\n\n`;
|
|
217
|
-
prompt += "Do not repeat these existing observations. Your new observations will be appended.\n\n";
|
|
218
|
-
}
|
|
219
|
-
prompt += `## New Message History to Observe\n\n${formattedMessages}\n\n---\n\n`;
|
|
220
|
-
prompt += `## Your Task\n\n`;
|
|
221
|
-
prompt += `Extract new observations from the message history above. Do not repeat observations already in previous observations.`;
|
|
222
|
-
if (options?.skipContinuationHints) {
|
|
223
|
-
prompt += `\n\nIMPORTANT: Do NOT include <current-task> or <suggested-response> sections. Only output <observations>.`;
|
|
224
|
-
}
|
|
225
|
-
return prompt;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Parse Observer output
|
|
229
|
-
*/
|
|
230
|
-
export function parseObserverOutput(output) {
|
|
231
|
-
// Check for degenerate repetition
|
|
232
|
-
if (detectDegenerateRepetition(output)) {
|
|
233
|
-
return {
|
|
234
|
-
observations: "",
|
|
235
|
-
rawOutput: output,
|
|
236
|
-
degenerate: true,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
const parsed = parseMemorySectionXml(output);
|
|
240
|
-
const observations = sanitizeObservationLines(parsed.observations || "");
|
|
241
|
-
return {
|
|
242
|
-
observations,
|
|
243
|
-
currentTask: parsed.currentTask || undefined,
|
|
244
|
-
suggestedContinuation: parsed.suggestedResponse || undefined,
|
|
245
|
-
rawOutput: output,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Parse XML tags from observer/reflector output
|
|
250
|
-
*/
|
|
251
|
-
function parseMemorySectionXml(content) {
|
|
252
|
-
const result = {
|
|
253
|
-
observations: "",
|
|
254
|
-
currentTask: "",
|
|
255
|
-
suggestedResponse: "",
|
|
256
|
-
};
|
|
257
|
-
// Extract <observations> content
|
|
258
|
-
const observationsRegex = /^[ \t]*<observations>([\s\S]*?)^[ \t]*<\/observations>/gim;
|
|
259
|
-
const observationsMatches = [...content.matchAll(observationsRegex)];
|
|
260
|
-
if (observationsMatches.length > 0) {
|
|
261
|
-
result.observations = observationsMatches
|
|
262
|
-
.map(m => m[1]?.trim() ?? "")
|
|
263
|
-
.filter(Boolean)
|
|
264
|
-
.join("\n");
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
result.observations = extractListItemsOnly(content);
|
|
268
|
-
}
|
|
269
|
-
// Extract <current-task> content
|
|
270
|
-
const currentTaskMatch = content.match(/^[ \t]*<current-task>([\s\S]*?)^[ \t]*<\/current-task>/im);
|
|
271
|
-
if (currentTaskMatch?.[1]) {
|
|
272
|
-
result.currentTask = currentTaskMatch[1].trim();
|
|
273
|
-
}
|
|
274
|
-
// Extract <suggested-response> content
|
|
275
|
-
const suggestedResponseMatch = content.match(/^[ \t]*<suggested-response>([\s\S]*?)^[ \t]*<\/suggested-response>/im);
|
|
276
|
-
if (suggestedResponseMatch?.[1]) {
|
|
277
|
-
result.suggestedResponse = suggestedResponseMatch[1].trim();
|
|
278
|
-
}
|
|
279
|
-
return result;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Extract only list items from content
|
|
283
|
-
*/
|
|
284
|
-
function extractListItemsOnly(content) {
|
|
285
|
-
const lines = content.split("\n");
|
|
286
|
-
const listLines = [];
|
|
287
|
-
for (const line of lines) {
|
|
288
|
-
if (/^\s*[-*]\s/.test(line) || /^\s*\d+\.\s/.test(line)) {
|
|
289
|
-
listLines.push(line);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return listLines.join("\n").trim();
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Maximum length for a single observation line
|
|
296
|
-
*/
|
|
297
|
-
const MAX_OBSERVATION_LINE_CHARS = 10_000;
|
|
298
|
-
/**
|
|
299
|
-
* Truncate observation lines that exceed max length
|
|
300
|
-
*/
|
|
301
|
-
export function sanitizeObservationLines(observations) {
|
|
302
|
-
if (!observations)
|
|
303
|
-
return observations;
|
|
304
|
-
const lines = observations.split("\n");
|
|
305
|
-
let changed = false;
|
|
306
|
-
for (let i = 0; i < lines.length; i++) {
|
|
307
|
-
if (lines[i].length > MAX_OBSERVATION_LINE_CHARS) {
|
|
308
|
-
lines[i] = lines[i].slice(0, MAX_OBSERVATION_LINE_CHARS) + " … [truncated]";
|
|
309
|
-
changed = true;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return changed ? lines.join("\n") : observations;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Detect degenerate repetition in output
|
|
316
|
-
*/
|
|
317
|
-
export function detectDegenerateRepetition(text) {
|
|
318
|
-
if (!text || text.length < 2000)
|
|
319
|
-
return false;
|
|
320
|
-
const windowSize = 200;
|
|
321
|
-
const step = Math.max(1, Math.floor(text.length / 50));
|
|
322
|
-
const seen = new Map();
|
|
323
|
-
let duplicateWindows = 0;
|
|
324
|
-
let totalWindows = 0;
|
|
325
|
-
for (let i = 0; i + windowSize <= text.length; i += step) {
|
|
326
|
-
const window = text.slice(i, i + windowSize);
|
|
327
|
-
totalWindows++;
|
|
328
|
-
const count = (seen.get(window) ?? 0) + 1;
|
|
329
|
-
seen.set(window, count);
|
|
330
|
-
if (count > 1)
|
|
331
|
-
duplicateWindows++;
|
|
332
|
-
}
|
|
333
|
-
if (totalWindows > 5 && duplicateWindows / totalWindows > 0.4) {
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
// Check for extremely long lines
|
|
337
|
-
const lines = text.split("\n");
|
|
338
|
-
for (const line of lines) {
|
|
339
|
-
if (line.length > 50_000)
|
|
340
|
-
return true;
|
|
341
|
-
}
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Optimize observations for token efficiency
|
|
346
|
-
*/
|
|
347
|
-
export function optimizeObservationsForContext(observations) {
|
|
348
|
-
let optimized = observations;
|
|
349
|
-
// Remove 🟡 and 🟢 emojis (keep 🔴)
|
|
350
|
-
optimized = optimized.replace(/🟡\s*/g, "");
|
|
351
|
-
optimized = optimized.replace(/🟢\s*/g, "");
|
|
352
|
-
// Remove semantic tags
|
|
353
|
-
optimized = optimized.replace(/\[(?![\d\s]*items collapsed)[^\]]+\]/g, "");
|
|
354
|
-
// Remove arrow indicators
|
|
355
|
-
optimized = optimized.replace(/\s*->\s*/g, " ");
|
|
356
|
-
// Clean up multiple spaces
|
|
357
|
-
optimized = optimized.replace(/ +/g, " ");
|
|
358
|
-
// Clean up multiple newlines
|
|
359
|
-
optimized = optimized.replace(/\n{3,}/g, "\n\n");
|
|
360
|
-
return optimized.trim();
|
|
361
|
-
}
|
|
362
|
-
//# sourceMappingURL=observer-agent.js.map
|