Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions src/powercontext/server/dashboard/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,37 +257,45 @@ async def load_prompts(api: DashboardAPI, request: Request, ctx: dict[str, Any])
"experience.generate",
"skill.generate",
"handoff.generate",
"topic_memory.probe",
"topic_memory.global",
"topic_memory.planner",
"topic_memory.evolve",
"topic_memory.temporary",
"topic_memory.reduce",
"topic_memory.reconcile",
"profile.generate",
)
for value in await api.prompt_configurations(ctx["scope"], keys):
if isinstance(value, ReadError):
ctx["errors"].setdefault("prompts", value)
else:
ctx["data"]["prompts"].append(value)
selected_key = request.query_params.get("prompt_key")
if selected_key:
configuration = next((item for item in ctx["data"]["prompts"] if item["prompt_key"] == selected_key), None)
artifact = None if configuration is None else configuration.get("artifact")
if artifact and str(artifact.get("revision", "")).isdigit():
selected = request.query_params.get("prompt_revision") or str(artifact["revision"])
if str(selected).isdigit():
ctx["prompt_key"] = selected_key
try:
ctx["prompt_opened"] = await api.artifact_revision(
ctx["scope"], "prompt", selected_key, int(selected)
)
except ReadError as error:
# Showing the current configuration here would mislabel it as the requested revision.
ctx["errors"]["prompt_selected"] = error
return
ctx["history"] = await load_history(
api,
request,
ctx,
family="prompt",
artifact_id=selected_key,
selected=int(selected),
cursor_key="prompt_revision_cursor",
)
if not selected_key:
return
ctx["prompt_key"] = selected_key
configuration = next((item for item in ctx["data"]["prompts"] if item["prompt_key"] == selected_key), None)
artifact = None if configuration is None else configuration.get("artifact")
raw_revision = request.query_params.get("prompt_revision")
if raw_revision is None and artifact is None:
return
try:
selected = positive_revision(raw_revision if raw_revision is not None else str(artifact["revision"]))
ctx["prompt_opened"] = await api.artifact_revision(ctx["scope"], "prompt", selected_key, selected)
except ReadError as error:
# Never substitute current content for an unavailable or invalid historical revision.
ctx["errors"]["prompt_selected"] = error
return
ctx["history"] = await load_history(
api,
request,
ctx,
family="prompt",
artifact_id=selected_key,
selected=selected,
cursor_key="prompt_revision_cursor",
)


