newtype-profile 1.0.13 → 1.0.16

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/cli/index.js CHANGED
@@ -2253,7 +2253,7 @@ var require_picocolors = __commonJS((exports, module) => {
2253
2253
  var require_package = __commonJS((exports, module) => {
2254
2254
  module.exports = {
2255
2255
  name: "newtype-profile",
2256
- version: "1.0.13",
2256
+ version: "1.0.16",
2257
2257
  description: "AI Agent Collaboration System for Content Creation - Based on oh-my-opencode",
2258
2258
  main: "dist/index.js",
2259
2259
  types: "dist/index.d.ts",
@@ -1,13 +1,16 @@
1
1
  /**
2
- * Confidence-based routing for fact-check results
2
+ * Confidence-based routing for agent outputs
3
3
  *
4
- * Parses confidence scores from fact-checker output and generates
4
+ * Parses confidence scores from agent outputs and generates
5
5
  * routing recommendations for the orchestrator.
6
6
  */
7
+ export type AgentType = "fact-checker" | "researcher" | "writer" | "editor";
8
+ export type Recommendation = "pass" | "polish" | "rewrite" | "escalate";
7
9
  export interface ConfidenceResult {
8
10
  confidence: number | null;
9
- recommendation: "pass" | "polish" | "rewrite" | null;
11
+ recommendation: Recommendation | null;
10
12
  directive: string | null;
13
+ agentType?: AgentType;
11
14
  }
12
15
  /**
13
16
  * Extract confidence score from fact-checker output
@@ -18,15 +21,44 @@ export declare function extractConfidence(output: string): number | null;
18
21
  * Determine routing recommendation based on confidence score
19
22
  */
20
23
  export declare function getRecommendation(confidence: number): "pass" | "polish" | "rewrite";
24
+ /**
25
+ * Get current rewrite attempt count for a session and agent type
26
+ */
27
+ export declare function getRewriteAttempts(sessionId: string, agentType: AgentType): number;
28
+ /**
29
+ * Increment and return the new rewrite attempt count for a session and agent type
30
+ */
31
+ export declare function incrementRewriteAttempts(sessionId: string, agentType: AgentType): number;
32
+ /**
33
+ * Clear rewrite attempts for a session (call on session cleanup)
34
+ */
35
+ export declare function clearRewriteAttempts(sessionId: string): void;
21
36
  /**
22
37
  * Build routing directive for Chief based on confidence
23
38
  */
24
- export declare function buildConfidenceDirective(confidence: number, sessionId: string): string;
39
+ export declare function buildConfidenceDirective(confidence: number, sessionId: string, agentType?: AgentType): string;
40
+ /**
41
+ * Build escalate directive when max rewrite attempts exceeded
42
+ */
43
+ export declare function buildEscalateDirective(confidence: number, attempts: number): string;
25
44
  /**
26
45
  * Analyze fact-check output and generate routing result
46
+ * Tracks rewrite attempts and escalates after MAX_REWRITE_ATTEMPTS
27
47
  */
28
48
  export declare function analyzeFactCheckOutput(output: string, sessionId: string): ConfidenceResult;
49
+ /**
50
+ * Generic analyzer for any agent type with confidence scoring
51
+ */
52
+ export declare function analyzeAgentOutput(output: string, sessionId: string, agentType: AgentType): ConfidenceResult;
29
53
  /**
30
54
  * Check if output is from a fact-check task
31
55
  */
32
56
  export declare function isFactCheckOutput(output: string): boolean;
57
+ /**
58
+ * Detect agent type from output content
59
+ */
60
+ export declare function detectAgentType(output: string, category?: string): AgentType | null;
61
+ /**
62
+ * Check if output contains a confidence score
63
+ */
64
+ export declare function hasConfidenceScore(output: string): boolean;
package/dist/index.js CHANGED
@@ -22894,6 +22894,8 @@ function clearTrackerForSession(sessionId) {
22894
22894
  }
22895
22895
 
22896
22896
  // src/hooks/chief-orchestrator/confidence-router.ts
22897
+ var MAX_REWRITE_ATTEMPTS = 2;
22898
+ var rewriteAttempts = new Map;
22897
22899
  function extractConfidence(output) {
22898
22900
  const match = output.match(/\*\*CONFIDENCE:\s*(\d+\.?\d*)\*\*/i);
22899
22901
  if (match) {
@@ -22913,55 +22915,229 @@ function getRecommendation(confidence) {
22913
22915
  return "rewrite";
22914
22916
  }
22915
22917
  }
22916
- function buildConfidenceDirective(confidence, sessionId) {
22918
+ function incrementRewriteAttempts(sessionId, agentType) {
22919
+ let sessionMap = rewriteAttempts.get(sessionId);
22920
+ if (!sessionMap) {
22921
+ sessionMap = new Map;
22922
+ rewriteAttempts.set(sessionId, sessionMap);
22923
+ }
22924
+ const current = sessionMap.get(agentType) ?? 0;
22925
+ const next = current + 1;
22926
+ sessionMap.set(agentType, next);
22927
+ return next;
22928
+ }
22929
+ function clearRewriteAttempts(sessionId) {
22930
+ rewriteAttempts.delete(sessionId);
22931
+ }
22932
+ function buildConfidenceDirective(confidence, sessionId, agentType = "fact-checker") {
22917
22933
  const recommendation = getRecommendation(confidence);
22918
22934
  const confidencePercent = Math.round(confidence * 100);
22935
+ const agentLabels = {
22936
+ "fact-checker": "FACT-CHECK",
22937
+ researcher: "RESEARCH",
22938
+ writer: "DRAFT",
22939
+ editor: "EDIT"
22940
+ };
22941
+ const label = agentLabels[agentType];
22919
22942
  switch (recommendation) {
22920
22943
  case "pass":
22921
- return `[FACT-CHECK PASSED]
22944
+ return `[${label} PASSED]
22922
22945
  Confidence: ${confidencePercent}% (HIGH)
22923
- Action: Content verified. Ready for delivery.`;
22946
+ Action: ${getPassAction(agentType)}`;
22924
22947
  case "polish":
22925
- return `[FACT-CHECK: NEEDS POLISH]
22948
+ return `[${label}: NEEDS POLISH]
22926
22949
  Confidence: ${confidencePercent}% (MEDIUM)
22927
- Action: Send to Editor for refinement.
22950
+ Action: ${getPolishAction(agentType)}
22928
22951
 
22929
22952
  REQUIRED: Call chief_task with:
22930
- category="editing"
22931
- prompt="Polish the content based on fact-check feedback. Address minor uncertainties while preserving verified claims."
22953
+ category="${getPolishCategory(agentType)}"
22954
+ prompt="${getPolishPrompt(agentType)}"
22932
22955
  resume="${sessionId}"`;
22933
22956
  case "rewrite":
22934
- return `[FACT-CHECK: NEEDS REWRITE]
22957
+ return `[${label}: NEEDS REWRITE]
22935
22958
  Confidence: ${confidencePercent}% (LOW)
22936
- Action: Significant issues found. Send back to Writer.
22959
+ Action: ${getRewriteAction(agentType)}
22937
22960
 
22938
22961
  REQUIRED: Call chief_task with:
22939
- category="writing"
22940
- prompt="Rewrite the content addressing the fact-check issues. Focus on: [list specific issues from fact-check report]"
22941
- resume="${sessionId}"
22942
-
22943
- NOTE: Max 2 rewrite attempts. If still failing after 2 rewrites, escalate to user.`;
22962
+ category="${getRewriteCategory(agentType)}"
22963
+ prompt="${getRewritePrompt(agentType)}"
22964
+ resume="${sessionId}"`;
22944
22965
  }
22945
22966
  }
22946
- function analyzeFactCheckOutput(output, sessionId) {
22967
+ function getPassAction(agentType) {
22968
+ switch (agentType) {
22969
+ case "fact-checker":
22970
+ return "Content verified. Ready for delivery.";
22971
+ case "researcher":
22972
+ return "Research complete. Proceed to writing.";
22973
+ case "writer":
22974
+ return "Draft complete. Send to editor.";
22975
+ case "editor":
22976
+ return "Edit complete. Send to fact-check.";
22977
+ }
22978
+ }
22979
+ function getPolishAction(agentType) {
22980
+ switch (agentType) {
22981
+ case "fact-checker":
22982
+ return "Send to Editor for refinement.";
22983
+ case "researcher":
22984
+ return "Needs additional research on specific gaps.";
22985
+ case "writer":
22986
+ return "Draft needs improvement before editing.";
22987
+ case "editor":
22988
+ return "Needs another editing pass.";
22989
+ }
22990
+ }
22991
+ function getPolishCategory(agentType) {
22992
+ switch (agentType) {
22993
+ case "fact-checker":
22994
+ return "editing";
22995
+ case "researcher":
22996
+ return "research";
22997
+ case "writer":
22998
+ return "writing";
22999
+ case "editor":
23000
+ return "editing";
23001
+ }
23002
+ }
23003
+ function getPolishPrompt(agentType) {
23004
+ switch (agentType) {
23005
+ case "fact-checker":
23006
+ return "Polish the content based on fact-check feedback. Address minor uncertainties while preserving verified claims.";
23007
+ case "researcher":
23008
+ return "Continue research on the identified gaps. Focus on: [list specific gaps from research report]";
23009
+ case "writer":
23010
+ return "Improve the draft addressing the identified issues. Focus on: [list specific issues]";
23011
+ case "editor":
23012
+ return "Continue editing to address remaining issues. Focus on: [list specific issues]";
23013
+ }
23014
+ }
23015
+ function getRewriteAction(agentType) {
23016
+ switch (agentType) {
23017
+ case "fact-checker":
23018
+ return "Significant issues found. Send back to Writer.";
23019
+ case "researcher":
23020
+ return "Research insufficient. Restart with different approach.";
23021
+ case "writer":
23022
+ return "Draft has fundamental issues. Needs major revision.";
23023
+ case "editor":
23024
+ return "Content not ready for editing. Send back to Writer.";
23025
+ }
23026
+ }
23027
+ function getRewriteCategory(agentType) {
23028
+ switch (agentType) {
23029
+ case "fact-checker":
23030
+ return "writing";
23031
+ case "researcher":
23032
+ return "research";
23033
+ case "writer":
23034
+ return "writing";
23035
+ case "editor":
23036
+ return "writing";
23037
+ }
23038
+ }
23039
+ function getRewritePrompt(agentType) {
23040
+ switch (agentType) {
23041
+ case "fact-checker":
23042
+ return "Rewrite the content addressing the fact-check issues. Focus on: [list specific issues from fact-check report]";
23043
+ case "researcher":
23044
+ return "Restart research with a different approach. Previous attempt was insufficient because: [list reasons]";
23045
+ case "writer":
23046
+ return "Rewrite the draft addressing fundamental issues. Focus on: [list specific issues]";
23047
+ case "editor":
23048
+ return "Content needs rewriting before editing. Issues: [list specific issues]";
23049
+ }
23050
+ }
23051
+ function buildEscalateDirective(confidence, attempts) {
23052
+ const confidencePercent = Math.round(confidence * 100);
23053
+ return `[FACT-CHECK: ESCALATE TO USER]
23054
+ Confidence: ${confidencePercent}% (LOW)
23055
+ Rewrite attempts: ${attempts}/${MAX_REWRITE_ATTEMPTS} (LIMIT REACHED)
23056
+
23057
+ \u26A0\uFE0F AUTOMATIC REWRITING HAS FAILED.
23058
+
23059
+ The content has been rewritten ${attempts} times but still fails fact-check.
23060
+ This requires human judgment.
23061
+
23062
+ ACTION REQUIRED:
23063
+ 1. Present the fact-check issues to the user
23064
+ 2. Ask for guidance on how to proceed
23065
+ 3. Do NOT attempt another automatic rewrite
23066
+
23067
+ Possible user decisions:
23068
+ - Provide additional sources or context
23069
+ - Accept lower confidence for this content
23070
+ - Manually revise the problematic claims
23071
+ - Abandon this content direction`;
23072
+ }
23073
+ function analyzeAgentOutput(output, sessionId, agentType) {
22947
23074
  const confidence = extractConfidence(output);
22948
23075
  if (confidence === null) {
22949
23076
  return {
22950
23077
  confidence: null,
22951
23078
  recommendation: null,
22952
- directive: null
23079
+ directive: null,
23080
+ agentType
22953
23081
  };
22954
23082
  }
22955
- const recommendation = getRecommendation(confidence);
22956
- const directive = buildConfidenceDirective(confidence, sessionId);
23083
+ const baseRecommendation = getRecommendation(confidence);
23084
+ if (baseRecommendation === "rewrite") {
23085
+ const attempts = incrementRewriteAttempts(sessionId, agentType);
23086
+ if (attempts > MAX_REWRITE_ATTEMPTS) {
23087
+ return {
23088
+ confidence,
23089
+ recommendation: "escalate",
23090
+ directive: buildEscalateDirective(confidence, attempts),
23091
+ agentType
23092
+ };
23093
+ }
23094
+ const directive2 = buildConfidenceDirective(confidence, sessionId, agentType) + `
23095
+
23096
+ Rewrite attempt: ${attempts}/${MAX_REWRITE_ATTEMPTS}`;
23097
+ return {
23098
+ confidence,
23099
+ recommendation: "rewrite",
23100
+ directive: directive2,
23101
+ agentType
23102
+ };
23103
+ }
23104
+ const directive = buildConfidenceDirective(confidence, sessionId, agentType);
22957
23105
  return {
22958
23106
  confidence,
22959
- recommendation,
22960
- directive
22961
- };
23107
+ recommendation: baseRecommendation,
23108
+ directive,
23109
+ agentType
23110
+ };
23111
+ }
23112
+ function detectAgentType(output, category) {
23113
+ if (category) {
23114
+ const categoryToAgent = {
23115
+ "fact-check": "fact-checker",
23116
+ research: "researcher",
23117
+ writing: "writer",
23118
+ editing: "editor"
23119
+ };
23120
+ if (categoryToAgent[category]) {
23121
+ return categoryToAgent[category];
23122
+ }
23123
+ }
23124
+ const lowerOutput = output.toLowerCase();
23125
+ if (lowerOutput.includes("fact-check") || lowerOutput.includes("verification") || output.includes("\u6838\u67E5")) {
23126
+ return "fact-checker";
23127
+ }
23128
+ if (lowerOutput.includes("research") || lowerOutput.includes("findings") || lowerOutput.includes("sources found")) {
23129
+ return "researcher";
23130
+ }
23131
+ if (lowerOutput.includes("edited") || lowerOutput.includes("polished") || lowerOutput.includes("revised")) {
23132
+ return "editor";
23133
+ }
23134
+ if (lowerOutput.includes("draft") || lowerOutput.includes("wrote") || lowerOutput.includes("created content")) {
23135
+ return "writer";
23136
+ }
23137
+ return null;
22962
23138
  }
22963
- function isFactCheckOutput(output) {
22964
- return output.includes("CONFIDENCE:") || output.toLowerCase().includes("fact-check") || output.includes("\u6838\u67E5") || output.includes("verification");
23139
+ function hasConfidenceScore(output) {
23140
+ return extractConfidence(output) !== null;
22965
23141
  }
22966
23142
 
22967
23143
  // src/hooks/chief-orchestrator/index.ts
@@ -23401,6 +23577,7 @@ function createChiefOrchestratorHook(ctx, options) {
23401
23577
  if (sessionInfo?.id) {
23402
23578
  sessions.delete(sessionInfo.id);
23403
23579
  clearTrackerForSession(sessionInfo.id);
23580
+ clearRewriteAttempts(sessionInfo.id);
23404
23581
  log(`[${HOOK_NAME6}] Session deleted: cleaned up`, { sessionID: sessionInfo.id });
23405
23582
  }
23406
23583
  return;
@@ -23537,19 +23714,23 @@ ${buildOrchestratorReminder(boulderState.plan_name, progress, subagentSessionId)
23537
23714
  const summarized = summarizeOutput(output.output, { category });
23538
23715
  const formattedSummary = formatSummarizedOutput(summarized);
23539
23716
  let confidenceDirective = "";
23540
- if (isFactCheckOutput(output.output)) {
23541
- const confidenceResult = analyzeFactCheckOutput(output.output, subagentSessionId);
23542
- if (confidenceResult.directive) {
23543
- confidenceDirective = `
23717
+ if (hasConfidenceScore(output.output)) {
23718
+ const agentType = detectAgentType(output.output, category);
23719
+ if (agentType) {
23720
+ const confidenceResult = analyzeAgentOutput(output.output, subagentSessionId, agentType);
23721
+ if (confidenceResult.directive) {
23722
+ confidenceDirective = `
23544
23723
 
23545
23724
  ---
23546
23725
  ${confidenceResult.directive}
23547
23726
  ---`;
23548
- log(`[${HOOK_NAME6}] Confidence routing detected`, {
23549
- sessionID: input.sessionID,
23550
- confidence: confidenceResult.confidence,
23551
- recommendation: confidenceResult.recommendation
23552
- });
23727
+ log(`[${HOOK_NAME6}] Confidence routing detected`, {
23728
+ sessionID: input.sessionID,
23729
+ agentType,
23730
+ confidence: confidenceResult.confidence,
23731
+ recommendation: confidenceResult.recommendation
23732
+ });
23733
+ }
23553
23734
  }
23554
23735
  }
23555
23736
  output.output = `${formattedSummary}
@@ -49231,7 +49412,23 @@ Always structure your findings as:
49231
49412
  - Use web search aggressively
49232
49413
  - Follow promising leads with targeted follow-up searches
49233
49414
  - When a source looks valuable, extract key quotes with attribution
49234
- </Tool_Usage>`
49415
+ </Tool_Usage>
49416
+
49417
+ <Confidence_Score>
49418
+ ## Research Completeness Score (REQUIRED)
49419
+ After completing your research, you MUST end your response with a confidence score in this EXACT format:
49420
+
49421
+ ---
49422
+ **CONFIDENCE: X.XX**
49423
+
49424
+ Where X.XX is a number between 0.00 and 1.00:
49425
+ - 0.90-1.00: Comprehensive coverage, multiple authoritative sources, all angles explored
49426
+ - 0.70-0.89: Good coverage, reliable sources, but some gaps or limited perspectives
49427
+ - 0.50-0.69: Partial coverage, mixed source quality, significant gaps remain
49428
+ - 0.00-0.49: Limited findings, unreliable sources, or topic poorly understood
49429
+
49430
+ This score helps Chief decide if more research is needed before proceeding.
49431
+ </Confidence_Score>`
49235
49432
  };
49236
49433
  }
49237
49434
  var researcherAgent = createResearcherAgent();
@@ -49516,7 +49713,23 @@ You take research, source materials, and briefs, then produce structured, engagi
49516
49713
  - Done is better than perfect (that's editor's job)
49517
49714
  - Structure is your foundation \u2014 get that right first
49518
49715
  - When stuck, write badly first, then improve
49519
- </Mindset>`
49716
+ </Mindset>
49717
+
49718
+ <Confidence_Score>
49719
+ ## Draft Quality Score (REQUIRED)
49720
+ After completing your draft, you MUST end your response with a confidence score in this EXACT format:
49721
+
49722
+ ---
49723
+ **CONFIDENCE: X.XX**
49724
+
49725
+ Where X.XX is a number between 0.00 and 1.00:
49726
+ - 0.90-1.00: Complete draft, strong structure, well-grounded in sources, ready for editing
49727
+ - 0.70-0.89: Solid draft, minor gaps or rough sections, needs polish
49728
+ - 0.50-0.69: Partial draft, structural issues or missing sections, needs significant work
49729
+ - 0.00-0.49: Incomplete or problematic draft, fundamental issues with structure or content
49730
+
49731
+ This score helps Chief decide if the draft needs revision before sending to Editor.
49732
+ </Confidence_Score>`
49520
49733
  };
49521
49734
  }
49522
49735
  var writerAgent = createWriterAgent();
@@ -49585,7 +49798,23 @@ You take drafts and make them excellent. You improve clarity, strengthen logic,
49585
49798
  - Every word should earn its place
49586
49799
  - Clarity > cleverness
49587
49800
  - Your job is to make the writer look good
49588
- </Mindset>`
49801
+ </Mindset>
49802
+
49803
+ <Confidence_Score>
49804
+ ## Edit Quality Score (REQUIRED)
49805
+ After completing your edit, you MUST end your response with a confidence score in this EXACT format:
49806
+
49807
+ ---
49808
+ **CONFIDENCE: X.XX**
49809
+
49810
+ Where X.XX is a number between 0.00 and 1.00:
49811
+ - 0.90-1.00: Polished and ready for publication, no remaining issues
49812
+ - 0.70-0.89: Good quality, minor improvements possible but acceptable
49813
+ - 0.50-0.69: Needs another pass, structural or clarity issues remain
49814
+ - 0.00-0.49: Significant problems, requires substantial revision or rewrite
49815
+
49816
+ This score helps Chief decide if the content is ready for fact-check or needs more work.
49817
+ </Confidence_Score>`
49589
49818
  };
49590
49819
  }
49591
49820
  var editorAgent = createEditorAgent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newtype-profile",
3
- "version": "1.0.13",
3
+ "version": "1.0.16",
4
4
  "description": "AI Agent Collaboration System for Content Creation - Based on oh-my-opencode",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",