The opinion of the court was delivered by
Miller, C.J.:The defendant, Richard A. Smith, was charged in the district court of Geary County with delivery of cocaine, a felony, in violation of K.S.A. 65-4127a. The trial court dismissed the case, holding that this prosecution was barred by the terms of a plea agreement which the State and Smith had entered into in an earlier and unrelated case. The State appeals.
The State has briefed two issues. It contends that the trial court abused its discretion in ruling that this prosecution was barred by the terms of the plea agreement, and that the trial court erred in construing the plea agreement. Since we conclude that the trial court erred in its construction of the plea agreement, we reverse without reaching the abuse of discretion argument.
The facts are undisputed and we shall attempt to give them in chronological order. On April 16, 1987, a federal undercover agent bought a quarter gram of cocaine from a man he knew only as “Smitty.”- Later that month, he reported this activity to Roger Williams, a Junction City police narcotics investigator. Williams knew the defendant, Richard Allen Smith, but did not know him as “Smitty.” The defendant’s photograph appeared in “mug” books of the Junction City Police Department in April 1987, but the federal agent did not review the books, and did not make an identification of the person from whom he made the narcotics purchase until several months later.
The defendant entered into a plea agreement with the State on *284July 13, 1987, in a consolidated proceeding involving three earlier cases in which he was charged with theft by force, forgery, and theft. The plea agreement, signed by the defendant, his attorney, and an assistant Geary County Attorney, contains the following language which lies at the heart of this appeal: “The State agrees [not] to file any other charges against the defendant based upon information presently known or which should be known by the Geary County Attorney’s office.” (Emphasis supplied.) The plea agreement was approved by the trial court. Defendant’s pleas of guilty to all three charged crimes were accepted and sentence was imposed pursuant to the plea agreement.
Thereafter, on August 18, 1987, the federal agent, while reviewing the Junction City “mug” books in connection with another matter, came across defendant’s photograph and identified him as the “Smitty” from whom he had purchased cocaine in April. This prosecution was commenced on September 8, 1987, based upon information furnished by the federal agent, and the identification made by him on August 18. It is undisputed that at the time the plea agreement was entered into, the Geary County Attorney’s Office had no actual knowledge of defendant’s alleged sale of cocaine in April. The issue then is whether, at the time it entered into the plea agreement, the county attorney’s office should have known of the facts upon which this prosecution is based.
Several rules which govern the interpretation of written contracts are relevant here. The interpretation of a written contract which is unambiguous is a judicial function. Wood River Pipeline Co. v. Willbros Energy Services Co., 241 Kan. 580, 582, 738 P.2d 866 (1987). In that same case, we noted that the intent of the parties and the meaning of a contract are to be determined from the plain, general, and common meaning of terms used. Also, in City of Arkansas City v. Anderson, 242 Kan. 875, Syl. ¶ 1, 752 P.2d 673 (1988), in Willbros, 241 Kan. at 586, and in Patrons Mut. Ins. Ass’n v. Harmon, 240 Kan. 707, Syl. ¶ 1, 732 P.2d 741 (1987), we stated and followed the familiar rule that, regardless of the construction given a written contract by the trial court, an appellate court may construe a written contract and determine its legal effect. See Kennedy & Mitchell, Inc. v. Anadarko Prod. Co., 243 Kan. 130, Syl. ¶ 1, 754 P.2d 803 (1988).
*285Is contract law helpful and properly applied in construing a plea agreement which was entered into in a criminal proceeding? We think so. Our research discloses that this proposition has widespread support. In United States v. Ocanas, 628 F.2d 353, 358 (5th Cir. 1980), cert, denied 451 U.S. 984 (1981), the court concluded that while principles of contract law cannot be blindly incorporated into the area of plea bargaining, they provide a useful analytical framework. In United States v. Calabrese, 645 F.2d 1379, 1390 (10th Cir. 1981), the court said: “Courts have frequently looked to contract law . analogies in determining the rights of defendants aggrieved in the plea negotiation process. See Coopere. United States, 594 F.2d 12, 15-16 (4th Cir. 1979); Westen & Westin, A Constitutional Law of Remedies for Broken Plea Bargains, 66 Cal. L. Rev. 471, 530 (1978).” Similarly, in Cooper v. United States, 594 F.2d at 16, the court commented: “To the extent . . . that there has evolved any general body of ‘plea bargain law,’ it is heavily freighted with . . . contract law analogies.”
Finally, in Note, The Standard of Proof Necessary to Establish that a Defendant Has Materially Breached a Plea Agreement, 55 Fordham L. Rev. 1059, 1065-67 (1987), the author states:
“Although a plea bargain is essentially a contract, it is a peculiar creature of contract law. The exchange that effectuates the agreement is the defendant’s guilty plea and its attendant waiver of constitutional rights. Acceptance of the guilty plea by the court validates the agreement and the waiver. A defendant who plea bargains thus has a due process interest in assuring that the state will not arbitrarily deny him the fulfillment of that agreement. Although contract law provides a framework for legal analysis of plea bargain disputes, it is an imperfect analogy.
“[P]lea agreements are essentially contracts to which contract law may be applied, and . . . the due process clause is the source of the defendant’s constitutional rights implied in plea agreements.”
A question somewhat similar to the one we have before us was considered by the Oregon Court of Appeals in State v. Hamming, 19 Or. App. 265, 527 P.2d 137 (1974), affd 271 Or. 749, 534 P.2d 501 (1975). The Oregon Court of Appeals was considering the rule that a prosecution is prohibited by the bar on double jeopardy if the prosecutor knew or reasonably should have known of facts relevant to the second charge at the time of the original prosecution. The court held that “should have *286known” means only that a reasonably diligent prosecutor would have acquired actual knowledge of the additional crime. The court went on to hold that there was no basis for concluding that greater diligence on the part of the prosecution would have brought additional evidence to light at the time defendant entered his plea to the crime first charged, theft of firearms. Most of the witnesses to the murder had promptly fled from the jurisdiction; only later, after defendant’s theft plea, did the police locate and interview two of the witnesses, whose testimony indicated for the first time that defendant participated in the homicide, the crime with which he was subsequently charged. The Oregon Court of Appeals agreed with the trial court’s holding that the prosecution neither knew nor should have known, at the time defendant pled guilty to the theft charge, that he had previously participated in the murder. The firearm that Hammang was convicted of stealing in the first case was used, on the day it was stolen, to commit the homicide charged in the second case. Although the prosecution was aware of several facts connecting Hammang to the chain of events leading up to the homicide, the court concluded that the prosecution neither knew nor should have known that Hammang was involved in the homicide when the plea to the firearms charge was entered.
In a later case, State v. Knowles, 289 Or. 813, 618 P.2d 1245 (1980), an Oregon State Police Officer came upon the defendant in possession of both an elk and a deer. The officer issued defendant a uniform citation for possession of the elk, but did not cite him for possession of the deer, a more serious offense, since he wished to consult with his superior officer before charging possession of a deer. The defendant appeared promptly in court and pled guilty to the elk offense. Approximately a month later, the officer swore out a felony complaint charging possession of the deer. On defendant’s motion, the latter charge was dismissed by the trial court. On appeal, the Oregon Supreme Court held that there was no evidence that the district attorney had actual knowledge of the various offenses when defendant entered his plea to the elk charge, nor was there evidence that the prosecutor “reasonably” knew of the offense concerning the deer at the time of the elk prosecution. The decision of the lower court was reversed and the case remanded for further proceedings. See State v. Anthony, 68 Or. App. 718, 683 P.2d 559 (1984).
*287A slightly different problem faced the Texas Court of Criminal Appeals in Joiner v. State, 578 S.W.2d 739 (Tex. Crim. 1979). There, Joiner had pled guilty to a charge of possession of heroin on July 3, 1976. The plea agreement in that case provided the prosecutor would drop all charges then “pending” against the accused. Some three months later, an undercover agent who had been working undercover in the county filed two charges against Joiner for delivery of heroin in May 1976. Joiner contended on appeal that the plea bargain was meant to cover offenses about which the prosecutor should have known, even though they were not officially filed, and that it was his understanding that the plea agreement would clear him of all such offenses. The Court of Criminal Appeals held that the evidence does not compel such a conclusion, and thus (in the absence of actual knowledge by the prosecutor of the earlier offense) the action of the trial court in overruling Joiner’s motion was not error.
In the case now before us, the defendant filed a motion to dismiss after arraignment, alleging that the prosecution was barred by the terms of the prior plea agreement. The trial court was required to determine, upon the basis of the record before it, whether the prosecutor knew or should have known of the facts upon which this prosecution is based at the time the plea agreement was entered into. The trial judge opined, “If a crime was committed, you [the prosecutor] should know who did it, and it should be known by you if somebody commits a crime.” The judge thereupon held that the language of the plea agreement was so broad as to include the crime charged in this case. He sustained the defendant’s motion and dismissed the case. We disagree.
The State, by its plea agreement with Smith, specifically limited its promise of no prosecution to charges based upon information known or which should be known by the prosecutor at the time of the plea agreement. The State did not promise that it would not prosecute any and all prior crimes of the defendant, known or unknown.
It is undisputed that neither the Geary County Attorney nor any state, city, or county employee had knowledge of the alleged sale of cocaine at t¿e time the plea agreement was entered into on July 13, 1987. The facts were known only to a federal undercover agent, an army investigator. Whether he would later be *288able to identify the person from whom the purchase was allegedly made, whether he could or would furnish sufficient information to the state prosecutor to justify prosecution, and whether the agent would be available to appear and testify were questions which no state agent or employee could have answered when the plea agreement was entered into. True, the federal agent could have inspected the “mug” books earlier, and perhaps could have made an identification at an earlier date, but he did not. He was not under the direction and control of the Geary County Attorney’s Office or any state agency. As in Hammang, there is no evidence that greater diligence on the part of the county attorney’s office would have brought the prior crime to light. A county attorney is not reasonably required to know everything that all federal agents, working in his or her county, have learned. We hold that the terms of the plea agreement simply do not encompass knowledge of this offense under the facts of this case.
It is a familiar rule that when the finding of fact of a trial court is attacked on appeal for insufficiency of evidentiary support, we search the record for any substantial competent evidence which supports the finding. We have done so in this case and we find that there was no evidence before the trial court to support a finding that the county attorney or his staff knew or should have known of the crime charged here.
The judgment of the trial court is reversed and the case is remanded for further proceedings.