async def load_note_history(api: DashboardAPI, request: Request, ctx: dict[str, Any], *, snapshot=None) -> None:
Expand Down
41 changes: 40 additions & 1 deletion src/powercontext/server/dashboard/labels.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@
"experience.generate": "Experience generation",
"skill.generate": "Skill generation",
"handoff.generate": "Handoff generation",
"topic_memory.probe": "Topic Memory probing",
"topic_memory.global": "Topic Memory global generation",
"topic_memory.planner": "Topic Memory planning",
"topic_memory.evolve": "Topic Memory evolution",
"topic_memory.temporary": "Temporary Topic Memory generation",
"topic_memory.reduce": "Topic Memory reduction",
"topic_memory.reconcile": "Topic Memory reconciliation",
"profile.generate": "Profile generation",
"usage_resources": "Token usage",
"usage_unknown": "Not recorded",
"work_followup": "Acknowledgement and subsequent outcomes",
Expand Down Expand Up @@ -650,5 +658,36 @@
"observability": "Cloud-native monitoring",
"nav_plugins": "Plugins",
"plugin": "Plugin",
"plugin_page_stopped": "The plugin page navigated away from its start page, so requests are no longer forwarded for it. Reopen the page to continue."
"plugin_page_stopped": "The plugin page navigated away from its start page, so requests are no longer forwarded for it. Reopen the page to continue.",
"prompt_search": "Search name or identifier",
"prompt_source": "Configuration source",
"prompt_source_all": "All",
"prompt_builtin_default": "Built-in default",
"prompt_no_match": "No matching prompt configurations.",
"prompt_topic_conditional": "Stages run conditionally based on input size and processing results; not every request runs every stage.",
"prompt_group_memory": "Memory",
"prompt_group_topics": "Topic Memory",
"prompt_group_experience": "Experience",
"prompt_group_skill": "Skill",
"prompt_group_handoff": "Handoff",
"prompt_group_profile": "Profile",
"prompt_reason_operation_disabled": "This operation is disabled in the current runtime.",
"prompt_reason_provider_not_configured": "The required model provider is not configured.",
"prompt_reason_injected_component": "This operation is managed by an injected component.",
"atomic_memory.extract_purpose": "Extract lasting memories from sources",
"atomic_memory.reconcile_purpose": "Reconcile new and existing memories",
"memory.rerank_purpose": "Rank recalled memories by relevance",
"experience.incubate_purpose": "Discover reusable experience candidates",
"experience.generate_purpose": "Generate experience proposals for review",
"skill.generate_purpose": "Generate reusable procedures for review",
"handoff.generate_purpose": "Capture current work and next actions",
"profile.generate_purpose": "Update lasting facts and preferences",
"topic_memory.probe_purpose": "Find topic candidates worth retaining",
"topic_memory.global_purpose": "Generate or update topics from sources",
"topic_memory.planner_purpose": "Plan topic tasks for complex inputs",
"topic_memory.evolve_purpose": "Update the complete content of a topic",
"topic_memory.temporary_purpose": "Summarize sources exceeding input limits",
"topic_memory.reduce_purpose": "Reduce intermediate results while preserving evidence",
"topic_memory.reconcile_purpose": "Reconcile proposed content with existing topics",
"prompt_revision_unavailable": "Selected revision unavailable"
}
41 changes: 40 additions & 1 deletion src/powercontext/server/dashboard/labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@
"experience.generate": "经验生成",
"skill.generate": "技能生成",
"handoff.generate": "交接生成",
"topic_memory.probe": "主题记忆探测",
"topic_memory.global": "主题记忆全局生成",
"topic_memory.planner": "主题记忆规划",
"topic_memory.evolve": "主题记忆演化",
"topic_memory.temporary": "临时主题记忆生成",
"topic_memory.reduce": "主题记忆归并",
"topic_memory.reconcile": "主题记忆协调",
"profile.generate": "画像生成",
"usage_resources": "Token用量",
"usage_unknown": "未记录",
"work_followup": "接收与后续结果",
Expand Down Expand Up @@ -650,5 +658,36 @@
"observability": "云原生监控",
"nav_plugins": "插件",
"plugin": "插件",
"plugin_page_stopped": "插件页面已离开起始页,已停止为它转发请求。重新打开页面后继续使用。"
"plugin_page_stopped": "插件页面已离开起始页,已停止为它转发请求。重新打开页面后继续使用。",
"prompt_search": "搜索名称或标识符",
"prompt_source": "配置来源",
"prompt_source_all": "全部",
"prompt_builtin_default": "内置默认",
"prompt_no_match": "没有匹配的提示词配置。",
"prompt_topic_conditional": "系统根据资料量和处理结果选择所需步骤,并非每次请求都会运行所有阶段。",
"prompt_group_memory": "记忆",
"prompt_group_topics": "主题记忆",
"prompt_group_experience": "经验",
"prompt_group_skill": "技能",
"prompt_group_handoff": "交接",
"prompt_group_profile": "画像",
"prompt_reason_operation_disabled": "当前运行时未启用此操作。",
"prompt_reason_provider_not_configured": "尚未配置所需的模型提供方。",
"prompt_reason_injected_component": "此操作由外部组件管理。",
"atomic_memory.extract_purpose": "从资料中提取值得保存的记忆",
"atomic_memory.reconcile_purpose": "协调新记忆与已有记忆",
"memory.rerank_purpose": "按相关性排序检索结果",
"experience.incubate_purpose": "发现值得提炼的经验线索",
"experience.generate_purpose": "生成可审核的经验内容",
"skill.generate_purpose": "生成可审核的操作流程",
"handoff.generate_purpose": "整理当前工作状态与下一步",
"profile.generate_purpose": "更新长期事实与偏好画像",
"topic_memory.probe_purpose": "找出值得保存的主题线索",
"topic_memory.global_purpose": "综合资料生成或更新主题",
"topic_memory.planner_purpose": "将复杂输入拆成主题任务",
"topic_memory.evolve_purpose": "更新一个主题的完整内容",
"topic_memory.temporary_purpose": "处理超出输入限制的资料",
"topic_memory.reduce_purpose": "压缩中间结果并保留证据",
"topic_memory.reconcile_purpose": "协调新增内容与已有主题",
"prompt_revision_unavailable": "所选版本不可用"
}
16 changes: 10 additions & 6 deletions src/powercontext/server/dashboard/revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from powercontext.builtin.artifacts.skill.models import SkillContent
from powercontext.builtin.artifacts.skill.package import SkillPackageError, comparable_skill_content
from powercontext.server.dashboard.api import DashboardAPI, ReadError, segment
from powercontext.server.dashboard.navigation import positive_revision
from powercontext.server.dashboard.pagination import PAGE_SIZE

ROLLBACK_FAMILIES = frozenset({"profile", "prompt", "experience", "skill", "handoff", "topic-memory"})
Expand Down Expand Up @@ -177,7 +178,13 @@ async def load_history(

scope = ctx["scope"]
query = request.query_params
compare = _revision_param(query.get("compare"))
invalid_compare = False
try:
compare = _revision_param(query.get("compare"))
except ReadError:
# A malformed comparison must not discard the selected revision or its history.
compare = None
invalid_compare = True
try:
if api.builtin is not None:
result = await api.revision_history(
Expand Down Expand Up @@ -210,7 +217,7 @@ async def load_history(
head_revision = result["head"]
left, right = values.get(selected), values.get(compare)
rows = None
compare_error = compare is not None and (left is None or right is None)
compare_error = invalid_compare or (compare is not None and (left is None or right is None))
if compare is not None and compare != selected and not compare_error:
rows = comparison(family, left["content"], right["content"])
head = values.get(head_revision)
Expand Down Expand Up @@ -264,10 +271,7 @@ async def _public_history(api, request, scope, family, artifact_id, selected, cu


def _revision_param(value: str | None) -> int | None:
if value is None or not value.isdigit() or value.startswith("0"):
return None
number = int(value)
return number if number >= 1 else None
return None if value is None else positive_revision(value)


async def _can_replace(request: Request, api: DashboardAPI, scope: str, family: str, artifact_id: str) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
no_results: (data, escape) => `<div class="no-results">${escape(component.dataset.noResults)}</div>`,
},
});
component.closest('#workspace').addEventListener('htmx:beforeSwap', event => {
if (event.detail.shouldSwap && event.detail.target.contains(component)) {
// Do not restore the outgoing picker's focus into the new workspace.
picker.blur();
}
}, {signal: controller.signal});
component.on('htmx:beforeCleanupElement', event => {
if (event.detail.elt === component) { controller.abort(); picker.destroy(); }
});
Expand Down
58 changes: 54 additions & 4 deletions src/powercontext/server/dashboard/templates/prompts.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,59 @@
{{ page_heading(t.prompts,t.prompts_subtitle) }}
{% if errors.get('prompts') %}{{ read_error(errors.prompts,t.prompts) }}{% endif %}
{% if not data.prompts and not errors.get('prompts') %}<div class="quiet-empty"><h2>{{ t.prompt_empty }}</h2><p>{{ t.prompt_empty_body }}</p></div>{% endif %}
<div class="record-list">{% for prompt in data.prompts %}{% set opened = prompt_opened if prompt_opened and prompt.prompt_key == prompt_key else none %}{% set mode = opened.content.mode if opened else prompt.mode %}
<article><details class="supporting-details prompt-record" {% if prompt.prompt_key == prompt_key %}open{% endif %}><summary><span class="record-row-title">{{ t.get(prompt.prompt_key,prompt.prompt_key) }}</span><span class="badge bg-secondary-lt ms-2">{{ t.get('prompt_state_' ~ prompt.status,prompt.status) }}</span><span class="text-secondary small ms-2">{{ t.prompt_mode }}: {{ t.prompt_custom if mode == 'custom' else t.prompt_auto }}</span></summary>
<div class="prompt-browser">
<style>
me .prompt-overview { display: inline-grid; grid-template-columns: minmax(10rem, 1fr) minmax(12rem, 2fr) auto; gap: 1rem; width: calc(100% - 1rem); align-items: baseline; }
@media (max-width: 767px) { me .prompt-overview { grid-template-columns: 1fr; gap: .25rem; } }
</style>
<div class="row g-3 mb-3">
<div class="col-md-8"><label class="form-label" for="prompt-search">{{ t.prompt_search }}</label><input id="prompt-search" type="search" class="form-control" autocomplete="off"></div>
<div class="col-md-4"><label class="form-label" for="prompt-source">{{ t.prompt_source }}</label><select id="prompt-source" class="form-select"><option value="">{{ t.prompt_source_all }}</option><option value="auto">{{ t.prompt_builtin_default }}</option><option value="custom">{{ t.prompt_custom }}</option></select></div>
</div>
{% set groups = [
('memory', ['atomic_memory.extract', 'atomic_memory.reconcile', 'memory.rerank']),
('topics', ['topic_memory.probe', 'topic_memory.global', 'topic_memory.planner', 'topic_memory.evolve', 'topic_memory.temporary', 'topic_memory.reduce', 'topic_memory.reconcile']),
('experience', ['experience.incubate', 'experience.generate']),
('skill', ['skill.generate']), ('handoff', ['handoff.generate']), ('profile', ['profile.generate'])
] %}
{% for group, keys in groups %}{% set prompts = data.prompts|selectattr('prompt_key', 'in', keys)|list %}
{% if prompts %}<details class="supporting-details prompt-group mb-3" {% if prompt_key in keys %}open{% endif %}>
<summary><strong>{{ t['prompt_group_' ~ group] }}</strong><span class="badge bg-secondary-lt ms-2" data-prompt-count>{{ prompts|length }}</span></summary>
{% if group == 'topics' %}<p class="text-secondary mt-3">{{ t.prompt_topic_conditional }}</p>{% endif %}
<div class="record-list">{% for prompt in prompts %}{% set opened = prompt_opened if prompt_opened and prompt.prompt_key == prompt_key else none %}{% set failed = prompt.prompt_key == prompt_key and errors.get('prompt_selected') %}{% set mode = none if failed else (opened.content.mode if opened else prompt.mode) %}
<article data-prompt-search="{{ (t.get(prompt.prompt_key,prompt.prompt_key) ~ ' ' ~ prompt.prompt_key)|lower }}" data-prompt-source="{{ mode }}"><details class="supporting-details prompt-record" {% if prompt.prompt_key == prompt_key %}open{% endif %}><summary><span class="prompt-overview"><span class="record-row-title">{{ t.get(prompt.prompt_key,prompt.prompt_key) }}</span><span class="text-secondary small">{{ t[prompt.prompt_key ~ '_purpose'] }}</span><span class="text-secondary small">{{ t.prompt_revision_unavailable if failed else (t.prompt_custom if mode == 'custom' else t.prompt_builtin_default) }}</span></span></summary>
<p class="text-secondary mt-3">{{ t.prompt_status }}: {{ t.get('prompt_state_' ~ prompt.status,t.get('prompt_' ~ prompt.status,prompt.status)) }}{% if prompt.reason %} — {{ t['prompt_reason_' ~ prompt.reason] }}{% endif %}</p>
{% if not failed %}<p class="small">{{ t.prompt_mode }}: {{ t.prompt_custom if mode == 'custom' else t.prompt_auto }}</p>
<div class="document-meta mb-3"><code>{{ prompt.prompt_key }}</code> · {{ t.prompt_revision }} {{ opened.revision if opened else (prompt.artifact.revision if prompt.artifact else t.prompt_auto) }} · {{ t.prompt_demonstrations }} {{ opened.content.demonstrations|length if opened else (prompt.effective.demonstrations|length if prompt.effective else 0) }}</div>
{% if prompt.prompt_key == prompt_key and errors.get('prompt_selected') %}{{ read_error(errors.prompt_selected,t.prompt_revision) }}{% else %}<h2 class="section-title">{{ t.prompt_instructions if opened or prompt.effective else t.prompt_builtin_template }}</h2><pre class="page-body-pre text-break">{{ opened.content.instructions if opened else (prompt.effective.instructions if prompt.effective else (prompt.builtin.instructions if prompt.builtin else '')) }}</pre>{% endif %}
<h2 class="section-title">{{ t.prompt_instructions if opened or prompt.effective else t.prompt_builtin_template }}</h2><pre class="page-body-pre text-break">{{ opened.content.instructions if opened else (prompt.effective.instructions if prompt.effective else (prompt.builtin.instructions if prompt.builtin else '')) }}</pre>
{% if prompt.artifact %}<a href="{{ link('prompts',prompt_key=prompt.prompt_key,prompt_revision=prompt.artifact.revision) }}">{{ t.revision_history }} →</a>{% endif %}
</details></article>{% endfor %}</div>{% include 'components/revision-history.html' %}
{% set demonstrations = opened.content.demonstrations if opened else (prompt.effective.demonstrations if prompt.effective else []) %}
{% if demonstrations %}<h2 class="section-title">{{ t.prompt_demonstrations }}</h2><pre class="page-body-pre text-break">{{ demonstrations|tojson(indent=2) }}</pre>{% endif %}
Comment on lines +47 to +48

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Do not fall back to current demonstrations when a historical revision fails to load

I reproduced this by creating memory.rerank revisions 1 and 2 with different demonstrations, then opening /dashboard/prompts?scope=<scope>&prompt_key=memory.rerank&prompt_revision=99. The page reports that the requested revision could not be loaded, but still renders revision 2’s demonstrations below the error. When prompt_opened is absent, this new block falls back to prompt.effective.demonstrations, outside the prompt_selected error guard used for the instructions. This mixes current content into a failed historical view. Please apply the same error guard to the demonstrations and cover this case with non-empty examples.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed independently at a647dce through the HTTP routes backed by SQLite: revision 1 shows only the old demonstration, while revision 99 shows the current revision 2 demonstration despite the load failure. The added historical-revision tests use empty demonstrations, so they do not catch this regression. This finding remains unresolved.

{% else %}<code>{{ prompt.prompt_key }}</code>{{ read_error(errors.prompt_selected,t.prompt_revision) }}{% endif %}
</details></article>{% endfor %}</div></details>{% endif %}{% endfor %}
<p class="text-secondary" data-prompt-empty hidden role="status">{{ t.prompt_no_match }}</p>
<script>
me().run(browser => {
const search = browser.querySelector('#prompt-search');
const source = browser.querySelector('#prompt-source');
function filter() {
const query = search.value.trim().toLowerCase();
let total = 0;
for (const group of browser.querySelectorAll('.prompt-group')) {
let count = 0;
for (const row of group.querySelectorAll('[data-prompt-search]')) {
row.hidden = !row.dataset.promptSearch.includes(query) || (source.value && row.dataset.promptSource !== source.value);
if (!row.hidden) count++;
}
group.hidden = count === 0;
group.querySelector('[data-prompt-count]').textContent = count;
if (query || source.value) group.open = count > 0;
total += count;
}
browser.querySelector('[data-prompt-empty]').hidden = total > 0;
}
search.addEventListener('input', filter);
source.addEventListener('change', filter);
});
</script>
</div>{% include 'components/revision-history.html' %}
Loading
Loading